We need something similar to hook_salesforce_push_entity_allowed() but for objects being pulled in. Could be done before the mappings are processed or after but before the entity is saved. Even though there are some cases were having the mapped values would be useful (ex. if the mapping didn't return a valid entity reference, don't save it), it would probably make sense for efficiency to not even run the mappings for the object.

Comments

tauno’s picture

#1961760: Add required field to SOQL query for Salesforce Pull has the start to another possible approach - add a condition to the salesforce query.

kostajh’s picture

I'd prefer to have a hook. I think the approach in #1961760: Add required field to SOQL query for Salesforce Pull has some potential problems.

Might also consider looking at using Rules to configure which entities can be be processed on pull.

levelos’s picture

Assigned: tauno » bleedev
levelos’s picture

Assigned: bleedev » Unassigned

Tauno, bleedev and I were discussing that we could handle this through a hook_salesforce_soql_query_alter() call, which would increase performance and be useful in other cases. Chime in, and we can adjust this ticket accordingly.

bleedev’s picture

Levelos and I discussed re-working the method being used to get the updated records. Currently salesforce_pull:salesforce_pull_get_updated_records calls the salesforce_get_api()->query method, passing a string for the query. If that method is modified to use an object or array containing the query definition (fields and conditions, etc.), the method could use a hook_salesforce_soql_query_alter() to modify the query definition before it is constructed into a string and processed.

kostajh’s picture

That sounds like a good approach to me. Let me know when you have a patch and I'll take a look.

tauno’s picture

I think this approach would work for my use case just fine. Thinking more abstract, if a mapping applies to multiple objects the hook_salesforce_soql_query_alter will prevent it from being pulled for any of those mappings. At least, this is how I think the pull process works right now.

kostajh’s picture

Just noting that this approach should also work well with #1969034: Create admin interface for Salesforce Pull - it could allow a UI for adjusting the SOQL query.

tauno’s picture

Assigned: Unassigned » bleedev
levelos’s picture

Status: Active » Fixed

The structured SOQL query and a corresponding are now implemented. Ref. http://drupalcode.org/project/salesforce.git/commit/83578cbe00883ee2cc52... and subsequent commits.

Status: Fixed » Closed (fixed)

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

gcb’s picture

Assigned: bleedev » Unassigned
Issue summary: View changes
Status: Closed (fixed) » Needs review
StatusFileSize
new1.88 KB

I've discovered a use case in which altering the SF query is not adequate: we want to exclude, in this case, contacts with duplicate emails from coming over, so the object needs to be blocked based on a local DB query to Drupal, as we can hardly pass all our existing email addresses over to Salesforce. If only SF had a "email address is unique on salesforce" query option!

Patch attached.

aaronbauman’s picture

Status: Needs review » Needs work

Instead of

    $skip = FALSE;
    foreach (module_implements('salesforce_pull_allow_sf_object') as $module) {
      if (module_invoke($module, 'salesforce_pull_allow_sf_object', $sf_object, $mapping_object, $sf_mapping) === FALSE) {
        $skip = TRUE;
        continue;
      }
    }
    if ($skip) {
      continue;
    }

Do this:

    foreach (module_implements('salesforce_pull_allow_sf_object') as $module) {
      if (module_invoke($module, 'salesforce_pull_allow_sf_object', $sf_object, $mapping_object, $sf_mapping) === FALSE) {
        continue 2;
      }
    }
gcb’s picture

StatusFileSize
new1.8 KB

What is this "php" you speak of?

Re-rolled with suggested change.

aaronbauman’s picture

Status: Needs work » Reviewed & tested by the community

Looks good

tauno’s picture

Status: Reviewed & tested by the community » Needs work

Let's change this to hook_salesforce_pull_object_allowed($sf_object, $mapping_object, $mapping) to more closely align with hook_salesforce_push_entity_allowed($entity_type, $entity, $sf_sync_trigger, $mapping).

tauno’s picture

gcb’s picture

Those are some remarkably similar patches.

yogaf’s picture

gcb’s picture

StatusFileSize
new1.86 KB

Re-rolled against 7.x-3.2.

acrosman’s picture

Status: Needs work » Reviewed & tested by the community

The patch from #20 works nicely. Looking back over the issue the only reason this isn't in the suite was a concern about the hook's name. Given that this issue has been sitting around for a couple years and several folks have code written against it with the current name it seems like makes more sense to move forward as written instead of modifying it at this point. So I'm resetting to RTBC.

  • aaronbauman committed e8a5809 on 7.x-3.x authored by gcb
    Issue #1967258 by gcb: Add hook to stop an individual SF object from...
aaronbauman’s picture

Status: Reviewed & tested by the community » Fixed

This is in

Status: Fixed » Closed (fixed)

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

bob.hinrichs’s picture

The beta dev with this patch broke my site (dedupe field errors), so I am using 7-2.x. I was going to ask if it is possible to use hook_salesforce_pull_entity_presave for this in absence of this change, but now I see it won't stop the processing. It would be easy to backport to 7-2.x but am unsure whether a full 7-3.x will be the next full release. I may do that anyway as this is superior to workarounds.