You are here

function drush_salesforce_pull_sf_pull_query in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 modules/salesforce_pull/salesforce_pull.drush.inc \drush_salesforce_pull_sf_pull_query()
  2. 5.0.x modules/salesforce_pull/salesforce_pull.drush.inc \drush_salesforce_pull_sf_pull_query()

Queues records for pull from salesforce for the given mapping.

Parameters

string $name: Mapping name.

File

modules/salesforce_pull/salesforce_pull.drush.inc, line 96
Salesforce Pull drush 8 commands.

Code

function drush_salesforce_pull_sf_pull_query($name) {
  _drush_salesforce_deprecated();
  if (!($mapping = _salesforce_drush_get_mapping($name))) {
    return;
  }
  if ($start = drush_get_option('start')) {
    $start = strtotime($start);
  }
  else {
    $start = 0;
  }
  if ($stop = drush_get_option('stop')) {
    $stop = strtotime($stop);
  }
  else {
    $stop = 0;
  }
  $where = drush_get_option('where');
  if (!($soql = $mapping
    ->getPullQuery([], $start, $stop))) {
    drush_log(dt('!mapping: Unable to generate pull query. Does this mapping have any Salesforce Action Triggers enabled?', [
      '!mapping' => $mapping
        ->id(),
    ]), 'error');
    return;
  }
  if ($where) {
    $soql->conditions[] = [
      $where,
    ];
  }
  \Drupal::service('event_dispatcher')
    ->dispatch(SalesforceEvents::PULL_QUERY, new SalesforceQueryEvent($mapping, $soql));
  drush_log(dt('!mapping: Issuing pull query: !query', [
    '!query' => (string) $soql,
    '!mapping' => $mapping
      ->id(),
  ]), 'notice');
  $results = \Drupal::service('salesforce.client')
    ->query($soql);
  if (empty($results)) {
    drush_log(dt('!mapping: No records found to pull.', [
      '!mapping' => $mapping
        ->id(),
    ]), 'warning');
    return;
  }
  $force_pull = drush_get_option('force-pull') ? TRUE : FALSE;
  \Drupal::service('salesforce_pull.queue_handler')
    ->enqueueAllResults($mapping, $results, $force_pull);
  drush_log(dt('!mapping: Queued !count items for pull.', [
    '!count' => $results
      ->size(),
    '!mapping' => $mapping
      ->id(),
  ]), 'success');
}