Commit | Line | Data |
---|---|---|
6a488035 | 1 | <?php |
6a488035 TO |
2 | /* |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
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. | | |
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 | /** | |
28 | * | |
29 | * @package CRM | |
06b69b18 | 30 | * @copyright CiviCRM LLC (c) 2004-2014 |
6a488035 TO |
31 | * $Id$ |
32 | * | |
33 | */ | |
34 | class CRM_Upgrade_Incremental_php_ThreeFour { | |
624e56fa EM |
35 | /** |
36 | * @param $errors | |
37 | * | |
38 | * @return bool | |
39 | */ | |
00be9182 | 40 | public function verifyPreDBstate(&$errors) { |
6a488035 TO |
41 | return TRUE; |
42 | } | |
43 | ||
624e56fa EM |
44 | /** |
45 | * @param $rev | |
46 | */ | |
00be9182 | 47 | public function upgrade_3_4_alpha3($rev) { |
6a488035 | 48 | // CRM-7681, update report instance criteria. |
353ffa53 TO |
49 | $modifiedReportIds = array( |
50 | 'contact/summary', | |
51 | 'contact/detail', | |
52 | 'event/participantListing', | |
53 | 'member/summary', | |
54 | 'pledge/summary', | |
55 | 'pledge/pbnp', | |
56 | 'member/detail', | |
57 | 'member/lapse', | |
58 | 'grant/detail', | |
59 | 'contribute/bookkeeping', | |
60 | 'contribute/lybunt', | |
61 | 'contribute/summary', | |
62 | 'contribute/repeat', | |
63 | 'contribute/detail', | |
64 | 'contribute/organizationSummary', | |
65 | 'contribute/sybunt', | |
66 | 'contribute/householdSummary', | |
67 | 'contact/relationship', | |
68 | 'contact/currentEmployer', | |
69 | 'case/demographics', | |
70 | 'walklist', | |
71 | 'case/detail', | |
72 | 'contact/log', | |
73 | 'activitySummary', | |
74 | 'case/timespent', | |
75 | 'case/summary' | |
76 | ); | |
6a488035 TO |
77 | |
78 | $instances = CRM_Core_DAO::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')"); | |
79 | ||
80 | while ($instances->fetch()) { | |
81 | $formValues = unserialize($instances->form_values); | |
82 | ||
83 | // replace display_name fields by sort_name | |
a7488080 | 84 | if (!empty($formValues['fields']) && isset($formValues['fields']['display_name'])) { |
6a488035 TO |
85 | $formValues['fields']['sort_name'] = $formValues['fields']['display_name']; |
86 | unset($formValues['fields']['display_name']); | |
87 | } | |
88 | ||
89 | // replace display_name filters by sort_name | |
90 | if (isset($formValues['display_name_op'])) { | |
91 | $formValues['sort_name_op'] = $formValues['display_name_op']; | |
92 | unset($formValues['display_name_op']); | |
93 | } | |
94 | if (isset($formValues['display_name_value'])) { | |
95 | $formValues['sort_name_value'] = $formValues['display_name_value']; | |
96 | unset($formValues['display_name_value']); | |
97 | } | |
98 | ||
99 | // for report id 'contact/log' replace field | |
100 | // display_name_touched by sort_name_touched | |
101 | if ($instances->report_id == 'contact/log' && isset($formValues['fields']['display_name_touched'])) { | |
102 | $formValues['fields']['sort_name_touched'] = $formValues['fields']['display_name_touched']; | |
103 | unset($formValues['fields']['display_name_touched']); | |
104 | } | |
105 | ||
106 | // for report id 'contact/relationship' replace field | |
107 | // display_name_a by sort_name_a and display_name_b by sort_name_b | |
108 | if ($instances->report_id == 'contact/relationship') { | |
109 | if (isset($formValues['fields']['display_name_a'])) { | |
110 | $formValues['fields']['sort_name_a'] = $formValues['fields']['display_name_a']; | |
111 | unset($formValues['fields']['display_name_a']); | |
112 | } | |
113 | ||
114 | if (isset($formValues['fields']['display_name_b'])) { | |
115 | $formValues['fields']['sort_name_b'] = $formValues['fields']['display_name_b']; | |
116 | unset($formValues['fields']['display_name_b']); | |
117 | } | |
118 | } | |
119 | ||
120 | // save updated instance criteria | |
353ffa53 TO |
121 | $dao = new CRM_Report_DAO_ReportInstance(); |
122 | $dao->id = $instances->id; | |
6a488035 TO |
123 | $dao->form_values = serialize($formValues); |
124 | $dao->save(); | |
125 | $dao->free(); | |
126 | } | |
127 | ||
128 | // Handled for typo in 3.3.2.mysql.tpl, rename column visibilty to | |
129 | // visibility in table civicrm_mailing | |
130 | $renameColumnVisibility = CRM_Core_DAO::checkFieldExists('civicrm_mailing', 'visibilty'); | |
131 | ||
132 | $upgrade = new CRM_Upgrade_Form(); | |
133 | $upgrade->assign('renameColumnVisibility', $renameColumnVisibility); | |
134 | $upgrade->processSQL($rev); | |
135 | } | |
136 | ||
624e56fa EM |
137 | /** |
138 | * @param $rev | |
139 | */ | |
00be9182 | 140 | public function upgrade_3_4_beta2($rev) { |
6a488035 TO |
141 | $addPetitionOptionGroup = !(boolean) CRM_Core_DAO::getFieldValue('CRM_Core_DAO_OptionGroup', 'msg_tpl_workflow_petition', 'id', 'name'); |
142 | $upgrade = new CRM_Upgrade_Form(); | |
143 | $upgrade->assign('addPetitionOptionGroup', $addPetitionOptionGroup); | |
144 | $upgrade->processSQL($rev); | |
145 | } | |
146 | ||
624e56fa EM |
147 | /** |
148 | * @param $rev | |
149 | */ | |
00be9182 | 150 | public function upgrade_3_4_beta3($rev) { |
6a488035 TO |
151 | // do the regular upgrade |
152 | $upgrade = new CRM_Upgrade_Form; | |
153 | $upgrade->processSQL($rev); | |
154 | ||
155 | if ($upgrade->multilingual) { | |
156 | ||
157 | // rebuild schema, because due to a CRM-7854 mis-fix some indices might be missing | |
158 | CRM_Core_I18n_Schema::rebuildMultilingualSchema($upgrade->locales, $rev); | |
159 | ||
160 | // turn a set of columns singlelingual | |
161 | $config = CRM_Core_Config::singleton(); | |
162 | $tables = array('civicrm_address', 'civicrm_contact', 'civicrm_mailing', 'civicrm_mailing_component'); | |
163 | $triggers = array(array('when' => 'before', 'event' => 'update'), array('when' => 'before', 'event' => 'insert')); | |
10824d34 | 164 | |
6a488035 TO |
165 | // FIXME: Doing require_once is a must here because a call like CRM_Core_I18n_SchemaStructure_3_4_beta2 makes |
166 | // class loader look for file like - CRM/Core/I18n/SchemaStructure/3/4/beta2.php which is not what we want to be loaded | |
167 | require_once "CRM/Core/I18n/SchemaStructure_3_4_beta2.php"; | |
168 | foreach ($tables as $table) { | |
169 | CRM_Core_I18n_Schema::makeSinglelingualTable($config->lcMessages, $table, 'CRM_Core_I18n_SchemaStructure_3_4_beta2', $triggers); | |
170 | } | |
171 | } | |
172 | } | |
173 | ||
624e56fa EM |
174 | /** |
175 | * @param $rev | |
176 | */ | |
00be9182 | 177 | public function upgrade_3_4_3($rev) { |
6a488035 TO |
178 | // CRM-8147, update group_type for uf groups, check and add component field types |
179 | $ufGroups = new CRM_Core_DAO_UFGroup(); | |
180 | $ufGroups->find(); | |
353ffa53 TO |
181 | $skipGroupTypes = array( |
182 | 'Individual,Contact', | |
183 | 'Organization,Contact', | |
184 | 'Household,Contact', | |
185 | 'Contact', | |
186 | 'Individual', | |
187 | 'Organization', | |
188 | 'Household' | |
189 | ); | |
6a488035 TO |
190 | while ($ufGroups->fetch()) { |
191 | if (!in_array($ufGroups->group_type, $skipGroupTypes)) { | |
192 | $groupTypes = CRM_Core_BAO_UFGroup::calculateGroupType($ufGroups->id, TRUE); | |
193 | CRM_Core_BAO_UFGroup::updateGroupTypes($ufGroups->id, $groupTypes); | |
194 | } | |
195 | } | |
196 | $ufGroups->free(); | |
197 | ||
198 | // CRM-8134 add phone_ext column if it wasn't already added for this site in 3.3.7 upgrade (3.3.7 was released after 3.4.0) | |
199 | $dao = new CRM_Contact_DAO_Contact(); | |
200 | $dbName = $dao->_database; | |
201 | ||
202 | $chkExtQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1 | |
203 | AND TABLE_NAME = 'civicrm_phone' AND COLUMN_NAME = 'phone_ext'"; | |
204 | $extensionExists = CRM_Core_DAO::singleValueQuery($chkExtQuery, | |
205 | array(1 => array($dbName, 'String')), | |
206 | TRUE, FALSE | |
207 | ); | |
208 | ||
209 | if (!$extensionExists) { | |
210 | $colQuery = 'ALTER TABLE `civicrm_phone` ADD `phone_ext` VARCHAR( 16 ) CHARACTER SET utf8 COLLATE utf8_unicode_ci NULL DEFAULT NULL AFTER `phone` '; | |
211 | CRM_Core_DAO::executeQuery($colQuery); | |
212 | } | |
213 | ||
214 | $sql = "SELECT id FROM civicrm_location_type WHERE name = 'Main'"; | |
215 | if (!CRM_Core_DAO::singleValueQuery($sql)) { | |
216 | $query = " | |
217 | INSERT INTO civicrm_location_type ( name, description, is_reserved, is_active ) | |
218 | VALUES ( 'Main', 'Main office location', 0, 1 );"; | |
219 | CRM_Core_DAO::executeQuery($query); | |
220 | } | |
221 | ||
222 | $upgrade = new CRM_Upgrade_Form; | |
223 | $upgrade->processSQL($rev); | |
224 | } | |
225 | ||
624e56fa EM |
226 | /** |
227 | * @param $rev | |
228 | */ | |
00be9182 | 229 | public function upgrade_3_4_4($rev) { |
6a488035 TO |
230 | // CRM-8315, update report instance criteria. |
231 | $modifiedReportIds = array('member/summary', 'member/detail'); | |
232 | ||
233 | $instances = CRM_Core_DAO::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')"); | |
234 | ||
235 | while ($instances->fetch()) { | |
236 | $formValues = unserialize($instances->form_values); | |
237 | ||
238 | // replace display_name fields by sort_name | |
239 | if (!isset($formValues['membership_start_date_relative']) && | |
240 | !isset($formValues['membership_end_date_relative']) | |
241 | ) { | |
242 | $formValues['membership_start_date_relative'] = '0'; | |
243 | $formValues['membership_start_date_from'] = ''; | |
244 | $formValues['membership_start_date_to'] = ''; | |
245 | $formValues['membership_end_date_relative'] = '0'; | |
246 | $formValues['membership_end_date_from'] = ''; | |
247 | $formValues['membership_end_date_to'] = ''; | |
248 | } | |
249 | ||
250 | // save updated instance criteria | |
353ffa53 TO |
251 | $dao = new CRM_Report_DAO_ReportInstance(); |
252 | $dao->id = $instances->id; | |
6a488035 TO |
253 | $dao->form_values = serialize($formValues); |
254 | $dao->save(); | |
255 | $dao->free(); | |
256 | } | |
257 | ||
258 | $upgrade = new CRM_Upgrade_Form(); | |
259 | $upgrade->processSQL($rev); | |
260 | } | |
261 | ||
624e56fa EM |
262 | /** |
263 | * @param $rev | |
264 | */ | |
00be9182 | 265 | public function upgrade_3_4_5($rev) { |
6a488035 TO |
266 | // handle db changes done for CRM-8218 |
267 | $alterContactDashboard = FALSE; | |
268 | $dao = new CRM_Contact_DAO_DashboardContact(); | |
269 | $dbName = $dao->_database; | |
270 | ||
271 | $chkContentQuery = "SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = %1 | |
272 | AND TABLE_NAME = 'civicrm_dashboard_contact' AND COLUMN_NAME = 'content'"; | |
273 | $contentExists = CRM_Core_DAO::singleValueQuery($chkContentQuery, | |
274 | array(1 => array($dbName, 'String')), | |
275 | TRUE, FALSE | |
276 | ); | |
277 | if (!$contentExists) { | |
278 | $alterContactDashboard = TRUE; | |
279 | } | |
280 | ||
281 | $upgrade = new CRM_Upgrade_Form(); | |
282 | $upgrade->assign('alterContactDashboard', $alterContactDashboard); | |
283 | $upgrade->processSQL($rev); | |
284 | } | |
285 | ||
624e56fa EM |
286 | /** |
287 | * @param $rev | |
288 | */ | |
00be9182 | 289 | public function upgrade_3_4_6($rev) { |
6a488035 TO |
290 | $modifiedReportIds = array('event/summary', 'activity', 'Mailing/bounce', 'Mailing/clicks', 'Mailing/opened'); |
291 | ||
292 | $instances = CRM_Core_DAO::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')"); | |
293 | while ($instances->fetch()) { | |
294 | $formValues = unserialize($instances->form_values); | |
295 | ||
296 | switch ($instances->report_id) { | |
297 | case 'event/summary': | |
353ffa53 TO |
298 | $eventDates = array( |
299 | 'event_start_date_from', | |
300 | 'event_start_date_to', | |
301 | 'event_end_date_from', | |
302 | 'event_end_date_to' | |
303 | ); | |
6a488035 TO |
304 | foreach ($eventDates as $date) { |
305 | if (isset($formValues[$date]) && $formValues[$date] == ' ') { | |
306 | $formValues[$date] = ''; | |
307 | } | |
308 | } | |
309 | break; | |
310 | ||
311 | case 'activity': | |
312 | if (isset($formValues['group_bys'])) { | |
313 | if (is_array($formValues['group_bys'])) { | |
314 | $orderBy = array(); | |
315 | $count = 0; | |
316 | foreach ($formValues['group_bys'] as $col => $isSet) { | |
317 | if (!$isSet) { | |
318 | continue; | |
319 | } | |
320 | ||
321 | $orderBy[++$count] = array( | |
322 | 'column' => $col, | |
323 | 'order' => 'ASC', | |
324 | ); | |
325 | } | |
326 | if (!empty($orderBy)) { | |
327 | $formValues['order_bys'] = $orderBy; | |
328 | } | |
329 | } | |
330 | unset($formValues['group_bys']); | |
331 | } | |
332 | break; | |
333 | ||
334 | case 'Mailing/bounce': | |
335 | case 'Mailing/clicks': | |
336 | case 'Mailing/opened': | |
337 | $formValues['fields']['mailing_name'] = 1; | |
338 | break; | |
339 | } | |
340 | ||
341 | // save updated instance criteria | |
353ffa53 TO |
342 | $dao = new CRM_Report_DAO_ReportInstance(); |
343 | $dao->id = $instances->id; | |
6a488035 TO |
344 | $dao->form_values = serialize($formValues); |
345 | $dao->save(); | |
346 | $dao->free(); | |
347 | } | |
348 | ||
349 | $bulkEmailActivityType = CRM_Core_DAO::singleValueQuery(" | |
350 | SELECT v.id | |
10824d34 | 351 | FROM civicrm_option_value v, |
352 | civicrm_option_group g | |
353 | WHERE v.option_group_id = g.id | |
354 | AND g.name = %1 | |
355 | AND g.is_active = 1 | |
e418776c | 356 | AND v.name = %2", array( |
353ffa53 TO |
357 | 1 => array('activity_type', 'String'), |
358 | 2 => array('Bulk Email', 'String'), | |
359 | )); | |
6a488035 TO |
360 | |
361 | // CRM-8852, reset contact field cache | |
362 | CRM_Core_BAO_Cache::deleteGroup('contact fields'); | |
363 | ||
364 | $upgrade = new CRM_Upgrade_Form(); | |
365 | $upgrade->assign('bulkEmailActivityType', $bulkEmailActivityType); | |
366 | ||
367 | $upgrade->processSQL($rev); | |
368 | } | |
369 | ||
624e56fa EM |
370 | /** |
371 | * @param $rev | |
372 | * | |
373 | * @throws Exception | |
374 | */ | |
00be9182 | 375 | public function upgrade_3_4_7($rev) { |
6a488035 TO |
376 | $onBehalfProfileId = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name'); |
377 | if (!$onBehalfProfileId) { | |
378 | CRM_Core_Error::fatal(); | |
379 | } | |
380 | ||
381 | $pages = CRM_Core_DAO::executeQuery(" | |
10824d34 | 382 | SELECT civicrm_contribution_page.id |
6a488035 | 383 | FROM civicrm_contribution_page |
10824d34 | 384 | LEFT JOIN civicrm_uf_join ON entity_table = 'civicrm_contribution_page' AND entity_id = civicrm_contribution_page.id AND module = 'OnBehalf' |
385 | WHERE is_for_organization = 1 | |
6a488035 TO |
386 | AND civicrm_uf_join.id IS NULL |
387 | "); | |
388 | ||
389 | while ($pages->fetch()) { | |
390 | $query = " | |
391 | INSERT INTO civicrm_uf_join | |
392 | (is_active, module, entity_table, entity_id, weight, uf_group_id) | |
393 | VALUES | |
394 | (1, 'OnBehalf', 'civicrm_contribution_page', %1, 1, %2)"; | |
395 | ||
e418776c | 396 | $params = array( |
353ffa53 | 397 | 1 => array($pages->id, 'Integer'), |
6a488035 TO |
398 | 2 => array($onBehalfProfileId, 'Integer'), |
399 | ); | |
400 | CRM_Core_DAO::executeQuery($query, $params); | |
401 | } | |
402 | ||
403 | // CRM-8774 | |
404 | $config = CRM_Core_Config::singleton(); | |
405 | if ($config->userFramework == 'Drupal' || $config->userFramework == 'Drupal6') { | |
406 | db_query("UPDATE {system} SET weight = 100 WHERE name = 'civicrm'"); | |
407 | drupal_flush_all_caches(); | |
408 | } | |
409 | ||
410 | $upgrade = new CRM_Upgrade_Form(); | |
411 | $upgrade->processSQL($rev); | |
412 | } | |
413 | } |