public function SalesforcePushCommands::requeue in Salesforce Suite 5.0.x
Same name and namespace in other branches
- 8.4 modules/salesforce_push/src/Commands/SalesforcePushCommands.php \Drupal\salesforce_push\Commands\SalesforcePushCommands::requeue()
Requeue mapped entities for asynchronous push.
Addresses the frequent need to re-push all entities for a given mapping. Given a mapping, re-queue all the mapped objects to the Salesforce push queue. The push queue will not be processed by this command, and no data will be pushed to salesforce. Run salesforce_push:push-queue to proceess the records queued by this command.
NOTE: Existing push queue records will be replaced by this operation.
@option ids If provided, only requeue the entities given by these ids. Comma-delimited. @usage drush sfpu foo Requeue all drupal entities mapped objects for mapping "foo". @usage drush sfpu foo --ids=1,2,3,4 Requeue entities for mapping "foo" with ids 1, 2, 3, 4, if they exist.
@command salesforce_push:requeue @aliases sfrq,salesforce-push-requeue
Parameters
string $name: The Drupal machine name of the mapping for the entities.
array $options: An associative array of options whose values come from cli, aliases, config, etc.
See also
salesforce_push:push-queue
File
- modules/
salesforce_push/ src/ Commands/ SalesforcePushCommands.php, line 149
Class
- SalesforcePushCommands
- A Drush commandfile.
Namespace
Drupal\salesforce_push\CommandsCode
public function requeue($name, array $options = [
'ids' => '',
]) {
// Dummy call to create item, to ensure table exists.
try {
\Drupal::service('queue.salesforce_push')
->createItem(NULL);
} catch (\Exception $e) {
}
$mappings = $this
->getPushMappingsFromName($name);
foreach ($mappings as $mapping) {
$ids = array_filter(array_map('intval', explode(',', $options['ids'])));
$mapping_name = $mapping
->id();
$op = MappingConstants::SALESFORCE_MAPPING_SYNC_DRUPAL_UPDATE;
$time = time();
$insertQuery = "REPLACE INTO salesforce_push_queue (name, entity_id, mapped_object_id, op, failures, expire, created, updated) \n (SELECT '{$mapping_name}', drupal_entity__target_id, id, '{$op}', 0, 0, {$time}, {$time} FROM salesforce_mapped_object WHERE salesforce_mapping = '{$mapping_name}' ";
if (!empty($ids)) {
$insertQuery .= " AND drupal_entity__target_id IN (" . implode(',', $ids) . ")";
}
$insertQuery .= ")";
$this->database
->query($insertQuery)
->execute();
}
}