/**
  * Method processAction to execute the action
  *
  * @param CRM_Civirules_TriggerData_TriggerData $triggerData
  * @access public
  *
  */
 public function processAction(CRM_Civirules_TriggerData_TriggerData $triggerData)
 {
     $contactId = $triggerData->getContactId();
     //we cannot delete domain contacts
     if (CRM_Contact_BAO_Contact::checkDomainContact($contactId)) {
         return;
     }
     CRM_Contact_BAO_Contact::deleteContact($contactId);
 }
Exemplo n.º 2
0
 /**
  * @param bool $useWhere
  *
  * @return mixed|void
  */
 public function delete($useWhere = FALSE)
 {
     $this->load_associations();
     $contacts_to_delete = array();
     foreach ($this->participants as $participant) {
         $defaults = array();
         $params = array('id' => $participant->contact_id);
         $temporary_contact = CRM_Contact_BAO_Contact::retrieve($params, $defaults);
         if ($temporary_contact->is_deleted) {
             $contacts_to_delete[$temporary_contact->id] = 1;
         }
         $participant->delete();
     }
     foreach (array_keys($contacts_to_delete) as $contact_id) {
         CRM_Contact_BAO_Contact::deleteContact($contact_id);
     }
     return parent::delete();
 }
Exemplo n.º 3
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  *
  * @return void
  */
 public function postProcess()
 {
     $session = CRM_Core_Session::singleton();
     $currentUserId = $session->get('userID');
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, FALSE, 'basic');
     $urlParams = 'force=1';
     $urlString = "civicrm/contact/search/{$context}";
     if (CRM_Utils_Rule::qfKey($this->_searchKey)) {
         $urlParams .= "&qfKey={$this->_searchKey}";
     } elseif ($context == 'search') {
         $urlParams .= "&qfKey={$this->controller->_key}";
         $urlString = 'civicrm/contact/search';
     } elseif ($context == 'smog') {
         $urlParams .= "&qfKey={$this->controller->_key}&context=smog";
         $urlString = 'civicrm/group/search';
     } else {
         $urlParams = "reset=1";
         $urlString = 'civicrm/dashboard';
     }
     // Delete/Restore Contacts. Report errors.
     $deleted = 0;
     $not_deleted = array();
     foreach ($this->_contactIds as $cid) {
         $name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $cid, 'display_name');
         if (CRM_Contact_BAO_Contact::checkDomainContact($cid)) {
             $session->setStatus(ts("'%1' cannot be deleted because the information is used for special system purposes.", array(1 => $name)), 'Cannot Delete Domain Contact', 'error');
             continue;
         }
         if ($currentUserId == $cid && !$this->_restore) {
             $session->setStatus(ts("You are currently logged in as '%1'. You cannot delete yourself.", array(1 => $name)), 'Unable To Delete', 'error');
             continue;
         }
         if (CRM_Contact_BAO_Contact::deleteContact($cid, $this->_restore, $this->_skipUndelete)) {
             $deleted++;
         } else {
             $url = CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$cid}");
             $not_deleted[$cid] = "<a href='{$url}'>{$name}</a>";
         }
     }
     if ($deleted) {
         $title = ts('Deleted');
         if ($this->_restore) {
             $title = ts('Restored');
             $status = ts('%1 has been restored from the trash.', array(1 => $name, 'plural' => '%count contacts restored from trash.', 'count' => $deleted));
         } elseif ($this->_skipUndelete) {
             $status = ts('%1 has been permanently deleted.', array(1 => $name, 'plural' => '%count contacts permanently deleted.', 'count' => $deleted));
         } else {
             $status = ts('%1 has been moved to the trash.', array(1 => $name, 'plural' => '%count contacts moved to trash.', 'count' => $deleted));
         }
         $session->setStatus($status, $title, 'success');
     }
     // Alert user of any failures
     if ($not_deleted) {
         $status = ts('The contact might be the Membership Organization of a Membership Type. You will need to edit the Membership Type and change the Membership Organization before you can delete this contact.');
         $title = ts('Unable to Delete');
         $session->setStatus('<ul><li>' . implode('</li><li>', $not_deleted) . '</li></ul>' . $status, $title, 'error');
     }
     if (isset($this->_sharedAddressMessage) && $this->_sharedAddressMessage['count'] > 0 && !$this->_restore) {
         if (count($this->_sharedAddressMessage['contactList']) == 1) {
             $message = ts('The following contact had been sharing an address with a contact you just deleted. Their address will no longer be shared, but has not been removed or altered.');
         } else {
             $message = ts('The following contacts had been sharing addresses with a contact you just deleted. Their addressses will no longer be shared, but have not been removed or altered.');
         }
         $message .= '<ul><li>' . implode('</li><li>', $this->_sharedAddressMessage['contactList']) . '</li></ul>';
         $session->setStatus($message, ts('Shared Addesses Owner Deleted'), 'info', array('expires' => 0));
         $this->set('sharedAddressMessage', NULL);
     }
     if ($this->_single && empty($this->_skipUndelete)) {
         $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactIds[0]}"));
     } else {
         $session->replaceUserContext(CRM_Utils_System::url($urlString, $urlParams));
     }
 }
