You are here

function _sf_import_process_records in Salesforce Suite 6.2

Same name and namespace in other branches
  1. 7.2 sf_import/sf_import.module \_sf_import_process_records()

Processes items in the sf_import_queue table.

3 calls to _sf_import_process_records()
drush_sf_import_sf_get_updated in sf_import/sf_import.drush.inc
Calls SF Import Get Updated
sf_import_cron in sf_import/sf_import.module
Implements hook_cron().
sf_import_settings_form_submit in sf_import/sf_import.admin.inc
Submit handler for the settings page.

File

sf_import/sf_import.module, line 203

Code

function _sf_import_process_records() {

  // Process sf_import_queue items
  $fieldmaps = salesforce_api_salesforce_field_map_load_all();
  $records = array();
  $sql = "SELECT sfid, fieldmap FROM {sf_import_queue}";
  while ($sfids = db_fetch_object(db_query($sql))) {
    $fieldmap = $sfids->fieldmap;
    $type = $fieldmaps[$fieldmap]->drupal;

    // "node" mappings are like "node_contenttype".
    // others are like "user", "uc_order", etc.
    if (strpos($type, 'node_') === 0) {
      $type = 'node';
    }
    $function = 'sf_' . $type . '_import';
    $drupal_id = salesforce_api_get_id_with_sfid($sfids->sfid, $type);
    if (function_exists($function)) {
      $oid = $function($sfids->sfid, $sfids->fieldmap, $drupal_id);
      $records[] = array(
        $sfids->sfid,
        $oid,
        $sfids->fieldmap,
      );
    }
    db_query("DELETE FROM {sf_import_queue} WHERE sfid = '%s'", $sfids->sfid);
  }
  if (count($records) > 0) {
    variable_set('sf_import_queue_processed_count', count($records));
    return $records;
  }
  else {
    variable_set('sf_import_queue_processed_count', 0);
    return FALSE;
  }
}