[REF] Remove setting on unused variables
[civicrm-core.git] / CRM / Admin / Form / Setting.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
5 | |
6 | This work is published under the GNU AGPLv3 license with some |
7 | permitted exceptions and without any warranty. For full license |
8 | and copyright information, see https://civicrm.org/licensing |
9 +--------------------------------------------------------------------+
10 */
11
12 /**
13 *
14 * @package CRM
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
16 */
17
18 /**
19 * This class generates form components generic to CiviCRM settings.
20 */
21 class CRM_Admin_Form_Setting extends CRM_Core_Form {
22
23 use CRM_Admin_Form_SettingTrait;
24
25 protected $_settings = [];
26
27 protected $includesReadOnlyFields;
28
29 /**
30 * Set default values for the form.
31 *
32 * Default values are retrieved from the database.
33 */
34 public function setDefaultValues() {
35 if (!$this->_defaults) {
36 $this->_defaults = [];
37 $this->setDefaultsForMetadataDefinedFields();
38
39 // @todo these should be retrievable from the above function.
40 $this->_defaults['enableSSL'] = Civi::settings()->get('enableSSL');
41 $this->_defaults['verifySSL'] = Civi::settings()->get('verifySSL');
42 $this->_defaults['environment'] = CRM_Core_Config::environment();
43 $this->_defaults['enableComponents'] = Civi::settings()->get('enable_components');
44 }
45
46 return $this->_defaults;
47 }
48
49 /**
50 * Build the form object.
51 *
52 * @throws \CRM_Core_Exception
53 */
54 public function buildQuickForm() {
55 CRM_Core_Session::singleton()->pushUserContext(CRM_Utils_System::url('civicrm/admin', 'reset=1'));
56 $this->addButtons([
57 [
58 'type' => 'next',
59 'name' => ts('Save'),
60 'isDefault' => TRUE,
61 ],
62 [
63 'type' => 'cancel',
64 'name' => ts('Cancel'),
65 ],
66 ]);
67
68 $this->addFieldsDefinedInSettingsMetadata();
69
70 if ($this->includesReadOnlyFields) {
71 CRM_Core_Session::setStatus(ts("Some fields are loaded as 'readonly' as they have been set (overridden) in civicrm.settings.php."), '', 'info', ['expires' => 0]);
72 }
73 }
74
75 /**
76 * Process the form submission.
77 */
78 public function postProcess() {
79 // store the submitted values in an array
80 $params = $this->controller->exportValues($this->_name);
81
82 self::commonProcess($params);
83 }
84
85 /**
86 * Common Process.
87 *
88 * @todo Document what I do.
89 *
90 * @param array $params
91 * @throws \CRM_Core_Exception
92 */
93 public function commonProcess(&$params) {
94
95 foreach (['verifySSL', 'enableSSL'] as $name) {
96 if (isset($params[$name])) {
97 Civi::settings()->set($name, $params[$name]);
98 unset($params[$name]);
99 }
100 }
101 try {
102 $this->saveMetadataDefinedSettings($params);
103 }
104 catch (CiviCRM_API3_Exception $e) {
105 CRM_Core_Session::setStatus($e->getMessage(), ts('Save Failed'), 'error');
106 }
107
108 $this->filterParamsSetByMetadata($params);
109
110 $params = CRM_Core_BAO_ConfigSetting::filterSkipVars($params);
111 if (!empty($params)) {
112 throw new CRM_Core_Exception('Unrecognized setting. This may be a config field which has not been properly migrated to a setting. (' . implode(', ', array_keys($params)) . ')');
113 }
114
115 CRM_Core_Config::clearDBCache();
116 // This doesn't make a lot of sense to me, but it maintains pre-existing behavior.
117 Civi::cache('session')->clear();
118 CRM_Utils_System::flushCache();
119 CRM_Core_Resources::singleton()->resetCacheCode();
120
121 CRM_Core_Session::setStatus(" ", ts('Changes Saved'), "success");
122 }
123
124 public function rebuildMenu() {
125 // ensure config is set with new values
126 $config = CRM_Core_Config::singleton(TRUE, TRUE);
127
128 // rebuild menu items
129 CRM_Core_Menu::store();
130 }
131
132 }