getRevisionDataTable example

return $this->database->query(
      'SELECT [vid] FROM {' . $this->getRevisionTable() . '} WHERE [nid] = :nid ORDER BY [vid]',
      [':nid' => $node->id()]
    )->fetchCol();
  }

  /** * {@inheritdoc} */
  public function userRevisionIds(AccountInterface $account) {
    return $this->database->query(
      'SELECT [vid] FROM {' . $this->getRevisionDataTable() . '} WHERE [uid] = :uid ORDER BY [vid]',
      [':uid' => $account->id()]
    )->fetchCol();
  }

  /** * {@inheritdoc} */
  public function countDefaultLanguageRevisions(NodeInterface $node) {
    return $this->database->query('SELECT COUNT(*) FROM {' . $this->getRevisionDataTable() . '} WHERE [nid] = :nid AND [default_langcode] = 1', [':nid' => $node->id()])->fetchField();
  }

  
$entity_tables[$base_table_data['table']['entity type']]['provider'] = $base_table_data['table']['provider'];
      }
    }

    // Include all relationships.     foreach ((array) $this->view->relationship as $relationship_id => $relationship) {
      $table_data = $views_data->get($relationship->definition['base']);
      if (isset($table_data['table']['entity type'])) {

        // If this is not one of the entity base tables, skip it.         $entity_type = \Drupal::entityTypeManager()->getDefinition($table_data['table']['entity type']);
        $entity_base_tables = [$entity_type->getBaseTable()$entity_type->getDataTable()$entity_type->getRevisionTable()$entity_type->getRevisionDataTable()];
        if (!in_array($relationship->definition['base']$entity_base_tables)) {
          continue;
        }

        $entity_tables[$relationship_id . '__' . $relationship->tableAlias] = [
          'base' => $relationship->definition['base'],
          'relationship_id' => $relationship_id,
          'alias' => $relationship->alias,
          'entity_type' => $table_data['table']['entity type'],
          'revision' => $table_data['table']['entity revision'],
        ];

        
$langcode_key = $entity_type->getKey('langcode');

    $expected = [];
    $expected[$entity_type->getBaseTable()] = [$id_key];
    if ($entity_type->isRevisionable()) {
      $expected[$entity_type->getRevisionTable()] = [$revision_key];
    }
    if ($entity_type->isTranslatable()) {
      $expected[$entity_type->getDataTable()] = [$id_key$langcode_key];
    }
    if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
      $expected[$entity_type->getRevisionDataTable()] = [$revision_key$langcode_key];
    }

    // First, test explicitly deleting and re-installing a field. Make sure that     // all primary keys are there to start with.     $this->assertSame($expected$this->findPrimaryKeys($entity_type));

    // Then uninstall the field and make sure all primary keys that the field     // was part of have been updated. Since this is not a valid state of the     // entity type (for example a revisionable entity type without a revision ID     // field or a translatable entity type without a language code field) the     // actual primary keys at this point are irrelevant.

  protected function hasSharedTableNameChanges(EntityTypeInterface $entity_type, EntityTypeInterface $original) {
    $base_table = $this->database->schema()->tableExists($entity_type->getBaseTable());
    $data_table = $this->database->schema()->tableExists($entity_type->getDataTable());
    $revision_table = $this->database->schema()->tableExists($entity_type->getRevisionTable());
    $revision_data_table = $this->database->schema()->tableExists($entity_type->getRevisionDataTable());

    // We first check if the new table already exists because the storage might     // have created it even though it wasn't specified in the entity type     // definition.     return (!$base_table && $entity_type->getBaseTable() != $original->getBaseTable()) ||
      (!$data_table && $entity_type->getDataTable() != $original->getDataTable()) ||
      (!$revision_table && $entity_type->getRevisionTable() != $original->getRevisionTable()) ||
      (!$revision_data_table && $entity_type->getRevisionDataTable() != $original->getRevisionDataTable());
  }

  /** * {@inheritdoc} */
