You are here

protected function AcsfDuplicationScrubCommentStorage::doDeleteFieldItemsById in Acquia Cloud Site Factory Connector 8

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

Deletes entity field values from the storage.

This is a near copy of SqlContentEntityStorage::doDeleteFieldItems() except it takes ids as argument instead of entities.

Parameters

array $ids: The entity ids.

1 call to AcsfDuplicationScrubCommentStorage::doDeleteFieldItemsById()
AcsfDuplicationScrubCommentStorage::deleteOrphanedItems in src/Event/AcsfDuplicationScrubCommentStorage.php
Deletes orphaned comments without having to load the full entities first.

File

src/Event/AcsfDuplicationScrubCommentStorage.php, line 178

Class

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

Namespace

Drupal\acsf\Event

Code

protected function doDeleteFieldItemsById(array $ids) {
  $this->database
    ->delete($this->entityType
    ->getBaseTable())
    ->condition($this->idKey, $ids, 'IN')
    ->execute();
  if ($this->revisionTable) {
    $this->database
      ->delete($this->revisionTable)
      ->condition($this->idKey, $ids, 'IN')
      ->execute();
  }
  if ($this->dataTable) {
    $this->database
      ->delete($this->dataTable)
      ->condition($this->idKey, $ids, 'IN')
      ->execute();
  }
  if ($this->revisionDataTable) {
    $this->database
      ->delete($this->revisionDataTable)
      ->condition($this->idKey, $ids, 'IN')
      ->execute();
  }

  // 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, ->getBundleInfo() is reachable through
  //   ContentEntityStorageBase -> entityManager -> entityTypeBundleInfo;
  // - starting with Drupal 8.7 ->getBundleInfo() is reachable through
  //   ContentEntityStorageBase -> entityTypeBundleInfo.
  // 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.
  $entityTypeBundleInfo = $this->entityTypeBundleInfo ?: \Drupal::service('entity_type.bundle.info');

  // Delete as many dedicated field tables as we can find. This is slightly
  // different from the original: since we don't know the original entities'
  // bundles, we loop through all bundles that exist for a comment.
  foreach (array_keys($entityTypeBundleInfo
    ->getBundleInfo('comment')) as $bundle) {
    $this
      ->deleteFromDedicatedTablesById($ids, $bundle);
  }
}