当前位置: 首页>>代码示例>>PHP>>正文


PHP CRM_Core_BAO_PrevNextCache类代码示例

本文整理汇总了PHP中CRM_Core_BAO_PrevNextCache的典型用法代码示例。如果您正苦于以下问题:PHP CRM_Core_BAO_PrevNextCache类的具体用法?PHP CRM_Core_BAO_PrevNextCache怎么用?PHP CRM_Core_BAO_PrevNextCache使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了CRM_Core_BAO_PrevNextCache类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: addSearchContactIdsToSession

 /**
  * @return $this
  */
 private function addSearchContactIdsToSession()
 {
     $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $form);
     $cacheKey = "civicrm search {$qfKey}";
     $selectedCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey);
     $contactIds = array();
     // Set contact IDs to the IDs of contacts selected (ticked) on the search result
     foreach ($selectedCids[$cacheKey] as $selectedCid => $ignore) {
         $contactIds[$selectedCid] = $selectedCid;
     }
     // So a bit of magic happens here
     // When you instantiate a CRM_Contract_Controller_Search object, it checks to see if a qfKey is passed in the $_REQUEST
     // in our case you should see it in the GET
     // If this is passed in, the controller tries to create itself using data from the SESSION
     // that means your controller is automatically populated with search data from a previous page
     $searchController = new CRM_Contact_Controller_Search();
     $totalContacts = count($contactIds);
     if ($totalContacts <= 0) {
         $totalContacts = $searchController->get('rowCount');
     }
     // CS: This needs to be commented out because the contact IDs are irrelevant at this point.
     // If the user hasn't ticked any users then this code would just give you back the first 50 contacts
     // Better to leave the contactIds empty which tells us that nothing is actually selected
     if (!$contactIds) {
         foreach ($this->get('rows') as $contact) {
             $contactIds[$contact['contact_id']] = $contact['contact_id'];
         }
     }
     simplemail_civicrm_addToSessionScope('contactCountFromSearch', $totalContacts);
     simplemail_civicrm_addToSessionScope('contactIds', $contactIds);
     return $this;
 }
开发者ID:jaapjansma,项目名称:uk.co.compucorp.civicrm.simplemail,代码行数:35,代码来源:SimpleMailRecipientsFromSearch.php

示例2: selectUnselectRelationships

 /**
  * Used to store selected contacts across multiple pages in advanced search.
  */
 public static function selectUnselectRelationships()
 {
     $name = CRM_Utils_Array::value('name', $_REQUEST);
     $cacheKey = CRM_Utils_Array::value('qfKey', $_REQUEST);
     $state = CRM_Utils_Array::value('state', $_REQUEST, 'checked');
     $variableType = CRM_Utils_Array::value('variableType', $_REQUEST, 'single');
     $actionToPerform = CRM_Utils_Array::value('action', $_REQUEST, 'select');
     if ($variableType == 'multiple') {
         // action post value only works with multiple type variable
         if ($name) {
             //multiple names like mark_x_1-mark_x_2 where 1,2 are cids
             $elements = explode('-', $name);
             foreach ($elements as $key => $element) {
                 $elements[$key] = self::_convertToId($element);
             }
             CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, $elements, 'civicrm_relationship');
         } else {
             CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $actionToPerform, NULL, 'civicrm_relationship');
         }
     } elseif ($variableType == 'single') {
         $cId = self::_convertToId($name);
         $action = $state == 'checked' ? 'select' : 'unselect';
         CRM_Core_BAO_PrevNextCache::markSelection($cacheKey, $action, $cId, 'civicrm_relationship');
     }
     $contactIds = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, 'get', 'civicrm_relationship');
     $countSelectionCids = count($contactIds[$cacheKey]);
     $arrRet = array('getCount' => $countSelectionCids);
     CRM_Utils_JSON::output($arrRet);
 }
开发者ID:Chirojeugd-Vlaanderen,项目名称:civicrm-relationship-entity,代码行数:32,代码来源:AJAX.php

