static function importableFields($contactType = 'HRJobContractRevision', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE) { if (empty($contactType)) { $contactType = 'HRJobContractRevision'; } $cacheKeyString = ""; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $showAll ? '_1' : '_0'; $cacheKeyString .= $isProfile ? '_1' : '_0'; $cacheKeyString .= $checkPermission ? '_1' : '_0'; $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields); if (!$fields) { $fields = CRM_Hrjobcontract_DAO_HRJobContractRevision::import(); $fields = array_merge($fields, CRM_Hrjobcontract_DAO_HRJobContractRevision::import()); //Sorting fields in alphabetical order(CRM-1507) $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title'); $fields = CRM_Utils_Array::index(array('name'), $fields); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; if (!$isProfile) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } return $fields; }
/** * combine all the importable fields from the lower levels object * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important * * @param int $contactType contact Type * @param boolean $status status is used to manipulate first title * @param boolean $showAll if true returns all fields (includes disabled fields) * @param boolean $isProfile if its profile mode * @param boolean $checkPermission if false, do not include permissioning clause (for custom data) * * @return array array of importable Fields * @access public * @static */ static function importableFields($contactType = 'HRJobLeave', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE) { if (empty($contactType)) { $contactType = 'HRJobLeave'; } $cacheKeyString = ""; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $showAll ? '_1' : '_0'; $cacheKeyString .= $isProfile ? '_1' : '_0'; $cacheKeyString .= $checkPermission ? '_1' : '_0'; $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields); if (!$fields) { $fields = CRM_HRJob_DAO_HRJobLeave::import(); $fields = array_merge($fields, CRM_HRJOB_DAO_HRJOBLEAVE::import()); foreach ($fields as $key => $v) { $fields[$key]['hasLocationType'] = TRUE; } //Sorting fields in alphabetical order $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title'); $fields = CRM_Utils_Array::index(array('name'), $fields); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; if (!$isProfile) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } return $fields; }
function batchSave() { // save in cache table $batchId = CRM_Utils_Type::escape($_POST['batch_id'], 'Positive'); $cacheKeyString = CRM_Core_BAO_Batch::getCacheKeyForBatch($batchId); // check if we can retrieve from database cache unset($_POST['qfKey']); CRM_Core_BAO_Cache::setItem($_POST, 'batch entry', $cacheKeyString); // return true if saved correctly CRM_Utils_System::civiExit(); }
/** * Test system flush. */ public function testFlush() { // Note: this operation actually flushes several different caches; we don't // check all of them -- just enough to make sure that the API is doing // something $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); $data = 'abc'; CRM_Core_BAO_Cache::setItem($data, self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH); $this->assertEquals('abc', CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); $params = array(); $result = $this->callAPIAndDocument('system', 'flush', $params, __FUNCTION__, __FILE__, "Flush all system caches", 'Flush'); $this->assertTrue(NULL === CRM_Core_BAO_Cache::getItem(self::TEST_CACHE_GROUP, self::TEST_CACHE_PATH)); }
public function testSetGetItem() { $originalValue = array('abc' => 'def'); CRM_Core_BAO_Cache::setItem($originalValue, __CLASS__, 'testSetGetItem'); $return_1 = CRM_Core_BAO_Cache::getItem(__CLASS__, 'testSetGetItem'); $this->assertEquals($originalValue, $return_1); // Wipe out any in-memory copies of the cache. Check to see if the SQL // read is correct. CRM_Core_BAO_Cache::$_cache = NULL; CRM_Utils_Cache::$_singleton = NULL; $return_2 = CRM_Core_BAO_Cache::getItem(__CLASS__, 'testSetGetItem'); $this->assertEquals($originalValue, $return_2); }
function buildPrevNextCache($sort) { //for prev/next pagination $crmPID = CRM_Utils_Request::retrieve('crmPID', 'Integer', CRM_Core_DAO::$_nullObject); if (!$crmPID) { $cacheKey = "civicrm search {$this->_key}"; CRM_Core_BAO_PrevNextCache::deleteItem(NULL, $cacheKey, 'civicrm_contact'); $sql = $this->_query->searchQuery(0, 0, $sort, FALSE, FALSE, FALSE, FALSE, TRUE, $this->_campaignWhereClause, NULL, $this->_campaignFromClause); list($select, $from) = explode(' FROM ', $sql); $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\nFROM {$from}\n"; CRM_Core_Error::ignoreException(); $result = CRM_Core_DAO::executeQuery($insertSQL); CRM_Core_Error::setCallback(); if (is_a($result, 'DB_Error')) { 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); } }
/** * Reset navigation for all contacts */ static function resetNavigation() { $query = "UPDATE civicrm_preferences SET navigation = NULL WHERE contact_id IS NOT NULL"; CRM_Core_DAO::executeQuery($query); require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::deleteGroup('navigation'); }
function prefetch() { $this->frontCache = CRM_Core_BAO_Cache::getItems($this->group, $this->componentID); }
/** * Load up settings metadata from files. */ public static function loadSettingsMetadata($metaDataFolder) { $settingMetaData = array(); $settingsFiles = CRM_Utils_File::findFiles($metaDataFolder, '*.setting.php'); foreach ($settingsFiles as $file) { $settings = (include $file); $settingMetaData = array_merge($settingMetaData, $settings); } CRM_Core_BAO_Cache::setItem($settingMetaData, 'CiviCRM setting Spec', 'All'); return $settingMetaData; }
/** * process the form after the input has been submitted and validated * * @access public * * @return None */ public function postProcess() { $params = $this->controller->exportValues($this->_name); $params['actualBatchTotal'] = 0; // get the profile information if ($this->_batchInfo['type_id'] == 1) { $this->processContribution($params); } else { $this->processMembership($params); } // update batch to close status $paramValues = array('id' => $this->_batchId, 'status_id' => 2, 'total' => $params['actualBatchTotal']); CRM_Core_BAO_Batch::create($paramValues); // delete from cache table $cacheKeyString = CRM_Core_BAO_Batch::getCacheKeyForBatch($this->_batchId); CRM_Core_BAO_Cache::deleteGroup('batch entry', $cacheKeyString, FALSE); // set success status CRM_Core_Session::setStatus("Your batch has been processed."); CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/batch', 'reset=1&status=2')); }
/** * combine all the importable fields from the lower levels object * * The ordering is important, since currently we do not have a weight * scheme. Adding weight is super important * * @param int $contactType contact Type * @param boolean $status status is used to manipulate first title * @param boolean $showAll if true returns all fields (includes disabled fields) * @param boolean $isProfile if its profile mode * @param boolean $checkPermission if false, do not include permissioning clause (for custom data) * * @return array array of importable Fields * @access public * @static */ static function importableFields($contactType = 'Individual', $status = FALSE, $showAll = FALSE, $isProfile = FALSE, $checkPermission = TRUE, $withMultiCustomFields = FALSE) { $cacheKeyString = ""; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $showAll ? '_1' : '_0'; $cacheKeyString .= $isProfile ? '_1' : '_0'; $cacheKeyString .= $checkPermission ? '_1' : '_0'; $contactType = 'Individual'; $fields = CRM_Utils_Array::value($cacheKeyString, self::$_importableFields); if (!$fields) { $fields = CRM_Appraisals_DAO_AppraisalCycle::import(); $tmpContactField = $contactFields = array(); $contactFields = CRM_Contact_BAO_Contact::importableFields($contactType, NULL); // Using new Dedupe rule. $ruleParams = array('contact_type' => $contactType, 'used' => 'Unsupervised'); $fieldsArray = CRM_Dedupe_BAO_Rule::dedupeRuleFields($ruleParams); if (is_array($fieldsArray)) { foreach ($fieldsArray as $value) { $customFieldId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_CustomField', $value, 'id', 'column_name'); $value = $customFieldId ? 'custom_' . $customFieldId : $value; $tmpContactField[trim($value)] = CRM_Utils_Array::value(trim($value), $contactFields); if (!$status) { $title = $tmpContactField[trim($value)]['title'] . ' (match to contact)'; } else { $title = $tmpContactField[trim($value)]['title']; } $tmpContactField[trim($value)]['title'] = $title; } } $extIdentifier = CRM_Utils_Array::value('external_identifier', $contactFields); if ($extIdentifier) { $tmpContactField['external_identifier'] = $extIdentifier; $tmpContactField['external_identifier']['title'] = CRM_Utils_Array::value('title', $extIdentifier) . ' (match to contact)'; } $fields = array_merge($fields, $tmpContactField); //Sorting fields in alphabetical order(CRM-1507) $fields = CRM_Utils_Array::crmArraySortByField($fields, 'title'); $fields = CRM_Utils_Array::index(array('name'), $fields); CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_importableFields[$cacheKeyString] = $fields; if (!$isProfile) { $fields = array_merge(array('do_not_import' => array('title' => ts('- do not import -'))), self::$_importableFields[$cacheKeyString]); } return $fields; }
/** * Combine all the exportable fields from the lower levels object. * * Currently we are using importable fields as exportable fields * * @param int|string $contactType contact Type * @param bool $status * True while exporting primary contacts. * @param bool $export * True when used during export. * @param bool $search * True when used during search, might conflict with export param?. * * @param bool $withMultiRecord * * @return array * array of exportable Fields */ public static function &exportableFields($contactType = 'Individual', $status = FALSE, $export = FALSE, $search = FALSE, $withMultiRecord = FALSE) { if (empty($contactType)) { $contactType = 'All'; } $cacheKeyString = "exportableFields {$contactType}"; $cacheKeyString .= $export ? '_1' : '_0'; $cacheKeyString .= $status ? '_1' : '_0'; $cacheKeyString .= $search ? '_1' : '_0'; //CRM-14501 it turns out that the impact of permissioning here is sometimes inconsistent. The field that //calculates custom fields takes into account the logged in user & caches that for all users //as an interim fix we will cache the fields by contact $cacheKeyString .= '_' . CRM_Core_Session::getLoggedInContactID(); if (!self::$_exportableFields || !CRM_Utils_Array::value($cacheKeyString, self::$_exportableFields)) { if (!self::$_exportableFields) { self::$_exportableFields = array(); } // check if we can retrieve from database cache $fields = CRM_Core_BAO_Cache::getItem('contact fields', $cacheKeyString); if (!$fields) { $fields = CRM_Contact_DAO_Contact::export(); // The fields are meant for contact types. if (in_array($contactType, array('Individual', 'Household', 'Organization', 'All'))) { $fields = array_merge($fields, CRM_Core_OptionValue::getFields('', $contactType)); } // add current employer for individuals $fields = array_merge($fields, array('current_employer' => array('name' => 'organization_name', 'title' => ts('Current Employer')))); $locationType = array('location_type' => array('name' => 'location_type', 'where' => 'civicrm_location_type.name', 'title' => ts('Location Type'))); $IMProvider = array('im_provider' => array('name' => 'im_provider', 'where' => 'civicrm_im.provider_id', 'title' => ts('IM Provider'))); $locationFields = array_merge($locationType, CRM_Core_DAO_Address::export(), CRM_Core_DAO_Phone::export(), CRM_Core_DAO_Email::export(), $IMProvider, CRM_Core_DAO_IM::export(TRUE), CRM_Core_DAO_OpenID::export()); $locationFields = array_merge($locationFields, CRM_Core_BAO_CustomField::getFieldsForImport('Address')); foreach ($locationFields as $key => $field) { $locationFields[$key]['hasLocationType'] = TRUE; } $fields = array_merge($fields, $locationFields); //add world region $fields = array_merge($fields, CRM_Core_DAO_Worldregion::export()); $fields = array_merge($fields, CRM_Contact_DAO_Contact::export()); //website fields $fields = array_merge($fields, CRM_Core_DAO_Website::export()); if ($contactType != 'All') { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($contactType, $status, FALSE, $search, TRUE, $withMultiRecord)); } else { foreach (array('Individual', 'Household', 'Organization') as $type) { $fields = array_merge($fields, CRM_Core_BAO_CustomField::getFieldsForImport($type, FALSE, FALSE, $search, TRUE, $withMultiRecord)); } } //fix for CRM-791 if ($export) { $fields = array_merge($fields, array('groups' => array('title' => ts('Group(s)'), 'name' => 'groups'), 'tags' => array('title' => ts('Tag(s)'), 'name' => 'tags'), 'notes' => array('title' => ts('Note(s)'), 'name' => 'notes'))); } else { $fields = array_merge($fields, array('group' => array('title' => ts('Group(s)'), 'name' => 'group'), 'tag' => array('title' => ts('Tag(s)'), 'name' => 'tag'), 'note' => array('title' => ts('Note(s)'), 'name' => 'note'))); } //Sorting fields in alphabetical order(CRM-1507) foreach ($fields as $k => $v) { $sortArray[$k] = CRM_Utils_Array::value('title', $v); } $fields = array_merge($sortArray, $fields); //unset the field which are not related to their contact type. if ($contactType != 'All') { $commonValues = array('Individual' => array('household_name', 'legal_name', 'sic_code', 'organization_name', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom'), 'Household' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'organization_name', 'legal_name', 'legal_identifier', 'sic_code', 'home_URL', 'is_deceased', 'deceased_date', 'current_employer', 'email_greeting_custom', 'postal_greeting_custom', 'addressee_custom', 'prefix_id', 'suffix_id'), 'Organization' => array('first_name', 'middle_name', 'last_name', 'formal_title', 'job_title', 'gender_id', 'prefix_id', 'suffix_id', 'birth_date', 'household_name', 'email_greeting_custom', 'postal_greeting_custom', 'prefix_id', 'suffix_id', 'gender_id', 'addressee_custom', 'is_deceased', 'deceased_date', 'current_employer')); foreach ($commonValues[$contactType] as $value) { unset($fields[$value]); } } CRM_Core_BAO_Cache::setItem($fields, 'contact fields', $cacheKeyString); } self::$_exportableFields[$cacheKeyString] = $fields; } if (!$status) { $fields = self::$_exportableFields[$cacheKeyString]; } else { $fields = array_merge(array('' => array('title' => ts('- Contact Fields -'))), self::$_exportableFields[$cacheKeyString]); } return $fields; }
/** * update the is_active flag in the db * * @param int $id id of the database record * @param boolean $is_active value we want to set the is_active field * * @return Object DAO object on sucess, null otherwise * @static */ static function setIsActive($id, $is_active) { // note this also resets any ACL cache CRM_Core_BAO_Cache::deleteGroup('contact fields'); return CRM_Core_DAO::setFieldValue('CRM_ACL_DAO_ACL', $id, 'is_active', $is_active); }
/** * Create a new group. * * @param array $params * * @return CRM_Contact_BAO_Group|NULL * The new group BAO (if created) */ public static function &create(&$params) { if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Group', NULL, $params); } // form the name only if missing: CRM-627 $nameParam = CRM_Utils_Array::value('name', $params, NULL); if (!$nameParam && empty($params['id'])) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // convert params if array type if (isset($params['group_type'])) { if (is_array($params['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $params['group_type'] = ''; } $session = CRM_Core_Session::singleton(); $cid = $session->get('userID'); // this action is add if ($cid && empty($params['id'])) { $params['created_id'] = $cid; } // this action is update if ($cid && !empty($params['id'])) { $params['modified_id'] = $cid; } $group = new CRM_Contact_BAO_Group(); $group->copyValues($params); //@todo very hacky fix for the fact this function wants to receive 'parents' as an array further down but // needs it as a separated string for the DB. Preferred approaches are having the copyParams or save fn // use metadata to translate the array to the appropriate DB type or altering the param in the api layer, // or at least altering the param in same section as 'group_type' rather than repeating here. However, further down // we need the $params one to be in it's original form & we are not sure what test coverage we have on that if (isset($group->parents) && is_array($group->parents)) { $group->parents = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($group->parents)) . CRM_Core_DAO::VALUE_SEPARATOR; } if (empty($params['id']) && !$nameParam) { $group->name .= "_tmp"; } $group->save(); if (!$group->id) { return NULL; } if (empty($params['id']) && !$nameParam) { $group->name = substr($group->name, 0, -4) . "_{$group->id}"; } $group->buildClause(); $group->save(); // add custom field values if (!empty($params['custom'])) { CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } // make the group, child of domain/site group by default. $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); if (CRM_Utils_Array::value('no_parent', $params) !== 1) { if (empty($params['parents']) && $domainGroupID != $group->id && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MULTISITE_PREFERENCES_NAME, 'is_enabled') && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) { // if no parent present and the group doesn't already have any parents, // make sure site group goes as parent $params['parents'] = array($domainGroupID => 1); } elseif (array_key_exists('parents', $params) && !is_array($params['parents'])) { $params['parents'] = array($params['parents'] => 1); } if (!empty($params['parents'])) { foreach ($params['parents'] as $parentId => $dnc) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } } } // clear any descendant groups cache if exists $finalGroups = CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); // this is always required, since we don't know when a // parent group is removed CRM_Contact_BAO_GroupNestingCache::update(); // update group contact cache for all parent groups $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); foreach ($parentIds as $parentId) { CRM_Contact_BAO_GroupContactCache::add($parentId); } } if (!empty($params['organization_id'])) { $groupOrg = array(); $groupOrg = $params; $groupOrg['group_id'] = $group->id; CRM_Contact_BAO_GroupOrganization::add($groupOrg); } CRM_Contact_BAO_GroupContactCache::add($group->id); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Group', $group->id, $group); } else { CRM_Utils_Hook::post('create', 'Group', $group->id, $group); } $recentOther = array(); if (CRM_Core_Permission::check('edit groups')) { $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=update&id=' . $group->id); // currently same permission we are using for delete a group $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/group', 'reset=1&action=delete&id=' . $group->id); } // add the recently added group (unless hidden: CRM-6432) if (!$group->is_hidden) { CRM_Utils_Recent::add($group->title, CRM_Utils_System::url('civicrm/group/search', 'reset=1&force=1&context=smog&gid=' . $group->id), $group->id, 'Group', NULL, NULL, $recentOther); } return $group; }
/** * Check that setting defined in extension can be retrieved. */ public function testGetExtensionSetting() { $this->hookClass->setHook('civicrm_alterSettingsFolders', array($this, 'setExtensionMetadata')); $data = NULL; // the caching of data to all duplicates the caching of data to the empty string CRM_Core_BAO_Cache::setItem($data, 'CiviCRM setting Spec', 'All'); CRM_Core_BAO_Cache::setItem($data, 'CiviCRM setting Specs', 'settingsMetadata__'); $fields = $this->callAPISuccess('setting', 'getfields', array('filters' => array('group_name' => 'Test Settings'))); $this->assertArrayHasKey('test_key', $fields['values']); $this->callAPISuccess('setting', 'create', array('test_key' => 'keyset')); $result = $this->callAPISuccess('setting', 'getvalue', array('name' => 'test_key', 'group' => 'Test Settings')); $this->assertEquals('keyset', $result); }
/** * Update the is_active flag in the db. * * @param int $id * Id of the database record. * @param bool $is_active * Value we want to set the is_active field. * * @return Object * DAO object on success, null otherwise */ public static function setIsActive($id, $is_active) { // reset the cache CRM_Core_BAO_Cache::deleteGroup('contact fields'); if (!$is_active) { CRM_Core_BAO_UFField::setUFFieldStatus($id, $is_active); } return CRM_Core_DAO::setFieldValue('CRM_Core_DAO_CustomGroup', $id, 'is_active', $is_active); }
/** * Get html and cache results. * * @param $url * * @return array|NULL * array of gettingStarted items; or NULL if not available */ public function _getHtml($url) { $httpClient = new CRM_Utils_HttpClient(self::CHECK_TIMEOUT); list($status, $html) = $httpClient->get($url); if ($status !== CRM_Utils_HttpClient::STATUS_OK) { return NULL; } $tokensList = CRM_Utils_Token::getTokens($html); $this->replaceLinkToken($tokensList, $html); if ($html) { CRM_Core_BAO_Cache::setItem($html, 'dashboard', 'gettingStarted'); } return $html; }
public function addGroup() { // add the 3 groups first $numGroup = count($this->group); require_once 'CRM/Contact/BAO/Group.php'; for ($i = 0; $i < $numGroup; $i++) { $group = new CRM_Contact_BAO_Group(); $group->name = $this->group[$i]; $group->title = $this->group[$i]; $group->group_type = "12"; $group->visibility = 'Public Pages'; $group->is_active = 1; $group->save(); $group->buildClause(); $group->save(); } // 60 are for newsletter for ($i = 0; $i < 60; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // newsletter subscribers $groupContact->group_id = 2; $groupContact->contact_id = $this->individual[$i]; // membership status $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus); $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->_getRandomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } // 15 volunteers for ($i = 0; $i < 15; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // Volunteers $groupContact->group_id = 3; $groupContact->contact_id = $this->individual[$i + 60]; // membership status $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus); $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->_getRandomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } // 8 advisory board group for ($i = 0; $i < 8; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // advisory board group $groupContact->group_id = 4; $groupContact->contact_id = $this->individual[$i * 7]; // membership status $groupContact->status = $this->_getRandomElement($this->groupMembershipStatus); $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->_getRandomElement($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->_getRandomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } //In this function when we add groups that time we are cache the contact fields //But at the end of setup we are appending sample custom data, so for consistency //reset the cache. require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::deleteGroup('contact fields'); }
/** * Store and return an array of all active custom fields. * * @param string $customDataType * Type of Custom Data; empty is a synonym for "all contact data types". * @param bool $showAll * If true returns all fields (includes disabled fields). * @param bool $inline * If true returns all inline fields (includes disabled fields). * @param int $customDataSubType * Custom Data sub type value. * @param int $customDataSubName * Custom Data sub name value. * @param bool $onlyParent * Return only top level custom data, for eg, only Participant and ignore subname and subtype. * @param bool $onlySubType * Return only custom data for subtype. * @param bool $checkPermission * If false, do not include permissioning clause. * * @return array * an array of active custom fields. * */ public static function &getFields($customDataType = 'Individual', $showAll = FALSE, $inline = FALSE, $customDataSubType = NULL, $customDataSubName = NULL, $onlyParent = FALSE, $onlySubType = FALSE, $checkPermission = TRUE) { if (empty($customDataType)) { $customDataType = array('Contact', 'Individual', 'Organization', 'Household'); } if ($customDataType && !is_array($customDataType)) { if (in_array($customDataType, CRM_Contact_BAO_ContactType::subTypes())) { // This is the case when getFieldsForImport() requires fields // limited strictly to a subtype. $customDataSubType = $customDataType; $customDataType = CRM_Contact_BAO_ContactType::getBasicType($customDataType); $onlySubType = TRUE; } if (in_array($customDataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) { // this makes the method flexible to support retrieving fields // for multiple extends value. $customDataType = array($customDataType); } } $customDataSubType = CRM_Utils_Array::explodePadded($customDataSubType); if (is_array($customDataType)) { $cacheKey = implode('_', $customDataType); } else { $cacheKey = $customDataType; } $cacheKey .= !empty($customDataSubType) ? '_' . implode('_', $customDataSubType) : '_0'; $cacheKey .= $customDataSubName ? "{$customDataSubName}_" : '_0'; $cacheKey .= $showAll ? '_1' : '_0'; $cacheKey .= $inline ? '_1_' : '_0_'; $cacheKey .= $onlyParent ? '_1_' : '_0_'; $cacheKey .= $onlySubType ? '_1_' : '_0_'; $cacheKey .= $checkPermission ? '_1_' : '_0_'; $cgTable = CRM_Core_DAO_CustomGroup::getTableName(); // also get the permission stuff here if ($checkPermission) { $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}."); } else { $permissionClause = '(1)'; } // lets md5 permission clause and take first 8 characters $cacheKey .= substr(md5($permissionClause), 0, 8); if (strlen($cacheKey) > 40) { $cacheKey = md5($cacheKey); } if (!self::$_importFields || CRM_Utils_Array::value($cacheKey, self::$_importFields) === NULL) { if (!self::$_importFields) { self::$_importFields = array(); } // check if we can retrieve from database cache $fields = CRM_Core_BAO_Cache::getItem('contact fields', "custom importableFields {$cacheKey}"); if ($fields === NULL) { $cfTable = self::getTableName(); $extends = ''; if (is_array($customDataType)) { $value = NULL; foreach ($customDataType as $dataType) { if (in_array($dataType, array_keys(CRM_Core_SelectValues::customGroupExtends()))) { if (in_array($dataType, array('Individual', 'Household', 'Organization'))) { $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "', 'Contact' "; } else { $val = "'" . CRM_Utils_Type::escape($dataType, 'String') . "'"; } $value = $value ? $value . ", {$val}" : $val; } } if ($value) { $extends = "AND {$cgTable}.extends IN ( {$value} ) "; } } if (!empty($customDataType) && empty($extends)) { // $customDataType specified a filter, but there is no corresponding SQL ($extends) self::$_importFields[$cacheKey] = array(); return self::$_importFields[$cacheKey]; } if ($onlyParent) { $extends .= " AND {$cgTable}.extends_entity_column_value IS NULL AND {$cgTable}.extends_entity_column_id IS NULL "; } $query = "SELECT {$cfTable}.id, {$cfTable}.label,\n {$cgTable}.title,\n {$cfTable}.data_type,\n {$cfTable}.html_type,\n {$cfTable}.default_value,\n {$cfTable}.options_per_line, {$cfTable}.text_length,\n {$cfTable}.custom_group_id,\n {$cfTable}.is_required,\n {$cgTable}.extends, {$cfTable}.is_search_range,\n {$cgTable}.extends_entity_column_value,\n {$cgTable}.extends_entity_column_id,\n {$cfTable}.is_view,\n {$cfTable}.option_group_id,\n {$cfTable}.date_format,\n {$cfTable}.time_format,\n {$cgTable}.is_multiple,\n og.name as option_group_name\n FROM {$cfTable}\n INNER JOIN {$cgTable}\n ON {$cfTable}.custom_group_id = {$cgTable}.id\n LEFT JOIN civicrm_option_group og\n ON {$cfTable}.option_group_id = og.id\n WHERE ( 1 ) "; if (!$showAll) { $query .= " AND {$cfTable}.is_active = 1 AND {$cgTable}.is_active = 1 "; } if ($inline) { $query .= " AND {$cgTable}.style = 'Inline' "; } //get the custom fields for specific type in //combination with fields those support any type. if (!empty($customDataSubType)) { $subtypeClause = array(); foreach ($customDataSubType as $subtype) { $subtype = CRM_Core_DAO::VALUE_SEPARATOR . $subtype . CRM_Core_DAO::VALUE_SEPARATOR; $subtypeClause[] = "{$cgTable}.extends_entity_column_value LIKE '%{$subtype}%'"; } if (!$onlySubType) { $subtypeClause[] = "{$cgTable}.extends_entity_column_value IS NULL"; } $query .= " AND ( " . implode(' OR ', $subtypeClause) . " )"; } if ($customDataSubName) { $query .= " AND ( {$cgTable}.extends_entity_column_id = {$customDataSubName} ) "; } // also get the permission stuff here if ($checkPermission) { $permissionClause = CRM_Core_Permission::customGroupClause(CRM_Core_Permission::VIEW, "{$cgTable}.", TRUE); } else { $permissionClause = '(1)'; } $query .= " {$extends} AND {$permissionClause}\n ORDER BY {$cgTable}.weight, {$cgTable}.title,\n {$cfTable}.weight, {$cfTable}.label"; $dao = CRM_Core_DAO::executeQuery($query); $fields = array(); while ($dao->fetch() != NULL) { $fields[$dao->id]['label'] = $dao->label; $fields[$dao->id]['groupTitle'] = $dao->title; $fields[$dao->id]['data_type'] = $dao->data_type; $fields[$dao->id]['html_type'] = $dao->html_type; $fields[$dao->id]['default_value'] = $dao->default_value; $fields[$dao->id]['text_length'] = $dao->text_length; $fields[$dao->id]['options_per_line'] = $dao->options_per_line; $fields[$dao->id]['custom_group_id'] = $dao->custom_group_id; $fields[$dao->id]['extends'] = $dao->extends; $fields[$dao->id]['is_search_range'] = $dao->is_search_range; $fields[$dao->id]['extends_entity_column_value'] = $dao->extends_entity_column_value; $fields[$dao->id]['extends_entity_column_id'] = $dao->extends_entity_column_id; $fields[$dao->id]['is_view'] = $dao->is_view; $fields[$dao->id]['is_multiple'] = $dao->is_multiple; $fields[$dao->id]['option_group_id'] = $dao->option_group_id; $fields[$dao->id]['date_format'] = $dao->date_format; $fields[$dao->id]['time_format'] = $dao->time_format; $fields[$dao->id]['is_required'] = $dao->is_required; self::getOptionsForField($fields[$dao->id], $dao->option_group_name); } CRM_Core_BAO_Cache::setItem($fields, 'contact fields', "custom importableFields {$cacheKey}"); } self::$_importFields[$cacheKey] = $fields; } return self::$_importFields[$cacheKey]; }
/** * Retrieve the settings values from db. * * @param $defaults * * @return array */ public static function retrieve(&$defaults) { $domain = new CRM_Core_DAO_Domain(); //we are initializing config, really can't use, CRM-7863 $urlVar = 'q'; if (defined('CIVICRM_UF') && CIVICRM_UF == 'Joomla') { $urlVar = 'task'; } if (CRM_Core_Config::isUpgradeMode()) { $domain->selectAdd('config_backend'); } elseif (CRM_Utils_Array::value($urlVar, $_GET) == 'admin/modules/list/confirm') { $domain->selectAdd('config_backend', 'locales'); } else { $domain->selectAdd('config_backend, locales, locale_custom_strings'); } $domain->id = CRM_Core_Config::domainID(); $domain->find(TRUE); if ($domain->config_backend) { $defaults = unserialize($domain->config_backend); if ($defaults === FALSE || !is_array($defaults)) { $defaults = array(); return FALSE; } $skipVars = self::skipVars(); foreach ($skipVars as $skip) { if (array_key_exists($skip, $defaults)) { unset($defaults[$skip]); } } // check if there are any locale strings if ($domain->locale_custom_strings) { $defaults['localeCustomStrings'] = unserialize($domain->locale_custom_strings); } else { $defaults['localeCustomStrings'] = NULL; } // are we in a multi-language setup? $multiLang = $domain->locales ? TRUE : FALSE; // set the current language $lcMessages = NULL; $session = CRM_Core_Session::singleton(); // on multi-lang sites based on request and civicrm_uf_match if ($multiLang) { $lcMessagesRequest = CRM_Utils_Request::retrieve('lcMessages', 'String', $this); $languageLimit = array(); if (array_key_exists('languageLimit', $defaults) && is_array($defaults['languageLimit'])) { $languageLimit = $defaults['languageLimit']; } if (in_array($lcMessagesRequest, array_keys($languageLimit))) { $lcMessages = $lcMessagesRequest; //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache. CRM_Core_BAO_Cache::deleteGroup('navigation'); } else { $lcMessagesRequest = NULL; } if (!$lcMessagesRequest) { $lcMessagesSession = $session->get('lcMessages'); if (in_array($lcMessagesSession, array_keys($languageLimit))) { $lcMessages = $lcMessagesSession; } else { $lcMessagesSession = NULL; } } if ($lcMessagesRequest) { $ufm = new CRM_Core_DAO_UFMatch(); $ufm->contact_id = $session->get('userID'); if ($ufm->find(TRUE)) { $ufm->language = $lcMessages; $ufm->save(); } $session->set('lcMessages', $lcMessages); } if (!$lcMessages and $session->get('userID')) { $ufm = new CRM_Core_DAO_UFMatch(); $ufm->contact_id = $session->get('userID'); if ($ufm->find(TRUE) && in_array($ufm->language, array_keys($languageLimit))) { $lcMessages = $ufm->language; } $session->set('lcMessages', $lcMessages); } } global $dbLocale; // try to inherit the language from the hosting CMS if (!empty($defaults['inheritLocale'])) { // FIXME: On multilanguage installs, CRM_Utils_System::getUFLocale() in many cases returns nothing if $dbLocale is not set $dbLocale = $multiLang ? "_{$defaults['lcMessages']}" : ''; $lcMessages = CRM_Utils_System::getUFLocale(); if ($domain->locales and !in_array($lcMessages, explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales))) { $lcMessages = NULL; } } if (empty($lcMessages)) { //CRM-11993 - if a single-lang site, use default $lcMessages = CRM_Utils_Array::value('lcMessages', $defaults); } // set suffix for table names - use views if more than one language $dbLocale = $multiLang ? "_{$lcMessages}" : ''; // FIXME: an ugly hack to fix CRM-4041 global $tsLocale; $tsLocale = $lcMessages; // FIXME: as bad aplace as any to fix CRM-5428 // (to be moved to a sane location along with the above) if (function_exists('mb_internal_encoding')) { mb_internal_encoding('UTF-8'); } } // dont add if its empty if (!empty($defaults)) { // retrieve directory and url preferences also CRM_Core_BAO_Setting::retrieveDirectoryAndURLPreferences($defaults); // Pickup enabled-components from settings table if found. $enableComponents = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components', NULL, array()); if (!empty($enableComponents)) { $defaults['enableComponents'] = $enableComponents; $components = CRM_Core_Component::getComponents(); $enabledComponentIDs = array(); foreach ($defaults['enableComponents'] as $name) { $enabledComponentIDs[] = $components[$name]->componentID; } $defaults['enableComponentIDs'] = $enabledComponentIDs; } } }
/** * Process the form * * @param null * * @return void * @access public */ public function postProcess() { // store the submitted values in an array $params = $this->controller->exportValues($this->_name); if ($this->_action == CRM_Core_Action::UPDATE) { $dataTypeKey = $this->_defaultDataType[0]; $params['data_type'] = self::$_dataTypeKeys[$this->_defaultDataType[0]]; $params['html_type'] = self::$_dataToHTML[$this->_defaultDataType[0]][$this->_defaultDataType[1]]; } else { $dataTypeKey = $params['data_type'][0]; $params['html_type'] = self::$_dataToHTML[$params['data_type'][0]][$params['data_type'][1]]; $params['data_type'] = self::$_dataTypeKeys[$params['data_type'][0]]; } //fix for 'is_search_range' field. if (in_array($dataTypeKey, array(1, 2, 3, 5))) { if (!CRM_Utils_Array::value('is_searchable', $params)) { $params['is_search_range'] = 0; } } else { $params['is_search_range'] = 0; } $filter = 'null'; if ($dataTypeKey == 11 && CRM_Utils_Array::value('filter_selected', $params)) { if ($params['filter_selected'] == 'Advance' && trim(CRM_Utils_Array::value('filter', $params))) { $filter = trim($params['filter']); } elseif ($params['filter_selected'] == 'Group' && CRM_Utils_Array::value('group_id', $params)) { $filter = 'action=lookup&group=' . implode(',', $params['group_id']); } } $params['filter'] = $filter; // fix for CRM-316 $oldWeight = NULL; if ($this->_action & (CRM_Core_Action::UPDATE | CRM_Core_Action::ADD)) { $fieldValues = array('custom_group_id' => $this->_gid); if ($this->_id) { $oldWeight = $this->_values['weight']; } $params['weight'] = CRM_Utils_Weight::updateOtherWeights('CRM_Core_DAO_CustomField', $oldWeight, $params['weight'], $fieldValues); } $strtolower = function_exists('mb_strtolower') ? 'mb_strtolower' : 'strtolower'; //store the primary key for State/Province or Country as default value. if (strlen(trim($params['default_value']))) { switch ($params['data_type']) { case 'StateProvince': $fieldStateProvince = $strtolower($params['default_value']); $query = "\nSELECT id\n FROM civicrm_state_province\n WHERE LOWER(name) = '{$fieldStateProvince}'\n OR abbreviation = '{$fieldStateProvince}'"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); if ($dao->fetch()) { $params['default_value'] = $dao->id; } break; case 'Country': $fieldCountry = $strtolower($params['default_value']); $query = "\nSELECT id\n FROM civicrm_country\n WHERE LOWER(name) = '{$fieldCountry}'\n OR iso_code = '{$fieldCountry}'"; $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); if ($dao->fetch()) { $params['default_value'] = $dao->id; } break; } } // The text_length attribute for Memo fields is in a different input as there // are different label, help text and default value than for other type fields if ($params['data_type'] == "Memo") { $params['text_length'] = $params['note_length']; } // need the FKEY - custom group id $params['custom_group_id'] = $this->_gid; if ($this->_action & CRM_Core_Action::UPDATE) { $params['id'] = $this->_id; } $customField = CRM_Core_BAO_CustomField::create($params); // reset the cache CRM_Core_BAO_Cache::deleteGroup('contact fields'); CRM_Core_Session::setStatus(ts('Your custom field \'%1\' has been saved.', array(1 => $customField->label)), ts('Saved'), 'success'); $buttonName = $this->controller->getButtonName(); $session = CRM_Core_Session::singleton(); if ($buttonName == $this->getButtonName('next', 'new')) { CRM_Core_Session::setStatus(ts(' You can add another custom field.'), '', 'info'); $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field/add', 'reset=1&action=add&gid=' . $this->_gid)); } else { $session->replaceUserContext(CRM_Utils_System::url('civicrm/admin/custom/group/field', 'reset=1&action=browse&gid=' . $this->_gid)); } }
/** * This method populates the civicrm_group_contact table */ private function addGroup() { // add the 3 groups first foreach ($this->sampleData['group'] as $groupName) { $group = new CRM_Contact_BAO_Group(); $group->name = $group->title = $groupName; $group->group_type = "12"; $group->visibility = 'Public Pages'; $group->is_active = 1; $group->save(); $group->buildClause(); $group->save(); } // 60 are for newsletter for ($i = 0; $i < 60; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // newsletter subscribers $groupContact->group_id = 2; $groupContact->contact_id = $this->Individual[$i]; // always add members $groupContact->status = 'Added'; $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->randomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } // 15 volunteers for ($i = 0; $i < 15; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // Volunteers $groupContact->group_id = 3; $groupContact->contact_id = $this->Individual[$i + 60]; // membership status $groupContact->status = 'Added'; $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->randomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } // 8 advisory board group for ($i = 0; $i < 8; $i++) { $groupContact = new CRM_Contact_DAO_GroupContact(); // advisory board group $groupContact->group_id = 4; $groupContact->contact_id = $this->Individual[$i * 7]; // membership status $groupContact->status = 'Added'; $subscriptionHistory = new CRM_Contact_DAO_SubscriptionHistory(); $subscriptionHistory->contact_id = $groupContact->contact_id; $subscriptionHistory->group_id = $groupContact->group_id; $subscriptionHistory->status = $groupContact->status; // method $subscriptionHistory->method = $this->randomItem($this->subscriptionHistoryMethod); $subscriptionHistory->date = $this->randomDate(); if ($groupContact->status != 'Pending') { $this->_insert($groupContact); } $this->_insert($subscriptionHistory); } //In this function when we add groups that time we are cache the contact fields //But at the end of setup we are appending sample custom data, so for consistency //reset the cache. CRM_Core_BAO_Cache::deleteGroup('contact fields'); }
public function postProcess() { $values = $this->exportValues(); //cache contact fields retaining localized titles //though we changed localization, so reseting cache. CRM_Core_BAO_Cache::deleteGroup('contact fields'); //CRM-8559, cache navigation do not respect locale if it is changed, so reseting cache. CRM_Core_BAO_Cache::deleteGroup('navigation'); // we do this only to initialize monetary decimal point and thousand separator $config = CRM_Core_Config::singleton(); // save enabled currencies and defaul currency in option group 'currencies_enabled' // CRM-1496 if (empty($values['currencyLimit'])) { $values['currencyLimit'] = array($values['defaultCurrency']); } elseif (!in_array($values['defaultCurrency'], $values['currencyLimit'])) { $values['currencyLimit'][] = $values['defaultCurrency']; } // sort so that when we display drop down, weights have right value sort($values['currencyLimit']); // get labels for all the currencies $options = array(); $currencySymbols = self::getCurrencySymbols(); for ($i = 0; $i < count($values['currencyLimit']); $i++) { $options[] = array('label' => $currencySymbols[$values['currencyLimit'][$i]], 'value' => $values['currencyLimit'][$i], 'weight' => $i + 1, 'is_active' => 1, 'is_default' => $values['currencyLimit'][$i] == $values['defaultCurrency']); } $dontCare = NULL; CRM_Core_OptionGroup::createAssoc('currencies_enabled', $options, $dontCare); // unset currencyLimit so we dont store there unset($values['currencyLimit']); // make the site multi-lang if requested if (!empty($values['makeMultilingual'])) { CRM_Core_I18n_Schema::makeMultilingual($values['lcMessages']); $values['languageLimit'][$values['lcMessages']] = 1; // make the site single-lang if requested } elseif (!empty($values['makeSinglelingual'])) { CRM_Core_I18n_Schema::makeSinglelingual($values['lcMessages']); $values['languageLimit'] = ''; } // add a new db locale if the requested language is not yet supported by the db if (!CRM_Utils_Array::value('makeSinglelingual', $values) and CRM_Utils_Array::value('addLanguage', $values)) { $domain = new CRM_Core_DAO_Domain(); $domain->find(TRUE); if (!substr_count($domain->locales, $values['addLanguage'])) { CRM_Core_I18n_Schema::addLocale($values['addLanguage'], $values['lcMessages']); } $values['languageLimit'][$values['addLanguage']] = 1; } // if we manipulated the language list, return to the localization admin screen $return = (bool) (CRM_Utils_Array::value('makeMultilingual', $values) or CRM_Utils_Array::value('addLanguage', $values)); $filteredValues = $values; unset($filteredValues['makeMultilingual']); unset($filteredValues['makeSinglelingual']); unset($filteredValues['addLanguage']); unset($filteredValues['languageLimit']); Civi::settings()->set('languageLimit', CRM_Utils_Array::value('languageLimit', $values)); // save all the settings parent::commonProcess($filteredValues); if ($return) { CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/localization', 'reset=1')); } }
/** * Reset navigation for all contacts * * @param integer $contactID - reset only entries belonging to that contact ID */ static function resetNavigation($contactID = NULL) { $params = array(); $query = "UPDATE civicrm_setting SET value = NULL WHERE name='navigation'"; if ($contactID) { $query .= " AND contact_id = %1"; $params[1] = array($contactID, 'Integer'); } else { $query .= " AND contact_id IS NOT NULL"; } CRM_Core_DAO::executeQuery($query, $params); CRM_Core_BAO_Cache::deleteGroup('navigation'); // also reset the dashlet cache in case permissions have changed etc CRM_Core_BAO_Dashboard::resetDashletCache($contactID); }
/** * Reset the various system caches and some important static variables. */ public static function flushCache() { // flush out all cache entries so we can reload new data // a bit aggressive, but livable for now $cache = CRM_Utils_Cache::singleton(); $cache->flush(); // also reset the various static memory caches // reset the memory or array cache CRM_Core_BAO_Cache::deleteGroup('contact fields', NULL, FALSE); // reset ACL cache CRM_ACL_BAO_Cache::resetCache(); // reset various static arrays used here CRM_Contact_BAO_Contact::$_importableFields = CRM_Contact_BAO_Contact::$_exportableFields = CRM_Contribute_BAO_Contribution::$_importableFields = CRM_Contribute_BAO_Contribution::$_exportableFields = CRM_Pledge_BAO_Pledge::$_exportableFields = CRM_Contribute_BAO_Query::$_contributionFields = CRM_Core_BAO_CustomField::$_importFields = CRM_Core_BAO_Cache::$_cache = CRM_Core_DAO::$_dbColumnValueCache = NULL; CRM_Core_OptionGroup::flushAll(); CRM_Utils_PseudoConstant::flushAll(); }
/** * function to delete batch entry * * @param int $batchId batch id * * @return void * @access public */ static function deleteBatch($batchId) { //delete batch entries from cache $cacheKeyString = CRM_Core_BAO_Batch::getCacheKeyForBatch($batchId); CRM_Core_BAO_Cache::deleteGroup('batch entry', $cacheKeyString, FALSE); // delete entry from batch table $batch = new CRM_Core_DAO_Batch(); $batch->id = $batchId; $batch->delete(); }
function fini() { CRM_Core_BAO_Cache::storeSessionToCache(array("_{$this->_name}_container", array('CiviCRM', $this->_scope)), TRUE); }
/** * Create a new group * * @param array $params Associative array of parameters * @return object|null The new group BAO (if created) * @access public * @static */ public static function &create(&$params) { require_once 'CRM/Utils/Hook.php'; if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::pre('edit', 'Group', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Group', null, $params); } // form the name only if missing: CRM-627 if (!CRM_Utils_Array::value('name', $params)) { require_once 'CRM/Utils/String.php'; $params['name'] = CRM_Utils_String::titleToVar($params['title']); } // convert params if array type if (isset($params['group_type'])) { if (is_array($params['group_type'])) { $params['group_type'] = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR, array_keys($params['group_type'])) . CRM_Core_DAO::VALUE_SEPARATOR; } } else { $params['group_type'] = ''; } $group =& new CRM_Contact_BAO_Group(); $group->copyValues($params); $group->save(); if (!$group->id) { return null; } $group->buildClause(); $group->save(); // add custom field values if (CRM_Utils_Array::value('custom', $params)) { require_once 'CRM/Core/BAO/CustomValueTable.php'; CRM_Core_BAO_CustomValueTable::store($params['custom'], 'civicrm_group', $group->id); } // make the group, child of domain/site group by default. require_once 'CRM/Contact/BAO/GroupContactCache.php'; require_once 'CRM/Core/BAO/Domain.php'; require_once 'CRM/Contact/BAO/GroupNesting.php'; $domainGroupID = CRM_Core_BAO_Domain::getGroupId(); if (CRM_Utils_Array::value('no_parent', $params) !== 1) { if (defined('CIVICRM_MULTISITE') && CIVICRM_MULTISITE && empty($params['parents']) && $domainGroupID != $group->id && !CRM_Contact_BAO_GroupNesting::hasParentGroups($group->id)) { // if no parent present and the group doesn't already have any parents, // make sure site group goes as parent $params['parents'] = array($domainGroupID => 1); } else { if (!is_array($params['parents'])) { $params['parents'] = array($params['parents'] => 1); } } foreach ($params['parents'] as $parentId => $dnc) { if ($parentId && !CRM_Contact_BAO_GroupNesting::isParentChild($parentId, $group->id)) { CRM_Contact_BAO_GroupNesting::add($parentId, $group->id); } } // clear any descendant groups cache if exists require_once 'CRM/Core/BAO/Cache.php'; $finalGroups =& CRM_Core_BAO_Cache::deleteGroup('descendant groups for an org'); // this is always required, since we don't know when a // parent group is removed require_once 'CRM/Contact/BAO/GroupNestingCache.php'; CRM_Contact_BAO_GroupNestingCache::update(); // update group contact cache for all parent groups $parentIds = CRM_Contact_BAO_GroupNesting::getParentGroupIds($group->id); foreach ($parentIds as $parentId) { CRM_Contact_BAO_GroupContactCache::add($parentId); } } if (CRM_Utils_Array::value('organization_id', $params)) { require_once 'CRM/Contact/BAO/GroupOrganization.php'; $groupOrg = array(); $groupOrg = $params; $groupOrg['group_id'] = $group->id; CRM_Contact_BAO_GroupOrganization::add($groupOrg); } CRM_Contact_BAO_GroupContactCache::add($group->id); if (CRM_Utils_Array::value('id', $params)) { CRM_Utils_Hook::post('edit', 'Group', $group->id, $group); } else { CRM_Utils_Hook::post('create', 'Group', $group->id, $group); } return $group; }
/** * @param object $sort * @param string $cacheKey * @param int $start * @param int $end */ function fillupPrevNextCache($sort, $cacheKey, $start = 0, $end = 500) { $coreSearch = TRUE; // For custom searches, use the contactIDs method if (is_a($this, 'CRM_Contact_Selector_Custom')) { $sql = $this->_search->contactIDs($start, $end, $sort, TRUE); $replaceSQL = "SELECT contact_a.id as contact_id"; $coreSearch = FALSE; } else { $sql = $this->_query->searchQuery($start, $end, $sort, FALSE, $this->_query->_includeContactIds, FALSE, TRUE, TRUE); $replaceSQL = "SELECT contact_a.id as id"; } // 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 DISTINCT 'civicrm_contact', contact_a.id, contact_a.id, '{$cacheKey}', contact_a.display_name\n"; $sql = str_replace($replaceSQL, $insertSQL, $sql); $errorScope = CRM_Core_TemporaryErrorScope::ignoreException(); $result = CRM_Core_DAO::executeQuery($sql); unset($errorScope); if (is_a($result, 'DB_Error')) { // check if we get error during core search if ($coreSearch) { // in the case of error, try rebuilding cache using full sql which is used for search selector display // this fixes the bugs reported in CRM-13996 & CRM-14438 $this->rebuildPreNextCache($start, $end, $sort, $cacheKey); } else { // return if above query fails 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); }
/** * Delete the Custom Field. * * @param object $field - the field object * * @return boolean * * @access public * @static * */ public static function deleteField($field) { // reset the cache require_once 'CRM/Core/BAO/Cache.php'; CRM_Core_BAO_Cache::deleteGroup('contact fields'); // reset various static arrays used here require_once 'CRM/Contact/BAO/Contact.php'; CRM_Contact_BAO_Contact::$_importableFields = CRM_Contact_BAO_Contact::$_exportableFields = self::$_importFields = null; // first delete the custom option group and values associated with this field if ($field->option_group_id) { //check if option group is related to any other field, if //not delete the option group and related option values self::checkOptionGroup($field->option_group_id); } // next drop the column from the custom value table self::createField($field, 'delete'); $field->delete(); return; }