Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
06b69b18 | 4 | | CiviCRM version 4.5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
06b69b18 | 6 | | Copyright CiviCRM LLC (c) 2004-2014 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
26 | */ | |
27 | ||
28 | /** | |
29 | * | |
30 | * @package CRM | |
06b69b18 | 31 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
32 | * $Id$ |
33 | * | |
34 | */ | |
35 | ||
36 | /** | |
37 | * This class generates form components for Error Handling and Debugging | |
38 | * | |
39 | */ | |
40 | class CRM_Admin_Form_Setting_UpdateConfigBackend extends CRM_Admin_Form_Setting { | |
41 | protected $_oldBaseDir; | |
42 | protected $_oldBaseURL; | |
43 | protected $_oldSiteName; | |
44 | ||
45 | /** | |
46 | * Function to build the form | |
47 | * | |
355ba699 | 48 | * @return void |
6a488035 TO |
49 | * @access public |
50 | */ | |
51 | public function buildQuickForm() { | |
52 | CRM_Utils_System::setTitle(ts('Settings - Cleanup Caches and Update Paths')); | |
53 | ||
e51744f5 DL |
54 | list( |
55 | $this->_oldBaseURL, | |
6a488035 TO |
56 | $this->_oldBaseDir, |
57 | $this->_oldSiteName | |
58 | ) = CRM_Core_BAO_ConfigSetting::getConfigSettings(); | |
59 | ||
60 | $this->assign('oldBaseURL', $this->_oldBaseURL); | |
61 | $this->assign('oldBaseDir', $this->_oldBaseDir); | |
62 | $this->assign('oldSiteName', $this->_oldSiteName); | |
63 | ||
e51744f5 DL |
64 | $this->addElement( |
65 | 'submit', $this->getButtonName('next', 'cleanup'), 'Cleanup Caches', | |
97e557d7 | 66 | array('class' => 'crm-form-submit', 'id' => 'cleanup-cache') |
e51744f5 | 67 | ); |
6a488035 TO |
68 | |
69 | $this->add('text', 'newBaseURL', ts('New Base URL'), NULL, TRUE); | |
70 | $this->add('text', 'newBaseDir', ts('New Base Directory'), NULL, TRUE); | |
71 | if ($this->_oldSiteName) { | |
72 | $this->add('text', 'newSiteName', ts('New Site Name'), NULL, TRUE); | |
73 | } | |
74 | $this->addFormRule(array('CRM_Admin_Form_Setting_UpdateConfigBackend', 'formRule')); | |
75 | ||
76 | parent::buildQuickForm(); | |
77 | } | |
78 | ||
79 | function setDefaultValues() { | |
80 | if (!$this->_defaults) { | |
81 | parent::setDefaultValues(); | |
82 | ||
83 | $config = CRM_Core_Config::singleton(); | |
e51744f5 DL |
84 | list( |
85 | $this->_defaults['newBaseURL'], | |
6a488035 TO |
86 | $this->_defaults['newBaseDir'], |
87 | $this->_defaults['newSiteName'] | |
88 | ) = CRM_Core_BAO_ConfigSetting::getBestGuessSettings(); | |
89 | } | |
90 | ||
91 | return $this->_defaults; | |
92 | } | |
93 | ||
e0ef6999 EM |
94 | /** |
95 | * @param $fields | |
96 | * | |
97 | * @return array | |
98 | */ | |
6a488035 TO |
99 | static function formRule($fields) { |
100 | $tmpDir = trim($fields['newBaseDir']); | |
101 | ||
102 | $errors = array(); | |
103 | if (!is_writeable($tmpDir)) { | |
104 | $errors['newBaseDir'] = ts('%1 directory does not exist or cannot be written by webserver', | |
105 | array(1 => $tmpDir) | |
106 | ); | |
107 | } | |
108 | return $errors; | |
109 | } | |
110 | ||
111 | function postProcess() { | |
a7488080 | 112 | if (!empty($_POST['_qf_UpdateConfigBackend_next_cleanup'])) { |
6a488035 TO |
113 | |
114 | $config = CRM_Core_Config::singleton(); | |
115 | ||
116 | // cleanup templates_c directory | |
117 | $config->cleanup(1, FALSE); | |
118 | ||
119 | // clear db caching | |
120 | CRM_Core_Config::clearDBCache(); | |
121 | parent::rebuildMenu(); | |
122 | ||
3e089a38 BS |
123 | CRM_Core_BAO_WordReplacement::rebuild(); |
124 | ||
6a488035 TO |
125 | CRM_Core_Session::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success"); |
126 | return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1')); | |
127 | } | |
128 | ||
129 | // redirect to admin page after saving | |
130 | $session = CRM_Core_Session::singleton(); | |
131 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin')); | |
132 | ||
133 | $params = $this->controller->exportValues($this->_name); | |
134 | ||
135 | //CRM-5679 | |
136 | foreach ($params as $name => & $val) { | |
137 | if ($val && in_array($name, array( | |
138 | 'newBaseURL', 'newBaseDir', 'newSiteName'))) { | |
139 | $val = CRM_Utils_File::addTrailingSlash($val); | |
140 | } | |
141 | } | |
142 | ||
143 | $from = array($this->_oldBaseURL, $this->_oldBaseDir); | |
144 | $to = array(trim($params['newBaseURL']), | |
145 | trim($params['newBaseDir']), | |
146 | ); | |
147 | if ($this->_oldSiteName && | |
148 | $params['newSiteName'] | |
149 | ) { | |
150 | $from[] = $this->_oldSiteName; | |
151 | $to[] = $params['newSiteName']; | |
152 | } | |
153 | ||
154 | $newValues = str_replace($from, | |
155 | $to, | |
156 | $this->_defaults | |
157 | ); | |
158 | ||
159 | parent::commonProcess($newValues); | |
160 | ||
161 | parent::rebuildMenu(); | |
162 | } | |
163 | } | |
164 |