示例3: testFlipData

 public function testFlipData()
 {
     $dao = new CRM_Core_BAO_PrevNextCache();
     $dao->entity_id1 = 1;
     $dao->entity_id2 = 2;
     $dao->data = serialize(array('srcID' => 1, 'srcName' => 'Ms. Meliissa Mouse II', 'dstID' => 2, 'dstName' => 'Mr. Maurice Mouse II', 'weight' => 20, 'canMerge' => TRUE));
     $dao->save();
     $dao = new CRM_Core_BAO_PrevNextCache();
     $dao->id = 1;
     CRM_Core_BAO_PrevNextCache::flipPair(array(1), 0);
     $dao->find(TRUE);
     $this->assertEquals(1, $dao->entity_id1);
     $this->assertEquals(2, $dao->entity_id2);
     $this->assertEquals(serialize(array('srcName' => 'Mr. Maurice Mouse II', 'dstID' => 1, 'dstName' => 'Ms. Meliissa Mouse II', 'weight' => 20, 'canMerge' => TRUE, 'srcID' => 2)), $dao->data);
     $this->quickCleanup(array('civicrm_prevnext_cache'));
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:16,代码来源:PrevNextCacheTest.php

示例4: preProcess

 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     //when user come from search context.
     $ssID = $this->get('ssID');
     $this->assign('ssid', $ssID);
     $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context'));
     if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID) {
         $params = array();
         $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts();
         $this->assign("value", $result);
     }
 }
开发者ID:BorislavZlatanov,项目名称:civicrm-core,代码行数:17,代码来源:Test.php

示例5: preProcess

 public function preProcess()
 {
     $this->_mailingID = $this->get('mailing_id');
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $this->assign('isAdmin', 1);
     }
     //when user come from search context.
     $ssID = $this->get('ssID');
     $this->assign('ssid', $ssID);
     $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context'));
     if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID) {
         $params = array();
         $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts();
         $this->assign("value", $result);
     }
 }
开发者ID:BorislavZlatanov,项目名称:civicrm-core,代码行数:16,代码来源:Upload.php

示例6: getRunner

 /**
  * Build a queue of tasks by dividing dupe pairs in batches.
  */
 public static function getRunner()
 {
     $rgid = CRM_Utils_Request::retrieve('rgid', 'Positive', $this, FALSE, 0);
     $gid = CRM_Utils_Request::retrieve('gid', 'Positive', $this, FALSE, 0);
     $action = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject);
     $mode = CRM_Utils_Request::retrieve('mode', 'String', CRM_Core_DAO::$_nullObject, FALSE, 'safe');
     $contactType = CRM_Core_DAO::getFieldValue('CRM_Dedupe_DAO_RuleGroup', $rgid, 'contact_type');
     $cacheKeyString = "merge {$contactType}";
     $cacheKeyString .= $rgid ? "_{$rgid}" : '_0';
     $cacheKeyString .= $gid ? "_{$gid}" : '_0';
     $urlQry = "reset=1&action=update&rgid={$rgid}";
     $urlQry = $gid ? $urlQry . "&gid={$gid}" : $urlQry;
     if ($mode == 'aggressive' && !CRM_Core_Permission::check('force merge duplicate contacts')) {
         CRM_Core_Session::setStatus(ts('You do not have permission to force merge duplicate contact records'), ts('Permission Denied'), 'error');
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry));
     }
     // Setup the Queue
     $queue = CRM_Queue_Service::singleton()->create(array('name' => $cacheKeyString, 'type' => 'Sql', 'reset' => TRUE));
     $where = NULL;
     if ($action == CRM_Core_Action::MAP) {
         $where = "pn.is_selected = 1";
         $isSelected = 1;
     } else {
         // else merge all (2)
         $isSelected = 2;
     }
     $total = CRM_Core_BAO_PrevNextCache::getCount($cacheKeyString, NULL, $where);
     if ($total <= 0) {
         // Nothing to do.
         CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry));
     }
     // reset merge stats, so we compute new stats
     CRM_Dedupe_Merger::resetMergeStats($cacheKeyString);
     for ($i = 1; $i <= ceil($total / self::BATCHLIMIT); $i++) {
         $task = new CRM_Queue_Task(array('CRM_Contact_Page_DedupeMerge', 'callBatchMerge'), array($rgid, $gid, $mode, TRUE, self::BATCHLIMIT, $isSelected), "Processed " . $i * self::BATCHLIMIT . " pair of duplicates out of " . $total);
         // Add the Task to the Queue
         $queue->createItem($task);
     }
     // Setup the Runner
     $urlQry .= "&context=conflicts";
     $runner = new CRM_Queue_Runner(array('title' => ts('Merging Duplicates..'), 'queue' => $queue, 'errorMode' => CRM_Queue_Runner::ERROR_ABORT, 'onEndUrl' => CRM_Utils_System::url('civicrm/contact/dedupefind', $urlQry, TRUE, NULL, FALSE)));
     return $runner;
 }
