You are here

function acquia_contenthub_publisher_enqueue_exported_entities_finished in Acquia Content Hub 8.2

Final function after enqueuing exported entities.

Takes care of deleting the legacy tracking table if empty.

Parameters

bool $success: The success parameter.

mixed $results: The results array.

mixed $operations: The operations array.

1 string reference to 'acquia_contenthub_publisher_enqueue_exported_entities_finished'
AcquiaContentHubPublisherCommands::upgrade in modules/acquia_contenthub_publisher/src/Commands/AcquiaContentHubPublisherCommands.php
Publisher Upgrade Command.

File

modules/acquia_contenthub_publisher/acquia_contenthub_publisher.migrate.inc, line 85
Batch API functions to enqueue entities from legacy tracking table.

Code

function acquia_contenthub_publisher_enqueue_exported_entities_finished($success, $results, $operations) {
  if ($success) {
    $message = t('Enqueued @num entities out of @total for export to Content Hub. Entities not enqueued will be exported as dependencies.', [
      '@num' => $results['enqueued'],
      '@total' => $results['max'],
    ]);
  }
  else {
    $message = t('Finished with an error. Some entities could not be exported. Please review all entities were enqueued for export.');
  }
  \Drupal::messenger()
    ->addStatus($message);
  $database = \Drupal::database();

  // Delete all enqueued items.
  $query = $database
    ->delete('acquia_contenthub_entities_tracking');
  $query
    ->condition('status_export', [
    'EXPORTED',
    'INITIATED',
    'QUEUED',
  ], 'IN');
  $query
    ->execute();

  // Delete legacy tracking table if empty.
  $query = $database
    ->select('acquia_contenthub_entities_tracking', 't')
    ->fields('t', [
    'entity_id',
  ]);
  $count = $query
    ->countQuery()
    ->execute()
    ->fetchField();
  if ($count === 0) {

    // If table is empty, drop it.
    \Drupal::database()
      ->schema()
      ->dropTable('acquia_contenthub_entities_tracking');
  }
}