I am working on a patch to bring sf_webform up to speed with the latest dev release of salesforce_api

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

AaronBauman’s picture

Status: Active » Needs review
FileSize
18.98 KB

This patch is meant to bring sf_webform into working order, not to address all critical issues (though some non-critical issues are addressed).
I have tried to document as best i could in the patch and in this ticket.
There are some TODOs in the patch, and there probably a lot more issues that I have just not had time to address.
However, this brings a simple sf_webform integration into working order for the latest dev version of salesforce_api.
I will try to enter tickets for some of the remaining issues as I found them.

In this patch:

  • node/%/webform becomes a local task -- TODO: add access callback so that it only shows up for webform mappings
  • replaced array notation with object notation as applicable
  • replaced autoincrement-id based fieldmap references with name references where necessary
  • moved auth vs. anon check/validation to fire during the form load, so that users are presented with only valid options (@see sf_webform_associate_webform_node())

In case you are unable to update your salesforce_api module, here are the two patches to salesforce_api module that made this possible. To be clear, the following two patches have been committed to salesforce dev:

--- salesforce_api.module	3 Nov 2010 15:49:27 -0000	1.2.2.51
+++ salesforce_api.module	11 Nov 2010 22:07:02 -0000	1.2.2.52
@@ -1174,6 +1174,13 @@ function salesforce_api_salesforce_field
   if (isset($result[$name])) {
     return $result[$name];
   }