开发者ID:nganivet,项目名称:civicrm-core,代码行数:46,代码来源:DedupeMerge.php

示例7: preProcess

 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     if (CRM_Mailing_Info::workflowEnabled() && !CRM_Core_Permission::check('schedule mailings')) {
         $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'reset=1&scheduled=false');
         CRM_Utils_System::redirect($url);
     }
     //when user come from search context.
     $ssID = $this->get('ssID');
     $this->assign('ssid', $ssID);
     $this->_searchBasedMailing = CRM_Contact_Form_Search::isSearchContext($this->get('context'));
     if (CRM_Contact_Form_Search::isSearchContext($this->get('context')) && !$ssID) {
         $params = array();
         $result = CRM_Core_BAO_PrevNextCache::getSelectedContacts();
         $this->assign("value", $result);
     }
     $this->_mailingID = $this->get('mailing_id');
     $this->_scheduleFormOnly = FALSE;
     if (!$this->_mailingID) {
         $this->_mailingID = CRM_Utils_Request::retrieve('mid', 'Integer', $this, TRUE);
         $this->_scheduleFormOnly = TRUE;
     }
 }
开发者ID:hguru,项目名称:224Civi,代码行数:28,代码来源:Schedule.php

示例8: fillupPrevNextCache

 function fillupPrevNextCache($sort, $cacheKey = NULL)
 {
     if (!$cacheKey) {
         $cacheKey = "civicrm search {$this->_key}";
     }
     CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey, 'civicrm_contact');
     // lets fill up the prev next cache here, so view can scroll thru
     $sql = $this->_query->searchQuery(0, 0, $sort, FALSE, FALSE, FALSE, TRUE, TRUE, NULL);
     // CRM-9096
     // due to limitations in our search query writer, the above query does not work
     // in cases where the query is being sorted on a non-contact table
     // this results in a fatal error :(
     // see below for the gross hack of trapping the error and not filling
     // the prev next cache in this situation
     // the other alternative of running the FULL query will just be incredibly inefficient
     // and slow things down way too much on large data sets / complex queries
     $insertSQL = "\nINSERT INTO civicrm_prevnext_cache ( entity_table, entity_id1, entity_id2, cacheKey, data )\nSELECT 'civicrm_contact', contact_a.id, contact_a.id, '{$cacheKey}', contact_a.display_name\n";
     $replaceSQL = "SELECT contact_a.id as id";
     $sql = str_replace($replaceSQL, $insertSQL, $sql);
     CRM_Core_Error::ignoreException();
     $result = CRM_Core_DAO::executeQuery($sql);
     CRM_Core_Error::setCallback();
     if (is_a($result, 'DB_Error')) {
         // oops the above query failed, so lets just ignore it
         // and return
         // we print a sorry cant figure it out on view page
         return;
     }
     // also record an entry in the cache key table, so we can delete it periodically
     CRM_Core_BAO_Cache::setItem($cacheKey, 'CiviCRM Search PrevNextCache', $cacheKey);
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:31,代码来源:Selector.php

