You are here

public function CommerceFileLicenseEntityController::delete in Commerce File 7

Implements EntityAPIControllerInterface::delete(). Deletes multiple entities by ID.

Parameters

$ids: An array of entity IDs to delete.

$transaction: Optionally a DatabaseTransaction object to use. Allows overrides to pass in their transaction object.

Overrides EntityAPIController::delete

File

includes/commerce_file_license.controller.inc, line 114
The controller for the File License entity containing the CRUD operations.

Class

CommerceFileLicenseEntityController
@file The controller for the File License entity containing the CRUD operations.

Code

public function delete($ids, DatabaseTransaction $transaction = NULL) {
  if (empty($ids)) {
    return TRUE;
  }

  // load entities
  $entities = $this
    ->load($ids);
  if (empty($entities)) {
    return TRUE;
  }

  // initialize transaction db
  $transaction = isset($transaction) ? $transaction : db_transaction();

  // delete licenses
  try {
    parent::delete($ids, $transaction);
  } catch (Exception $e) {
    $transaction
      ->rollback();
    watchdog_exception($this->entityType, $e);
    throw $e;
  }

  // delete logs for the license ids

  /** @todo should we delete logs also ? *************************************/
  db_delete('commerce_file_license_log')
    ->condition($this->idKey, $ids, 'IN')
    ->execute();
  watchdog('commerce_file', 'Deleted file licenses: @ids.', array(
    '@ids' => implode(', ', $ids),
  ), WATCHDOG_NOTICE);
  return TRUE;
}