You are here

protected function AcsfDuplicationScrubCommentStorage::deleteFromDedicatedTablesById in Acquia Cloud Site Factory Connector 8.2

Same name and namespace in other branches
  1. 8 src/Event/AcsfDuplicationScrubCommentStorage.php \Drupal\acsf\Event\AcsfDuplicationScrubCommentStorage::deleteFromDedicatedTablesById()

Deletes values of fields in dedicated tables for all revisions.

This is a lookalike of SqlContentEntityStorage::deleteFromDedicatedTables() which takes an array of ids + a bundle as arguments, instead of a single entity.

Parameters

array $ids: The entity ids.

string $bundle: A bundle id; must be an existing bundle for 'comment'.

1 call to AcsfDuplicationScrubCommentStorage::deleteFromDedicatedTablesById()
AcsfDuplicationScrubCommentStorage::doDeleteFieldItemsById in src/Event/AcsfDuplicationScrubCommentStorage.php
Deletes entity field values from the storage.

File

src/Event/AcsfDuplicationScrubCommentStorage.php, line 248

Class

AcsfDuplicationScrubCommentStorage
Comment storage class (using a SQL backend) which ignores load failures.

Namespace

Drupal\acsf\Event

Code

protected function deleteFromDedicatedTablesById(array $ids, $bundle) {
  $table_mapping = $this
    ->getTableMapping();

  // For backwards compatibility (Drupal >=8.5.0 and <8.7.0).
  // This class extends CommentStorage which extends SqlContentEntityStorage
  // which extends ContentEntityStorageBase:
  // - before Drupal 8.7.0, ->getFieldDefinitions() is reachable through
  //   ContentEntityStorageBase -> entityManager -> entityFieldManager;
  // - starting with Drupal 8.7.0 ->getFieldDefinitions() is reachable through
  //   ContentEntityStorageBase -> entityFieldManager.
  // The EntityManager class is deprecated; lately the purpose of this class
  // was only to delegate all method calls to the appropriate service.
  //
  // The complete removal of the EntityManager class will happen before
  // Drupal 9.0.0.
  // Although we noticed that in Drupal 8.7.0, core developers started ripping
  // off the usage of EntityManager from various entity classes, like:
  // -- CommentStorage.php
  // -- SqlContentEntityStorage.php
  // -- ContentEntityStorageBase.php
  // which, starting from Drupal 8.7.0 have the necessary service classes
  // properly injected.
  // @see https://www.drupal.org/project/drupal/issues/3025427
  // @see https://git.drupalcode.org/project/drupal/commit/81915a9
  // - the core commit which contains these changes.
  // Keep using EntityManager is not an option since it is deprecated, and for
  // Drupal versions >=8.5.0 and <8.7.0 we need to pull in the service in the
  // non-elegant way.
  $entityFieldManager = $this->entityFieldManager ?: \Drupal::service('entity_field.manager');
  foreach ($entityFieldManager
    ->getFieldDefinitions('comment', $bundle) as $field_definition) {

    /** @var \Drupal\Core\Field\FieldStorageDefinitionInterface $field_definition */
    $storage_definition = $field_definition
      ->getFieldStorageDefinition();
    if (!$table_mapping
      ->requiresDedicatedTableStorage($storage_definition)) {
      continue;
    }
    $table_name = $table_mapping
      ->getDedicatedDataTableName($storage_definition);
    $revision_name = $table_mapping
      ->getDedicatedRevisionTableName($storage_definition);
    $this->database
      ->delete($table_name)
      ->condition('entity_id', $ids, 'IN')
      ->execute();
    if ($this->entityType
      ->isRevisionable()) {
      $this->database
        ->delete($revision_name)
        ->condition('entity_id', $ids, 'IN')
        ->execute();
    }
  }
}