You are here

protected function PushQueue::doCreateItem in Salesforce Suite 5.0.x

Same name and namespace in other branches
  1. 8.4 modules/salesforce_push/src/PushQueue.php \Drupal\salesforce_push\PushQueue::doCreateItem()
  2. 8.3 modules/salesforce_push/src/PushQueue.php \Drupal\salesforce_push\PushQueue::doCreateItem()

Adds a queue item and store it directly to the queue.

@TODO convert $data to a proper class and make sure that's what we get for this argument.

Parameters

array $data: Data array with the following key-value pairs:

  • 'name': the name of the salesforce mapping for this entity
  • 'entity_id': the entity id being mapped / pushed
  • 'op': the operation which triggered this push.

Return value

int On success, \Drupal\Core\Database\Query\Merge::STATUS_INSERT or Drupal\Core\Database\Query\Merge::STATUS_UPDATE whether item was inserted or updated.

Throws

\Exception If the required indexes are not provided.

Overrides DatabaseQueue::doCreateItem

1 call to PushQueue::doCreateItem()
PushQueue::failItem in modules/salesforce_push/src/PushQueue.php
Failed item handler.

File

modules/salesforce_push/src/PushQueue.php, line 232

Class

PushQueue
Salesforce push queue.

Namespace

Drupal\salesforce_push

Code

protected function doCreateItem($data) {

  // @codingStandardsIgnoreLine
  if (empty($data['name']) || empty($data['entity_id']) || empty($data['op'])) {
    throw new \Exception('Salesforce push queue data values are required for "name", "entity_id" and "op"');
  }
  $this->name = $data['name'];
  $time = $this->time
    ->getRequestTime();
  $fields = [
    'name' => $this->name,
    'entity_id' => $data['entity_id'],
    'op' => $data['op'],
    'updated' => $time,
    'failures' => empty($data['failures']) ? 0 : $data['failures'],
    'mapped_object_id' => empty($data['mapped_object_id']) ? 0 : $data['mapped_object_id'],
  ];
  $query = $this->connection
    ->merge(static::TABLE_NAME)
    ->key([
    'name' => $this->name,
    'entity_id' => $data['entity_id'],
  ])
    ->fields($fields);

  // Return Merge::STATUS_INSERT or Merge::STATUS_UPDATE.
  $ret = $query
    ->execute();

  // Drupal still doesn't support now() https://www.drupal.org/node/215821
  // 11 years.
  if ($ret == Merge::STATUS_INSERT) {
    $this->connection
      ->merge(static::TABLE_NAME)
      ->key([
      'name' => $this->name,
      'entity_id' => $data['entity_id'],
    ])
      ->fields([
      'created' => $time,
    ])
      ->execute();
  }
  return $ret;
}