You are here

public function DrupalCommerceEntityController::delete in Commerce Core 7

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

4 calls to DrupalCommerceEntityController::delete()
CommerceCustomerProfileEntityController::delete in modules/customer/includes/commerce_customer_profile.controller.inc
Deletes multiple customer profiles by ID.
CommerceLineItemEntityController::delete in modules/line_item/includes/commerce_line_item.controller.inc
Delete permanently saved line items.
CommerceOrderEntityController::delete in modules/order/includes/commerce_order.controller.inc
Deletes multiple orders by ID.
CommerceProductEntityController::delete in modules/product/includes/commerce_product.controller.inc
Deletes multiple products by ID.
4 methods override DrupalCommerceEntityController::delete()
CommerceCustomerProfileEntityController::delete in modules/customer/includes/commerce_customer_profile.controller.inc
Deletes multiple customer profiles by ID.
CommerceLineItemEntityController::delete in modules/line_item/includes/commerce_line_item.controller.inc
Delete permanently saved line items.
CommerceOrderEntityController::delete in modules/order/includes/commerce_order.controller.inc
Deletes multiple orders by ID.
CommerceProductEntityController::delete in modules/product/includes/commerce_product.controller.inc
Deletes multiple products by ID.

File

includes/commerce.controller.inc, line 158
Provides a central controller for Drupal Commerce.

Class

DrupalCommerceEntityController
Default implementation of DrupalCommerceEntityControllerInterface.

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