+  // For backwards compatibility, search on fieldmap (numeric id)
+  $result = ctools_export_load_object('salesforce_field_map', 'conditions', array('fieldmap' => $name));
+  if (!empty($result)) {
+    // "fieldmap" is always unique - if nonempty, this will always contain a
+    // direct hit.
+    return current($result);
+  }
 }
 
 function salesforce_api_salesforce_field_map_load_by ($conditions) {

and

--- salesforce_api.admin.inc	8 Jun 2010 21:08:11 -0000	1.2.2.34
+++ salesforce_api.admin.inc	11 Nov 2010 22:11:47 -0000
@@ -304,10 +304,10 @@ function salesforce_api_fieldmap_add_for
  */
 function salesforce_api_fieldmap_add_form_submit($form, &$form_state) {
   // Create the new fieldmap.
-  $index = salesforce_api_fieldmap_create($form_state['values']);
-
+  $map = salesforce_api_fieldmap_create($form_state['values']);
+  $form_state['values']['fieldmap'] = $map;
   // Redirect to its edit form.
-  $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS .'/'. $index .'/edit';
+  $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS .'/'. $map->name .'/edit';
 }
 
 /**
@@ -327,7 +327,7 @@ function salesforce_api_fieldmap_create(
   // Save the new fieldmap.
   salesforce_api_fieldmap_save($map);
 
-  return $map->name;
+  return $map;
 }
 
 /**
AaronBauman’s picture

Category: task » bug

changing this to a bug since sf_webform simply doesn't work with salesforce alpha or dev

AaronBauman’s picture

After some additional dogfooding, here is a patch for the latest version of sf_webform that we're using.

This patch supercedes the one above, and includes all the improvements therein but also:

  • Access settings were still broken. Trying to change webform settings for a fieldmap would sometimes delete the fieldmap.
    Updated relevant database operations in sf_webform.module and created a hook_update_n() in sf_webform.install function to deal with moving from numeric indexes to machine names.
  • Compatibility with code-based fieldmaps was not implemented (specifically in sf_webform_associate_webform_node())
  • Removed sf_webform_process_webform() and addressed #969324: sf_webform should use export/import handlers to populate the export/import object, adding functions sf_webform_export_component_default(), sf_webform_export_component_select(), sf_webform_export_component_uid(), and sf_webform_export_component_sfid()
  • Added support for mapping keys OR labels for "select" webform components, instead of just keys.
  • Updated sf_webform_export() to always use the submission object, instead of the form_state values. In this way, other modules that intercept processing and make changes to the submission object can see their changes reflected in the Salesforce export, whether or not they mess with the form_state array.
  • Removed some lingering instances of well-meaning but unnecessary calls to preg_match(). strpos() is sufficient.

There are definitely still issues, some of which may be compatibility problems, and some of which merit their own issues nodes.
However, before basic compatibility with Salesforce Suite is implemented, it is too inefficient for me to separate my contrib patches into independent issues.

Anyway, besides a small flurry of commits 2 months ago from stella, the inactivity in this queue leads me to believe I'm talking into a vacuum.
Regardless, I will continue to post new patches for what has become a forked version of this module.

WillHall’s picture

Both patches fail for me against the latest(lol...) dev - would you mind packaging up your version for comparison?

WillHall’s picture

Let me correct that - If I first use your patch from the other topic - the first patch above works great - however this second patch fails completely for me. And This "Added support for mapping keys OR labels for "select" webform components, instead of just keys. " Is very critical for me because we can't tell which webform value is being passed to prematch.

EvanDonovan’s picture

@aaronbauman: Posting the new version as a tar.gz in here might be the best idea for now...

AaronBauman’s picture

FileSize
14.84 KB

No problem, here's the latest version I'm using.

I think this matches the patch above ftmp, and hopefully not too much of my own debugging cruft.

joeybaker’s picture

@aaronbauman I for one, am very grateful. Thank you!

joeybaker’s picture

FileSize
16.24 KB

I spent some time working on this today, and I think I've got this module back in working order with the latest release of the salesforce module.

Diff:


85,86c85
< 
<     if ($map->fields && preg_match('/^node_webform_(\d+)$/', $map->drupal, $matches)) {
---
>     if (!empty($map['fields']) && preg_match('/^node_webform_(\d+)$/', $map['drupal'], $matches)) {
98c97
<         '#value' => t('This fieldmap is associated with webform node %title (nid %nid) - !link', array("%title" => $webform_node->title, "%nid" => $webform_node->nid, '!link' => l("edit", SALESFORCE_PATH_FIELDMAPS ."/".  $map->fieldmap ."/webform", $options = array("query" => "edit=1&destination=". SALESFORCE_PATH_FIELDMAPS ."/". $map->fieldmap ."/edit"))))
---
>         '#value' => t('This fieldmap is associated with webform node %title (nid %nid) - !link', array("%title" => $webform_node->title, "%nid" => $webform_node->nid, '!link' => l("edit", SALESFORCE_PATH_FIELDMAPS ."/".  $map['fieldmap'] ."/webform", $options = array("query" => "edit=1&destination=". SALESFORCE_PATH_FIELDMAPS ."/". $map['fieldmap'] ."/edit"))))
210c209
<     if ($access && $exported && !$salesforce_submission->sfid) {
---
>     if ($access && $exported && empty($salesforce_submission['sfid'])) {
218,219c217,218
<       if (!$salesforce_submission->sfid && $salesforce_submission->sfid == 0) $submissions[$submission->sid] = '';
<       if (!$show_all && $salesforce_submission->sfid) continue;
---
>       if (empty($salesforce_submission['sfid']) && $salesforce_submission['sfid'] == 0) $submissions[$submission->sid] = '';
>       if (!$show_all && $salesforce_submission['sfid']) continue;
305,306c304,305
< 		
<       if ($access && $exported && !$salesforce_submission->sfid) {
---
> 
>       if ($access && $exported && empty($salesforce_submission['sfid'])) {
314,315c313,314
<         if (!$salesforce_submission->sfid && $salesforce_submission->sfid == 0) $submissions[$submission->sid] = '';
<         if ($salesforce_submission->sfid) continue;
---
>         if (empty($salesforce_submission['sfid']) && $salesforce_submission['sfid'] == 0) $submissions[$submission->sid] = '';
>         if ($salesforce_submission['sfid']) continue;
616c615
<   $map->fields = array();
---
>   $map['fields'] = array();
620c619
<   _sf_webform_set_webform_index($form_state['values']['webform_nid'], $map->fieldmap, $form_state['values']['login_status']);
---
>   _sf_webform_set_webform_index($form_state['values']['webform_nid'], $map['fieldmap'], $form_state['values']['login_status']);
622c621
<   $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS .'/'. $map->fieldmap .'/edit';
---
>   $form_state['redirect'] = SALESFORCE_PATH_FIELDMAPS .'/'. $map['fieldmap'] .'/edit';
698c697
<     if ($uid_key = array_search(SALESFORCE_WEBFORM_FIELD_UID, $map->fields)) {
---
>     if ($uid_key = array_search(SALESFORCE_WEBFORM_FIELD_UID, $map['fields'])) {
703c702
<     if ($sfid_key = array_search(SALESFORCE_WEBFORM_FIELD_SFID, $map->fields)) {
---
>     if ($sfid_key = array_search(SALESFORCE_WEBFORM_FIELD_SFID, $map['fields'])) {
714c713
<     if ($uid_key = array_search(SALESFORCE_WEBFORM_FIELD_UID, $map->fields)) {
---
>     if ($uid_key = array_search(SALESFORCE_WEBFORM_FIELD_UID, $map['fields'])) {
719c718
<     if ($sfid_key = array_search(SALESFORCE_WEBFORM_FIELD_SFID, $map->fields)) {
---
>     if ($sfid_key = array_search(SALESFORCE_WEBFORM_FIELD_SFID, $map['fields'])) {
738c737
<       $response = $sf->client->create(array($object), $map->salesforce);
---
>       $response = $sf->client->create(array($object), $map['salesforce']);
742c741
<       watchdog(SALESFORCE_LOG_SOME, 'Could not export webform submission with: %error.', array("%error" => $e->faultstring), WATCHDOG_ERROR);
---
>       $sf->watchdog(SALESFORCE_LOG_SOME, 'Could not export webform submission with: %error.', array("%error" => $e->faultstring), WATCHDOG_ERROR);
753c752
<     $response = $sf->client->update(array($object), $map->salesforce);
---
>     $response = $sf->client->update(array($object), $map['salesforce']);
869c868
<   foreach ($fieldmap->fields as $component => $form_key)  {
---
>   foreach ($fieldmap['fields'] as $component => $form_key)  {
1029c1028
<         if ($salesforce_submission->sfid) continue;
---
>         if ($salesforce_submission['sfid']) continue;
Scott M. Sanders’s picture

Issue tags: +API

Subscribing

EvanDonovan’s picture

@stella/openbook:

Do either of you have the time to look at this patch and commit?

If not, would you be open to having a co-maintainer who could proceed with this, either in the same 6.x branch or in a 6.x-2.x branch?

AaronBauman’s picture

See also
#790690: Move Salesforce Webform Integration into project/salesforce; deprecate project/sf_webform
and #1101632: Include webform support

Evan,
sf_webform has not been compatible with salesforce module -- its primary dependency along with webform -- for the better part of a year.
If you or another maintainer has time to roll webform support into the suite, that's probably the best approach.

EvanDonovan’s picture

@aaronbauman: I would be strongly opposed to adding it to the core suite. I think the suite should only contain the bare minimum of modules needed to connect with Salesforce, make fieldmaps, queueing, etc. I would actually argue that it should be smaller than it is.

If the maintainers aren't responding to this issue, then I would rather go through the Abandoned Projects process, and get maintainership of this module.

EvanDonovan’s picture

For now, I've put the code from #9 into a sandbox: http://drupal.org/sandbox/evandonovan/1198324.

I plan on working with it some in the next few weeks, since Salesforce/Webform integration is a requirement for a current project I'm working on. Eventually, I would hope to deprecate the sandbox in favor of getting the code back into the main module.

dasmart’s picture

subscribing

EvanDonovan’s picture

@joeybaker: Does the module still work for you using the code that you posted? In my development site, it doesn't actually export to Salesforce, nor does the Salesforce Export tab indicate that there is data to be exported to Salesforce. I will have to look into this further.

jay_N’s picture

Evan, I'm very interested in this as I'm currently forced to use nodes for Salesforce-synched event bookings on one of my clients' sites. I'm not familiar with this code but am happy to have a look at the sandbox if it helps. Are you planning a second commit soon?

EvanDonovan’s picture

My sandbox version of this code should work again now, although I haven't tested everything yet, just the manual export. It was a beast to fix it for compatibility with the latest API of the Salesforce module for 6.x. Any testing is welcome. You can also use the issue queue there to report bugs, etc., and I'll make an update into this issue later.

For anyone else subscribing, the link again is http://drupal.org/sandbox/evandonovan/1198324. You will need to git clone in order to get the code - Drupal.org doesn't package sandboxes.

rjacobs’s picture

Subscribing. Also, just a note regarding the point about git clone being the only option on sandbox projects. I think you can still share a tar.gz via the "snapshot" links provided in the repository viewer, e.g.:

http://drupalcode.org/sandbox/evandonovan/1198324.git/snapshot/80da2fc4b...

rjacobs’s picture

Title: Current version of sf_webform is incompatible with latest version of salesforce_api » sf_webform Abandoned/Outdated? Alternative available as sandbox project

I just altered the title a bit to make it easier for new users to find the working version of this code. Unless you have not upgraded the Salesforce API or webform in over a year, this project's version simply will not work.

Please try the 6.x-1.x branch in the sandbox at: http://drupal.org/sandbox/evandonovan/1198324

Of course there is some debate about where this project should ultimately live, etc, but in the meantime I'm just hoping others who may now need this functionality in D6 can benefit from our recent attempts to support a working version elsewhere. In fact, I just committed a barrage of new updates to the sandbox project linked above in the last couple weeks (see the commit history for more). So I just wanted to point out that this code has seen some attention recently.

I too am happy to bring this repository up-to-date with what's in the sandbox (independent of the ongoing discussion about the final home for webform support, as a resolution to that may be some time coming). I am probably the one who has been working with this D6 code most recently and am happy to segment and push updates here that I have already applied to the sandbox, etc...