diff -u b/modules/salesforce_pull/salesforce_pull.module b/modules/salesforce_pull/salesforce_pull.module --- b/modules/salesforce_pull/salesforce_pull.module +++ b/modules/salesforce_pull/salesforce_pull.module @@ -183,6 +183,57 @@ } /** + * Determines whether record should be pulled from Salesforce. + * + * @param array $record + * A single Salesforce record as returned by SOQL pull query. + * + * @return bool + * FALSE if the record should not be pulled from Salesforce. + */ +function salesforce_pull_record_allowed($record) { + // Invoke a hook to allow other modules to prevent this record from being + // pulled. + foreach (module_implements('salesforce_pull_record_allowed') as $module) { + if (module_invoke($module, 'salesforce_pull_record_allowed', $record) === FALSE) { + return FALSE; + } + } + + return TRUE; +} + +/** + * Determines whether to allow processing of a mapped Drupal entity. + * + * Allows other modules to prevent processing and saving of a Drupal entity + * that is mapped to a Salesforce pull queue item. + * + * @param string $drupal_entity_type + * The entity type of the mapped Drupal entity. + * @param EntityMetadataWrapper $entity_wrapper + * Entity wrapper for the mapped Drupal entity. + * @param array $sf_object + * The pulled Salesforce record, as claimed from the pull queue. + * @param SalesforceMapping $sf_mapping + * Mapping object for this pull operation. + * + * @return bool + * FALSE if the queue item should be skipped, and the pull ignored. + */ +function salesforce_pull_entity_allowed($drupal_entity_type, $entity_wrapper, $sf_object, $sf_mapping) { + // Invoke a hook to allow other modules to stop processing of Salesforce + // record and prevent this entity from being saved in Drupal. + foreach (module_implements('salesforce_pull_entity_allowed') as $module) { + if (module_invoke($module, 'salesforce_pull_entity_allowed', $drupal_entity_type, $entity_wrapper, $sf_object, $sf_mapping) === FALSE) { + return FALSE; + } + } + + return TRUE; +} + +/** * Pull updated records from Salesforce and place them in the queue. * * Executes a SOQL query based on defined mappings, loops through the results, @@ -219,6 +270,10 @@ if (!isset($results['errorCode'])) { // Write items to the queue. foreach ($results['records'] as $result) { + // Skip items that are not allowed to be pulled. + if (!salesforce_pull_record_allowed($result)) { + continue; + } $queue->createItem($result); } @@ -231,6 +286,10 @@ if (!isset($new_result['errorCode'])) { // Write items to the queue. foreach ($new_result['records'] as $result) { + // Skip items that are not allowed to be pulled. + if (!salesforce_pull_record_allowed($result)) { + continue; + } $queue->createItem($result); } } @@ -267,13 +326,6 @@ if (!isset($results['errorCode'])) { // Write items to the queue. foreach ($results['records'] as $result) { - // Trigger a hook to allow other modules to prevent this - // entity/operation from triggering a sync with Drupal. - foreach (module_implements('salesforce_pull_record_allowed') as $module) { - if (module_invoke($module, 'salesforce_pull_record_allowed', $result) === FALSE) { - continue 2; - } - } $queue->createItem($result); } @@ -286,13 +338,6 @@ if (!isset($new_result['errorCode'])) { // Write items to the queue. foreach ($new_result['records'] as $result) { - // Trigger a hook to allow other modules to prevent this - // entity/operation from triggering a sync with Drupal. - foreach (module_implements('salesforce_pull_record_allowed') as $module) { - if (module_invoke($module, 'salesforce_pull_record_allowed', $result) === FALSE) { - continue 2; - } - } $queue->createItem($result); } } @@ -361,12 +406,9 @@ // Set fields values on the Drupal entity. salesforce_pull_map_fields($sf_mapping->field_mappings, $wrapper, $sf_object); - // Trigger a hook to allow other modules to prevent this entity from - // from being saved in Drupal. - foreach (module_implements('salesforce_pull_entity_allowed') as $module) { - if (module_invoke($module, 'salesforce_pull_entity_allowed', $sf_mapping->drupal_entity_type, $wrapper, $sf_object, $sf_mapping) === FALSE) { - continue 2; - } + // Allow other modules to prevent this entity from being saved. + if (!salesforce_pull_entity_allowed($sf_mapping->drupal_entity_type, $wrapper, $sf_object, $sf_mapping)) { + continue; } // Allow modules to react just prior to entity save. @@ -458,12 +500,9 @@ salesforce_pull_map_fields($sf_mapping->field_mappings, $wrapper, $sf_object); - // Trigger a hook to allow other modules to prevent this entity from - // from being saved in Drupal. - foreach (module_implements('salesforce_pull_entity_allowed') as $module) { - if (module_invoke($module, 'salesforce_pull_entity_allowed', $sf_mapping->drupal_entity_type, $wrapper, $sf_object, $sf_mapping) === FALSE) { - continue 2; - } + // Allow other modules to prevent this entity from being saved. + if (!salesforce_pull_entity_allowed($sf_mapping->drupal_entity_type, $wrapper, $sf_object, $sf_mapping)) { + continue; } // Allow modules to react just prior to entity save. diff -u b/salesforce.api.php b/salesforce.api.php --- b/salesforce.api.php +++ b/salesforce.api.php @@ -178,7 +178,7 @@ } /** - * Prevent a Salesforce object from being added to the pull queue. For example, + * Prevent a Salesforce object from being added to the pull queue. For example, * prevent pull of Contacts without email address. * * @param array $result @@ -202,7 +202,7 @@ * @param string $drupal_entity_type * The entity type of the existing or new mapped Drupal entity. * @param EntityMetadataWrapper $entity_wrapper - * Entity wrapper for the mapped Drupal entity. + * Entity wrapper for the mapped Drupal entity. * @param array $sf_object * The pulled Salesforce record, as claimed from the pull queue. * @param SalesforceMapping $sf_mapping