Exemplo n.º 4
0
/**
 * Delete a Contact with given contact_id.
 *
 * @param array $params
 *   input parameters per getfields
 *
 * @throws \Civi\API\Exception\UnauthorizedException
 * @return array
 *   API Result Array
 */
function civicrm_api3_contact_delete($params)
{
    $contactID = CRM_Utils_Array::value('id', $params);
    if (!empty($params['check_permissions']) && !CRM_Contact_BAO_Contact_Permission::allow($contactID, CRM_Core_Permission::DELETE)) {
        throw new \Civi\API\Exception\UnauthorizedException('Permission denied to modify contact record');
    }
    $session = CRM_Core_Session::singleton();
    if ($contactID == $session->get('userID')) {
        return civicrm_api3_create_error('This contact record is linked to the currently logged in user account - and cannot be deleted.');
    }
    $restore = !empty($params['restore']) ? $params['restore'] : FALSE;
    $skipUndelete = !empty($params['skip_undelete']) ? $params['skip_undelete'] : FALSE;
    // CRM-12929
    // restrict permanent delete if a contact has financial trxn associated with it
    $error = NULL;
    if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($contactID), $error)) {
        return civicrm_api3_create_error($error['_qf_default']);
    }
    if (CRM_Contact_BAO_Contact::deleteContact($contactID, $restore, $skipUndelete, CRM_Utils_Array::value('check_permissions', $params))) {
        return civicrm_api3_create_success();
    } else {
        return civicrm_api3_create_error('Could not delete contact');
    }
}
/**
 * Delete a contact with given contact id
 *
 * @param  array   	  $params (reference ) input parameters, contact_id element required
 *
 * @return boolean        true if success, else false
 * @static void
 * @access public
 */