示例9: postProcess

 /**
  * Process the form submission.
  *
  *
  * @return void
  */
 public function postProcess()
 {
     $values = $this->exportValues();
     //FIXME: Handle logic to replace is_default column by usage
     // reset used column to General (since there can only
     // be one 'Supervised' or 'Unsupervised' rule)
     if ($values['used'] != 'General') {
         $query = "\nUPDATE civicrm_dedupe_rule_group\n   SET used = 'General'\n WHERE contact_type = %1\n   AND used = %2";
         $queryParams = array(1 => array($this->_contactType, 'String'), 2 => array($values['used'], 'String'));
         CRM_Core_DAO::executeQuery($query, $queryParams);
     }
     $rgDao = new CRM_Dedupe_DAO_RuleGroup();
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $rgDao->id = $this->_rgid;
     }
     $rgDao->title = $values['title'];
     $rgDao->is_reserved = CRM_Utils_Array::value('is_reserved', $values, FALSE);
     $rgDao->used = $values['used'];
     $rgDao->contact_type = $this->_contactType;
     $rgDao->threshold = $values['threshold'];
     $rgDao->save();
     // make sure name is set only during insert
     if ($this->_action & CRM_Core_Action::ADD) {
         // generate name based on title
         $rgDao->name = CRM_Utils_String::titleToVar($values['title']) . "_{$rgDao->id}";
         $rgDao->save();
     }
     // lets skip updating of fields for reserved dedupe group
     if ($rgDao->is_reserved) {
         CRM_Core_Session::setStatus(ts("The rule '%1' has been saved.", array(1 => $rgDao->title)), ts('Saved'), 'success');
         return;
     }
     $ruleDao = new CRM_Dedupe_DAO_Rule();
     $ruleDao->dedupe_rule_group_id = $rgDao->id;
     $ruleDao->delete();
     $ruleDao->free();
     $substrLenghts = array();
     $tables = array();
     $daoObj = new CRM_Core_DAO();
     $database = $daoObj->database();
     for ($count = 0; $count < self::RULES_COUNT; $count++) {
         if (empty($values["where_{$count}"])) {
             continue;
         }
         list($table, $field) = explode('.', CRM_Utils_Array::value("where_{$count}", $values));
         $length = !empty($values["length_{$count}"]) ? CRM_Utils_Array::value("length_{$count}", $values) : NULL;
         $weight = $values["weight_{$count}"];
         if ($table and $field) {
             $ruleDao = new CRM_Dedupe_DAO_Rule();
             $ruleDao->dedupe_rule_group_id = $rgDao->id;
             $ruleDao->rule_table = $table;
             $ruleDao->rule_field = $field;
             $ruleDao->rule_length = $length;
             $ruleDao->rule_weight = $weight;
             $ruleDao->save();
             $ruleDao->free();
             if (!array_key_exists($table, $tables)) {
                 $tables[$table] = array();
             }
             $tables[$table][] = $field;
         }
         // CRM-6245: we must pass table/field/length triples to the createIndexes() call below
         if ($length) {
             if (!isset($substrLenghts[$table])) {
                 $substrLenghts[$table] = array();
             }
             //CRM-13417 to avoid fatal error "Incorrect prefix key; the used key part isn't a string, the used length is longer than the key part, or the storage engine doesn't support unique prefix keys, 1089"
             $schemaQuery = "SELECT * FROM INFORMATION_SCHEMA.COLUMNS\n          WHERE TABLE_SCHEMA = '{$database}' AND\n          TABLE_NAME = '{$table}' AND COLUMN_NAME = '{$field}';";
             $dao = CRM_Core_DAO::executeQuery($schemaQuery);
             if ($dao->fetch()) {
                 // set the length to null for all the fields where prefix length is not supported. eg. int,tinyint,date,enum etc dataTypes.
                 if ($dao->COLUMN_NAME == $field && !in_array($dao->DATA_TYPE, array('char', 'varchar', 'binary', 'varbinary', 'text', 'blob'))) {
                     $length = NULL;
                 } elseif ($dao->COLUMN_NAME == $field && !empty($dao->CHARACTER_MAXIMUM_LENGTH) && $length > $dao->CHARACTER_MAXIMUM_LENGTH) {
                     //set the length to CHARACTER_MAXIMUM_LENGTH in case the length provided by the user is greater than the limit
                     $length = $dao->CHARACTER_MAXIMUM_LENGTH;
                 }
             }
             $substrLenghts[$table][$field] = $length;
         }
     }
     // also create an index for this dedupe rule
     // CRM-3837
     CRM_Utils_Hook::dupeQuery($ruleDao, 'dedupeIndexes', $tables);
     CRM_Core_BAO_SchemaHandler::createIndexes($tables, 'dedupe_index', $substrLenghts);
     //need to clear cache of deduped contacts
     //based on the previous rule
     $cacheKey = "merge {$this->_contactType}_{$this->_rgid}_%";
     CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey);
     CRM_Core_Session::setStatus(ts("The rule '%1' has been saved.", array(1 => $rgDao->title)), ts('Saved'), 'success');
 }
