Merge pull request #6058 from monishdeb/CRM-16575
[civicrm-core.git] / CRM / Admin / Form / Setting.php
index 14455159a74f9c2142aac2f721a4916328e93a35..910e5f90d35ef8df960762b633f88b06399f60ab 100644 (file)
@@ -3,7 +3,7 @@
  +--------------------------------------------------------------------+
  | CiviCRM version 4.6                                                |
  +--------------------------------------------------------------------+
- | Copyright CiviCRM LLC (c) 2004-2014                                |
+ | Copyright CiviCRM LLC (c) 2004-2015                                |
  +--------------------------------------------------------------------+
  | This file is a part of CiviCRM.                                    |
  |                                                                    |
  | GNU Affero General Public License or the licensing of CiviCRM,     |
  | see the CiviCRM license FAQ at http://civicrm.org/licensing        |
  +--------------------------------------------------------------------+
-*/
+ */
 
 /**
  *
  * @package CRM
- * @copyright CiviCRM LLC (c) 2004-2014
+ * @copyright CiviCRM LLC (c) 2004-2015
  * $Id$
- *
  */
 
 /**
  * This class generates form components generic to CiviCRM settings
- *
  */
 class CRM_Admin_Form_Setting extends CRM_Core_Form {
 
@@ -44,16 +42,14 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
 
   /**
    * Set default values for the form.
-   * default values are retrieved from the database
-   *
    *
-   * @return void
+   * Default values are retrieved from the database.
    */
   public function setDefaultValues() {
     if (!$this->_defaults) {
       $this->_defaults = array();
-      $formArray       = array('Component', 'Localization');
-      $formMode        = FALSE;
+      $formArray = array('Component', 'Localization');
+      $formMode = FALSE;
       if (in_array($this->_name, $formArray)) {
         $formMode = TRUE;
       }
@@ -63,12 +59,12 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
       CRM_Core_Config_Defaults::setValues($this->_defaults, $formMode);
 
       $list = array_flip(CRM_Core_OptionGroup::values('contact_autocomplete_options',
-          FALSE, FALSE, TRUE, NULL, 'name'
-        ));
+        FALSE, FALSE, TRUE, NULL, 'name'
+      ));
 
       $cRlist = array_flip(CRM_Core_OptionGroup::values('contact_reference_options',
-          FALSE, FALSE, TRUE, NULL, 'name'
-        ));
+        FALSE, FALSE, TRUE, NULL, 'name'
+      ));
 
       $listEnabled = CRM_Core_BAO_Setting::valueOptions(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
         'contact_autocomplete_options'
@@ -89,18 +85,20 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
 
       //Set defaults for autocomplete and contact reference options
       $this->_defaults['autocompleteContactSearch'] = array(
-        '1' => 1) + $autoSearchFields;
+        '1' => 1,
+      ) + $autoSearchFields;
       $this->_defaults['autocompleteContactReference'] = array(
-        '1' => 1) + $cRSearchFields;
+        '1' => 1,
+      ) + $cRSearchFields;
 
       // we can handle all the ones defined in the metadata here. Others to be converted
-      foreach ($this->_settings as $setting => $group){
+      foreach ($this->_settings as $setting => $group) {
         $settingMetaData = civicrm_api('setting', 'getfields', array('version' => 3, 'name' => $setting));
         $this->_defaults[$setting] = civicrm_api('setting', 'getvalue', array(
-          'version' => 3,
-          'name' => $setting,
-          'group' => $group,
-          'default_value' => CRM_Utils_Array::value('default', $settingMetaData['values'][$setting])
+            'version' => 3,
+            'name' => $setting,
+            'group' => $group,
+            'default_value' => CRM_Utils_Array::value('default', $settingMetaData['values'][$setting]),
           )
         );
       }
@@ -113,9 +111,7 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
   }
 
   /**
-   * Build the form object
-   *
-   * @return void
+   * Build the form object.
    */
   public function buildQuickForm() {
     $session = CRM_Core_Session::singleton();
@@ -135,12 +131,12 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
       )
     );
 
