3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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. |
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 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 +--------------------------------------------------------------------+
30 * @copyright CiviCRM LLC (c) 2004-2014
34 class CRM_Upgrade_Incremental_php_ThreeFour
{
40 public function verifyPreDBstate(&$errors) {
47 public function upgrade_3_4_alpha3($rev) {
48 // CRM-7681, update report instance criteria.
49 $modifiedReportIds = array(
52 'event/participantListing',
59 'contribute/bookkeeping',
64 'contribute/organizationSummary',
66 'contribute/householdSummary',
67 'contact/relationship',
68 'contact/currentEmployer',
78 $instances = CRM_Core_DAO
::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')");
80 while ($instances->fetch()) {
81 $formValues = unserialize($instances->form_values
);
83 // replace display_name fields by sort_name
84 if (!empty($formValues['fields']) && isset($formValues['fields']['display_name'])) {
85 $formValues['fields']['sort_name'] = $formValues['fields']['display_name'];
86 unset($formValues['fields']['display_name']);
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']);
94 if (isset($formValues['display_name_value'])) {
95 $formValues['sort_name_value'] = $formValues['display_name_value'];
96 unset($formValues['display_name_value']);
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']);
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']);
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']);
120 // save updated instance criteria
121 $dao = new CRM_Report_DAO_ReportInstance();
122 $dao->id
= $instances->id
;
123 $dao->form_values
= serialize($formValues);
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');
132 $upgrade = new CRM_Upgrade_Form();
133 $upgrade->assign('renameColumnVisibility', $renameColumnVisibility);
134 $upgrade->processSQL($rev);
140 public function upgrade_3_4_beta2($rev) {
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);
150 public function upgrade_3_4_beta3($rev) {
151 // do the regular upgrade
152 $upgrade = new CRM_Upgrade_Form();
153 $upgrade->processSQL($rev);
155 if ($upgrade->multilingual
) {
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);
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'));
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);
177 public function upgrade_3_4_3($rev) {
178 // CRM-8147, update group_type for uf groups, check and add component field types
179 $ufGroups = new CRM_Core_DAO_UFGroup();
181 $skipGroupTypes = array(
182 'Individual,Contact',
183 'Organization,Contact',
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);
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
;
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')),
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);
214 $sql = "SELECT id FROM civicrm_location_type WHERE name = 'Main'";
215 if (!CRM_Core_DAO
::singleValueQuery($sql)) {
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);
222 $upgrade = new CRM_Upgrade_Form();
223 $upgrade->processSQL($rev);
229 public function upgrade_3_4_4($rev) {
230 // CRM-8315, update report instance criteria.
231 $modifiedReportIds = array('member/summary', 'member/detail');
233 $instances = CRM_Core_DAO
::executeQuery("SELECT id, form_values, report_id FROM civicrm_report_instance WHERE report_id IN ('" . implode("','", $modifiedReportIds) . "')");
235 while ($instances->fetch()) {
236 $formValues = unserialize($instances->form_values
);
238 // replace display_name fields by sort_name
239 if (!isset($formValues['membership_start_date_relative']) &&
240 !isset($formValues['membership_end_date_relative'])
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'] = '';
250 // save updated instance criteria
251 $dao = new CRM_Report_DAO_ReportInstance();
252 $dao->id
= $instances->id
;
253 $dao->form_values
= serialize($formValues);
258 $upgrade = new CRM_Upgrade_Form();
259 $upgrade->processSQL($rev);
265 public function upgrade_3_4_5($rev) {
266 // handle db changes done for CRM-8218
267 $alterContactDashboard = FALSE;
268 $dao = new CRM_Contact_DAO_DashboardContact();
269 $dbName = $dao->_database
;
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')),
277 if (!$contentExists) {
278 $alterContactDashboard = TRUE;
281 $upgrade = new CRM_Upgrade_Form();
282 $upgrade->assign('alterContactDashboard', $alterContactDashboard);
283 $upgrade->processSQL($rev);
289 public function upgrade_3_4_6($rev) {
290 $modifiedReportIds = array('event/summary', 'activity', 'Mailing/bounce', 'Mailing/clicks', 'Mailing/opened');
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
);
296 switch ($instances->report_id
) {
297 case 'event/summary':
299 'event_start_date_from',
300 'event_start_date_to',
301 'event_end_date_from',
304 foreach ($eventDates as $date) {
305 if (isset($formValues[$date]) && $formValues[$date] == ' ') {
306 $formValues[$date] = '';
312 if (isset($formValues['group_bys'])) {
313 if (is_array($formValues['group_bys'])) {
316 foreach ($formValues['group_bys'] as $col => $isSet) {
321 $orderBy[++
$count] = array(
326 if (!empty($orderBy)) {
327 $formValues['order_bys'] = $orderBy;
330 unset($formValues['group_bys']);
334 case 'Mailing/bounce':
335 case 'Mailing/clicks':
336 case 'Mailing/opened':
337 $formValues['fields']['mailing_name'] = 1;
341 // save updated instance criteria
342 $dao = new CRM_Report_DAO_ReportInstance();
343 $dao->id
= $instances->id
;
344 $dao->form_values
= serialize($formValues);
349 $bulkEmailActivityType = CRM_Core_DAO
::singleValueQuery("
351 FROM civicrm_option_value v,
352 civicrm_option_group g
353 WHERE v.option_group_id = g.id
358 1 => array('activity_type', 'String'),
359 2 => array('Bulk Email', 'String'),
362 // CRM-8852, reset contact field cache
363 CRM_Core_BAO_Cache
::deleteGroup('contact fields');
365 $upgrade = new CRM_Upgrade_Form();
366 $upgrade->assign('bulkEmailActivityType', $bulkEmailActivityType);
368 $upgrade->processSQL($rev);
376 public function upgrade_3_4_7($rev) {
377 $onBehalfProfileId = CRM_Core_DAO
::getFieldValue('CRM_Core_DAO_UFGroup', 'on_behalf_organization', 'id', 'name');
378 if (!$onBehalfProfileId) {
379 CRM_Core_Error
::fatal();
382 $pages = CRM_Core_DAO
::executeQuery("
383 SELECT civicrm_contribution_page.id
384 FROM civicrm_contribution_page
385 LEFT JOIN civicrm_uf_join ON entity_table = 'civicrm_contribution_page' AND entity_id = civicrm_contribution_page.id AND module = 'OnBehalf'
386 WHERE is_for_organization = 1
387 AND civicrm_uf_join.id IS NULL
390 while ($pages->fetch()) {
392 INSERT INTO civicrm_uf_join
393 (is_active, module, entity_table, entity_id, weight, uf_group_id)
395 (1, 'OnBehalf', 'civicrm_contribution_page', %1, 1, %2)";
398 1 => array($pages->id
, 'Integer'),
399 2 => array($onBehalfProfileId, 'Integer'),
401 CRM_Core_DAO
::executeQuery($query, $params);
405 $config = CRM_Core_Config
::singleton();
406 if ($config->userFramework
== 'Drupal' ||
$config->userFramework
== 'Drupal6') {
407 db_query("UPDATE {system} SET weight = 100 WHERE name = 'civicrm'");
408 drupal_flush_all_caches();
411 $upgrade = new CRM_Upgrade_Form();
412 $upgrade->processSQL($rev);