in salesforce_push.module

/**
 * Implements hook_cron().
 */
function salesforce_push_cron() {
  $sfapi = salesforce_get_api();
  if (!$sfapi->isAuthorized()) {
    return;
  }

  $queue = DrupalQueue::get(SALESFORCE_PUSH_QUEUE);
  $limit = variable_get('salesforce_pull_limit', 50);
  $use_soap = module_exists('salesforce_soap');
  for ($delta = 0; ($item = $queue->claimItem()) && $delta < $limit; $delta++) {
    $mapping = $item->data['mapping'];

    // duplicate entity in the queue
    if ($item->data['entity_type'] == $entity_type && $item->data['entity_id'] == $entity_id) {
      $queue->deleteItem($item);
      continue;
    }

in

 if ($item->data['entity_type'] == $entity_type && $item->data['entity_id'] == $entity_id)

$entity_type and $entity_id are not defined.

Comments

haza’s picture

Status: Active » Needs review
StatusFileSize
new1017 bytes

Those variables are defined just below in the code. Here is a patch that move them just above the check.

kostajh’s picture

Status: Needs review » Needs work

I see the problem that $entity_type and $entity_id are not defined, but with the patch in #1 that conditional check will always return true, right?

haza’s picture

Oh ! Yes, you're right. I think I was really lacking sleep last week.

So, we really need to check against what we need to check those values.

adanielyan’s picture

Is there any update on this issue?

kostajh’s picture

Assigned: Unassigned » levelos

@levelos can you take a look at this? Not sure what was intended here.

aaronbauman’s picture

Title: Check against undefined variables » Prevent duplicate object processing during cron, check against undefined variables
Issue summary: View changes
StatusFileSize
new1.44 KB

I believe the intention is to prevent duplicates during cron run.
The existing catch will only work if queue items are sorted sequentially by entity id.

A better mechanism is to explicitly track which entity ids have been processed.
See attached patch (which also solves issue of undefined variables)

aaronbauman’s picture

Status: Needs work » Needs review
tauno’s picture

Status: Needs review » Fixed

Applied manually and committed with comments in d98c272. Thanks!

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

  • Commit d98c272 on 7.x-3.x, process-deleted-refactor authored by aaronbauman, committed by tauno:
    Issue #1944138 by aaronbauman: Prevent duplicate object processing...

  • Commit d98c272 on 7.x-3.x, mapped-object-ui authored by aaronbauman, committed by tauno:
    Issue #1944138 by aaronbauman: Prevent duplicate object processing...
Deester4x4jr’s picture

This doesn't seem to have been fixed. I'm running 7.x-3.0+17-dev and I am still getting this issue on salesforce_push.

I downgraded to 7.x-3.0 prod, and still am seeing issues. Made a small change, and the issue is now gone:

    // Duplicate entity in the queue.
    /**     replaced $entity_id with $item->data['entity_id'], as $entity_id doesn't exist yet     **/
    if (in_array($item->data['entity_id'], $entity_ids[$item->data['entity_type']])) {
      $queue->deleteItem($item);
      continue;
    }
coatezy’s picture

I'm also experiencing this issue. Can this be reopened?