3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2015
37 * This class generates form components for Error Handling and Debugging
40 class CRM_Admin_Form_Setting_UpdateConfigBackend
extends CRM_Admin_Form_Setting
{
41 protected $_oldBaseDir;
42 protected $_oldBaseURL;
43 protected $_oldSiteName;
46 * Build the form object.
50 public function buildQuickForm() {
51 CRM_Utils_System
::setTitle(ts('Settings - Cleanup Caches and Update Paths'));
57 ) = CRM_Core_BAO_ConfigSetting
::getConfigSettings();
59 $this->assign('oldBaseURL', $this->_oldBaseURL
);
60 $this->assign('oldBaseDir', $this->_oldBaseDir
);
61 $this->assign('oldSiteName', $this->_oldSiteName
);
64 'submit', $this->getButtonName('next', 'cleanup'), 'Cleanup Caches',
65 array('class' => 'crm-form-submit', 'id' => 'cleanup-cache')
68 $this->add('text', 'newBaseURL', ts('New Base URL'), NULL, TRUE);
69 $this->add('text', 'newBaseDir', ts('New Base Directory'), NULL, TRUE);
70 if ($this->_oldSiteName
) {
71 $this->add('text', 'newSiteName', ts('New Site Name'), NULL, TRUE);
73 $this->addFormRule(array('CRM_Admin_Form_Setting_UpdateConfigBackend', 'formRule'));
75 parent
::buildQuickForm();
78 public function setDefaultValues() {
79 if (!$this->_defaults
) {
80 parent
::setDefaultValues();
82 $config = CRM_Core_Config
::singleton();
84 $this->_defaults
['newBaseURL'],
85 $this->_defaults
['newBaseDir'],
86 $this->_defaults
['newSiteName']
87 ) = CRM_Core_BAO_ConfigSetting
::getBestGuessSettings();
90 return $this->_defaults
;
98 public static function formRule($fields) {
99 $tmpDir = trim($fields['newBaseDir']);
102 if (!is_writable($tmpDir)) {
103 $errors['newBaseDir'] = ts('%1 directory does not exist or cannot be written by webserver',
110 public function postProcess() {
111 if (!empty($_POST['_qf_UpdateConfigBackend_next_cleanup'])) {
113 $config = CRM_Core_Config
::singleton();
115 // cleanup templates_c directory
116 $config->cleanup(1, FALSE);
119 CRM_Core_Config
::clearDBCache();
120 CRM_Utils_System
::flushCache();
122 parent
::rebuildMenu();
124 CRM_Core_BAO_WordReplacement
::rebuild();
126 CRM_Core_Session
::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success");
127 return CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/setting/updateConfigBackend', 'reset=1'));
130 // redirect to admin page after saving
131 $session = CRM_Core_Session
::singleton();
132 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin'));
134 $params = $this->controller
->exportValues($this->_name
);
137 foreach ($params as $name => & $val) {
138 if ($val && in_array($name, array('newBaseDir', 'newSiteName'))) {
139 $val = CRM_Utils_File
::addTrailingSlash($val);
143 //CRM-15365 - Fix BaseURL to avoid wrong trailing slash on Windows installs
144 foreach ($params as $name => & $val) {
145 if ($val && in_array($name, array('newBaseURL'))) {
146 $val = CRM_Utils_File
::addTrailingSlash($val, "/");
150 $from = array($this->_oldBaseURL
, $this->_oldBaseDir
);
152 trim($params['newBaseURL']),
153 trim($params['newBaseDir']),
155 if ($this->_oldSiteName
&&
156 $params['newSiteName']
158 $from[] = $this->_oldSiteName
;
159 $to[] = $params['newSiteName'];
162 $newValues = str_replace($from,
167 parent
::commonProcess($newValues);
169 parent
::rebuildMenu();