$sql_column = $table_mapping->getFieldColumnName($field_storage$column);
      }
      // The field is stored in a shared table.       else {
        // ensureEntityTable() decides whether an entity property will be         // queried from the data table or the base table based on where it         // finds the property first. The data table is preferred, which is why         // it gets added before the base table.         $entity_tables = [];
        $revision_table = NULL;
        if ($query_revisions) {
          $data_table = $entity_type->getRevisionDataTable();
          $entity_base_table = $entity_type->getRevisionTable();
        }
        else {
          $data_table = $entity_type->getDataTable();
          $entity_base_table = $entity_type->getBaseTable();

          if ($field_storage && $field_storage->isRevisionable() && in_array($field_storage->getName()$entity_type->getRevisionMetadataKeys())) {
            $revision_table = $entity_type->getRevisionTable();
          }
        }
        if ($data_table) {
          
$data_table = '';
    if ($translatable) {
      $data_table = $this->entityType->getDataTable() ?: $this->entityType->id() . '_field_data';
    }

    // Some entity types do not have a revision data table defined, but still     // have a revision table name set in     // \Drupal\Core\Entity\Sql\SqlContentEntityStorage::initTableLayout() so we     // apply the same kind of logic.     $revision_data_table = '';
    if ($revisionable && $translatable) {
      $revision_data_table = $this->entityType->getRevisionDataTable() ?: $this->entityType->id() . '_field_revision';
    }
    $entity_revision_key = $this->entityType->getKey('revision');
    $revision_field = $entity_revision_key;

    // Setup base information of the views data.     $data[$base_table]['table']['group'] = $this->entityType->getLabel();
    $data[$base_table]['table']['provider'] = $this->entityType->getProvider();

    $views_base_table = $base_table;
    if ($data_table) {
      $views_base_table = $data_table;
    }
    /** @var \Drupal\Core\Entity\ContentEntityTypeInterface $entity_type */
    $entity_type = $this->entityDefinitionUpdateManager->getEntityType($this->entityTypeId);
    $langcode_key = $entity_type->getKey('langcode');
    $revision_translation_affected_key = $entity_type->getKey('revision_translation_affected');
    $revision_translation_affected_field = $this->entityDefinitionUpdateManager->getFieldStorageDefinition($revision_translation_affected_key$entity_type->id());
    $this->assertNotNull($revision_translation_affected_field);

    $database_schema = $this->database->schema();
    $base_table = $entity_type->getBaseTable();
    $data_table = $entity_type->getDataTable();
    $revision_table = $entity_type->getRevisionTable();
    $revision_data_table = $entity_type->getRevisionDataTable();
    $this->assertTrue($database_schema->tableExists($revision_data_table));

    $this->assertTrue($database_schema->fieldExists($base_table$langcode_key));
    $this->assertTrue($database_schema->fieldExists($data_table$langcode_key));
    $this->assertTrue($database_schema->fieldExists($revision_table$langcode_key));
    $this->assertTrue($database_schema->fieldExists($revision_data_table$langcode_key));

    $this->assertFalse($database_schema->fieldExists($base_table$revision_translation_affected_key));
    $this->assertFalse($database_schema->fieldExists($revision_table$revision_translation_affected_key));
    $this->assertTrue($database_schema->fieldExists($data_table$revision_translation_affected_key));
    $this->assertTrue($database_schema->fieldExists($revision_data_table$revision_translation_affected_key));

    
    // place, and adding a new table, we must ensure that the new table appears     // prior to this one. So we recorded at what index we saw that table, and     // then use array_splice() to move the workspace_association table join to     // the correct position.     foreach ($move_workspace_tables as $workspace_association_table => $alias) {
      $this->moveEntityTable($query$workspace_association_table$alias);
    }

    $base_entity_table = $entity_type->isTranslatable() ? $entity_type->getDataTable() : $entity_type->getBaseTable();

    $base_fields = array_diff($table_mapping->getFieldNames($entity_type->getBaseTable())[$entity_type->getKey('langcode')]);
    $revisionable_fields = array_diff($table_mapping->getFieldNames($entity_type->getRevisionDataTable())$base_fields);

    // Go through and look to see if we have to modify fields and filters.     foreach ($query->fields as &$field_info) {
      // Some fields don't actually have tables, meaning they're formulae and       // whatnot. At this time we are going to ignore those.       if (empty($field_info['table'])) {
        continue;
      }

      // Dereference the alias into the actual table.       $table = $table_queue[$field_info['table']]['table'];
      

  protected function assertItemsTableCount(int $count, EntityTypeInterface $definition): void {
    $connection = Database::getConnection();
    $this->assertEquals(1, (int) $connection->select($definition->getBaseTable())->countQuery()->execute()->fetchField());
    $this->assertEquals(1, (int) $connection->select($definition->getDataTable())->countQuery()->execute()->fetchField());
    $this->assertEquals($count(int) $connection->select($definition->getRevisionTable())->countQuery()->execute()->fetchField());
    $this->assertEquals($count(int) $connection->select($definition->getRevisionDataTable())->countQuery()->execute()->fetchField());

  }

  /** * Creates a new revision in the entity of this test class. * * @param \Drupal\Core\Entity\EntityInterface $entity * The entity where revision will be created. * @param \Drupal\user\UserInterface $user * The author of the new revision. * @param int $timestamp * The timestamp of the new revision. * @param string $log_message * The log message of the new revision. */