function civicrm_contact_delete(&$params)
{
    require_once 'CRM/Contact/BAO/Contact.php';
    $contactID = CRM_Utils_Array::value('contact_id', $params);
    if (!$contactID) {
        return civicrm_create_error(ts('Could not find contact_id in input parameters'));
    }
    $session = CRM_Core_Session::singleton();
    if ($contactID == $session->get('userID')) {
        return civicrm_create_error(ts('This contact record is linked to the currently logged in user account - and cannot be deleted.'));
    }
    $restore = CRM_Utils_Array::value('restore', $params) ? $params['restore'] : FALSE;
    $skipUndelete = CRM_Utils_Array::value('skip_undelete', $params) ? $params['skip_undelete'] : FALSE;
    if (CRM_Contact_BAO_Contact::deleteContact($contactID, $restore, $skipUndelete)) {
        return civicrm_create_success();
    } else {
        return civicrm_create_error(ts('Could not delete contact'));
    }
}
Exemplo n.º 6
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $session = CRM_Core_Session::singleton();
     $currentUserId = $session->get('userID');
     $context = CRM_Utils_Request::retrieve('context', 'String', $this, false, 'basic');
     $urlParams = 'force=1';
     if (CRM_Utils_Rule::qfKey($this->_searchKey)) {
         $urlParams .= "&qfKey={$this->_searchKey}";
     } elseif ($context == 'search') {
         $urlParams .= "&qfKey={$this->controller->_key}";
     }
     $urlString = "civicrm/contact/search/{$context}";
     if ($context == 'search') {
         $urlString = 'civicrm/contact/search';
     }
     $selfDelete = false;
     $deletedContacts = 0;
     foreach ($this->_contactIds as $contactId) {
         if ($currentUserId == $contactId) {
             $selfDelete = true;
             continue;
         }
         if (CRM_Contact_BAO_Contact::deleteContact($contactId, $this->_restore, $this->_skipUndelete)) {
             $deletedContacts++;
         }
     }
     if (!$this->_single) {
         $label = $this->_restore ? ts('Restored Contact(s): %1', array(1 => $deletedContacts)) : ts('Deleted Contact(s): %1', array(1 => $deletedContacts));
         $status = array($label, ts('Total Selected Contact(s): %1', array(1 => count($this->_contactIds))));
         if ($selfDelete) {
             $display_name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $currentUserId, 'display_name');
             $status[] = ts('The contact record which is linked to the currently logged in user account - \'%1\' - cannot be deleted.', array(1 => $display_name));
         }
     } else {
         if ($deletedContacts) {
             $session->replaceUserContext(CRM_Utils_System::url($urlString, $urlParams));
             if ($this->_restore) {
                 $status = ts('Selected contact was restored sucessfully.');
                 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactIds[0]}"));
             } else {
                 $status = ts('Selected contact was deleted sucessfully.');
             }
         } else {
             $status = array(ts('Selected contact cannot be deleted.'));
             if ($selfDelete) {
                 $display_name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $currentUserId, 'display_name');
                 $status[] = ts('This contact record is linked to the currently logged in user account - \'%1\' - and cannot be deleted.', array(1 => $display_name));
             } else {
                 $status[] = ts('The contact might be the Membership Organization of a Membership Type. You will need to edit the Membership Type and change the Membership Organization before you can delete this contact.');
             }
         }
     }
     if (isset($this->_sharedAddressMessage) && $this->_sharedAddressMessage['count'] > 0 && !$this->_restore) {
         if (count($this->_contactIds) > 1) {
             $sharedAddressMessage = ts('The following contact(s) have address records which were shared with the address you removed from selected contacts. These address records are no longer shared - but they have not been removed or altered.') . '<br>' . implode('<br>', $this->_sharedAddressMessage['contactList']);
         } else {
             $sharedAddressMessage = ts('The following contact(s) have address records which were shared with the address you removed from this contact. These address records are no longer shared - but they have not been removed or altered.') . '<br>' . implode('<br>', $this->_sharedAddressMessage['contactList']);
         }
         if (is_array($status)) {
             $status[] = $sharedAddressMessage;
         } else {
             $status .= $sharedAddressMessage;
         }
         $this->set('sharedAddressMessage', null);
     }
     CRM_Core_Session::setStatus($status);
     $session->replaceUserContext(CRM_Utils_System::url($urlString, $urlParams));
 }
Exemplo n.º 7
0
/**
 * Delete a contact with given contact id
 *
 * @param  array   	  $params (reference ) input parameters, contact_id element required
 *
 * @return boolean        true if success, else false
 * @static void
 * @access public
 */
function civicrm_contact_delete(&$params)
{
    require_once 'CRM/Contact/BAO/Contact.php';
    $contactID = CRM_Utils_Array::value('contact_id', $params);
    if (!$contactID) {
        return civicrm_create_error(ts('Could not find contact_id in input parameters'));
    }
    if (CRM_Contact_BAO_Contact::deleteContact($contactID)) {
        return civicrm_create_success();
    } else {
        return civicrm_create_error(ts('Could not delete contact'));
    }
}
Exemplo n.º 8
0
 /**
  * Helper function to delete a contact
  *
  * @param  int  $contactID   id of the contact to delete
  * @return boolean true if contact deleted, false otherwise
  */
 static function delete($contactID)
 {
     require_once 'CRM/Contact/BAO/Contact.php';
     return CRM_Contact_BAO_Contact::deleteContact($contactID);
 }