开发者ID:rajeshrhino,项目名称:civicrm-core,代码行数:97,代码来源:DedupeRules.php

示例10: preProcess

 /**
  * Build all the data structures needed to build the form.
  */
 public function preProcess()
 {
     $values = $this->controller->exportValues('Search');
     $this->_task = $values['task'];
     $campaignTasks = CRM_Campaign_Task::tasks();
     $taskName = CRM_Utils_Array::value($this->_task, $campaignTasks);
     $this->assign('taskName', $taskName);
     $ids = array();
     if ($values['radio_ts'] == 'ts_sel') {
         foreach ($values as $name => $value) {
             if (substr($name, 0, CRM_Core_Form::CB_PREFIX_LEN) == CRM_Core_Form::CB_PREFIX) {
                 $ids[] = substr($name, CRM_Core_Form::CB_PREFIX_LEN);
             }
         }
     } else {
         $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
         $cacheKey = "civicrm search {$qfKey}";
         $allCids = CRM_Core_BAO_PrevNextCache::getSelection($cacheKey, "getall");
         $ids = array_keys($allCids[$cacheKey]);
         $this->assign('totalSelectedVoters', count($ids));
     }
     if (!empty($ids)) {
         $this->_componentClause = 'contact_a.id IN ( ' . implode(',', $ids) . ' ) ';
         $this->assign('totalSelectedVoters', count($ids));
     }
     $this->_voterIds = $this->_contactIds = $this->_componentIds = $ids;
     $this->assign('totalSelectedContacts', count($this->_contactIds));
     //set the context for redirection for any task actions
     $session = CRM_Core_Session::singleton();
     $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', $this);
     $urlParams = 'force=1';
     if (CRM_Utils_Rule::qfKey($qfKey)) {
         $urlParams .= '&qfKey=' . $qfKey;
     }
     $session->replaceUserContext(CRM_Utils_System::url('civicrm/survey/search', $urlParams));
 }
开发者ID:nielosz,项目名称:civicrm-core,代码行数:39,代码来源:Task.php

示例11: 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;
 }
开发者ID:JSProffitt,项目名称:civicrm-website-org,代码行数:101,代码来源:Contact.php

示例12: moveAllBelongings