// Verify that all data got deleted.     $definition = \Drupal::entityTypeManager()->getDefinition($entity_type);
    $connection = Database::getConnection();
    $this->assertEquals(0, (int) $connection->select($definition->getBaseTable())->countQuery()->execute()->fetchField(), 'Base table was emptied');

    if ($data_table = $definition->getDataTable()) {
      $this->assertEquals(0, (int) $connection->select($data_table)->countQuery()->execute()->fetchField(), 'Data table was emptied');
    }
    if ($revision_table = $definition->getRevisionTable()) {
      $this->assertEquals(0, (int) $connection->select($revision_table)->countQuery()->execute()->fetchField(), 'Revision table was emptied');
    }
    if ($revision_data_table = $definition->getRevisionDataTable()) {
      $this->assertEquals(0, (int) $connection->select($revision_data_table)->countQuery()->execute()->fetchField(), 'Revision data table was emptied');
    }

    // Test deleting a list of entities not indexed by entity id.     $entities = [];
    $entity = $storage->create(['name' => 'test', 'user_id' => $user1->id()]);
    $entity->save();
    $entities['test'] = $entity;
    $entity = $storage->create(['name' => 'test2', 'user_id' => $user1->id()]);
    $entity->save();
    $entities['test2'] = $entity;
    

  public function __construct(array $configuration$plugin_id$plugin_definition, EntityTypeBundleInfoInterface $bundle_info_service, MenuParentFormSelectorInterface $parent_form_selector) {
    parent::__construct($configuration$plugin_id$plugin_definition);

    $this->bundleInfoService = $bundle_info_service;
    $this->base_table = $this->definition['base_table'];

    $this->parentFormSelector = $parent_form_selector;

    $entity_types = \Drupal::entityTypeManager()->getDefinitions();
    foreach ($entity_types as $entity_type_id => $entity_type) {
      if (in_array($this->base_table, [$entity_type->getBaseTable()$entity_type->getDataTable()$entity_type->getRevisionTable()$entity_type->getRevisionDataTable()], TRUE)) {
        $this->entityType = $entity_type;
        $this->entityTypeId = $entity_type_id;
      }
    }
  }

  /** * Gets the createdColumn property. * * @return string * The name of the column containing the created date. */
'content_entity_type_id',
      'content_entity_id',
      'content_entity_revision_id',
      'workflow',
      'langcode',
    ];
    if ($data_table = $this->storage->getDataTable()) {
      $schema[$data_table]['unique keys'] += [
        'content_moderation_state__lookup' => $unique_keys,
      ];
    }
    if ($revision_data_table = $this->storage->getRevisionDataTable()) {
      $schema[$revision_data_table]['unique keys'] += [
        'content_moderation_state__lookup' => $unique_keys,
      ];
    }

    return $schema;
  }

}
/** * {@inheritdoc} */
  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")
      
/** * {@inheritdoc} */
  public function getMenuLinkIdsWithPendingRevisions() {
    $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(), 'mlfr');
    $query->fields('mlfr', [$id_field]);
    $query->addExpression("MAX([mlfr].[$revision_field])", $revision_field);

    $query->join($this->getRevisionTable(), 'mlr', "[mlfr].[$revision_field] = [mlr].[$revision_field] AND [mlr].[$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")
      
elseif ($translation_remove) {
      $changes[] = static::DATA_TABLE_REMOVAL;
    }
    elseif ($entity_type->isTranslatable() && $entity_type->getDataTable() != $original->getDataTable()) {
      $changes[] = static::DATA_TABLE_RENAME;
    }

    if ($entity_type->isRevisionable() && $entity_type->isTranslatable()) {
      if ($revision_add || $translation_add) {
        $changes[] = static::REVISION_DATA_TABLE_ADDITION;
      }
      elseif ($entity_type->getRevisionDataTable() != $original->getRevisionDataTable()) {
        $changes[] = static::REVISION_DATA_TABLE_RENAME;
      }
    }
    elseif ($original->isRevisionable() && $original->isTranslatable() && ($revision_remove || $translation_remove)) {
      $changes[] = static::REVISION_DATA_TABLE_REMOVAL;
    }

    // Stop here if no changes are needed.     if (empty($changes)) {
      return;
    }

    
Home | Imprint | This part of the site doesn't use cookies.