本文整理汇总了PHP中CRM_Core_DAO::freeResult方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_DAO::freeResult方法的具体用法?PHP CRM_Core_DAO::freeResult怎么用?PHP CRM_Core_DAO::freeResult使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_DAO
的用法示例。
在下文中一共展示了CRM_Core_DAO::freeResult方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteContact
//.........这里部分代码省略.........
*/
public static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE)
{
if (!$id) {
return FALSE;
}
// If trash is disabled in system settings then we always skip
if (!CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'contact_undelete', NULL, 1)) {
$skipUndelete = TRUE;
}
// make sure we have edit permission for this contact
// before we delete
if ($skipUndelete && !CRM_Core_Permission::check('delete contacts') || $restore && !CRM_Core_Permission::check('access deleted contacts')) {
return FALSE;
}
// CRM-12929
// Restrict contact to be delete if contact has financial trxns
$error = NULL;
if ($skipUndelete && CRM_Financial_BAO_FinancialItem::checkContactPresent(array($id), $error)) {
return FALSE;
}
// make sure this contact_id does not have any membership types
$membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id');
if ($membershipTypeID) {
return FALSE;
}
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $id;
if (!$contact->find(TRUE)) {
return FALSE;
}
$contactType = $contact->contact_type;
// currently we only clear employer cache.
// we are now deleting inherited membership if any.
if ($contact->contact_type == 'Organization') {
$action = $restore ? CRM_Core_Action::ENABLE : CRM_Core_Action::DISABLE;
$relationshipDtls = CRM_Contact_BAO_Relationship::getRelationship($id);
if (!empty($relationshipDtls)) {
foreach ($relationshipDtls as $rId => $details) {
CRM_Contact_BAO_Relationship::disableEnableRelationship($rId, $action);
}
}
CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id);
}
if ($restore) {
return self::contactTrashRestore($contact, TRUE);
}
// start a new transaction
$transaction = new CRM_Core_Transaction();
if ($skipUndelete) {
CRM_Utils_Hook::pre('delete', $contactType, $id, CRM_Core_DAO::$_nullArray);
//delete billing address if exists.
CRM_Contribute_BAO_Contribution::deleteAddress(NULL, $id);
// delete the log entries since we dont have triggers enabled as yet
$logDAO = new CRM_Core_DAO_Log();
$logDAO->entity_table = 'civicrm_contact';
$logDAO->entity_id = $id;
$logDAO->delete();
// delete contact participants CRM-12155
CRM_Event_BAO_Participant::deleteContactParticipant($id);
// delete contact contributions CRM-12155
CRM_Contribute_BAO_Contribution::deleteContactContribution($id);
// do activity cleanup, CRM-5604
CRM_Activity_BAO_Activity::cleanupActivity($id);
// delete all notes related to contact
CRM_Core_BAO_Note::cleanContactNotes($id);
// delete cases related to contact
$contactCases = CRM_Case_BAO_Case::retrieveCaseIdsByContactId($id);
if (!empty($contactCases)) {
foreach ($contactCases as $caseId) {
//check if case is associate with other contact or not.
$caseContactId = CRM_Case_BAO_Case::getCaseClients($caseId);
if (count($caseContactId) <= 1) {
CRM_Case_BAO_Case::deleteCase($caseId);
}
}
}
$contact->delete();
} else {
self::contactTrashRestore($contact);
}
//delete the contact id from recently view
CRM_Utils_Recent::delContact($id);
// Update the group contact cache
if ($restore) {
CRM_Contact_BAO_GroupContactCache::remove();
} else {
CRM_Contact_BAO_GroupContactCache::removeContact($id);
}
// delete any dupe cache entry
CRM_Core_BAO_PrevNextCache::deleteItem($id);
$transaction->commit();
if ($skipUndelete) {
CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact);
}
// also reset the DB_DO global array so we can reuse the memory
// http://issues.civicrm.org/jira/browse/CRM-4387
CRM_Core_DAO::freeResult();
return TRUE;
}
示例2: contact_create
private function contact_create($mode = 'import')
{
$this->import_status_update('contact');
// bug fix for $this->contacts keep being appended
if (!empty($this->contacts)) {
unset($this->contacts);
$this->contacts = array();
}
for ($i = 0; $i < count($this->csv->data); $i++) {
$param = array('version' => '3', 'contact_type' => 'Individual');
if ($mode == 'import') {
$param['dupe_check'] = $this->data->dupe_check == 1 ? TRUE : FALSE;
// #FIX issue 87: auto-append contact source if it is not mapped
// appending the date and the job id to the import
if (!in_array('contact_source', $this->contacts)) {
$param['contact_source'] = date('Ymd') . '_' . $this->data->jobid;
}
// #FIX issue 72: Add email only de-dupe feature
if ($this->data->dupe_check == 2) {
$mapping = array_flip($this->contact_data);
$email = $this->csv->data[$i][$mapping['email']];
$contact_id = $this->check_email($email);
if (is_numeric($contact_id)) {
// for email only dedupe, we delete the param and skip this iteration
$this->log->_log('Error on CSV line ' . $i . ':, (Matching contact found:, ' . $contact_id . '),' . implode(',', $this->csv->data[$i]), 'error_csv');
unset($param);
continue;
}
}
}
// in case we are doing an append with *ONLY* Location data we still need to fill $this->contact
if (count($this->contact_data) == 1) {
$id = array_values($this->contact_data);
$column = array_keys($this->contact_data);
if ($id[0] == 'external_identifier') {
$contact_id = $this->fetch_contact_id($this->csv->data[$i][$column[0]]);
} else {
$contact_id = $this->csv->data[$i][$column[0]];
}
if (isset($contact_id) && $contact_id != '') {
$this->contacts[$contact_id] = $this->csv->data[$i];
} else {
// unmatched append row
$this->log->_log('Record not found in database:,' . implode(',', $this->csv->data[$i]), 'error_csv');
}
} else {
foreach ($this->contact_data as $column => $field) {
// dealing with some special fields because of CiviCRM's internal workings
switch ($field) {
case 'birth_date':
$param[$field] = civicrm_import_utils::format_date($this->csv->data[$i][$column], $this->data->date_format);
break;
case 'gender':
$param[$field] = civicrm_import_utils::format_gender($this->csv->data[$i][$column]);
break;
// in appending job you have to get contact_id if they choose to match to external identifier
// in appending job you have to get contact_id if they choose to match to external identifier
case 'external_identifier':
// get the contact id
if ($mode == 'import') {
$param[$field] = $this->csv->data[$i][$column];
} else {
$param['contact_id'] = $this->fetch_contact_id($this->csv->data[$i][$column]);
}
break;
default:
$param[$field] = $this->csv->data[$i][$column];
break;
}
}
// print_r($param);
// data filtering validation:
// if the $param does not fit our validation requirement
// i.e. First name, Last name, Email, we do not import them.
// #FEATURE: $this->check_filter should return an array of bad fields so we can pin them down in
// the log
if ($this->check_filter($param, $mode)) {
if ($mode == 'import') {
// @CiviCRM API (v3)
$contact = civicrm_api('contact', 'create', $param);
} else {
if (isset($param['contact_id']) && $param['contact_id'] != '') {
// @CiviCRM API (v3)
$param['id'] = $param['contact_id'];
unset($param['contact_id']);
$contact = civicrm_api('contact', 'create', $param);
} else {
// log all the ones that did not find a matching record into the error_csv
$this->log->_log('Error on CSV line ' . $i . ':, (No matching contact found with the id provided),' . implode(',', $this->csv->data[$i]), 'error_csv');
}
}
// #FIXED: memory leak from API call
CRM_Core_DAO::freeResult();
if ($contact['is_error'] == 1) {
$this->log->_log('Error on CSV line ' . $i . ':, (' . $contact['error_message'] . '),' . implode(',', $this->csv->data[$i]), 'error_csv');
} else {
$this->contacts[$contact['id']] = $this->csv->data[$i];
$this->contact_imported++;
// record the contact import count for tracking
if ($this->contact_imported % 100 == 0) {
//.........这里部分代码省略.........
示例3: civicrm_contact_format_create
/**
* @todo Move this to ContactFormat.php
* @deprecated
*/
function civicrm_contact_format_create(&$params)
{
_civicrm_initialize();
CRM_Core_DAO::freeResult();
// return error if we have no params
if (empty($params)) {
return civicrm_create_error('Input Parameters empty');
}
$error = _civicrm_required_formatted_contact($params);
if (civicrm_error($error)) {
return $error;
}
$error = _civicrm_validate_formatted_contact($params);
if (civicrm_error($error)) {
return $error;
}
//get the prefix id etc if exists
require_once 'CRM/Contact/BAO/Contact.php';
CRM_Contact_BAO_Contact::resolveDefaults($params, TRUE);
require_once 'CRM/Import/Parser.php';
if (CRM_Utils_Array::value('onDuplicate', $params) != CRM_Import_Parser::DUPLICATE_NOCHECK) {
CRM_Core_Error::reset();
$error = _civicrm_duplicate_formatted_contact($params);
if (civicrm_error($error)) {
return $error;
}
}
$contact = CRM_Contact_BAO_Contact::create($params, CRM_Utils_Array::value('fixAddress', $params));
_civicrm_object_to_array($contact, $contactArray);
return $contactArray;
}
示例4: getRowsElementsAndInfo
/**
* A function to build an array of information required by merge function and the merge UI.
*
* @param int $mainId
* Main contact with whom merge has to happen.
* @param int $otherId
* Duplicate contact which would be deleted after merge operation.
*
* @return array|bool|int
*/
public static function getRowsElementsAndInfo($mainId, $otherId)
{
$qfZeroBug = 'e8cddb72-a257-11dc-b9cc-0016d3330ee9';
// Fetch contacts
foreach (array('main' => $mainId, 'other' => $otherId) as $moniker => $cid) {
$params = array('contact_id' => $cid, 'version' => 3, 'return' => array_merge(array('display_name'), self::getContactFields()));
$result = civicrm_api('contact', 'get', $params);
if (empty($result['values'][$cid]['contact_type'])) {
return FALSE;
}
${$moniker} = $result['values'][$cid];
}
static $fields = array();
if (empty($fields)) {
$fields = CRM_Contact_DAO_Contact::fields();
CRM_Core_DAO::freeResult();
}
// FIXME: there must be a better way
foreach (array('main', 'other') as $moniker) {
$contact =& ${$moniker};
$preferred_communication_method = CRM_Utils_array::value('preferred_communication_method', $contact);
$value = empty($preferred_communication_method) ? array() : $preferred_communication_method;
$specialValues[$moniker] = array('preferred_communication_method' => $value, 'communication_style_id' => $value);
if (!empty($contact['preferred_communication_method'])) {
// api 3 returns pref_comm_method as an array, which breaks the lookup; so we reconstruct
$prefCommList = is_array($specialValues[$moniker]['preferred_communication_method']) ? implode(CRM_Core_DAO::VALUE_SEPARATOR, $specialValues[$moniker]['preferred_communication_method']) : $specialValues[$moniker]['preferred_communication_method'];
$specialValues[$moniker]['preferred_communication_method'] = CRM_Core_DAO::VALUE_SEPARATOR . $prefCommList . CRM_Core_DAO::VALUE_SEPARATOR;
}
$names = array('preferred_communication_method' => array('newName' => 'preferred_communication_method_display', 'groupName' => 'preferred_communication_method'));
CRM_Core_OptionGroup::lookupValues($specialValues[$moniker], $names);
if (!empty($contact['communication_style'])) {
$specialValues[$moniker]['communication_style_id_display'] = $contact['communication_style'];
}
}
static $optionValueFields = array();
if (empty($optionValueFields)) {
$optionValueFields = CRM_Core_OptionValue::getFields();
}
foreach ($optionValueFields as $field => $params) {
$fields[$field]['title'] = $params['title'];
}
$diffs = self::findDifferences($main, $other);
$rows = $elements = $relTableElements = $migrationInfo = array();
$genders = CRM_Core_PseudoConstant::get('CRM_Contact_DAO_Contact', 'gender_id');
foreach ($diffs['contact'] as $field) {
if ($field == 'contact_sub_type') {
// CRM-15681 don't display sub-types in UI
continue;
}
foreach (array('main', 'other') as $moniker) {
$contact =& ${$moniker};
$value = CRM_Utils_Array::value($field, $contact);
if (isset($specialValues[$moniker][$field]) && is_string($specialValues[$moniker][$field])) {
$value = CRM_Core_DAO::VALUE_SEPARATOR . trim($specialValues[$moniker][$field], CRM_Core_DAO::VALUE_SEPARATOR) . CRM_Core_DAO::VALUE_SEPARATOR;
}
$label = isset($specialValues[$moniker]["{$field}_display"]) ? $specialValues[$moniker]["{$field}_display"] : $value;
if (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_DATE) {
if ($value) {
$value = str_replace('-', '', $value);
$label = CRM_Utils_Date::customFormat($label);
} else {
$value = "null";
}
} elseif (!empty($fields[$field]['type']) && $fields[$field]['type'] == CRM_Utils_Type::T_BOOLEAN) {
if ($label === '0') {
$label = ts('[ ]');
}
if ($label === '1') {
$label = ts('[x]');
}
} elseif ($field == 'individual_prefix' || $field == 'prefix_id') {
$label = CRM_Utils_Array::value('individual_prefix', $contact);
$value = CRM_Utils_Array::value('prefix_id', $contact);
$field = 'prefix_id';
} elseif ($field == 'individual_suffix' || $field == 'suffix_id') {
$label = CRM_Utils_Array::value('individual_suffix', $contact);
$value = CRM_Utils_Array::value('suffix_id', $contact);
$field = 'suffix_id';
} elseif ($field == 'gender_id' && !empty($value)) {
$label = $genders[$value];
} elseif ($field == 'current_employer_id' && !empty($value)) {
$label = "{$value} (" . CRM_Contact_BAO_Contact::displayName($value) . ")";
}
$rows["move_{$field}"][$moniker] = $label;
if ($moniker == 'other') {
//CRM-14334
if ($value === NULL || $value == '') {
$value = 'null';
}
if ($value === 0 or $value === '0') {
//.........这里部分代码省略.........
示例5: csv
public static function csv()
{
$csvFile = '/home/deepak/Desktop/crm-4247.csv';
$delimiter = ";";
$row = 1;
$handle = fopen($csvFile, "r");
if (!$handle) {
CRM_Core_Error::fatal("Can't locate csv file.");
}
require_once "CRM/Contribute/BAO/Contribution/Utils.php";
while (($data = fgetcsv($handle, 1000, $delimiter)) !== FALSE) {
if ($row !== 1) {
$data['header'] = $header;
$params = self::formatAPIParams($data, self::$_csvParamsMapper, 'csv');
if (self::processAPIContribution($params)) {
CRM_Core_Error::debug_log_message("Processed - line {$row} of csv file .. {$params['email']}, {$params['transaction']['total_amount']}, {$params['transaction']['trxn_id']} ..<p>", TRUE);
} else {
CRM_Core_Error::debug_log_message("Skipped - line {$row} of csv file .. {$params['email']}, {$params['transaction']['total_amount']}, {$params['transaction']['trxn_id']} ..<p>", TRUE);
}
// clean up memory from dao's
CRM_Core_DAO::freeResult();
} else {
// we assuming - first row is always the header line
$header = $data;
CRM_Core_Error::debug_log_message("Considering first row ( line {$row} ) as HEADER ..<p>", TRUE);
if (empty($header)) {
CRM_Core_Error::fatal("Header is empty.");
}
}
$row++;
}
fclose($handle);
}
示例6: getRowsElementsAndInfo
//.........这里部分代码省略.........
// End if 'other' location for this type exists
}
// End loop through each location block entity
// add the related tables and unset the ones that don't sport any of the duplicate contact's info
$config = CRM_Core_Config::singleton();
$mainUfId = CRM_Core_BAO_UFMatch::getUFId($mainId);
$mainUser = NULL;
if ($mainUfId) {
// d6 compatible
if ($config->userSystem->is_drupal == '1' && function_exists($mainUser)) {
$mainUser = user_load($mainUfId);
} elseif ($config->userFramework == 'Joomla') {
$mainUser = JFactory::getUser($mainUfId);
}
}
$otherUfId = CRM_Core_BAO_UFMatch::getUFId($otherId);
$otherUser = NULL;
if ($otherUfId) {
// d6 compatible
if ($config->userSystem->is_drupal == '1' && function_exists($mainUser)) {
$otherUser = user_load($otherUfId);
} elseif ($config->userFramework == 'Joomla') {
$otherUser = JFactory::getUser($otherUfId);
}
}
$relTables = CRM_Dedupe_Merger::relTables();
$activeRelTables = CRM_Dedupe_Merger::getActiveRelTables($otherId);
$activeMainRelTables = CRM_Dedupe_Merger::getActiveRelTables($mainId);
foreach ($relTables as $name => $null) {
if (!in_array($name, $activeRelTables) && !($name == 'rel_table_users' && in_array($name, $activeMainRelTables))) {
unset($relTables[$name]);
continue;
}
$relTableElements[] = array('checkbox', "move_{$name}");
$migrationInfo["move_{$name}"] = 1;
$relTables[$name]['main_url'] = str_replace('$cid', $mainId, $relTables[$name]['url']);
$relTables[$name]['other_url'] = str_replace('$cid', $otherId, $relTables[$name]['url']);
if ($name == 'rel_table_users') {
$relTables[$name]['main_url'] = str_replace('%ufid', $mainUfId, $relTables[$name]['url']);
$relTables[$name]['other_url'] = str_replace('%ufid', $otherUfId, $relTables[$name]['url']);
$find = array('$ufid', '$ufname');
if ($mainUser) {
$replace = array($mainUfId, $mainUser->name);
$relTables[$name]['main_title'] = str_replace($find, $replace, $relTables[$name]['title']);
}
if ($otherUser) {
$replace = array($otherUfId, $otherUser->name);
$relTables[$name]['other_title'] = str_replace($find, $replace, $relTables[$name]['title']);
}
}
if ($name == 'rel_table_memberships') {
$elements[] = array('checkbox', "operation[move_{$name}][add]", NULL, ts('add new'));
$migrationInfo["operation"]["move_{$name}"]['add'] = 1;
}
}
foreach ($relTables as $name => $null) {
$relTables["move_{$name}"] = $relTables[$name];
unset($relTables[$name]);
}
// handle custom fields
$mainTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], CRM_Core_DAO::$_nullObject, $mainId, -1, CRM_Utils_Array::value('contact_sub_type', $main));
$otherTree = CRM_Core_BAO_CustomGroup::getTree($main['contact_type'], CRM_Core_DAO::$_nullObject, $otherId, -1, CRM_Utils_Array::value('contact_sub_type', $other));
CRM_Core_DAO::freeResult();
foreach ($otherTree as $gid => $group) {
$foundField = FALSE;
if (!isset($group['fields'])) {
continue;
}
foreach ($group['fields'] as $fid => $field) {
if (in_array($fid, $compareFields['custom'])) {
if (!$foundField) {
$rows["custom_group_{$gid}"]['title'] = $group['title'];
$foundField = TRUE;
}
if (!empty($mainTree[$gid]['fields'][$fid]['customValue'])) {
foreach ($mainTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) {
$rows["move_custom_{$fid}"]['main'] = CRM_Core_BAO_CustomField::displayValue($values['data'], $fid);
}
}
$value = "null";
if (!empty($otherTree[$gid]['fields'][$fid]['customValue'])) {
foreach ($otherTree[$gid]['fields'][$fid]['customValue'] as $valueId => $values) {
$rows["move_custom_{$fid}"]['other'] = CRM_Core_BAO_CustomField::displayValue($values['data'], $fid);
if ($values['data'] === 0 || $values['data'] === '0') {
$values['data'] = $qfZeroBug;
}
$value = $values['data'] ? $values['data'] : $value;
}
}
$rows["move_custom_{$fid}"]['title'] = $field['label'];
$elements[] = array('advcheckbox', "move_custom_{$fid}", NULL, NULL, NULL, $value);
$migrationInfo["move_custom_{$fid}"] = $value;
}
}
}
$result = array('rows' => $rows, 'elements' => $elements, 'rel_table_elements' => $relTableElements, 'main_loc_block' => $mainLocBlock, 'rel_tables' => $relTables, 'main_details' => $main, 'other_details' => $other, 'migration_info' => $migrationInfo);
$result['main_details']['location_blocks'] = $locations['main'];
$result['other_details']['location_blocks'] = $locations['other'];
return $result;
}
示例7: run
//.........这里部分代码省略.........
$this->_validCount++;
if ($mode == self::MODE_MAPFIELD) {
$this->_rows[] = $values;
$this->_activeFieldCount = max($this->_activeFieldCount, count($values));
}
}
if ($returnCode & self::WARNING) {
$this->_warningCount++;
if ($this->_warningCount < $this->_maxWarningCount) {
$this->_warningCount[] = $line;
}
}
if ($returnCode & self::ERROR) {
$this->_invalidRowCount++;
if ($this->_invalidRowCount < $this->_maxErrorCount) {
array_unshift($values, $this->_rowCount);
$this->_errors[] = $values;
}
}
if ($returnCode & self::CONFLICT) {
$this->_conflictCount++;
array_unshift($values, $this->_rowCount);
$this->_conflicts[] = $values;
}
if ($returnCode & self::NO_MATCH) {
$this->_unMatchCount++;
array_unshift($values, $this->_rowCount);
$this->_unMatch[] = $values;
}
if ($returnCode & self::DUPLICATE) {
if ($returnCode & self::MULTIPLE_DUPE) {
/* TODO: multi-dupes should be counted apart from singles
* on non-skip action */
}
$this->_duplicateCount++;
array_unshift($values, $this->_rowCount);
$this->_duplicates[] = $values;
if ($onDuplicate != self::DUPLICATE_SKIP) {
$this->_validCount++;
}
}
if ($returnCode & self::UNPARSED_ADDRESS_WARNING) {
$this->_unparsedAddressCount++;
array_unshift($values, $this->_rowCount);
$this->_unparsedAddresses[] = $values;
}
// we give the derived class a way of aborting the process
// note that the return code could be multiple code or'ed together
if ($returnCode & self::STOP) {
break;
}
// if we are done processing the maxNumber of lines, break
if ($this->_maxLinesToProcess > 0 && $this->_validCount >= $this->_maxLinesToProcess) {
break;
}
// clean up memory from dao's
CRM_Core_DAO::freeResult();
// see if we've hit our timeout yet
/* if ( $the_thing_with_the_stuff ) {
do_something( );
} */
}
if ($mode == self::MODE_PREVIEW || $mode == self::MODE_IMPORT) {
$customHeaders = $mapper;
$customfields = CRM_Core_BAO_CustomField::getFields($this->_contactType);
foreach ($customHeaders as $key => $value) {
if ($id = CRM_Core_BAO_CustomField::getKeyID($value)) {
$customHeaders[$key] = $customfields[$id][0];
}
}
if ($this->_invalidRowCount) {
// removed view url for invlaid contacts
$headers = array_merge(array(ts('Line Number'), ts('Reason')), $customHeaders);
$this->_errorFileName = self::errorFileName(self::ERROR);
self::exportCSV($this->_errorFileName, $headers, $this->_errors);
}
if ($this->_conflictCount) {
$headers = array_merge(array(ts('Line Number'), ts('Reason')), $customHeaders);
$this->_conflictFileName = self::errorFileName(self::CONFLICT);
self::exportCSV($this->_conflictFileName, $headers, $this->_conflicts);
}
if ($this->_duplicateCount) {
$headers = array_merge(array(ts('Line Number'), ts('View Contact URL')), $customHeaders);
$this->_duplicateFileName = self::errorFileName(self::DUPLICATE);
self::exportCSV($this->_duplicateFileName, $headers, $this->_duplicates);
}
if ($this->_unMatchCount) {
$headers = array_merge(array(ts('Line Number'), ts('Reason')), $customHeaders);
$this->_misMatchFilemName = self::errorFileName(self::NO_MATCH);
self::exportCSV($this->_misMatchFilemName, $headers, $this->_unMatch);
}
if ($this->_unparsedAddressCount) {
$headers = array_merge(array(ts('Line Number'), ts('Contact Edit URL')), $customHeaders);
$this->_errorFileName = self::errorFileName(self::UNPARSED_ADDRESS_WARNING);
self::exportCSV($this->_errorFileName, $headers, $this->_unparsedAddresses);
}
}
//echo "$this->_totalCount,$this->_invalidRowCount,$this->_conflictCount,$this->_duplicateCount";
return $this->fini();
}
示例8: triggerUpdate
/**
* This function acts as a listener to dao->update whenever there is an update,
* and propagates any changes to all related entities present in recurring entity table
*
* @param object $event
* An object of /Civi/Core/DAO/Event/PostUpdate containing dao object that was just updated .
*
*
* @return void
*/
public static function triggerUpdate($event)
{
// if DB version is earlier than 4.6 skip any processing
static $currentVer = NULL;
if (!$currentVer) {
$currentVer = CRM_Core_BAO_Domain::version();
}
if (version_compare($currentVer, '4.6.alpha1') < 0) {
return;
}
static $processedEntities = array();
$obj =& $event->object;
if (empty($obj->id) || empty($obj->__table)) {
return FALSE;
}
$key = "{$obj->__table}_{$obj->id}";
if (array_key_exists($key, $processedEntities)) {
// already processed
return NULL;
}
// get related entities
$repeatingEntities = self::getEntitiesFor($obj->id, $obj->__table, FALSE, NULL);
if (empty($repeatingEntities)) {
// return if its not a recurring entity parent
return NULL;
}
// mark being processed
$processedEntities[$key] = 1;
// to make sure we not copying to source itself
unset($repeatingEntities[$key]);
foreach ($repeatingEntities as $key => $val) {
$entityID = $val['id'];
$entityTable = $val['table'];
$processedEntities[$key] = 1;
if (array_key_exists($entityTable, self::$_tableDAOMapper)) {
$daoName = self::$_tableDAOMapper[$entityTable];
$skipData = array();
if (array_key_exists($entityTable, self::$_updateSkipFields)) {
$skipFields = self::$_updateSkipFields[$entityTable];
foreach ($skipFields as $sfield) {
$skipData[$sfield] = NULL;
}
}
$updateDAO = CRM_Core_DAO::cascadeUpdate($daoName, $obj->id, $entityID, $skipData);
CRM_Core_DAO::freeResult();
} else {
CRM_Core_Error::fatal("DAO Mapper missing for {$entityTable}.");
}
}
// done with processing. lets unset static var.
unset($processedEntities);
}
示例9: deleteContact
/**
* Delete a contact and all its associated records
*
* @param int $id id of the contact to delete
*
* @return boolean true if contact deleted, false otherwise
* @access public
* @static
*/
function deleteContact($id)
{
require_once 'CRM/Activity/BAO/Activity.php';
if (!$id) {
return false;
}
// make sure we have edit permission for this contact
// before we delete
require_once 'CRM/Contact/BAO/Contact/Permission.php';
if (!CRM_Core_Permission::check('delete contacts')) {
return false;
}
// make sure this contact_id does not have any membership types
$membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id');
if ($membershipTypeID) {
return false;
}
$contact =& new CRM_Contact_DAO_Contact();
$contact->id = $id;
if (!$contact->find(true)) {
return false;
}
$contactType = $contact->contact_type;
// currently we only clear employer cache.
// we are not deleting inherited membership if any.
if ($contact->contact_type == 'Organization') {
require_once 'CRM/Contact/BAO/Contact/Utils.php';
CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id);
}
require_once 'CRM/Utils/Hook.php';
CRM_Utils_Hook::pre('delete', $contactType, $id, CRM_Core_DAO::$_nullArray);
// start a new transaction
require_once 'CRM/Core/Transaction.php';
$transaction = new CRM_Core_Transaction();
//delete billing address if exists.
require_once 'CRM/Contribute/BAO/Contribution.php';
CRM_Contribute_BAO_Contribution::deleteAddress(null, $id);
// delete the log entries since we dont have triggers enabled as yet
require_once 'CRM/Core/DAO/Log.php';
$logDAO =& new CRM_Core_DAO_Log();
$logDAO->entity_table = 'civicrm_contact';
$logDAO->entity_id = $id;
$logDAO->delete();
$contact->delete();
//delete the contact id from recently view
require_once 'CRM/Utils/Recent.php';
CRM_Utils_Recent::delContact($id);
// reset the group contact cache for this group
require_once 'CRM/Contact/BAO/GroupContactCache.php';
CRM_Contact_BAO_GroupContactCache::remove();
$transaction->commit();
CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact);
// also reset the DB_DO global array so we can reuse the memory
// http://issues.civicrm.org/jira/browse/CRM-4387
CRM_Core_DAO::freeResult();
return true;
}
示例10: dedupePair
/**
* Dedupe a pair of contacts.
*
* @param array $migrationInfo
* @param array $resultStats
* @param array $deletedContacts
* @param string $mode
* @param bool $checkPermissions
* @param int $mainId
* @param int $otherId
* @param string $cacheKeyString
*/
protected static function dedupePair(&$migrationInfo, &$resultStats, &$deletedContacts, $mode, $checkPermissions, $mainId, $otherId, $cacheKeyString)
{
// go ahead with merge if there is no conflict
$conflicts = array();
if (!CRM_Dedupe_Merger::skipMerge($mainId, $otherId, $migrationInfo, $mode, $conflicts)) {
CRM_Dedupe_Merger::moveAllBelongings($mainId, $otherId, $migrationInfo, $checkPermissions);
$resultStats['merged'][] = array('main_id' => $mainId, 'other_id' => $otherId);
$deletedContacts[] = $otherId;
} else {
$resultStats['skipped'][] = array('main_id' => $mainId, 'other_id' => $otherId);
}
// store any conflicts
if (!empty($conflicts)) {
foreach ($conflicts as $key => $dnc) {
$conflicts[$key] = "{$migrationInfo['rows'][$key]['title']}: '{$migrationInfo['rows'][$key]['main']}' vs. '{$migrationInfo['rows'][$key]['other']}'";
}
CRM_Core_BAO_PrevNextCache::markConflict($mainId, $otherId, $cacheKeyString, $conflicts);
} else {
// delete entry from PrevNextCache table so we don't consider the pair next time
// pair may have been flipped, so make sure we delete using both orders
CRM_Core_BAO_PrevNextCache::deletePair($mainId, $otherId, $cacheKeyString, TRUE);
}
CRM_Core_DAO::freeResult();
}
示例11: deleteContact
/**
* Delete a contact and all its associated records
*
* @param int $id id of the contact to delete
* @param bool $restore whether to actually restore, not delete
* @param bool $skipUndelete whether to force contact delete or not
*
* @return boolean true if contact deleted, false otherwise
* @access public
* @static
*/
static function deleteContact($id, $restore = FALSE, $skipUndelete = FALSE)
{
if (!$id) {
return FALSE;
}
// make sure we have edit permission for this contact
// before we delete
if ($skipUndelete && !CRM_Core_Permission::check('delete contacts') || $restore && !CRM_Core_Permission::check('access deleted contacts')) {
return FALSE;
}
// make sure this contact_id does not have any membership types
$membershipTypeID = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $id, 'id', 'member_of_contact_id');
if ($membershipTypeID) {
return FALSE;
}
$contact = new CRM_Contact_DAO_Contact();
$contact->id = $id;
if (!$contact->find(TRUE)) {
return FALSE;
}
$contactType = $contact->contact_type;
$action = $restore ? 'restore' : 'delete';
CRM_Utils_Hook::pre($action, $contactType, $id, CRM_Core_DAO::$_nullArray);
if ($restore) {
self::contactTrashRestore($contact, TRUE);
CRM_Utils_Hook::post($action, $contactType, $contact->id, $contact);
return TRUE;
}
// currently we only clear employer cache.
// we are not deleting inherited membership if any.
if ($contact->contact_type == 'Organization') {
CRM_Contact_BAO_Contact_Utils::clearAllEmployee($id);
}
// start a new transaction
$transaction = new CRM_Core_Transaction();
$config = CRM_Core_Config::singleton();
if ($skipUndelete or !$config->contactUndelete) {
//delete billing address if exists.
CRM_Contribute_BAO_Contribution::deleteAddress(NULL, $id);
// delete the log entries since we dont have triggers enabled as yet
$logDAO = new CRM_Core_DAO_Log();
$logDAO->entity_table = 'civicrm_contact';
$logDAO->entity_id = $id;
$logDAO->delete();
// do activity cleanup, CRM-5604
CRM_Activity_BAO_Activity::cleanupActivity($id);
// delete all notes related to contact
CRM_Core_BAO_Note::cleanContactNotes($id);
$contact->delete();
} else {
self::contactTrashRestore($contact);
}
//delete the contact id from recently view
CRM_Utils_Recent::delContact($id);
// reset the group contact cache for this group
CRM_Contact_BAO_GroupContactCache::remove();
// delete any dupe cache entry
CRM_Core_BAO_PrevNextCache::deleteItem($id);
$transaction->commit();
CRM_Utils_Hook::post('delete', $contactType, $contact->id, $contact);
// also reset the DB_DO global array so we can reuse the memory
// http://issues.civicrm.org/jira/browse/CRM-4387
CRM_Core_DAO::freeResult();
return TRUE;
}