You are here

function _acquia_contenthub_dispatch_not_confirmed_entities_event in Acquia Content Hub 8.2

Dispatches "NOT_CONFIRMED_ENTITIES_FOUND" event.

2 calls to _acquia_contenthub_dispatch_not_confirmed_entities_event()
acquia_contenthub_publisher_cron in modules/acquia_contenthub_publisher/acquia_contenthub_publisher.module
Implements hook_cron().
NotConfirmedEntitiesTest::testNotConfirmedEntities in tests/src/Kernel/NotConfirmedEntitiesTest.php
Tests "stale" entities functionality.

File

modules/acquia_contenthub_publisher/acquia_contenthub_publisher.module, line 209
Drupal Module: Acquia Content Hub - Publisher.

Code

function _acquia_contenthub_dispatch_not_confirmed_entities_event() {

  /** @var \Drupal\Core\Config\Config $config */
  $config = \Drupal::service('config.factory')
    ->get('acquia_contenthub_publisher.settings');
  $threshold_stale_entities = $config
    ->get('threshold_stale_entities');
  if (!$threshold_stale_entities) {
    return;
  }
  $request_time = \Drupal::service('datetime.time')
    ->getRequestTime();
  $threshold_timestamp = $request_time - $threshold_stale_entities;
  $query = \Drupal::database()
    ->select('acquia_contenthub_publisher_export_tracking', 'tracking');
  $query
    ->fields('tracking', [
    'entity_type',
    'entity_id',
    'entity_uuid',
    'created',
    'modified',
  ]);
  $query
    ->addExpression(":threshold_timestamp - UNIX_TIMESTAMP(CONVERT_TZ(DATE_FORMAT(modified, '%Y-%m-%dT%H:%i:%s'), '+00:00', @@SESSION.time_zone))", 'overdue', [
    ':threshold_timestamp' => $threshold_timestamp,
  ]);
  $query
    ->condition('status', PublisherTracker::EXPORTED);
  $query
    ->orderBy('modified');
  $items = $query
    ->execute()
    ->fetchAllAssoc('entity_uuid');
  $items = array_filter($items, function ($item) {
    return $item->overdue >= 0;
  });
  if (!$items) {
    return;
  }
  $event = new NotConfirmedEntitiesFoundEvent($items);

  /** @var \Symfony\Component\EventDispatcher\EventDispatcherInterface $dispatcher */
  $dispatcher = \Drupal::service('event_dispatcher');
  $dispatcher
    ->dispatch(ContentHubPublisherEvents::NOT_CONFIRMED_ENTITIES_FOUND, $event);
}