DrupalCommerceEntityController::delete

  1. commerce
    1. 7
Versions
7 public DrupalCommerceEntityController::delete($ids, DatabaseTransaction $transaction = NULL)

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.

Code

includes/commerce.controller.inc, line 85

<?php
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;
  }
}
?>