Index: salesforce_api/salesforce_api.module =================================================================== --- salesforce_api/salesforce_api.module (revision 21) +++ salesforce_api/salesforce_api.module (working copy) @@ -34,6 +34,12 @@ define('SALESFORCE_LOG_SOME', 5); define('SALESFORCE_LOG_ALL', 10); +// Option values for fieldmap automatic synchronization settings. +// @see salesforce_api.admin.inc +define('SALESFORCE_AUTO_SYNC_OFF', 0); +define('SALESFORCE_AUTO_SYNC_ALL', 1); +define('SALESFORCE_AUTO_SYNC_CREATE', 2); +define('SALESFORCE_AUTO_SYNC_UPDATE', 3); /** * Implementation of hook_menu(). @@ -632,5 +636,8 @@ 'file' => 'salesforce_api.admin.inc', 'arguments' => array('form' => NULL), ), + 'salesforce_api_drupal_sfapi_automatic' => array( + 'arguments' => array('element' => NULL), + ), ); } Index: salesforce_api/salesforce_api.install =================================================================== --- salesforce_api/salesforce_api.install (revision 21) +++ salesforce_api/salesforce_api.install (working copy) @@ -101,11 +101,11 @@ 'default' => '', ), 'automatic' => array( - 'description' => 'Boolean indicating whether this action/map is automatic or triggered.', + 'description' => 'Indicates whether this action/map is automatic or triggered.', 'type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, - 'default' => 0, + 'default' => SALESFORCE_AUTO_SYNC_OFF, 'size' => 'tiny' ), 'fields' => array( Index: salesforce_api/salesforce_api.admin.inc =================================================================== --- salesforce_api/salesforce_api.admin.inc (revision 21) +++ salesforce_api/salesforce_api.admin.inc (working copy) @@ -285,11 +284,19 @@ } $form['drupal_sfapi_automatic'] = array( - '#type' => 'checkbox', - '#title' => t('Automatically Populate Salesforce?'), + '#type' => 'radios', + '#title' => t('Synchronize automatically with Salesforce'), + '#options' => array( + SALESFORCE_AUTO_SYNC_OFF => t('Never (Do not autopopulate)'), + SALESFORCE_AUTO_SYNC_ALL => t('On create and update'), + SALESFORCE_AUTO_SYNC_CREATE => t('On create only'), + SALESFORCE_AUTO_SYNC_UPDATE => t('On update only'), + // @see theme_salesforce_api_drupal_sfapi_automatic for option descriptions + ), '#return_value' => 1, '#default_value' => $map['automatic'], - '#description' => t('Automatically create and link new salesforce objects when Drupal objects are created?'), + '#theme' => 'salesforce_api_drupal_sfapi_automatic', + '#description' => 'Please indicate how Salesforce records should be handled when Drupal records are created or updated.' ); // Add the data to the form for the required fields table. @@ -426,6 +433,19 @@ return theme('table', $header, $rows, $attributes, $caption); } +// +function theme_salesforce_api_drupal_sfapi_automatic($element) { + $element[SALESFORCE_AUTO_SYNC_OFF]['#description'] = + t('Do not create or update Salesforce records automatically.'); + $element[SALESFORCE_AUTO_SYNC_ALL]['#description'] = + t('Create and link Salesforce records automatically when Drupal records are created and updated.'); + $element[SALESFORCE_AUTO_SYNC_CREATE]['#description'] = + t('Create and link Salesforce records automatically when Drupal records are created, but do not update them automatically.'); + $element[SALESFORCE_AUTO_SYNC_UPDATE]['#description'] = + t('Do not create and link Salesforce records automatically, but update Salesforce records if a link already exists.'); + return drupal_render($element); +} + /** * Demonstrates some of the API functionality through the Salesforce class and * fieldmap functionality. Index: sf_node/sf_node.module =================================================================== --- sf_node/sf_node.module (revision 21) +++ sf_node/sf_node.module (working copy) @@ -60,8 +60,9 @@ return; } - // Are there any automatic fieldmaps for this node type? - $result = db_query("SELECT fieldmap FROM {salesforce_field_map} WHERE drupal = '%s' AND automatic = 1", 'node_'. $node->type); + // Are there any automatic-synch-on-insert fieldmaps for this node type? + $result = db_query("SELECT fieldmap FROM {salesforce_field_map} WHERE drupal = '%s' AND automatic IN (%d, %d)", + 'node_'. $node->type, SALESFORCE_AUTO_SYNC_ALL, SALESFORCE_AUTO_SYNC_CREATE); $map = db_fetch_object($result); if (!$map) { return; @@ -85,7 +86,13 @@ } $salesforce = salesforce_api_id_load('node', $node->nid); if ($salesforce['fieldmap'] && $salesforce['sfid']) { - sf_node_export($node, $salesforce['fieldmap'], $salesforce['sfid']); + // check if we should auto-update Salesforce + $result = db_query("SELECT automatic FROM {salesforce_field_map} WHERE fieldmap = '%d'", $salesforce['fieldmap']); + $automatic_obj = db_fetch_object($result); + if ($automatic_obj->automatic == SALESFORCE_AUTO_SYNC_ALL + || $automatic_obj->automatic == SALESFORCE_AUTO_SYNC_UPDATE) { + sf_node_export($node, $salesforce['fieldmap'], $salesforce['sfid']); + } } break; }