protected function AcquiaContentHubPublisherAuditEntityCommands::auditEntityCdf in Acquia Content Hub 8.2
Audits the Entity CDF.
Parameters
\Drupal\Core\Entity\EntityInterface $entity: The entity to audit.
string $origin: The locally generated origin.
string $remote_origin: The remote origin from the CDF.
string $hash: The locally generated hash.
string $remote_hash: The remote hash.
array $dependencies: The locally generated entity dependencies.
array $remote_dependencies: The remote dependencies obtained from the CDF.
\Acquia\ContentHubClient\CDF\CDFObjectInterface $cdf: The CDF locally generated CDF.
\Acquia\ContentHubClient\CDF\CDFObjectInterface $remote_cdf: The remote CDF stored in Acquia Content Hub.
1 call to AcquiaContentHubPublisherAuditEntityCommands::auditEntityCdf()
- 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 201
Class
- AcquiaContentHubPublisherAuditEntityCommands
- Drush commands for Acquia Content Hub Publishers Audit Entity.
Namespace
Drupal\acquia_contenthub_publisher\CommandsCode
protected function auditEntityCdf(EntityInterface $entity, string $origin, string $remote_origin, string $hash, string $remote_hash, array $dependencies, array $remote_dependencies, CDFObjectInterface $cdf, CDFObjectInterface $remote_cdf) {
// Obtaining the record in the Publisher Tracking Table.
$tracked_entity = $this->tracker
->getRecord($entity
->uuid());
$tracked_state = strtoupper($tracked_entity->status);
if ($tracked_entity->status === PublisherTracker::QUEUED) {
$tracked_status = "<fg=yellow;options=bold>{$tracked_state}</>";
$queue_id = $this->tracker
->getQueueId($tracked_entity->entity_uuid);
if ($queue_id) {
$tracked_label = sprintf("<comment>Entity is already in the Publisher Queue with item_id = %s.</comment>", $queue_id);
}
else {
$tracked_label = sprintf("<error>Entity is reported as Queued but is not in the Publisher Queue. Requires a re-export.</error>", $queue_id);
$this
->setResults(self::NEEDS_REEXPORT);
}
}
elseif ($tracked_entity->status === PublisherTracker::EXPORTED) {
$tracked_status = "<fg=yellow;options=bold>{$tracked_state}</>";
$tracked_label = '<comment>Entity did not receive confirmation status. Check that this site is receiving webhooks.</comment>';
$this
->setResults(self::WEBHOOK_CHECK);
}
else {
$tracked_status = "<info>{$tracked_state}</info>";
$tracked_label = '<info>OK</info>';
}
// Verifying the origin matches remote origin.
if ($origin !== $remote_origin) {
$origin_label = sprintf('<error>Remote CDF was exported from another origin. Requires re-origination or purge to fix.</error>', $tracked_entity->hash);
$this
->setResults(self::RE_ORIGINATE);
}
else {
$origin_label = "<info>OK</info>";
}
// Verifying that the tracked hash coincides with local or remote CDF.
if ($tracked_entity->hash !== $hash) {
$hash_label = sprintf('<error>Exported with an outdated hash: "%s". Requires a re-export.</error>', $tracked_entity->hash);
$this
->setResults(self::NEEDS_REEXPORT);
}
elseif ($hash !== $remote_hash) {
$hash_label = '<error>Hash Mismatch. Requires a re-export.</error>';
$this
->setResults(self::NEEDS_REEXPORT);
}
else {
$hash_label = '<info>OK</info>';
}
// Verifying number of dependencies.
if (count($dependencies) == count($remote_dependencies)) {
$dependencies_label = '<info>OK</info>';
}
else {
$dependencies_label = '<error># of Dependencies Mismatch. Requires a re-export.</error>';
$this
->setResults(self::NEEDS_REEXPORT);
}
// Writing data into the terminal.
$content = [
[
'Type',
$cdf
->getType(),
$remote_cdf
->getType(),
'',
],
[
'Entity Type',
$entity
->getEntityTypeId(),
$remote_cdf
->getAttribute('entity_type')
->getValue()['und'],
'',
],
[
'Entity Bundle',
$entity
->bundle(),
$remote_cdf
->getAttribute('bundle')
->getValue()['und'],
'',
],
[
'Entity ID',
$entity
->id(),
'',
'',
],
[
'Entity UUID',
$entity
->uuid(),
$remote_cdf
->getUuid(),
'',
],
[
'Origin',
$origin,
$remote_origin,
$origin_label,
],
[
'Hash',
$hash,
$remote_hash,
$hash_label,
],
[
'Publisher Tracker Status',
$tracked_status,
'',
$tracked_label,
],
[
'Publisher Tracker Created',
$tracked_entity->created,
$remote_cdf
->getCreated(),
'There could be small variations.',
],
[
'Publisher Tracker Modified',
$tracked_entity->modified,
$remote_cdf
->getModified(),
'There could be small variations.',
],
[
'# of Dependencies',
count($dependencies),
count($remote_dependencies),
$dependencies_label,
],
];
$message = sprintf("Analyzing CDF Entity: {$entity->getEntityTypeId()}/{$entity->id()}: {$entity->uuid()}");
$headers = [
'Parameter',
'Local',
'Remote',
'Notes',
];
$this
->printTableOutput($message, $headers, $content);
}