You are here

public function TermStorage::getTermIdsWithPendingRevisions in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/taxonomy/src/TermStorage.php \Drupal\taxonomy\TermStorage::getTermIdsWithPendingRevisions()

Gets a list of term IDs with pending revisions.

@internal

Return value

int[] An array of term IDs which have pending revisions, keyed by their revision IDs.

Overrides TermStorageInterface::getTermIdsWithPendingRevisions

File

core/modules/taxonomy/src/TermStorage.php, line 379

Class

TermStorage
Defines a Controller class for taxonomy terms.

Namespace

Drupal\taxonomy

Code

public function getTermIdsWithPendingRevisions() {
  $table_mapping = $this
    ->getTableMapping();
  $id_field = $table_mapping
    ->getColumnNames($this->entityType
    ->getKey('id'))['value'];
  $revision_field = $table_mapping
    ->getColumnNames($this->entityType
    ->getKey('revision'))['value'];
  $rta_field = $table_mapping
    ->getColumnNames($this->entityType
    ->getKey('revision_translation_affected'))['value'];
  $langcode_field = $table_mapping
    ->getColumnNames($this->entityType
    ->getKey('langcode'))['value'];
  $revision_default_field = $table_mapping
    ->getColumnNames($this->entityType
    ->getRevisionMetadataKey('revision_default'))['value'];
  $query = $this->database
    ->select($this
    ->getRevisionDataTable(), 'tfr');
  $query
    ->fields('tfr', [
    $id_field,
  ]);
  $query
    ->addExpression("MAX([tfr].[{$revision_field}])", $revision_field);
  $query
    ->join($this
    ->getRevisionTable(), 'tr', "[tfr].[{$revision_field}] = [tr].[{$revision_field}] AND [tr].[{$revision_default_field}] = 0");
  $inner_select = $this->database
    ->select($this
    ->getRevisionDataTable(), 't');
  $inner_select
    ->condition("t.{$rta_field}", '1');
  $inner_select
    ->fields('t', [
    $id_field,
    $langcode_field,
  ]);
  $inner_select
    ->addExpression("MAX([t].[{$revision_field}])", $revision_field);
  $inner_select
    ->groupBy("t.{$id_field}")
    ->groupBy("t.{$langcode_field}");
  $query
    ->join($inner_select, 'mr', "[tfr].[{$revision_field}] = [mr].[{$revision_field}] AND [tfr].[{$langcode_field}] = [mr].[{$langcode_field}]");
  $query
    ->groupBy("tfr.{$id_field}");
  return $query
    ->execute()
    ->fetchAllKeyed(1, 0);
}