/**
  * WARNING: This interface may change.
  *
  * This provides information about the setting - similar to the fields concept for DAO information.
  * As the setting is serialized code creating validation setting input needs to know the data type
  * This also helps move information out of the form layer into the data layer where people can interact with
  * it via the API or other mechanisms. In order to keep this consistent it is important the form layer
  * also leverages it.
  *
  * Note that this function should never be called when using the runtime getvalue function. Caching works
  * around the expectation it will be called during setting administration
  *
  * Function is intended for configuration rather than runtime access to settings
  *
  * The following params will filter the result. If none are passed all settings will be returns
  *
  * @param array $filters
  * @param int $domainID
  *
  * @return array
  *   the following information as appropriate for each setting
  *   - name
  *   - type
  *   - default
  *   - add (CiviCRM version added)
  *   - is_domain
  *   - is_contact
  *   - description
  *   - help_text
  */
 public static function getMetadata($filters = array(), $domainID = NULL)
 {
     if ($domainID === NULL) {
         $domainID = \CRM_Core_Config::domainID();
     }
     $cache = \Civi::cache('settings');
     $cacheString = 'settingsMetadata_' . $domainID . '_';
     // the caching into 'All' seems to be a duplicate of caching to
     // settingsMetadata__ - I think the reason was to cache all settings as defined & then those altered by a hook
     $settingsMetadata = $cache->get($cacheString);
     $cached = is_array($settingsMetadata);
     if (!$cached) {
         $settingsMetadata = $cache->get(self::ALL);
         if (empty($settingsMetadata)) {
             global $civicrm_root;
             $metaDataFolders = array($civicrm_root . '/settings');
             \CRM_Utils_Hook::alterSettingsFolders($metaDataFolders);
             $settingsMetadata = self::loadSettingsMetaDataFolders($metaDataFolders);
             $cache->set(self::ALL, $settingsMetadata);
         }
     }
     \CRM_Utils_Hook::alterSettingsMetaData($settingsMetadata, $domainID, NULL);
     if (!$cached) {
         $cache->set($cacheString, $settingsMetadata);
     }
     self::_filterSettingsSpecification($filters, $settingsMetadata);
     return $settingsMetadata;
 }
 /**
  * Flush all in-memory and persistent caches related to settings.
  *
  * @return $this
  */
 public function flush()
 {
     $this->mandatory = NULL;
     $this->cache->flush();
     \Civi::cache('settings')->flush();
     // SettingsMetadata; not guaranteed to use same cache.
     foreach ($this->bagsByDomain as $bag) {
         /** @var SettingsBag $bag */
         $bag->loadValues();
         $bag->loadDefaults($this->getDefaults('domain'));
         $bag->loadMandatory($this->getMandatory('domain'));
     }
     foreach ($this->bagsByContact as $bag) {
         /** @var SettingsBag $bag */
         $bag->loadValues();
         $bag->loadDefaults($this->getDefaults('contact'));
         $bag->loadMandatory($this->getMandatory('contact'));
     }
     return $this;
 }
 /**
  * Create default instance.
  *
  * @return CRM_Core_CommunityMessages
  */
 public static function create()
 {
     return new CRM_Core_CommunityMessages(Civi::cache('community_messages'), CRM_Utils_HttpClient::singleton());
 }
 /**
  * Get or set the single instance of CRM_Core_Resources.
  *
  * @param CRM_Core_Resources $instance
  *   New copy of the manager.
  * @return CRM_Core_Resources
  */
 public static function singleton(CRM_Core_Resources $instance = NULL)
 {
     if ($instance !== NULL) {
         self::$_singleton = $instance;
     }
     if (self::$_singleton === NULL) {
         $sys = CRM_Extension_System::singleton();
         $cache = Civi::cache('js_strings');
         self::$_singleton = new CRM_Core_Resources($sys->getMapper(), $cache, CRM_Core_Config::isUpgradeMode() ? NULL : 'resCacheCode');
     }
     return self::$_singleton;
 }
Beispiel #5
0
 /**
  * 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__');
     Civi::cache('settings')->flush();
     $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'));
     $this->assertEquals('keyset', Civi::settings()->get('test_key'));
     $result = $this->callAPISuccess('setting', 'getvalue', array('name' => 'test_key', 'group' => 'Test Settings'));
     $this->assertEquals('keyset', $result);
 }
Beispiel #6
0
 /**
  * Run some sanity checks.
  *
  * This could become a hook so that CiviCRM can run both built-in
  * configuration & sanity checks, and modules/extensions can add
  * their own checks.
  *
  * We might even expose the results of these checks on the Wordpress
  * plugin status page or the Drupal admin/reports/status path.
  *
  * @param bool $max
  *   Whether to return just the maximum non-hushed severity
  *
  * @return array
  *   Array of messages
  * @link https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_requirements
  */
 public static function checkAll($max = FALSE)
 {
     $checks = array();
     $checks[] = new CRM_Utils_Check_Security();
     $checks[] = new CRM_Utils_Check_Env();
     $compInfo = CRM_Core_Component::getEnabledComponents();
     foreach ($compInfo as $compObj) {
         switch ($compObj->info['name']) {
             case 'CiviCase':
                 $checks[] = new CRM_Utils_Check_Case(CRM_Case_XMLRepository::singleton(), CRM_Case_PseudoConstant::caseType('name'));
                 break;
             default:
         }
     }
     $messages = array();
     foreach ($checks as $check) {
         $messages = array_merge($messages, $check->checkAll());
     }
     CRM_Utils_Hook::check($messages);
     foreach ($messages as $key => $message) {
         $hush = self::checkHushSnooze($message);
         $message->setVisible(!$hush);
     }
     uasort($messages, array(__CLASS__, 'severitySort'));
     $maxSeverity = 1;
     foreach ($messages as $message) {
         if (!$message->isVisible()) {
             continue;
         }
         $maxSeverity = max(1, $message->getLevel());
         break;
     }
     Civi::cache()->set('systemCheckSeverity', $maxSeverity);
     $timestamp = time();
     Civi::cache()->set('systemCheckDate', $timestamp);
     return $max ? $maxSeverity : $messages;
 }
Beispiel #7
0
 /**
  * Show status in the footer
  *
  * @param CRM_Core_Smarty $template
  */
 public static function statusCheck($template)
 {
     if (CRM_Core_Config::isUpgradeMode()) {
         return;
     }
     //  check date of last cache and compare to today's date
     $systemCheckDate = Civi::cache()->get('systemCheckDate');
     if ($systemCheckDate > strtotime("one day ago")) {
         $statusSeverity = Civi::cache()->get('systemCheckSeverity');
     }
     //  calls helper function in CRM_Utils_Check
     if (empty($statusSeverity)) {
         $statusSeverity = CRM_Utils_Check::checkAll(TRUE);
     }
     switch ($statusSeverity) {
         case 7:
             $statusMessage = ts('System Status: Emergency');
             break;
         case 6:
             $statusMessage = ts('System Status: Alert');
             break;
         case 5:
             $statusMessage = ts('System Status: Critical');
             break;
         case 4:
             $statusMessage = ts('System Status: Error');
             break;
         case 3:
             $statusMessage = ts('System Status: Warning');
             break;
         case 2:
             $statusMessage = ts('System Status: Notice');
             break;
         default:
             $statusMessage = ts('System Status: Ok');
     }
     // TODO: get status from CRM_Utils_Check, if cached
     $template->assign('footer_status_severity', $statusSeverity);
     $template->assign('footer_status_message', $statusMessage);
 }