public function DatabaseStorageControllerNG::delete

Overwrites \Drupal\Core\Entity\DatabaseStorageController::delete().

Overrides DatabaseStorageController::delete

File

drupal/core/lib/Drupal/Core/Entity/DatabaseStorageControllerNG.php, line 591
Contains \Drupal\Core\Entity\DatabaseStorageControllerNG.

Class

DatabaseStorageControllerNG
Implements Field API specific enhancements to the DatabaseStorageController class.

Namespace

Drupal\Core\Entity

Code

public function delete(array $entities) {
  if (!$entities) {

    // If no IDs or invalid IDs were passed, do nothing.
    return;
  }
  $transaction = $this->database
    ->startTransaction();
  try {

    // Ensure we are dealing with the actual entities.
    foreach ($entities as $id => $entity) {
      $entities[$id] = $entity
        ->getNGEntity();
    }
    $this
      ->preDelete($entities);
    foreach ($entities as $id => $entity) {
      $this
        ->invokeHook('predelete', $entity);
    }
    $ids = array_keys($entities);
    $this->database
      ->delete($this->entityInfo['base_table'])
      ->condition($this->idKey, $ids)
      ->execute();
    if ($this->revisionKey) {
      $this->database
        ->delete($this->revisionTable)
        ->condition($this->idKey, $ids)
        ->execute();
    }
    if ($this->dataTable) {
      $this->database
        ->delete($this->dataTable)
        ->condition($this->idKey, $ids)
        ->execute();
    }

    // Reset the cache as soon as the changes have been applied.
    $this
      ->resetCache($ids);
    $this
      ->postDelete($entities);
    foreach ($entities as $id => $entity) {
      $this
        ->invokeHook('delete', $entity);
    }

    // Ignore slave server temporarily.
    db_ignore_slave();
  } catch (\Exception $e) {
    $transaction
      ->rollback();
    watchdog_exception($this->entityType, $e);
    throw new EntityStorageException($e
      ->getMessage(), $e
      ->getCode(), $e);
  }
}