3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
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
35 * This class generates form components for Error Handling and Debugging
37 class CRM_Admin_Form_Setting_UpdateConfigBackend
extends CRM_Admin_Form_Setting
{
38 protected $_oldBaseDir;
39 protected $_oldBaseURL;
40 protected $_oldSiteName;
43 * Build the form object.
45 public function buildQuickForm() {
46 CRM_Utils_System
::setTitle(ts('Settings - Cleanup Caches and Update Paths'));
52 ) = CRM_Core_BAO_ConfigSetting
::getConfigSettings();
54 $this->assign('oldBaseURL', $this->_oldBaseURL
);
55 $this->assign('oldBaseDir', $this->_oldBaseDir
);
56 $this->assign('oldSiteName', $this->_oldSiteName
);
59 'submit', $this->getButtonName('next', 'cleanup'), 'Cleanup Caches',
60 array('class' => 'crm-form-submit', 'id' => 'cleanup-cache')
63 $this->add('text', 'newBaseURL', ts('New Base URL'), NULL, TRUE);
64 $this->add('text', 'newBaseDir', ts('New Base Directory'), NULL, TRUE);
65 if ($this->_oldSiteName
) {
66 $this->add('text', 'newSiteName', ts('New Site Name'), NULL, TRUE);
68 $this->addFormRule(array('CRM_Admin_Form_Setting_UpdateConfigBackend', 'formRule'));
70 parent
::buildQuickForm();
73 public function setDefaultValues() {
74 if (!$this->_defaults
) {
75 parent
::setDefaultValues();
77 $config = CRM_Core_Config
::singleton();
79 $this->_defaults
['newBaseURL'],
80 $this->_defaults
['newBaseDir'],
81 $this->_defaults
['newSiteName']
82 ) = CRM_Core_BAO_ConfigSetting
::getBestGuessSettings();
85 return $this->_defaults
;
93 public static function formRule($fields) {
94 $tmpDir = trim($fields['newBaseDir']);
97 if (!is_writable($tmpDir)) {
98 $errors['newBaseDir'] = ts('%1 directory does not exist or cannot be written by webserver',
105 public function postProcess() {
106 if (!empty($_POST['_qf_UpdateConfigBackend_next_cleanup'])) {
108 $config = CRM_Core_Config
::singleton();
110 // cleanup templates_c directory
111 $config->cleanup(1, FALSE);
114 CRM_Core_Config
::clearDBCache();
115 CRM_Utils_System
::flushCache();
117 parent
::rebuildMenu();
119 CRM_Core_BAO_WordReplacement
::rebuild();
121 CRM_Core_Session
::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success");
122 return CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/admin/setting/updateConfigBackend', 'reset=1'));
125 // redirect to admin page after saving
126 $session = CRM_Core_Session
::singleton();
127 $session->pushUserContext(CRM_Utils_System
::url('civicrm/admin'));
129 $params = $this->controller
->exportValues($this->_name
);
132 foreach ($params as $name => & $val) {
133 if ($val && in_array($name, array('newBaseDir', 'newSiteName'))) {
134 $val = CRM_Utils_File
::addTrailingSlash($val);
138 //CRM-15365 - Fix BaseURL to avoid wrong trailing slash on Windows installs
139 foreach ($params as $name => & $val) {
140 if ($val && in_array($name, array('newBaseURL'))) {
141 $val = CRM_Utils_File
::addTrailingSlash($val, "/");
145 $from = array($this->_oldBaseURL
, $this->_oldBaseDir
);
147 trim($params['newBaseURL']),
148 trim($params['newBaseDir']),
150 if ($this->_oldSiteName
&&
151 $params['newSiteName']
153 $from[] = $this->_oldSiteName
;
154 $to[] = $params['newSiteName'];
157 $newValues = str_replace($from,
162 parent
::commonProcess($newValues);
164 parent
::rebuildMenu();