Exemplo n.º 9
0
 function delete($contactID)
 {
     return CRM_Contact_BAO_Contact::deleteContact($contactID);
 }
Exemplo n.º 10
0
 /**
  * Function to delete Gender 
  * 
  * @param int $genderId  ID of the gender to be deleted.
  * 
  * @return boolean true if success, false otherwise
  * 
  * @access public
  * @static
  */
 function del($genderId)
 {
     //check dependencies
     require_once 'CRM/Contact/DAO/Individual.php';
     require_once 'CRM/Contact/BAO/Contact.php';
     $deleteContactId = array();
     $session =& CRM_Core_Session::singleton();
     $currentUserId = $session->get('userID');
     $individual =& new CRM_Contact_DAO_Individual();
     $individual->gender_id = $genderId;
     $individual->find();
     while ($individual->fetch()) {
         $contactId = $individual->contact_id;
         if ($currentUserId != $contactId) {
             $deleteContactId[] = $contactId;
         } else {
             return false;
         }
     }
     foreach ($deleteContactId as $cid) {
         CRM_Contact_BAO_Contact::deleteContact($cid);
     }
     $gender =& new CRM_Core_DAO_Gender();
     $gender->id = $genderId;
     $gender->delete();
     return true;
 }
Exemplo n.º 11
0
/**
 * Delete a contact with given contact id
 *
 * @param  array       $params (reference ) input parameters, contact_id element required
 *
 * @return array API Result Array
 * @access public
 *
 * @example ContactDelete.php
 * {@getfields contact_delete}
 */
function civicrm_api3_contact_delete($params)
{
    $contactID = CRM_Utils_Array::value('id', $params);
    $session = CRM_Core_Session::singleton();
    if ($contactID == $session->get('userID')) {
        return civicrm_api3_create_error('This contact record is linked to the currently logged in user account - and cannot be deleted.');
    }
    $restore = CRM_Utils_Array::value('restore', $params) ? $params['restore'] : FALSE;
    $skipUndelete = CRM_Utils_Array::value('skip_undelete', $params) ? $params['skip_undelete'] : FALSE;
    // CRM-12929
    // restrict permanent delete if a contact has financial trxn associated with it
    $error = NULL;
    if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($contactID), $error)) {
        return civicrm_api3_create_error($error['_qf_default']);
    }
    if (CRM_Contact_BAO_Contact::deleteContact($contactID, $restore, $skipUndelete)) {
        return civicrm_api3_create_success();
    } else {
        return civicrm_api3_create_error('Could not delete contact');
    }
}
Exemplo n.º 12
0
 public function testFindById()
 {
     $params = $this->sampleContact('Individual', 4);
     $existing_contact = CRM_Contact_BAO_Contact::add($params);
     $contact = CRM_Contact_BAO_Contact::findById($existing_contact->id);
     $this->assertEquals($existing_contact->id, $contact->id);
     $deleted_contact_id = $existing_contact->id;
     CRM_Contact_BAO_Contact::deleteContact($contact->id, FALSE, TRUE);
     $exception_thrown = FALSE;
     try {
         $deleted_contact = CRM_Contact_BAO_Contact::findById($deleted_contact_id);
     } catch (Exception $e) {
         $exception_thrown = TRUE;
     }
     $this->assertTrue($exception_thrown);
 }
Exemplo n.º 13
0
/**
 * Delete a specified contact.
 *
 * <b>Versioning and Un-delete</b>
 *
 * <ul>
 * <li>CRM will implement a 'Versioning' utility which will include
 * structural support for 'un-delete' operations. The API and UI
 * interfaces for 'un-delete' will probably be available in v1.x.</li>
 * </ul>
 *
 * @param CRM_Contact $contact Contact object to be deleted
 *
 * @return void|CRM_Core_Error  An error if 'contact' is invalid,
 *                         permissions are insufficient, etc.
 *
 * @access public
 *
 */