//.........这里部分代码省略.........
             }
         }
     }
     // **** Do file custom fields related migrations
     // FIXME: move this someplace else (one of the BAOs) after discussing
     // where to, and whether CRM_Core_BAO_File::deleteFileReferences() shouldn't actually,
     // like, delete a file...
     if (!isset($customFiles)) {
         $customFiles = array();
     }
     foreach ($customFiles as $customId) {
         list($tableName, $columnName, $groupID) = CRM_Core_BAO_CustomField::getTableColumnGroup($customId);
         // get the contact_id -> file_id mapping
         $fileIds = array();
         $sql = "SELECT entity_id, {$columnName} AS file_id FROM {$tableName} WHERE entity_id IN ({$mainId}, {$otherId})";
         $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
         while ($dao->fetch()) {
             $fileIds[$dao->entity_id] = $dao->file_id;
         }
         $dao->free();
         // delete the main contact's file
         if (!empty($fileIds[$mainId])) {
             CRM_Core_BAO_File::deleteFileReferences($fileIds[$mainId], $mainId, $customId);
         }
         // move the other contact's file to main contact
         //NYSS need to INSERT or UPDATE depending on whether main contact has an existing record
         if (CRM_Core_DAO::singleValueQuery("SELECT id FROM {$tableName} WHERE entity_id = {$mainId}")) {
             $sql = "UPDATE {$tableName} SET {$columnName} = {$fileIds[$otherId]} WHERE entity_id = {$mainId}";
         } else {
             $sql = "INSERT INTO {$tableName} ( entity_id, {$columnName} ) VALUES ( {$mainId}, {$fileIds[$otherId]} )";
         }
         CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
         if (CRM_Core_DAO::singleValueQuery("\n        SELECT id\n        FROM civicrm_entity_file\n        WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}")) {
             $sql = "\n          UPDATE civicrm_entity_file\n          SET entity_id = {$mainId}\n          WHERE entity_table = '{$tableName}' AND file_id = {$fileIds[$otherId]}";
         } else {
             $sql = "\n          INSERT INTO civicrm_entity_file ( entity_table, entity_id, file_id )\n          VALUES ( '{$tableName}', {$mainId}, {$fileIds[$otherId]} )";
         }
         CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
     }
     // move view only custom fields CRM-5362
     $viewOnlyCustomFields = array();
     foreach ($submitted as $key => $value) {
         $fid = (int) substr($key, 7);
         if (array_key_exists($fid, $cFields) && !empty($cFields[$fid]['attributes']['is_view'])) {
             $viewOnlyCustomFields[$key] = $value;
         }
     }
     // special case to set values for view only, CRM-5362
     if (!empty($viewOnlyCustomFields)) {
         $viewOnlyCustomFields['entityID'] = $mainId;
         CRM_Core_BAO_CustomValueTable::setValues($viewOnlyCustomFields);
     }
     // **** Delete other contact & update prev-next caching
     $otherParams = array('contact_id' => $otherId, 'id' => $otherId, 'version' => 3);
     if (CRM_Core_Permission::check('merge duplicate contacts') && CRM_Core_Permission::check('delete contacts')) {
         // if ext id is submitted then set it null for contact to be deleted
         if (!empty($submitted['external_identifier'])) {
             $query = "UPDATE civicrm_contact SET external_identifier = null WHERE id = {$otherId}";
             CRM_Core_DAO::executeQuery($query);
         }
         civicrm_api('contact', 'delete', $otherParams);
         CRM_Core_BAO_PrevNextCache::deleteItem($otherId);
     }
     // FIXME: else part
     /*         else { */
     /*             CRM_Core_Session::setStatus( ts('Do not have sufficient permission to delete duplicate contact.') ); */
     /*         } */
     // CRM-15681 merge sub_types
     if ($other_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['other_details'])) {
         if ($main_sub_types = CRM_Utils_array::value('contact_sub_type', $migrationInfo['main_details'])) {
             $submitted['contact_sub_type'] = array_unique(array_merge($main_sub_types, $other_sub_types));
         } else {
             $submitted['contact_sub_type'] = $other_sub_types;
         }
     }
     // **** Update contact related info for the main contact
     if (!empty($submitted)) {
         $submitted['contact_id'] = $mainId;
         //update current employer field
         if ($currentEmloyerId = CRM_Utils_Array::value('current_employer_id', $submitted)) {
             if (!CRM_Utils_System::isNull($currentEmloyerId)) {
                 $submitted['current_employer'] = $submitted['current_employer_id'];
             } else {
                 $submitted['current_employer'] = '';
             }
             unset($submitted['current_employer_id']);
         }
         //CRM-14312 include prefix/suffix from mainId if not overridden for proper construction of display/sort name
         if (!isset($submitted['prefix_id']) && !empty($migrationInfo['main_details']['prefix_id'])) {
             $submitted['prefix_id'] = $migrationInfo['main_details']['prefix_id'];
         }
         if (!isset($submitted['suffix_id']) && !empty($migrationInfo['main_details']['suffix_id'])) {
             $submitted['suffix_id'] = $migrationInfo['main_details']['suffix_id'];
         }
         CRM_Contact_BAO_Contact::createProfileContact($submitted, CRM_Core_DAO::$_nullArray, $mainId);
         unset($submitted);
     }
     CRM_Utils_Hook::post('merge', 'Contact', $mainId, CRM_Core_DAO::$_nullObject);
     return TRUE;
 }
开发者ID:BorislavZlatanov,项目名称:civicrm-core,代码行数:101,代码来源:Merger.php

示例13: 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);
     }
 }
开发者ID:peteainsworth,项目名称:civicrm-4.2.9-drupal,代码行数:52,代码来源:PrevNextCache.php

