You are here

public function ContentHubEntityExportController::trackExportedEntity in Acquia Content Hub 8

Save this entity in the Tracking table.

Parameters

array $cdf: The entity that has to be tracked as exported entity.

bool $set_exported: Set the export status to exported in the tracking table.

Return value

bool TRUE if this entity was saved in the tracking table, FALSE otherwise.

Throws

\Drupal\Core\Entity\EntityStorageException

2 calls to ContentHubEntityExportController::trackExportedEntity()
ContentHubEntityExportController::exportEntities in src/Controller/ContentHubEntityExportController.php
Export entities to Content Hub (using the queue if enabled).
ContentHubEntityExportController::getDrupalEntities in src/Controller/ContentHubEntityExportController.php
Collects all Drupal Entities that needs to be sent to Hub.

File

src/Controller/ContentHubEntityExportController.php, line 299

Class

ContentHubEntityExportController
Controller for Content Hub Export Entities using bulk upload.

Namespace

Drupal\acquia_contenthub\Controller

Code

public function trackExportedEntity(array $cdf, $set_exported = FALSE) {
  $exported_entity = $this->contentHubEntitiesTracking
    ->loadExportedByUuid($cdf['uuid']);
  if ($exported_entity) {
    $exported_entity
      ->setModified($cdf['modified'])
      ->setInitiated();
    if ($set_exported) {
      $exported_entity
        ->setExported();
    }
    return $this->contentHubEntitiesTracking
      ->save();
  }
  $entity = $this->entityRepository
    ->loadEntityByUuid($cdf['type'], $cdf['uuid']);
  if (!$entity) {
    $this->loggerFactory
      ->get('acquia_contenthub')
      ->warning('Cannot create record in the tracking table, because the entity cannot be loaded in Drupal. uuid: @uuid type: @type', [
      '@uuid' => $cdf['uuid'],
      '@type' => $cdf['type'],
    ]);
    return FALSE;
  }

  // Add a new tracking record with exported status set, and
  // imported status empty.
  $exported_entity = $this->contentHubEntitiesTracking
    ->setExportedEntity($cdf['type'], $entity
    ->id(), $cdf['uuid'], $cdf['modified'], $this->contentHubEntitiesTracking
    ->getSiteOrigin());
  if (!$exported_entity) {

    // In case of $exported_entity == FALSE.
    $this->loggerFactory
      ->get('acquia_contenthub')
      ->warning('Cannot save into Acquia ContentHub tracking table; entity UUID: @uuid, @backtrack', [
      '@uuid' => $entity
        ->uuid(),
      '@backtrack' => __FUNCTION__,
    ]);
    return FALSE;
  }
  if ($set_exported) {
    $exported_entity
      ->setExported();
  }

  // Now save the entity.
  $result = $this->contentHubEntitiesTracking
    ->save();
  if ($result === FALSE) {
    $this->loggerFactory
      ->get('acquia_contenthub')
      ->debug('Unable to save entity to the tracking table: entity_type = @type, entity_uuid = @uuid, entity_id = @id, origin = @origin, mmodified = @modified.', [
      '@uuid' => $this->contentHubEntitiesTracking
        ->getUuid(),
      '@type' => $this->contentHubEntitiesTracking
        ->getEntityType(),
      '@id' => $this->contentHubEntitiesTracking
        ->getEntityId(),
      '@origin' => $this->contentHubEntitiesTracking
        ->getOrigin(),
      '@modified' => $this->contentHubEntitiesTracking
        ->getModified(),
    ]);
  }
  return $result;
}