function crm_delete_contact(&$contact)
{
    _crm_initialize();
    if (!isset($contact->id) || !isset($contact->contact_type)) {
        return _crm_error('Invalid contact object passed in');
    }
    CRM_Contact_BAO_Contact::deleteContact($contact->id);
}
Exemplo n.º 14
0
 /**
  * test case for deleteContact( )
  */
 function testDeleteContact()
 {
     $contactParams = $this->contactParams();
     //create contact
     require_once 'CRM/Contact/BAO/Contact.php';
     $contact = CRM_Contact_BAO_Contact::create($contactParams);
     $contactId = $contact->id;
     //delete contact.
     CRM_Contact_BAO_Contact::deleteContact($contactId);
     //Now check DB for location elements.
     //Now check DB for Address
     $this->assertDBNull('CRM_Core_DAO_Address', CRM_Utils_Array::value('street_address', $contactParams['address'][1]), 'id', 'street_address', 'Database check, Address deleted successfully.');
     //Now check DB for Email
     $this->assertDBNull('CRM_Core_DAO_Email', CRM_Utils_Array::value('email', $contactParams['email'][1]), 'id', 'email', 'Database check, Email deleted successfully.');
     //Now check DB for Phone
     $this->assertDBNull('CRM_Core_DAO_Phone', CRM_Utils_Array::value('phone', $contactParams['phone'][1]), 'id', 'phone', 'Database check, Phone deleted successfully.');
     //Now check DB for Mobile
     $this->assertDBNull('CRM_Core_DAO_Phone', CRM_Utils_Array::value('phone', $contactParams['phone'][2]), 'id', 'phone', 'Database check, Mobile deleted successfully.');
     //Now check DB for IM
     $this->assertDBNull('CRM_Core_DAO_IM', CRM_Utils_Array::value('name', $contactParams['im'][1]), 'id', 'name', 'Database check, IM deleted successfully.');
     //Now check DB for openId
     $this->assertDBNull('CRM_Core_DAO_OpenID', CRM_Utils_Array::value('openid', $contactParams['openid'][1]), 'id', 'name', 'Database check, openId deleted successfully.');
     require_once 'CRM/Core/BAO/CustomValueTable.php';
     // Check that the custom field value is no longer present
     $params = array('entityID' => $contactId, 'custom_' . $fieldID => 1);
     $values = CRM_Core_BAO_CustomValueTable::getValues($params);
     $this->assertEquals(CRM_Utils_Array::value("custom_{$fieldID}", $values), '', 'Verify that the data value is empty for contact ' . $contactId);
     $this->assertEquals($values['is_error'], 1, 'Verify that is_error = 0 (success).');
     //Now check DB for contact.
     $this->assertDBNull('CRM_Contact_DAO_Contact', $contactParams['last_name'] . ', ' . $contactParams['first_name'], 'id', 'sort_name', 'Database check, contact deleted successfully.');
 }
Exemplo n.º 15
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 public function postProcess()
 {
     $session =& CRM_Core_Session::singleton();
     $currentUserId = $session->get('userID');
     $selfDelete = false;
     $deletedContacts = 0;
     foreach ($this->_contactIds as $contactId) {
         if ($currentUserId == $contactId) {
             $selfDelete = true;
             continue;
         }
         if (CRM_Contact_BAO_Contact::deleteContact($contactId)) {
             $deletedContacts++;
         }
     }
     if (!$this->_single) {
         $status = array();
         $status = array(ts('Deleted Contact(s): %1', array(1 => $deletedContacts)), ts('Total Selected Contact(s): %1', array(1 => count($this->_contactIds))));
         if ($selfDelete) {
             $display_name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $currentUserId, 'display_name');
             $status[] = ts('The contact record which is linked to the currently logged in user account - \'%1\' - cannot be deleted.', array(1 => $display_name));
         }
     } else {
         if ($deletedContacts) {
             $isAdvanced = $session->get('isAdvanced');
             $isSearchBuilder = $session->get('isSearchBuilder');
             if ($isAdvanced == 1) {
                 $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/search/advanced', 'force=1'));
             } else {
                 if ($isAdvanced == 2 && $isSearchBuilder == 1) {
                     $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/search/builder', 'force=1'));
                 } else {
                     $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/search/basic', 'force=1'));
                 }
             }
             $status = ts('Selected contact was deleted sucessfully.');
         } else {
             $status = array(ts('Selected contact cannot be deleted.'));
             if ($selfDelete) {
                 $display_name = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $currentUserId, 'display_name');
                 $status[] = ts('This contact record is linked to the currently logged in user account - \'%1\' - and cannot be deleted.', array(1 => $display_name));
             } else {
                 $status[] = ts('The contact might be the Membership Organization of a Membership Type. You will need to edit the Membership Type and change the Membership Organization before you can delete this contact.');
             }
         }
     }
     CRM_Core_Session::setStatus($status);
 }
