You are here

protected function SyncHealth::countStaleEntities in CMS Content Sync 8

Same name and namespace in other branches
  1. 2.1.x modules/cms_content_sync_health/src/Controller/SyncHealth.php \Drupal\cms_content_sync_health\Controller\SyncHealth::countStaleEntities()
  2. 2.0.x modules/cms_content_sync_health/src/Controller/SyncHealth.php \Drupal\cms_content_sync_health\Controller\SyncHealth::countStaleEntities()
1 call to SyncHealth::countStaleEntities()
SyncHealth::pushing in modules/cms_content_sync_health/src/Controller/SyncHealth.php
Render the overview page.

File

modules/cms_content_sync_health/src/Controller/SyncHealth.php, line 362

Class

SyncHealth
Provides a listing of Flow.

Namespace

Drupal\cms_content_sync_health\Controller

Code

protected function countStaleEntities() {
  $checked = [];
  $count = 0;
  foreach (Flow::getAll() as $flow) {
    foreach ($flow
      ->getEntityTypeConfig(NULL, NULL, TRUE) as $id => $config) {
      if (in_array($id, $checked)) {
        continue;
      }
      if ($config['export'] != PushIntent::PUSH_AUTOMATICALLY) {
        continue;
      }
      if (!in_array(Pool::POOL_USAGE_FORCE, array_values($config['export_pools']))) {
        continue;
      }
      $checked[] = $id;
      $type_name = $config['entity_type_name'];
      $bundle_name = $config['bundle_name'];

      /**
       * @var \Drupal\Core\Entity\EntityTypeManager $entityTypeManager
       */
      $entityTypeManager = $this->entityTypeManager;
      $type = $entityTypeManager
        ->getDefinition($type_name);
      $query = $this->database
        ->select($type
        ->getBaseTable(), 'e');
      $query
        ->leftJoin('cms_content_sync_entity_status', 's', 'e.uuid=s.entity_uuid AND s.entity_type=:type', [
        ':type' => $type_name,
      ]);
      $query = $query
        ->isNull('s.id');

      // Some entity types don't store their bundle information in their table if they don't actually have multiple
      // bundles.
      if (!in_array($type_name, [
        'bibcite_contributor',
        'bibcite_keyword',
      ])) {
        $query = $query
          ->condition('e.' . $type
          ->getKey('bundle'), $bundle_name);
      }
      $result = $query
        ->countQuery()
        ->execute();
      $count += (int) $result
        ->fetchField();
    }
  }
  return $count;
}