You are here

public function RedhenContactEntityController::deleteUser in RedHen CRM 7

Delete or unlink the active user for a contact.

Parameters

RedhenContact $contact: RedHen contact object.

bool $delete: If true, the connection is deleted and can be recreated. False sets the connection to inactive which will prevent it from being reconnected on subsequent attempts.

Return value

bool TRUE if user is successfully deleted or unlinked from contact.

File

modules/redhen_contact/lib/redhen_contact.controller.inc, line 242
The controller for the contact entity containing the CRUD operations.

Class

RedhenContactEntityController
The controller class for contacts.

Code

public function deleteUser(RedhenContact $contact, $delete = FALSE, DatabaseTransaction $transaction = NULL) {
  try {
    $wrapper = entity_metadata_wrapper('redhen_contact', $contact);
    $user = $wrapper->user
      ->value();
    if ($delete) {
      db_delete('redhen_contact_user')
        ->condition('contact_id', $contact->contact_id)
        ->condition('uid', $user->uid)
        ->execute();
    }
    else {
      db_update('redhen_contact_user')
        ->condition('contact_id', $contact->contact_id)
        ->condition('uid', $user->uid)
        ->fields(array(
        'status' => NULL,
      ))
        ->execute();
    }
    module_invoke_all('redhen_contact_user_update', 'delete', $contact);
    unset($contact->uid);
    return TRUE;
  } catch (Exception $e) {
    if (isset($transaction)) {
      $transaction
        ->rollback();
    }
    watchdog_exception($this->entityType, $e);
    throw $e;
  }
}