1.20.x entity.controller.inc public EntityDatabaseStorageController::delete($ids)

Implements EntityStorageControllerInterface::delete().

Overrides EntityStorageControllerInterface::delete

File

modules/entity/entity.controller.inc, line 603
Entity API controller classes and interface.

Class

EntityDatabaseStorageController
Implements the entity storage controller interface for the database.

Code

public function delete($ids) {
  $entities = $ids ? $this->load($ids) : FALSE;
  if (!$entities) {
    // If no IDs or invalid IDs were passed, do nothing.
    return;
  }
  $transaction = db_transaction();

  try {
    $this->preDelete($entities);
    foreach ($entities as $id => $entity) {
      $this->invokeHook('predelete', $entity);
    }
    $ids = array_keys($entities);

    db_delete($this->entityInfo['base table'])
      ->condition($this->idKey, $ids, 'IN')
      ->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(), (int) $e->getCode(), $e);
  }
}