public function RedhenContactEntityController::delete in RedHen CRM 7
Deletes multiple contacts by ID.
Parameters
array $contact_ids: An array of contact IDs to delete.
Return value
bool TRUE on success, FALSE otherwise.
Overrides EntityAPIController::delete
File
- modules/
redhen_contact/ lib/ redhen_contact.controller.inc, line 69 - The controller for the contact entity containing the CRUD operations.
Class
- RedhenContactEntityController
- The controller class for contacts.
Code
public function delete($contact_ids, DatabaseTransaction $transaction = NULL) {
if (!empty($contact_ids)) {
$contacts = $this
->load($contact_ids, array());
// Ensure the contacts can actually be deleted.
foreach ((array) $contacts as $contact_id => $contact) {
if (in_array(FALSE, module_invoke_all('redhen_contact_can_delete', $contact))) {
unset($contacts[$contact_id]);
}
else {
module_invoke_all('redhen_entity_predelete', $contact, 'redhen_contact');
}
}
// If none of the specified contacts can be deleted, return FALSE.
if (empty($contacts)) {
return FALSE;
}
else {
$contact_ids = array_keys($contacts);
}
$transaction = db_transaction();
try {
parent::delete($contact_ids, $transaction);
// Delete user connections.
db_delete('redhen_contact_user')
->condition('contact_id', $contact_ids, 'IN')
->execute();
} catch (Exception $e) {
if (isset($transaction)) {
$transaction
->rollback();
}
watchdog_exception($this->entityType, $e);
throw $e;
}
}
return TRUE;
}