You are here

function sf_queue_form_salesforce_api_settings_form_alter in Salesforce Suite 7.2

Same name and namespace in other branches
  1. 6.2 sf_queue/sf_queue.module \sf_queue_form_salesforce_api_settings_form_alter()

Implements hook_form_salesforce_api_settings_form_alter().

See also

salesforce_api/salesforce_api.admin.inc::salesforce_api_settings_form

File

sf_queue/sf_queue.module, line 457
sf_queue.module Implements export queue and administrativa for Salesforce API

Code

function sf_queue_form_salesforce_api_settings_form_alter(&$form, $form_state) {
  $enabled = variable_get('sf_queue_enabled', FALSE);
  $form['sf_queue'] = array(
    '#type' => 'fieldset',
    '#title' => t('Queue Settings'),
    '#collapsible' => TRUE,
    '#collapsed' => TRUE,
    '#weight' => -1,
  );
  if ($enabled) {
    $description = l('View the export queue', 'admin/reports/sf_queue');
  }
  else {
    $description = t('Salesforce Export Queue will attempt to optimize your Salesforce API usage by scheduling transactions for delayed processing, combining multiple object insert/updates, and backlogging failed transactions for re-processing. Enable the Export Queue to configure settings for these features.');
  }
  $form['sf_queue']['sf_queue_enabled'] = array(
    '#type' => 'checkbox',
    '#title' => t('Enable Salesforce Export Queue'),
    '#description' => $description,
    '#default_value' => $enabled,
  );
  if (!$enabled) {
    return;
  }
  $sf_queue_settings = variable_get('sf_queue_settings', _sf_queue_default_settings());
  $frequency = drupal_map_assoc(array(
    0,
    60,
    180,
    300,
    600,
    900,
    1800,
    2700,
    3600,
    10800,
    21600,
    32400,
    43200,
    86400,
  ), 'format_interval');
  $frequency[0] = t('Every cron run');
  $fieldmaps = salesforce_api_salesforce_fieldmap_load_all();
  $objects = array();
  foreach ($fieldmaps as $map) {
    $objects[$map->salesforce] = $map->salesforce;
  }
  $num_objects = drupal_map_assoc(array(
    5,
    10,
    15,
    30,
    50,
    75,
    100,
    125,
    150,
    175,
    200,
  ));
  $threshold = drupal_map_assoc(array(
    0,
    5,
    10,
    15,
    30,
    50,
    75,
    100,
    125,
    150,
    175,
    200,
  ));
  $threshold[0] = t('No minimum');
  $attempts = drupal_map_assoc(array(
    0,
    1,
    2,
    3,
    4,
    5,
    6,
    7,
    8,
    9,
    10,
    -1,
  ));
  $attempts[-1] = t('No limit');
  $period = array(
    '.05' => t('5% of cron run'),
    '.1' => t('10% of cron run'),
    '.15' => t('15% of cron run'),
    '.2' => t('20% of cron run'),
    '.25' => t('25% of cron run'),
    '.3' => t('30% of cron run'),
    '.35' => t('35% of cron run'),
    '.4' => t('40% of cron run'),
    '.45' => t('45% of cron run'),
    '.5' => t('50% of cron run'),
  );
  $settings = array(
    '#tree' => TRUE,
    'cron_operations' => array(
      '#title' => 'Queued Operations',
      '#type' => 'checkboxes',
      '#options' => array(
        'create' => t('Create'),
        'update' => t('Update'),
        'delete' => t('Delete'),
      ),
      '#default_value' => $sf_queue_settings['cron_operations'],
      '#description' => t('Which operations should be queued? Check each operation that should cause an API transaction to be queued. Unchecked operations will trigger an API transaction immediately. <strong>Check more of these options if you are running out of API calls.</strong>'),
    ),
    'cron_frequency' => array(
      '#title' => 'Frequency',
      '#type' => 'select',
      '#options' => $frequency,
      '#default_value' => $sf_queue_settings['cron_frequency'],
      '#description' => t('How often should exports be attempted? Note: exports will only be attempted when cron is run. If your site-wide cron runs less frequently than this setting, the exports will be attempted on every cron run. <strong>If cron is timing out, you should lower this setting so that the queue is processed more frequently.</strong>'),
    ),
    'cron_period' => array(
      '#title' => 'Time',
      '#type' => 'select',
      '#options' => $period,
      '#default_value' => $sf_queue_settings['cron_period'],
      '#description' => t('Amount of time as a percentage of allotted cron run time that should be devoted to the export queue.'),
    ),
    'cron_num_objects' => array(
      '#title' => 'Number of Object Types',
      '#type' => 'select',
      '#options' => $num_objects,
      '#default_value' => $sf_queue_settings['cron_num_objects'],
      '#description' => t('How many object types should be processed per cron run? Salesforce allows up to 200 objects of the same type to be created, updated, or deleted in a single API transaction. The export queue will group objects of the same type to maximize efficient use of API transactions. This setting determines how many such object groups should be processed per cron run. <strong>If cron is timing out, you should lower this setting so that fewer API transactions are attempted per cron run.</strong>'),
    ),
    'cron_min_threshold' => array(
      '#title' => 'Minimum Number of Objects to Trigger Export',
      '#type' => 'select',
      '#options' => $threshold,
      '#default_value' => $sf_queue_settings['cron_min_threshold'],
      '#description' => t('How many objects of should be required to trigger an export? The settings "No minimum" means that the export queue will be processed as fully as possible on each cron run, even if only one object is to be created, updated, or deleted. Setting this value too high may delay processing of queued data. <strong>If you are running out of API calls, try raising this setting so that more objects are queued before an API call is made. If your cron runs are timing out, try lowering this setting so that the queue load is smaller on each cron run.</strong>'),
    ),
    'retry_num_attempts' => array(
      '#title' => 'Number of Retry Attempts',
      '#type' => 'select',
      '#options' => $attempts,
      '#default_value' => $sf_queue_settings['retry_num_attempts'],
      '#description' => t('How many times should an API transacrion be retried after a failed attempt? "No limit" means that failed attempts will be retried either until they succeed or are manually removed from the queue. <strong>If you are running out of API calls, try lowering this setting. If your cron runs are timing out, try lowering this setting.</strong>'),
    ),
  );
  $form['sf_queue']['sf_queue_settings'] = $settings;
}