本文整理汇总了PHP中CRM_Core_BAO_PrevNextCache::setItem方法的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_PrevNextCache::setItem方法的具体用法?PHP CRM_Core_BAO_PrevNextCache::setItem怎么用?PHP CRM_Core_BAO_PrevNextCache::setItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CRM_Core_BAO_PrevNextCache
的用法示例。
在下文中一共展示了CRM_Core_BAO_PrevNextCache::setItem方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: updateMergeStats
public static function updateMergeStats($cacheKeyString, $result = array())
{
// gather latest stats
$merged = count($result['merged']);
$skipped = count($result['skipped']);
if ($merged <= 0 && $skipped <= 0) {
return;
}
// get previous stats
$previousStats = CRM_Core_BAO_PrevNextCache::retrieve("{$cacheKeyString}_stats");
if (!empty($previousStats)) {
if ($previousStats[0]['merged']) {
$merged = $merged + $previousStats[0]['merged'];
}
if ($previousStats[0]['skipped']) {
$skipped = $skipped + $previousStats[0]['skipped'];
}
}
// delete old stats
CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
// store the updated stats
$data = array('merged' => $merged, 'skipped' => $skipped);
$data = CRM_Core_DAO::escapeString(serialize($data));
$values = array();
$values[] = " ( 'civicrm_contact', 0, 0, '{$cacheKeyString}_stats', '{$data}' ) ";
CRM_Core_BAO_PrevNextCache::setItem($values);
}
示例2: refillCache
static function refillCache($rgid = NULL, $gid = NULL, $cacheKeyString = NULL)
{
if (!$cacheKeyString && $rgid) {
$contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
$cacheKeyString = "merge {$contactType}";
$cacheKeyString .= $rgid ? "_{$rgid}" : '_0';
$cacheKeyString .= $gid ? "_{$gid}" : '_0';
}
if (!$cacheKeyString) {
return FALSE;
}
// 1. Clear cache if any
$sql = "DELETE FROM civicrm_prevnext_cache WHERE cacheKey LIKE %1";
CRM_Core_DAO::executeQuery($sql, array(1 => array("{$cacheKeyString}%", 'String')));
// FIXME: we need to start using temp tables / queries here instead of arrays.
// And cleanup code in CRM/Contact/Page/DedupeFind.php
// 2. FILL cache
$foundDupes = array();
if ($rgid && $gid) {
$foundDupes = CRM_Dedupe_Finder::dupesInGroup($rgid, $gid);
} elseif ($rgid) {
$foundDupes = CRM_Dedupe_Finder::dupes($rgid);
}
if (!empty($foundDupes)) {
$cids = $displayNames = $values = array();
foreach ($foundDupes as $dupe) {
$cids[$dupe[0]] = 1;
$cids[$dupe[1]] = 1;
}
$cidString = implode(', ', array_keys($cids));
$sql = "SELECT id, display_name FROM civicrm_contact WHERE id IN ({$cidString}) ORDER BY sort_name";
$dao = new CRM_Core_DAO();
$dao->query($sql);
while ($dao->fetch()) {
$displayNames[$dao->id] = $dao->display_name;
}
$session = CRM_Core_Session::singleton();
$userId = $session->get('userID');
foreach ($foundDupes as $dupes) {
$srcID = $dupes[0];
$dstID = $dupes[1];
if ($dstID == $userId) {
$srcID = $dupes[1];
$dstID = $dupes[0];
}
$row = array('srcID' => $srcID, 'srcName' => $displayNames[$srcID], 'dstID' => $dstID, 'dstName' => $displayNames[$dstID], 'weight' => $dupes[2], 'canMerge' => TRUE);
$data = CRM_Core_DAO::escapeString(serialize($row));
$values[] = " ( 'civicrm_contact', {$srcID}, {$dstID}, '{$cacheKeyString}', '{$data}' ) ";
}
CRM_Core_BAO_PrevNextCache::setItem($values);
}
}
示例3: run
//.........这里部分代码省略.........
$foundDupes = CRM_Dedupe_Finder::dupes($rgid);
}
$this->set('dedupe_dupes', $foundDupes);
}
if (!$foundDupes) {
$ruleGroup = new CRM_Dedupe_BAO_RuleGroup();
$ruleGroup->id = $rgid;
$ruleGroup->find(TRUE);
$session = CRM_Core_Session::singleton();
$session->setStatus(ts('No possible duplicates were found using %1 rule.', array(1 => $ruleGroup->name)), ts('None Found'), 'info');
$url = CRM_Utils_System::url('civicrm/contact/deduperules', 'reset=1');
if ($context == 'search') {
$url = $session->readUserContext();
}
CRM_Utils_System::redirect($url);
} else {
$cids = array();
foreach ($foundDupes as $dupe) {
$cids[$dupe[0]] = 1;
$cids[$dupe[1]] = 1;
}
$cidString = implode(', ', array_keys($cids));
$sql = "SELECT id, display_name FROM civicrm_contact WHERE id IN ({$cidString}) ORDER BY sort_name";
$dao = new CRM_Core_DAO();
$dao->query($sql);
$displayNames = array();
while ($dao->fetch()) {
$displayNames[$dao->id] = $dao->display_name;
}
// FIXME: sort the contacts; $displayName
// is already sort_name-sorted, so use that
// (also, consider sorting by dupe count first)
// lobo - change the sort to by threshold value
// so the more likely dupes are sorted first
$session = CRM_Core_Session::singleton();
$userId = $session->get('userID');
$mainContacts = $permission = array();
foreach ($foundDupes as $dupes) {
$srcID = $dupes[0];
$dstID = $dupes[1];
if ($dstID == $userId) {
$srcID = $dupes[1];
$dstID = $dupes[0];
}
/***
* Eliminate this since it introduces 3 queries PER merge row
* and hence is very expensive
* CRM-8822
* if ( !array_key_exists( $srcID, $permission ) ) {
* $permission[$srcID] = CRM_Contact_BAO_Contact_Permission::allow( $srcID, CRM_Core_Permission::EDIT );
* }
* if ( !array_key_exists( $dstID, $permission ) ) {
* $permission[$dstID] = CRM_Contact_BAO_Contact_Permission::allow( $dstID, CRM_Core_Permission::EDIT );
* }
*
* $canMerge = ( $permission[$dstID] && $permission[$srcID] );
*
*/
// we'll do permission checking during the merge process
$canMerge = TRUE;
$mainContacts[] = $row = array('srcID' => $srcID, 'srcName' => $displayNames[$srcID], 'dstID' => $dstID, 'dstName' => $displayNames[$dstID], 'weight' => $dupes[2], 'canMerge' => $canMerge);
$data = CRM_Core_DAO::escapeString(serialize($row));
$values[] = " ( 'civicrm_contact', {$srcID}, {$dstID}, '{$cacheKeyString}', '{$data}' ) ";
}
if ($cid) {
$this->_cid = $cid;
}
if ($gid) {
$this->_gid = $gid;
}
$this->_rgid = $rgid;
$this->_mainContacts = $mainContacts;
CRM_Core_BAO_PrevNextCache::setItem($values);
$session = CRM_Core_Session::singleton();
if ($this->_cid) {
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/deduperules', "action=update&rgid={$this->_rgid}&gid={$this->_gid}&cid={$this->_cid}"));
} else {
$session->pushUserContext(CRM_Utils_System::url('civicrm/contact/dedupefind', "reset=1&action=update&rgid={$this->_rgid}"));
}
}
} else {
if ($cid) {
$this->_cid = $cid;
}
if ($gid) {
$this->_gid = $gid;
}
$this->_rgid = $rgid;
}
$this->assign('action', $this->action);
$this->browse();
} else {
$this->action = CRM_Core_Action::UPDATE;
$this->edit($this->action);
$this->assign('action', $this->action);
}
$this->assign('context', $context);
// parent run
return parent::run();
}
示例4: parseAndStoreDupePairs
/**
* Parse duplicate pairs into a standardised array and store in the prev_next_cache.
*
* @param array $foundDupes
* @param string $cacheKeyString
*
* @return array Dupe pairs with the keys
* Dupe pairs with the keys
* -srcID
* -srcName
* -dstID
* -dstName
* -weight
* -canMerge
*
* @throws CRM_Core_Exception
*/
public static function parseAndStoreDupePairs($foundDupes, $cacheKeyString)
{
$cids = array();
foreach ($foundDupes as $dupe) {
$cids[$dupe[0]] = 1;
$cids[$dupe[1]] = 1;
}
$cidString = implode(', ', array_keys($cids));
$dao = CRM_Core_DAO::executeQuery("SELECT id, display_name FROM civicrm_contact WHERE id IN ({$cidString}) ORDER BY sort_name");
$displayNames = array();
while ($dao->fetch()) {
$displayNames[$dao->id] = $dao->display_name;
}
$userId = CRM_Core_Session::singleton()->getLoggedInContactID();
foreach ($foundDupes as $dupes) {
$srcID = $dupes[1];
$dstID = $dupes[0];
// The logged in user should never be the src (ie. the contact to be removed).
if ($srcID == $userId) {
$srcID = $dstID;
$dstID = $userId;
}
$mainContacts[] = $row = array('dstID' => $dstID, 'dstName' => $displayNames[$dstID], 'srcID' => $srcID, 'srcName' => $displayNames[$srcID], 'weight' => $dupes[2], 'canMerge' => TRUE);
$data = CRM_Core_DAO::escapeString(serialize($row));
$values[] = " ( 'civicrm_contact', {$dstID}, {$srcID}, '{$cacheKeyString}', '{$data}' ) ";
}
CRM_Core_BAO_PrevNextCache::setItem($values);
return $mainContacts;
}