-    foreach ($this->_settings as $setting => $group){
+    foreach ($this->_settings as $setting => $group) {
       $settingMetaData = civicrm_api('setting', 'getfields', array('version' => 3, 'name' => $setting));
       $props = $settingMetaData['values'][$setting];
-      if(isset($props['quick_form_type'])){
+      if (isset($props['quick_form_type'])) {
         $add = 'add' . $props['quick_form_type'];
-        if($add == 'addElement'){
+        if ($add == 'addElement') {
           $this->$add(
             $props['html_type'],
             $setting,
@@ -149,15 +145,15 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
             $props['html_type'] == 'select' ? CRM_Utils_Array::value('html_attributes', $props) : NULL
           );
         }
-        else{
+        else {
           $this->$add($setting, ts($props['title']));
         }
         $this->assign("{$setting}_description", ts($props['description']));
-        if($setting == 'max_attachments'){
+        if ($setting == 'max_attachments') {
           //temp hack @todo fix to get from metadata
           $this->addRule('max_attachments', ts('Value should be a positive number'), 'positiveInteger');
         }
-        if($setting == 'maxFileSize'){
+        if ($setting == 'maxFileSize') {
           //temp hack
           $this->addRule('maxFileSize', ts('Value should be a positive number'), 'positiveInteger');
         }
@@ -167,10 +163,7 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
   }
 
   /**
-   * Process the form submission
-   *
-   *
-   * @return void
+   * Process the form submission.
    */
   public function postProcess() {
     // store the submitted values in an array
@@ -180,6 +173,10 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
   }
 
   /**
+   * Common Process.
+   *
+   * @todo Document what I do.
+   *
    * @param array $params
    */
   public function commonProcess(&$params) {
@@ -187,8 +184,8 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
     // save autocomplete search options
     if (!empty($params['autocompleteContactSearch'])) {
       $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
-        array_keys($params['autocompleteContactSearch'])
-      ) . CRM_Core_DAO::VALUE_SEPARATOR;
+          array_keys($params['autocompleteContactSearch'])
+        ) . CRM_Core_DAO::VALUE_SEPARATOR;
 
       CRM_Core_BAO_Setting::setItem($value,
         CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
@@ -201,8 +198,8 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
     // save autocomplete contact reference options
     if (!empty($params['autocompleteContactReference'])) {
       $value = CRM_Core_DAO::VALUE_SEPARATOR . implode(CRM_Core_DAO::VALUE_SEPARATOR,
-        array_keys($params['autocompleteContactReference'])
-      ) . CRM_Core_DAO::VALUE_SEPARATOR;
+          array_keys($params['autocompleteContactReference'])
+        ) . CRM_Core_DAO::VALUE_SEPARATOR;
 
       CRM_Core_BAO_Setting::setItem($value,
         CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME,
@@ -214,12 +211,10 @@ class CRM_Admin_Form_Setting extends CRM_Core_Form {
 
     // save components to be enabled
     if (array_key_exists('enableComponents', $params)) {
-      CRM_Core_BAO_Setting::setItem($params['enableComponents'],
-        CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'enable_components');
-
-      // unset params by emptying the values, so while retrieving we can detect and load from settings table
-      // instead of config-backend for backward compatibility. We could use unset() in later releases.
-      $params['enableComponents'] = $params['enableComponentIDs'] = array();
+      civicrm_api3('setting', 'create', array(
+        'enable_components' => $params['enableComponents'],
+      ));
+      unset($params['enableComponents']);
     }
 
     // save checksum timeout
@@ -261,11 +256,16 @@ AND    time_format <> ''
     }
     $settings = array_intersect_key($params, $this->_settings);
     $result = civicrm_api('setting', 'create', $settings + array('version' => 3));
-    foreach ($settings as $setting => $settingGroup){
+    foreach ($settings as $setting => $settingGroup) {
       //@todo array_diff this
       unset($params[$setting]);
     }
     CRM_Core_BAO_ConfigSetting::create($params);
+
+    CRM_Core_Config::clearDBCache();
+    CRM_Utils_System::flushCache();
+    CRM_Core_Resources::singleton()->resetCacheCode();
+
     CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success");
   }
 
@@ -280,4 +280,5 @@ AND    time_format <> ''
     $configFile = $config->uploadDir . 'Config.IDS.ini';
     @unlink($configFile);
   }
+
 }