function drush_acquia_contenthub_audit_publisher in Acquia Content Hub 8
Audits exported entities and republishes if inconsistencies are found.
Parameters
string|null $entity_type_id: The entity type.
Return value
mixed|false Drush Output.
File
- ./
acquia_contenthub.drush.inc, line 981 - ContentHub Drush Commands.
Code
function drush_acquia_contenthub_audit_publisher($entity_type_id = NULL) {
// Obtaining the query.
$publish = drush_get_option("publish") ?: FALSE;
$status = drush_get_option("status") ?: ContentHubEntitiesTracking::EXPORTED;
if ($publish) {
$warning_message = dt('Are you sure you want to republish entities to Content Hub?');
if (drush_confirm($warning_message) == FALSE) {
return drush_user_abort();
}
}
/** @var \Drupal\acquia_contenthub\ContentHubEntitiesTracking $entities_tracking */
$entities_tracking = \Drupal::getContainer()
->get('acquia_contenthub.acquia_contenthub_entities_tracking');
switch ($status) {
case ContentHubEntitiesTracking::EXPORTED:
$entities = $entities_tracking
->getPublishedEntities($entity_type_id);
break;
case ContentHubEntitiesTracking::INITIATED:
$entities = $entities_tracking
->getInitiatedEntities($entity_type_id);
break;
case ContentHubEntitiesTracking::REINDEX:
$entities = $entities_tracking
->getEntitiesToReindex($entity_type_id);
break;
case ContentHubEntitiesTracking::QUEUED:
// If we want to queue "queued" entities, then we have to make sure the
// export queue is empty or we might be re-queuing entities that already
// are in the queue.
/** @var \Drupal\Core\Queue\QueueInterface $queue */
$queue = \Drupal::getContainer()
->get('queue')
->get('acquia_contenthub_export_queue');
if ($queue
->numberOfItems() > 0) {
return drush_set_error('You cannot audit queued entities when the queue is not empty because you run the risk of re-queuing the same entities. Please retry when the queue is empty.');
}
$entities = $entities_tracking
->getQueuedEntities($entity_type_id);
break;
default:
return drush_set_error('You can only use the following values for status: EXPORTED, INITIATED, REINDEX, QUEUED.');
}
drush_print(dt('Auditing entities with export status = @status...', [
'@status' => $status,
]));
// Creating the batch process.
$operations = [];
$chunks = array_chunk($entities, 50);
foreach ($chunks as $chunk) {
$operations[] = [
'acquia_contenthub_audit_publisher',
[
$chunk,
$publish,
],
];
}
// Setting up batch process.
$batch = [
'title' => dt("Checks published entities with Content Hub for correct status"),
'operations' => $operations,
'finished' => 'acquia_contenthub_audit_publisher_finished',
];
// Batch processing.
batch_set($batch);
// Start the batch process.
drush_backend_batch_process();
}