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