You are here

public function PullBase::processItem in Salesforce Suite 8.4

Same name and namespace in other branches
  1. 8.3 modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php \Drupal\salesforce_pull\Plugin\QueueWorker\PullBase::processItem()
  2. 5.0.x modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php \Drupal\salesforce_pull\Plugin\QueueWorker\PullBase::processItem()

Queue item process callback.

Parameters

\Drupal\salesforce_pull\PullQueueItem $item: Pull queue item. Note: typehint missing because we can't change the inherited API.

Return value

string|null Return \Drupal\salesforce_mapping\MappingConstants::SALESFORCE_MAPPING_SYNC_SF_UPDATE or Return \Drupal\salesforce_mapping\MappingConstants::SALESFORCE_MAPPING_SYNC_SF_CREATE on successful update or create, NULL otherwise.

Throws

\Exception

Overrides QueueWorkerInterface::processItem

File

modules/salesforce_pull/src/Plugin/QueueWorker/PullBase.php, line 110

Class

PullBase
Provides base functionality for the Salesforce Pull Queue Workers.

Namespace

Drupal\salesforce_pull\Plugin\QueueWorker

Code

public function processItem($item) {

  // @codingStandardsIgnoreLine
  $sf_object = $item
    ->getSobject();
  $mapping = $this->mappingStorage
    ->load($item
    ->getMappingId());
  if (!$mapping) {
    return;
  }

  // loadMappedObjects returns an array, but providing salesforce id and
  // mapping guarantees at most one result.
  $mapped_object = $this->mappedObjectStorage
    ->loadByProperties([
    'salesforce_id' => (string) $sf_object
      ->id(),
    'salesforce_mapping' => $mapping->id,
  ]);

  // @TODO one-to-many: this is a blocker for OTM support:
  $mapped_object = current($mapped_object);
  if (!empty($mapped_object)) {
    return $this
      ->updateEntity($mapping, $mapped_object, $sf_object, $item
      ->getForcePull());
  }
  else {
    return $this
      ->createEntity($mapping, $sf_object);
  }
}