Exemplo n.º 16
0
 /**
  * Update the contact with subtype to another valid subtype.
  * success expected
  */
 public function testUpdateContactSubtype()
 {
     $params = array('first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', 'contact_sub_type' => $this->student);
     try {
         $contact = CRM_Contact_BAO_Contact::add($params);
     } catch (Exception $expected) {
     }
     $updateParams = array('contact_sub_type' => $this->parent, 'contact_type' => 'Individual', 'contact_id' => $contact->id);
     try {
         $updatedContact = CRM_Contact_BAO_Contact::add($updateParams);
     } catch (Exception $expected) {
     }
     $this->assertEquals($updatedContact->id, $contact->id);
     $this->assertEquals($updatedContact->contact_type, 'Individual');
     $this->assertEquals(str_replace(CRM_Core_DAO::VALUE_SEPARATOR, '', $updatedContact->contact_sub_type), $this->parent);
     CRM_Contact_BAO_Contact::deleteContact($contact->id);
     $params = array('organization_name' => 'Compumentor', 'contact_type' => 'Organization', 'contact_sub_type' => $this->sponsor);
     try {
         $contact = CRM_Contact_BAO_Contact::add($params);
     } catch (Exception $expected) {
     }
     $updateParams = array('contact_sub_type' => $this->team, 'contact_type' => 'Organization', 'contact_id' => $contact->id);
     try {
         $updatedContact = CRM_Contact_BAO_Contact::add($updateParams);
     } catch (Exception $expected) {
     }
     $this->assertEquals($updatedContact->id, $contact->id);
     $this->assertEquals($updatedContact->contact_type, 'Organization');
     $this->assertEquals(str_replace(CRM_Core_DAO::VALUE_SEPARATOR, '', $updatedContact->contact_sub_type), $this->team);
     CRM_Contact_BAO_Contact::deleteContact($contact->id);
     $params = array('first_name' => 'Anne', 'last_name' => 'Grant', 'contact_type' => 'Individual', 'contact_sub_type' => $this->student);
     try {
         $contact = CRM_Contact_BAO_Contact::add($params);
     } catch (Exception $expected) {
     }
     $updateParams = array('contact_sub_type' => NULL, 'contact_type' => 'Individual', 'contact_id' => $contact->id);
     try {
         $updatedContact = CRM_Contact_BAO_Contact::add($updateParams);
     } catch (Exception $expected) {
     }
     $this->assertEquals($updatedContact->id, $contact->id);
     $this->assertEquals($updatedContact->contact_type, 'Individual');
     $this->assertEquals($updatedContact->contact_sub_type, 'null');
     CRM_Contact_BAO_Contact::deleteContact($contact->id);
 }
