public function TripalEntityController::delete

3.x TripalEntityController.inc public TripalEntityController::delete($ids, $transaction = NULL)

Overrides EntityAPIController::delete().

Parameters

array $ids: An array of the ids denoting which entities to delete.

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

File

tripal/includes/TripalEntityController.inc, line 64

Class

TripalEntityController
TripalEntityController extends DrupalDefaultEntityController.

Code

public function delete($ids, $transaction = NULL) {

  if (!$transaction) {
    $transaction = db_transaction();
  }

  try {
    // First load the entity.
    $entities = entity_load('TripalEntity', $ids);

    // Then properly delete each one.
    foreach ($entities as $entity) {

      // Invoke hook_entity_delete().
      module_invoke_all('entity_delete', $entity, $entity->type);

      // Delete any field data for this entity.
      field_attach_delete('TripalEntity', $entity);

      // Delete the entity record from our base table.
      db_delete('tripal_entity')
        ->condition('id', $entity->id)
        ->execute();
    }
  }
  catch (Exception $e) {
    $transaction->rollback();
    watchdog_exception('tripal', $e);
    throw $e;
    return FALSE;
  }

  return TRUE;
}