示例14: buildPrevNextCache

 /**
  * @param $sort
  *
  * @return string
  */
 function buildPrevNextCache($sort)
 {
     $cacheKey = 'civicrm search ' . $this->_key;
     // Get current page requested
     $pageNum = CRM_Utils_Request::retrieve('crmPID', 'Integer', CRM_Core_DAO::$_nullObject);
     // When starting from scratch, clear any old cache
     if (!$pageNum) {
         CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey, 'civicrm_contact');
         $pageNum = 1;
     }
     $pageSize = CRM_Utils_Request::retrieve('crmRowCount', 'Integer', CRM_Core_DAO::$_nullObject, FALSE, 50);
     $firstRecord = ($pageNum - 1) * $pageSize;
     //for alphabetic pagination selection save
     $sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', CRM_Core_DAO::$_nullObject);
     //for text field pagination selection save
     $countRow = CRM_Core_BAO_PrevNextCache::getCount($cacheKey, NULL, "entity_table = 'civicrm_contact'");
     // $sortByCharacter triggers a refresh in the prevNext cache
     if ($sortByCharacter && $sortByCharacter != 'all') {
         $cacheKey .= "_alphabet";
         $this->fillupPrevNextCache($sort, $cacheKey);
     } elseif ($firstRecord >= $countRow) {
         $this->fillupPrevNextCache($sort, $cacheKey, $countRow, 500);
     }
     return $cacheKey;
 }
开发者ID:prashantgajare,项目名称:civicrm-core,代码行数:30,代码来源:Selector.php

示例15: cleanup

 /**
  * Do periodic cleanup of the CiviCRM session table. Also delete all session cache entries
  * which are a couple of days old. This keeps the session cache to a manageable size
  *
  * @return void
  * @static
  * @access private
  */
 static function cleanup($session = false, $table = false, $prevNext = false)
 {
     // clean up the session cache every $cacheCleanUpNumber probabilistically
     $cleanUpNumber = 757;
     // clean up all sessions older than $cacheTimeIntervalDays days
     $timeIntervalDays = 2;
     $timeIntervalMins = 30;
     if (mt_rand(1, 100000) % $cleanUpNumber == 0) {
         $session = $table = $prevNext = true;
     }
     if (!$session && !$table && !$prevNext) {
         return;
     }
     if ($prevNext) {
         // delete all PrevNext caches
         CRM_Core_BAO_PrevNextCache::cleanupCache();
     }
     if ($table) {
         // also delete all the action temp tables
         // that were created the same interval ago
         $dao = new CRM_Core_DAO();
         $query = "\nSELECT TABLE_NAME as tableName\nFROM   INFORMATION_SCHEMA.TABLES\nWHERE  TABLE_SCHEMA = %1\nAND    ( TABLE_NAME LIKE 'civicrm_task_action_temp_%'\n OR      TABLE_NAME LIKE 'civicrm_export_temp_%'\n OR      TABLE_NAME LIKE 'civicrm_import_job_%' )\nAND    CREATE_TIME < date_sub( NOW( ), INTERVAL {$timeIntervalDays} day )\n";
         $params = array(1 => array($dao->database(), 'String'));
         $tableDAO = CRM_Core_DAO::executeQuery($query, $params);
         $tables = array();
         while ($tableDAO->fetch()) {
             $tables[] = $tableDAO->tableName;
         }
         if (!empty($tables)) {
             $table = implode(',', $tables);
             // drop leftover temporary tables
             CRM_Core_DAO::executeQuery("DROP TABLE {$table}");
         }
     }
     if ($session) {
         // first delete all sessions which are related to any potential transaction
         // page
         $transactionPages = array('CRM_Contribute_Controller_Contribution', 'CRM_Event_Controller_Registration');
         $params = array(1 => array(date('Y-m-d H:i:s', time() - $timeIntervalMins * 60), 'String'));
         foreach ($transactionPages as $trPage) {
             $params[] = array("%{$trPage}%", 'String');
             $where[] = 'path LIKE %' . sizeof($params);
         }
         $sql = "\nDELETE FROM civicrm_cache\nWHERE       group_name = 'CiviCRM Session'\nAND         created_date <= %1\nAND         (" . implode(' OR ', $where) . ")";
         CRM_Core_DAO::executeQuery($sql, $params);
         $sql = "\nDELETE FROM civicrm_cache\nWHERE       group_name = 'CiviCRM Session'\nAND         created_date < date_sub( NOW( ), INTERVAL {$timeIntervalDays} DAY )\n";
         CRM_Core_DAO::executeQuery($sql);
     }
 }
开发者ID:hguru,项目名称:224Civi,代码行数:57,代码来源:Cache.php


注:本文中的CRM_Core_BAO_PrevNextCache类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。