public function AcquiaContentHubPublisherAuditEntityCommands::auditEntity in Acquia Content Hub 8.2
Audits an entity for differences with existing CDF in Acquia Content Hub.
@usage drush acquia:contenthub-audit-entity node 123 Audits the node with nid = 123 and all its dependencies. @usage drush ach-audit-entity taxonomy_term d470026c-f248-4771-acd1-300a7d6ccbce Audits the taxonomy term with UUID=d470026c-f248-4771-acd1-300a7d6ccbce. @usage drush ach-ae node 53fd2ed2-5d29-4028-9423-0713ef2f82b3 Audits the node with UUID = 53fd2ed2-5d29-4028-9423-0713ef2f82b3.
@command acquia:contenthub-audit-entity @aliases ach-audit-entity, ach-ae
Parameters
string $entity_type: Entity type.
string $id: Entity ID or UUID.
Throws
\Exception
File
- modules/
acquia_contenthub_publisher/ src/ Commands/ AcquiaContentHubPublisherAuditEntityCommands.php, line 122
Class
- AcquiaContentHubPublisherAuditEntityCommands
- Drush commands for Acquia Content Hub Publishers Audit Entity.
Namespace
Drupal\acquia_contenthub_publisher\CommandsCode
public function auditEntity(string $entity_type, string $id) {
if (empty($entity_type) || empty($id)) {
throw new \Exception(dt("Missing required parameters: entity_type and entity_id (or entity_uuid)"));
}
$storage = \Drupal::entityTypeManager()
->getStorage($entity_type);
if (empty($storage)) {
throw new \Exception(sprintf("The provided entity_type = '%s' does not exist.", $entity_type));
}
if (Uuid::isValid($id)) {
$entity = $storage
->loadByProperties([
'uuid' => $id,
]);
$entity = reset($entity);
}
else {
$entity = $storage
->load($id);
}
if (empty($entity)) {
throw new \Exception(sprintf("The entity (%s, %s) does not exist.", $entity_type, $id));
}
// Obtaining Client Connection to Acquia Content Hub.
$this->client = $this->factory
->getClient();
if (empty($this->client)) {
throw new \Exception("This site is not Connected to Acquia Content Hub. Please check your configuration settings.");
}
$remote_cdf = $this->client
->getEntity($entity
->uuid());
if (!$remote_cdf instanceof CDFObjectInterface) {
throw new \Exception("This entity was not exported yet. Please export it first.");
}
// Calculate the dependencies for the local entity.
$data = $this->commonActions
->getEntityCdfFullKeyedByUuids($entity);
$cdf = $data[$entity
->uuid()];
$hash = $cdf
->getAttribute('hash')
->getValue()['und'];
$remote_hash = $remote_cdf
->getAttribute('hash')
->getValue()['und'];
$remote_dependencies = $remote_cdf
->getDependencies();
$dependencies = $cdf
->getDependencies();
// Verifying local and remote origins.
$origin = $cdf
->getOrigin();
$remote_origin = $remote_cdf
->getOrigin();
// Auditing given Entity.
$this
->auditEntityCdf($entity, $origin, $remote_origin, $hash, $remote_hash, $dependencies, $remote_dependencies, $cdf, $remote_cdf);
// Only keep analyzing if we are in the correct site.
if ($origin == $remote_origin) {
// Analyzing entity dependencies.
$this
->auditEntityDependencies($entity, $cdf, $dependencies, $data, $remote_dependencies, $hash, $remote_hash);
// Analyzing module dependencies.
$this
->auditModuleDependencies($cdf, $remote_cdf);
}
// Present the action that needs to be taken.
return $this
->showAuditResults($entity, $cdf, $dependencies, $origin, $remote_origin);
}