You are here

protected function ContentHubEntitiesTracking::setTrackingEntity in Acquia Content Hub 8

Explicitly sets the Tracking Entity.

Parameters

string $entity_type: The Entity Type.

int $entity_id: The Entity ID.

string $entity_uuid: The Entity UUID.

string $modified: The CDF's modified timestamp.

string $origin: The origin UUID.

string $status_export: The Export Status.

string $status_import: The Import Status.

Return value

\Drupal\acquia_contenthub\ContentHubEntitiesTracking This same object.

4 calls to ContentHubEntitiesTracking::setTrackingEntity()
ContentHubEntitiesTracking::loadByDrupalEntity in src/ContentHubEntitiesTracking.php
Loads a record using Drupal entity key information.
ContentHubEntitiesTracking::loadByUuid in src/ContentHubEntitiesTracking.php
Loads a record using an Entity's UUID.
ContentHubEntitiesTracking::setExportedEntity in src/ContentHubEntitiesTracking.php
Helper function to set the Exported Tracking Entity.
ContentHubEntitiesTracking::setImportedEntity in src/ContentHubEntitiesTracking.php
Helper function to set the Imported Tracking Entity.

File

src/ContentHubEntitiesTracking.php, line 113

Class

ContentHubEntitiesTracking
Tracks in a table the list of all entities imported from Content Hub.

Namespace

Drupal\acquia_contenthub

Code

protected function setTrackingEntity($entity_type, $entity_id, $entity_uuid, $modified, $origin, $status_export, $status_import) {

  // If we don't have a valid input, return FALSE.
  $valid_input = !empty($entity_type) && !empty($entity_id) && Uuid::isValid($entity_uuid) && Uuid::isValid($origin);
  if (!$valid_input) {
    return FALSE;
  }

  // Either export status or import status has to exist, but not both or
  // neither. Otherwise return FALSE.
  $export_xor_import = empty($status_export) && !empty($status_import) || !empty($status_export) && empty($status_import);
  if (!$export_xor_import) {
    return FALSE;
  }

  // If we have a valid import status but site origin is the same as the
  // entity origin then return FALSE.
  // If we have a valid export status but site origin is not the same as the
  // entity origin then return FALSE.
  $site_origin = $this->contentHubAdminConfig
    ->get('origin');
  if ($this
    ->isImportedEntity() && $this
    ->getOrigin() === $site_origin) {
    return FALSE;
  }
  if ($this
    ->isExportedEntity() && $this
    ->getOrigin() !== $site_origin) {
    return FALSE;
  }

  // Set the current tracking entity.
  $this->trackingEntity = (object) [
    'entity_type' => $entity_type,
    'entity_id' => $entity_id,
    'entity_uuid' => $entity_uuid,
    'modified' => $modified,
    'origin' => $origin,
    'status_export' => $status_export,
    'status_import' => $status_import,
  ];

  // Cache the entity object.
  $this->cachedTrackingEntities[$entity_type][$entity_id] = $this->trackingEntity;
  return $this;
}