You are here

public function MerciDefaultEntityController::delete in MERCI (Manage Equipment Reservations, Checkout and Inventory) 7.3

Delete permanently saved entities.

In case of failures, an exception is thrown.

Parameters

$ids: An array of entity IDs.

$transaction: An optional transaction object to pass thru. If passed the caller is responsible for rolling back the transaction if something goes wrong.

Overrides EntityAPIControllerInterface::delete

1 call to MerciDefaultEntityController::delete()
MerciLineItemEntityControllerDeprecated::delete in merci_line_item/includes/merci_line_item.controller.inc
Delete permanently saved line items.
1 method overrides MerciDefaultEntityController::delete()
MerciLineItemEntityControllerDeprecated::delete in merci_line_item/includes/merci_line_item.controller.inc
Delete permanently saved line items.

File

merci_line_item/includes/merci_line_item.controller.inc, line 120
Provides a central controller for Drupal Commerce.

Class

MerciDefaultEntityController
@file Provides a central controller for Drupal Commerce.

Code

public function delete($ids, DatabaseTransaction $transaction = NULL) {
  $entities = $ids ? $this
    ->load($ids) : FALSE;
  if (!$entities) {

    // Do nothing, in case invalid or no ids have been passed.
    return;
  }
  if (!isset($transaction)) {
    $transaction = db_transaction();
    $started_transaction = TRUE;
  }
  try {
    db_delete($this->entityInfo['base table'])
      ->condition($this->idKey, array_keys($entities), 'IN')
      ->execute();
    if (!empty($this->revisionKey)) {
      db_delete($this->entityInfo['revision table'])
        ->condition($this->idKey, array_keys($entities), 'IN')
        ->execute();
    }

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

    // Ignore slave server temporarily.
    db_ignore_slave();
    return TRUE;
  } catch (Exception $e) {
    if (!empty($started_transaction)) {
      $transaction
        ->rollback();
      watchdog_exception($this->entityType, $e);
    }
    throw $e;
  }
}