Exemplo n.º 17
0
 /**
  * Test case for deleteContact( ).
  */
 public function testDeleteContact()
 {
     $contactParams = $this->contactParams();
     $customGroup = $this->customGroupCreate();
     $fields = array('label' => 'testFld', 'data_type' => 'String', 'html_type' => 'Text', 'custom_group_id' => $customGroup['id']);
     $customField = CRM_Core_BAO_CustomField::create($fields);
     $contactParams['custom'] = array($customField->id => array(-1 => array('value' => 'Test custom value', 'type' => 'String', 'custom_field_id' => $customField->id, 'custom_group_id' => $customGroup['id'], 'table_name' => $customGroup['values'][$customGroup['id']]['table_name'], 'column_name' => $customField->column_name, 'file_id' => NULL)));
     //create contact
     $contact = CRM_Contact_BAO_Contact::create($contactParams);
     $contactId = $contact->id;
     //delete contact permanently.
     CRM_Contact_BAO_Contact::deleteContact($contactId, FALSE, TRUE);
     //Now check DB for location elements.
     //Now check DB for Address
     $this->assertDBNull('CRM_Core_DAO_Address', $contactId, 'id', 'street_address', 'Database check, Address deleted successfully.');
     //Now check DB for Email
     $this->assertDBNull('CRM_Core_DAO_Email', $contactId, 'id', 'email', 'Database check, Email deleted successfully.');
     //Now check DB for Phone
     $this->assertDBNull('CRM_Core_DAO_Phone', $contactId, 'id', 'phone', 'Database check, Phone deleted successfully.');
     //Now check DB for Mobile
     $this->assertDBNull('CRM_Core_DAO_Phone', $contactId, 'id', 'phone', 'Database check, Mobile deleted successfully.');
     //Now check DB for IM
     $this->assertDBNull('CRM_Core_DAO_IM', $contactId, 'id', 'name', 'Database check, IM deleted successfully.');
     //Now check DB for openId
     $this->assertDBNull('CRM_Core_DAO_OpenID', $contactId, 'id', 'openid', 'Database check, openId deleted successfully.');
     // Check that the custom field value is no longer present
     $params = array('entityID' => $contactId, 'custom_' . $customField->id => 1);
     $values = CRM_Core_BAO_CustomValueTable::getValues($params);
     $this->assertEquals(CRM_Utils_Array::value("custom_" . $customField->id, $values), '', 'Verify that the data value is empty for contact ' . $contactId);
     $this->assertEquals($values['is_error'], 1, 'Verify that is_error = 0 (success).');
     //Now check DB for contact.
     $this->assertDBNull('CRM_Contact_DAO_Contact', $contactId, 'id', 'sort_name', 'Database check, contact deleted successfully.');
     $this->quickCleanup(array('civicrm_contact', 'civicrm_note'));
     $this->customGroupDelete($customGroup['id']);
 }
Exemplo n.º 18
0
 /**
  * process the form after the input has been submitted and validated
  *
  * @access public
  * @return None
  */
 function postProcess()
 {
     $session =& CRM_Core_Session::singleton();
     $currentUserId = $session->get('userID');
     $selfDelete = false;
     $deletedContacts = 0;
     foreach ($this->_contactIds as $contactId) {
         if ($currentUserId == $contactId) {
             $selfDelete = true;
             continue;
         }
         if (CRM_Contact_BAO_Contact::deleteContact($contactId)) {
             $deletedContacts++;
         }
     }
     if (!$this->_single) {
         $status = array();
         $status = array(ts('Deleted Contact(s): %1', array(1 => $deletedContacts)), ts('Total Selected Contact(s): %1', array(1 => count($this->_contactIds))));
         if ($selfDelete) {
             $display_name = CRM_Contact_BAO_Contact::displayName($currentUserId);
             $status[] = ts('The contact record which is linked to the currently logged in user account - "%1" - can not be deleted.', array(1 => $display_name));
         }
     } else {
         if ($deletedContacts) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/search', 'force=1'));
             $status = ts('Selected contact was deleted sucessfully.');
         } else {
             $status = array(ts('Selected contact cannot be deleted.'));
             if ($selfDelete) {
                 $display_name = CRM_Contact_BAO_Contact::displayName($currentUserId);
                 $status[] = ts('This contact record is linked to the currently logged in user account - "%1" - and can not be deleted.', array(1 => $display_name));
             }
         }
     }
     CRM_Core_Session::setStatus($status);
 }