Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.3 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
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 | |
31 | * @copyright CiviCRM LLC (c) 2004-2013 | |
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 | * | |
48 | * @return None | |
49 | * @access public | |
50 | */ | |
51 | public function buildQuickForm() { | |
52 | CRM_Utils_System::setTitle(ts('Settings - Cleanup Caches and Update Paths')); | |
53 | ||
54 | list($this->_oldBaseURL, | |
55 | $this->_oldBaseDir, | |
56 | $this->_oldSiteName | |
57 | ) = CRM_Core_BAO_ConfigSetting::getConfigSettings(); | |
58 | ||
59 | $this->assign('oldBaseURL', $this->_oldBaseURL); | |
60 | $this->assign('oldBaseDir', $this->_oldBaseDir); | |
61 | $this->assign('oldSiteName', $this->_oldSiteName); | |
62 | ||
63 | $this->addElement('submit', $this->getButtonName('next', 'cleanup'), 'Cleanup Caches', array('class' => 'form-submit', 'id' => 'cleanup-cache')); | |
64 | ||
65 | $this->add('text', 'newBaseURL', ts('New Base URL'), NULL, TRUE); | |
66 | $this->add('text', 'newBaseDir', ts('New Base Directory'), NULL, TRUE); | |
67 | if ($this->_oldSiteName) { | |
68 | $this->add('text', 'newSiteName', ts('New Site Name'), NULL, TRUE); | |
69 | } | |
70 | $this->addFormRule(array('CRM_Admin_Form_Setting_UpdateConfigBackend', 'formRule')); | |
71 | ||
72 | parent::buildQuickForm(); | |
73 | } | |
74 | ||
75 | function setDefaultValues() { | |
76 | if (!$this->_defaults) { | |
77 | parent::setDefaultValues(); | |
78 | ||
79 | $config = CRM_Core_Config::singleton(); | |
80 | list($this->_defaults['newBaseURL'], | |
81 | $this->_defaults['newBaseDir'], | |
82 | $this->_defaults['newSiteName'] | |
83 | ) = CRM_Core_BAO_ConfigSetting::getBestGuessSettings(); | |
84 | } | |
85 | ||
86 | return $this->_defaults; | |
87 | } | |
88 | ||
89 | static function formRule($fields) { | |
90 | $tmpDir = trim($fields['newBaseDir']); | |
91 | ||
92 | $errors = array(); | |
93 | if (!is_writeable($tmpDir)) { | |
94 | $errors['newBaseDir'] = ts('%1 directory does not exist or cannot be written by webserver', | |
95 | array(1 => $tmpDir) | |
96 | ); | |
97 | } | |
98 | return $errors; | |
99 | } | |
100 | ||
101 | function postProcess() { | |
102 | if (CRM_Utils_Array::value('_qf_UpdateConfigBackend_next_cleanup', $_POST)) { | |
103 | ||
104 | $config = CRM_Core_Config::singleton(); | |
105 | ||
106 | // cleanup templates_c directory | |
107 | $config->cleanup(1, FALSE); | |
108 | ||
109 | // clear db caching | |
110 | CRM_Core_Config::clearDBCache(); | |
111 | parent::rebuildMenu(); | |
112 | ||
113 | CRM_Core_Session::setStatus(ts('Cache has been cleared and menu has been rebuilt successfully.'), ts("Success"), "success"); | |
114 | return CRM_Utils_System::redirect(CRM_Utils_System::url('civicrm/admin/setting/updateConfigBackend', 'reset=1')); | |
115 | } | |
116 | ||
117 | // redirect to admin page after saving | |
118 | $session = CRM_Core_Session::singleton(); | |
119 | $session->pushUserContext(CRM_Utils_System::url('civicrm/admin')); | |
120 | ||
121 | $params = $this->controller->exportValues($this->_name); | |
122 | ||
123 | //CRM-5679 | |
124 | foreach ($params as $name => & $val) { | |
125 | if ($val && in_array($name, array( | |
126 | 'newBaseURL', 'newBaseDir', 'newSiteName'))) { | |
127 | $val = CRM_Utils_File::addTrailingSlash($val); | |
128 | } | |
129 | } | |
130 | ||
131 | $from = array($this->_oldBaseURL, $this->_oldBaseDir); | |
132 | $to = array(trim($params['newBaseURL']), | |
133 | trim($params['newBaseDir']), | |
134 | ); | |
135 | if ($this->_oldSiteName && | |
136 | $params['newSiteName'] | |
137 | ) { | |
138 | $from[] = $this->_oldSiteName; | |
139 | $to[] = $params['newSiteName']; | |
140 | } | |
141 | ||
142 | $newValues = str_replace($from, | |
143 | $to, | |
144 | $this->_defaults | |
145 | ); | |
146 | ||
147 | parent::commonProcess($newValues); | |
148 | ||
149 | parent::rebuildMenu(); | |
150 | } | |
151 | } | |
152 |