It would be nice to have pre and post import hooks in the same way that there are pre and post export hooks on sf_user and sf_node.

I made a patch for this. I've tested everything except the sf_node pre import.

Comments

aaronbauman’s picture

Status: Active » Needs review

I should have time to review this this week or early next.

aaronbauman’s picture

StatusFileSize
new7.51 KB

OK, this makes good sense.

We should use the foreach(module_implements()) pattern instead of module_invoke_all() so that we can pass arguments by reference, in case implementations need to make last-minute changes.

Also, in the attached patch:

  • Moved pre_import hooks to after the import object creation loop
  • Added $changes array to values passed to salesforce_api_pre_import
  • Added documentation for _import hooks
  • Updated pre_export hooks to use module_implements()
  • Switched hooks to pass fieldmap names instead of full objects

Let me know.

kostajh’s picture

Status: Needs review » Needs work

I did not test this, but read through the code and it looks good. Thanks for your work on this. I don't understand why $name is passed twice in the post_import hook?

+++ hooks.php	2 Feb 2011 22:06:44 -0000
@@ -211,7 +211,41 @@ function hook_salesforce_api_pre_export(
+function hook_salesforce_api_post_import($object, $name, $sf_data, $name, $create) {

$name is passed twice.

Powered by Dreditor.

+++ sf_user/sf_user.module	2 Feb 2011 22:06:44 -0000
@@ -518,6 +527,7 @@ function sf_user_import($sf_data, $name,
+  module_invoke_all('salesforce_api_post_import', $account, $name, $sf_data, $name, $create);

$name is passed twice again.

Powered by Dreditor.

kostajh’s picture

Status: Needs work » Needs review
kostajh’s picture

Just another comment to say that after a day of testing and working with the hooks provided by this patch, I've been able to get past a number of issues that have been affecting the site I'm working on. The hooks are extremely useful in mitigating weaknesses / bugs elsewhere in the Salesforce suite code, so I support getting this into dev sooner rather than later.

aaronbauman’s picture

StatusFileSize
new7.89 KB

I agree that this should get in ASAP, especially in light of the discussion on #1058870: user_save fails in sf_user_import().

Here is an updated patch to address Kosta's points in comment #3 -- should be passing $changes at the last parameter, not $name twice.

This is my first git patch, so please be gentle.
I'll let this marinate over the weekend, and then it's going into dev.

kostajh’s picture

Looks great. Thanks Aaron!

aaronbauman’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

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

aaronbauman’s picture

Sborsody’s picture

Status: Closed (fixed) » Needs review
StatusFileSize
new476 bytes

The duplicate variable for hook_salesforce_api_pre_import() still appears in hooks.php. I was getting "Missing argument 5" errors when implementing the hook. Here's the patch.

kostajh’s picture

Version: 6.x-2.x-dev » 7.x-2.x-dev
Status: Needs review » Patch (to be ported)
EvanDonovan’s picture

Version: 7.x-2.x-dev » 6.x-2.x-dev
Status: Patch (to be ported) » Fixed

Wasn't applicable to 7.x, because in that branch, there is no separate user_import, and thus no changes parameter. If people need to track changes between the old and new versions of a user, that will have to be a separate feature request in 7.x.

Status: Fixed » Closed (fixed)

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