Commit | Line | Data |
---|---|---|
6cc25669 CW |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
4 | | CiviCRM version 4.7 | | |
5 | +--------------------------------------------------------------------+ | |
6 | | Copyright CiviCRM LLC (c) 2004-2015 | | |
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. | | |
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 along with this program; if not, contact CiviCRM LLC | | |
21 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
22 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
23 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
24 | +--------------------------------------------------------------------+ | |
25 | */ | |
26 | ||
27 | /** | |
bf6a5362 | 28 | * Upgrade logic for 4.7 |
6cc25669 | 29 | */ |
bf6a5362 | 30 | class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base { |
6cc25669 | 31 | |
f431d51f J |
32 | /** |
33 | * Compute any messages which should be displayed beforeupgrade. | |
34 | * | |
35 | * Note: This function is called iteratively for each upcoming | |
36 | * revision to the database. | |
37 | * | |
38 | * @param $preUpgradeMessage | |
39 | * @param string $rev | |
40 | * a version number, e.g. '4.4.alpha1', '4.4.beta3', '4.4.0'. | |
41 | * @param null $currentVer | |
42 | * | |
43 | * @return void | |
44 | */ | |
45 | public function setPreUpgradeMessage(&$preUpgradeMessage, $rev, $currentVer = NULL) { | |
46 | if ($rev == '4.7.alpha1') { | |
058b8a5e CW |
47 | // CRM-17004 Warn of Moneris removal |
48 | $monerisProcessors = civicrm_api3('PaymentProcessor', 'getcount', array('payment_processor_type_id' => "Moneris")); | |
49 | if (!empty($monerisProcessors['result']) && !function_exists('moneris_civicrm_managed')) { | |
50 | $preUpgradeMessage .= '<p>' . ts('The %1 payment processor is no longer bundled with CiviCRM. After upgrading you will need to install the extension to continue using it.', array(1 => 'Moneris')) . '</p>'; | |
51 | } | |
f431d51f J |
52 | |
53 | // CRM-16478 Remove custom fatal error template path option | |
54 | $config = CRM_Core_Config::singleton(); | |
18b3bef6 | 55 | if (!empty($config->fatalErrorTemplate) && $config->fatalErrorTemplate != 'CRM/common/fatal.tpl') { |
f431d51f J |
56 | $preUpgradeMessage .= '<p>' . ts('The custom fatal error template setting will be removed during the upgrade. You are currently using this custom template: %1 . Following the upgrade you will need to use the standard approach to overriding template files, as described in the documentation.', array(1 => $config->fatalErrorTemplate)) . '</p>'; |
57 | } | |
f431d51f J |
58 | } |
59 | } | |
60 | ||
6cc25669 CW |
61 | /** |
62 | * Compute any messages which should be displayed after upgrade. | |
63 | * | |
64 | * @param string $postUpgradeMessage | |
65 | * alterable. | |
66 | * @param string $rev | |
67 | * an intermediate version; note that setPostUpgradeMessage is called repeatedly with different $revs. | |
68 | * @return void | |
69 | */ | |
70 | public function setPostUpgradeMessage(&$postUpgradeMessage, $rev) { | |
6dbe2c23 CW |
71 | if ($rev == '4.7.alpha1') { |
72 | $config = CRM_Core_Config::singleton(); | |
bf6a5362 | 73 | // FIXME: Performing an upgrade step during postUpgrade message phase is probably bad |
6dbe2c23 CW |
74 | $editor_id = self::updateWysiwyg(); |
75 | $msg = NULL; | |
76 | $ext_href = 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1') . '"'; | |
77 | $dsp_href = 'href="' . CRM_Utils_System::url('civicrm/admin/setting/preferences/display', 'reset=1') . '"'; | |
78 | $blog_href = 'href="https://civicrm.org/blogs/colemanw/big-changes-wysiwyg-editing-47"'; | |
79 | switch ($editor_id) { | |
80 | // TinyMCE | |
81 | case 1: | |
82 | $msg = ts('Your configured editor "TinyMCE" is no longer part of the main CiviCRM download. To continue using it, visit the <a %1>Manage Extensions</a> page to download and install the TinyMCE extension.', array(1 => $ext_href)); | |
83 | break; | |
84 | ||
85 | // Drupal/Joomla editor | |
86 | case 3: | |
87 | case 4: | |
88 | $msg = ts('CiviCRM no longer integrates with the "%1 Default Editor." Your wysiwyg setting has been reset to the built-in CKEditor. <a %2>Learn more...</a>', array(1 => $config->userFramework, 2 => $blog_href)); | |
89 | break; | |
90 | } | |
91 | if ($msg) { | |
92 | $postUpgradeMessage .= '<p>' . $msg . '</p>'; | |
93 | } | |
94 | $postUpgradeMessage .= '<p>' . ts('CiviCRM now includes the easy-to-use CKEditor Configurator. To customize the features and display of your wysiwyg editor, visit the <a %1>Display Preferences</a> page. <a %2>Learn more...</a>', array(1 => $dsp_href, 2 => $blog_href)) . '</p>'; | |
dd55005c | 95 | |
96 | $postUpgradeMessage .= '<br /><br />' . ts('Default version of the following System Workflow Message Templates have been modified: <ul><li>Personal Campaign Pages - Owner Notification</li></ul> If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).'); | |
f431d51f J |
97 | |
98 | $postUpgradeMessage .= '<p>' . ts('The custom fatal error template setting has been removed.') . '</p>'; | |
6dbe2c23 | 99 | } |
6cc25669 CW |
100 | } |
101 | ||
6cc25669 CW |
102 | /** |
103 | * Upgrade function. | |
104 | * | |
105 | * @param string $rev | |
106 | */ | |
107 | public function upgrade_4_7_alpha1($rev) { | |
18a687d7 | 108 | $this->addTask(ts('Migrate \'on behalf of\' information to module_data'), 'migrateOnBehalfOfInfo'); |
bf6a5362 | 109 | $this->addTask(ts('Upgrade DB to %1: SQL', array(1 => $rev)), 'runSql', $rev); |
f806379b | 110 | $this->addTask(ts('Migrate Settings to %1', array(1 => $rev)), 'migrateSettings', $rev); |
0a95c936 | 111 | $this->addTask(ts('Add Getting Started dashlet to %1: SQL', array(1 => $rev)), 'addGettingStartedDashlet', $rev); |
058b8a5e | 112 | $this->addTask(ts('Remove %1', array(1 => 'Moneris')), 'removePaymentProcessorType', 'Moneris'); |
6cc25669 CW |
113 | } |
114 | ||
115 | /** | |
116 | * CRM-16354 | |
117 | * | |
6dbe2c23 | 118 | * @return int |
6cc25669 | 119 | */ |
6dbe2c23 | 120 | public static function updateWysiwyg() { |
6cc25669 | 121 | $editorID = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id'); |
6dbe2c23 CW |
122 | // Previously a numeric value indicated one of 4 wysiwyg editors shipped in core, and no value indicated 'Textarea' |
123 | // Now the options are "Textarea", "CKEditor", and the rest have been dropped from core. | |
124 | $newEditor = $editorID ? "CKEditor" : "Textarea"; | |
125 | CRM_Core_BAO_Setting::setItem($newEditor, CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'editor_id'); | |
6cc25669 | 126 | |
6dbe2c23 | 127 | return $editorID; |
6cc25669 CW |
128 | } |
129 | ||
f806379b TO |
130 | /** |
131 | * Migrate any last remaining options from `civicrm_domain.config_backend` to `civicrm_setting`. | |
132 | * Cleanup setting schema. | |
133 | * | |
134 | * @param CRM_Queue_TaskContext $ctx | |
135 | * @return bool | |
136 | */ | |
137 | public function migrateSettings(CRM_Queue_TaskContext $ctx) { | |
138 | CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting DROP INDEX index_group_name'); | |
139 | CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting DROP COLUMN group_name'); | |
140 | CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_setting ADD UNIQUE INDEX index_domain_contact_name (domain_id, contact_id, name)'); | |
141 | ||
142 | $domainDao = CRM_Core_DAO::executeQuery('SELECT id, config_backend FROM civicrm_domain'); | |
143 | while ($domainDao->fetch()) { | |
144 | $settings = CRM_Upgrade_Incremental_php_FourSeven::convertBackendToSettings($domainDao->id, $domainDao->config_backend); | |
145 | CRM_Core_Error::debug_var('convertBackendToSettings', array( | |
146 | 'domainId' => $domainDao->id, | |
147 | 'backend' => $domainDao->config_backend, | |
148 | 'settings' => $settings, | |
149 | )); | |
150 | ||
151 | foreach ($settings as $name => $value) { | |
152 | $rowParams = array( | |
153 | 1 => array($domainDao->id, 'Positive'), | |
154 | 2 => array($name, 'String'), | |
155 | 3 => array(serialize($value), 'String'), | |
156 | ); | |
157 | $settingId = CRM_Core_DAO::singleValueQuery( | |
158 | 'SELECT id FROM civicrm_setting WHERE domain_id = %1 AND name = %2', | |
159 | $rowParams); | |
160 | if (!$settingId) { | |
161 | CRM_Core_DAO::executeQuery( | |
162 | 'INSERT INTO civicrm_setting (domain_id, name, value, is_domain) VALUES (%1,%2,%3,1)', | |
163 | $rowParams); | |
164 | } | |
165 | } | |
166 | } | |
167 | ||
168 | // TODO Should drop config_backend, but keeping it during alpha/beta cycle in case we miss something. | |
169 | // CRM_Core_DAO::executeQuery('ALTER TABLE civicrm_domain DROP COLUMN config_backend'); | |
170 | ||
171 | return TRUE; | |
172 | } | |
173 | ||
174 | /** | |
175 | * Take a config_backend blob and produce an equivalent list of settings. | |
176 | * | |
177 | * @param int $domainId | |
178 | * Domain ID. | |
179 | * @param string $config_backend | |
180 | * Serialized blob. | |
181 | * @return array | |
182 | */ | |
183 | public static function convertBackendToSettings($domainId, $config_backend) { | |
184 | if (!$config_backend) { | |
185 | return array(); | |
186 | } | |
187 | ||
188 | $backend = unserialize($config_backend); | |
189 | if (!$backend) { | |
190 | return array(); | |
191 | } | |
192 | ||
193 | $mappings = \CRM_Core_Config_MagicMerge::getPropertyMap(); | |
194 | $settings = array(); | |
195 | foreach ($backend as $propertyName => $propertyValue) { | |
196 | if (isset($mappings[$propertyName][0]) && preg_match('/^setting/', $mappings[$propertyName][0])) { | |
197 | // $mapping format: $propertyName => Array(0 => $type, 1 => $setting|NULL). | |
198 | $settingName = isset($mappings[$propertyName][1]) ? $mappings[$propertyName][1] : $propertyName; | |
199 | $settings[$settingName] = $propertyValue; | |
200 | } | |
201 | } | |
202 | ||
203 | return $settings; | |
204 | } | |
205 | ||
0a95c936 | 206 | /** |
207 | * Add Getting Started dashlet to dashboard | |
208 | * | |
209 | * @param \CRM_Queue_TaskContext $ctx | |
210 | * | |
211 | * @return bool | |
212 | */ | |
213 | public function addGettingStartedDashlet(CRM_Queue_TaskContext $ctx) { | |
e1674273 | 214 | $sql = "SELECT count(*) FROM civicrm_dashboard WHERE name='gettingStarted'"; |
215 | $res = CRM_Core_DAO::singleValueQuery($sql); | |
216 | $domainId = CRM_Core_Config::domainID(); | |
217 | if ($res <= 0) { | |
218 | $sql = "INSERT INTO `civicrm_dashboard` | |
a8b704c5 | 219 | ( `domain_id`, `name`, `label`, `url`, `permission`, `permission_operator`, `column_no`, `is_minimized`, `is_active`, `weight`, `fullscreen_url`, `is_fullscreen`, `is_reserved`) VALUES ( {$domainId}, 'getting-started', 'Getting Started', 'civicrm/dashlet/getting-started?reset=1&snippet=5', 'access CiviCRM', NULL, 0, 0, 1, 0, 'civicrm/dashlet/getting-started?reset=1&snippet=5&context=dashletFullscreen', 1, 1)"; |
e1674273 | 220 | CRM_Core_DAO::executeQuery($sql); |
221 | // Add default position for Getting Started Dashlet ( left column) | |
222 | $sql = "INSERT INTO `civicrm_dashboard_contact` (dashboard_id, contact_id, column_no, is_active) | |
223 | SELECT (SELECT MAX(id) FROM `civicrm_dashboard`), contact_id, 0, IF (SUM(is_active) > 0, 1, 0) | |
224 | FROM `civicrm_dashboard_contact` WHERE 1 GROUP BY contact_id"; | |
225 | CRM_Core_DAO::executeQuery($sql); | |
226 | } | |
0a95c936 | 227 | return TRUE; |
e1674273 | 228 | } |
4175ee03 | 229 | |
6b1e1a2c | 230 | /** |
231 | * Migrate on-behalf information to uf_join.module_data as on-behalf columns will be dropped | |
232 | * on DB upgrade | |
233 | * | |
234 | * @param CRM_Queue_TaskContext $ctx | |
235 | * | |
236 | * @return bool | |
237 | * TRUE for success | |
238 | */ | |
239 | public static function migrateOnBehalfOfInfo(CRM_Queue_TaskContext $ctx) { | |
d3e92c88 | 240 | $domain = new CRM_Core_DAO_Domain(); |
241 | $domain->find(TRUE); | |
6b1e1a2c | 242 | |
d3e92c88 | 243 | // fetch onBehalf entry in UFJoin table |
6b1e1a2c | 244 | $ufGroupDAO = new CRM_Core_DAO_UFJoin(); |
245 | $ufGroupDAO->module = 'OnBehalf'; | |
246 | $ufGroupDAO->find(TRUE); | |
247 | ||
d3e92c88 | 248 | $forOrgColums = array(); |
249 | if ($domain->locales) { | |
250 | $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales); | |
251 | foreach ($locales as $locale) { | |
252 | $forOrgColums[] = "for_organization_{$locale}"; | |
253 | } | |
254 | } | |
255 | else { | |
256 | $forOrgColums[] = "for_organization"; | |
257 | } | |
258 | ||
259 | $query = " | |
260 | SELECT " . implode(", ", $forOrgColums) . ", uj.id as join_id, uj.uf_group_id as uf_group_id | |
261 | FROM civicrm_contribution_page cp | |
262 | INNER JOIN civicrm_uf_join uj ON uj.entity_id = cp.id AND uj.module = 'OnBehalf'"; | |
263 | $dao = CRM_Core_DAO::executeQuery($query, array(), TRUE, NULL, FALSE, FALSE); | |
6b1e1a2c | 264 | |
265 | if ($dao->N) { | |
6b1e1a2c | 266 | while ($dao->fetch()) { |
267 | $onBehalfParams['on_behalf'] = array('is_for_organization' => $dao->is_for_organization); | |
268 | if ($domain->locales) { | |
6b1e1a2c | 269 | foreach ($locales as $locale) { |
270 | $for_organization = "for_organization_{$locale}"; | |
271 | $onBehalfParams['on_behalf'] += array( | |
272 | $locale => array( | |
273 | 'for_organization' => $dao->$for_organization, | |
274 | ), | |
275 | ); | |
276 | } | |
277 | } | |
278 | else { | |
279 | $onBehalfParams['on_behalf'] += array( | |
280 | 'default' => array( | |
281 | 'for_organization' => $dao->for_organization, | |
282 | ), | |
283 | ); | |
284 | } | |
285 | $ufJoinParam = array( | |
286 | 'id' => $dao->join_id, | |
287 | 'module' => 'on_behalf', | |
d3e92c88 | 288 | 'uf_group_id' => $dao->uf_group_id, |
6b1e1a2c | 289 | 'module_data' => json_encode($onBehalfParams), |
290 | ); | |
291 | CRM_Core_BAO_UFJoin::create($ufJoinParam); | |
292 | } | |
293 | } | |
294 | ||
295 | return TRUE; | |
296 | } | |
cb804cd9 | 297 | |
6cc25669 | 298 | } |