You are here

protected function AcquiaContentHubPublisherAuditEntityCommands::auditEntityDependencies in Acquia Content Hub 8.2

Audits Entity Dependencies.

Parameters

\Drupal\Core\Entity\EntityInterface $entity: The entity to analyze.

\Acquia\ContentHubClient\CDF\CDFObjectInterface $cdf: The locally generated CDF.

array $dependencies: An array of depedendencies.

array $data: An array of CDF Objects generated locally.

array $remote_dependencies: The remote dependencies.

string $hash: The locally generated entity hash.

string $remote_hash: The remote CDF hash.

Throws

\Exception

1 call to AcquiaContentHubPublisherAuditEntityCommands::auditEntityDependencies()
AcquiaContentHubPublisherAuditEntityCommands::auditEntity in modules/acquia_contenthub_publisher/src/Commands/AcquiaContentHubPublisherAuditEntityCommands.php
Audits an entity for differences with existing CDF in Acquia Content Hub.

File

modules/acquia_contenthub_publisher/src/Commands/AcquiaContentHubPublisherAuditEntityCommands.php, line 320

Class

AcquiaContentHubPublisherAuditEntityCommands
Drush commands for Acquia Content Hub Publishers Audit Entity.

Namespace

Drupal\acquia_contenthub_publisher\Commands

Code

protected function auditEntityDependencies(EntityInterface $entity, CDFObjectInterface $cdf, array $dependencies, array $data, array $remote_dependencies, string $hash, string $remote_hash) {
  $entity_type = $entity
    ->getEntityTypeId();
  $content = [];
  $dep = 0;
  $content[] = [
    $dep++,
    $this
      ->getTypeShort($cdf
      ->getType()),
    $entity_type,
    $entity
      ->bundle(),
    $entity
      ->uuid(),
    $hash,
    $remote_hash,
    $remote_hash === $hash ? '<info>OK</info>' : '<error>Fail</error>',
  ];
  $dependencies_check = TRUE;
  foreach ($dependencies as $duuid => $dhash) {
    $remote_hash = $remote_dependencies[$duuid] ?: '<error>Not found</error>';
    if (isset($remote_dependencies[$duuid])) {
      unset($remote_dependencies[$duuid]);
    }
    $content[] = [
      $dep++,
      $this
        ->getTypeShort($data[$duuid]
        ->getType()),
      $data[$duuid]
        ->getAttribute('entity_type')
        ->getValue()['und'],
      $data[$duuid]
        ->getAttribute('bundle') ? $data[$duuid]
        ->getAttribute('bundle')
        ->getValue()['und'] : '',
      $duuid,
      $dhash,
      $remote_hash,
      $remote_hash === $dhash ? '<info>OK</info>' : '<error>Fail</error>',
    ];
    $dependencies_check = $dependencies_check && $remote_hash === $dhash;
  }

  // Iterating among the last remote dependencies.
  foreach ($remote_dependencies as $ruuid => $rhash) {
    $dependencies_check = FALSE;

    // Check if we can get the remote entity.
    $remote_entity = $this->client
      ->getEntity($ruuid);
    if ($remote_entity) {
      $remote_type = $this
        ->getTypeShort($remote_entity
        ->getType());
      $rentity_type = $remote_entity
        ->getAttribute('entity_type')
        ->getValue()['und'];
      $remote_bundle = $remote_entity
        ->getAttribute('bundle') ? $remote_entity
        ->getAttribute('bundle')
        ->getValue()['und'] : NULL;
    }
    $content[] = [
      '-',
      $remote_type ?: '<comment>Unknown</comment>',
      $rentity_type ?: '<comment>Unknown</comment>',
      $remote_bundle ?: '<comment>Unknown</comment>',
      $ruuid,
      '',
      $rhash,
      '<error>Fail</error>',
    ];
  }
  if (!$dependencies_check) {
    $this
      ->setResults(self::NEEDS_REEXPORT);
  }
  $message = sprintf('CDF Entity Dependencies, Local vs Remote Analysis:');
  $headers = [
    '#',
    'Type',
    'Entity Type',
    'Entity Bundle',
    'UUID',
    'Hash',
    'Remote Hash',
    'Match',
  ];
  $this
    ->printTableOutput($message, $headers, $content);
}