function drush_acquia_contenthub_compare in Acquia Content Hub 8
Compares a CDF entity from local and remote source.
Parameters
string $entity_type: The Entity type.
string $uuid: The Entity's UUID.
Return value
mixed|false Returns an array containing the differences between local and remote entities.
File
- ./
acquia_contenthub.drush.inc, line 315 - ContentHub Drush Commands.
Code
function drush_acquia_contenthub_compare($entity_type, $uuid) {
$entity_type_manager = \Drupal::entityTypeManager();
if (!$entity_type_manager
->getDefinition($entity_type)) {
return drush_set_error(dt("The entity type provided does not exist."));
}
if (!Uuid::isValid($uuid)) {
return drush_set_error(dt("Argument provided is not a UUID."));
}
/** @var \Symfony\Component\Serializer\Serializer $serializer */
$serializer = \Drupal::service('serializer');
/** @var \Drupal\Core\Entity\EntityRepository $entity_repository */
$entity_repository = \Drupal::service('entity.repository');
/** @var \Drupal\acquia_contenthub\Client\ClientManager $client_manager */
$client_manager = \Drupal::service('acquia_contenthub.client_manager');
$client = $client_manager
->getConnection();
// Get our local CDF version.
$local_entity = $entity_repository
->loadEntityByUuid($entity_type, $uuid);
$local_cdf = $serializer
->normalize($local_entity, 'acquia_contenthub_cdf');
if (!$local_cdf) {
$local_cdf = [];
}
// Get the Remote CDF version.
$remote_cdf = $client
->readEntity($uuid);
if (!$remote_cdf) {
$remote_cdf = [];
}
$local_compare = array_diff($local_cdf, (array) $remote_cdf);
drush_print("Data from the local entity that doesn't appear in the remote entity, retrieved from Content Hub Backend:");
drush_print_r(json_encode($local_compare, JSON_PRETTY_PRINT));
drush_print("Data from the remote entity that doesn't appear in the local entity:");
$remote_compare = array_diff((array) $remote_cdf, $local_cdf);
drush_print_r(json_encode($remote_compare, JSON_PRETTY_PRINT));
}