You are here

public function CivicrmEntityController::delete in CiviCRM Entity 7.2

Implements EntityAPIControllerInterface.

Parameters

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

Overrides EntityAPIController::delete

File

./civicrm_entity_controller.inc, line 231

Class

CivicrmEntityController
Entity Controller for CiviCRM entities

Code

public function delete($ids, DatabaseTransaction $transaction = NULL) {
  if (!civicrm_initialize()) {
    throw new Exception('civicrm inaccessible');
  }
  $entities = entity_load($this->entityType, $ids);
  if (count($entities)) {
    foreach ($ids as $id) {
      $params['version'] = 3;
      $params['id'] = $id;
      try {
        $entity = $entities[$id];
        $this
          ->invoke('predelete', $entity);
        $result = civicrm_api(substr($this->entityType, 8), 'delete', $params);
        if (!civicrm_error($result)) {
          field_attach_delete($this->entityType, $entity);

          // $this->invoke('delete', $entity);
          return;
        }
        throw new Exception($result['error_message']);
      } catch (Exception $e) {
        watchdog_exception($this->entityType, $e);
        throw $e;
      }
    }

    //end foreach id
  }
}