CRM/Upgrade add missing comment blocks
[civicrm-core.git] / CRM / Upgrade / TwoOne / Form / TwoOneTwo.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
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-2014
32 * $Id$
33 *
34 */
35 class CRM_Upgrade_TwoOne_Form_TwoOneTwo extends CRM_Upgrade_Form {
36 /**
37 * @param null|object $version
38 */
39 function __construct($version) {
40 parent::__construct();
41 $this->latestVersion = $version;
42 }
43
44 /**
45 * @param $errorMessage
46 *
47 * @return bool
48 */
49 function verifyPreDBState(&$errorMessage) {
50 $errorMessage = ts('Pre-condition failed for upgrade to 2.1.2.');
51 // check if the db is 2.2
52 if (!CRM_Core_DAO::checkTableExists('civicrm_event_page') &&
53 CRM_Core_DAO::checkTableExists('civicrm_pcp_block') &&
54 CRM_Core_DAO::checkTableExists('civicrm_pcp') &&
55 CRM_Core_DAO::checkTableExists('civicrm_contribution_soft')
56 ) {
57 $errorMessage = ts('Database check failed - it looks like you have already upgraded to the latest version (v2.2) of the database.');
58 return FALSE;
59 }
60 // check if the db is 2.2
61 if (CRM_Core_DAO::checkFieldExists('civicrm_participant', 'registered_by_id') &&
62 CRM_Core_DAO::checkFieldExists('civicrm_event', 'intro_text') &&
63 CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_multiple_registrations') &&
64 CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'tellfriend_limit') &&
65 CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'supporter_profile_id') &&
66 CRM_Core_DAO::checkFieldExists('civicrm_pcp', 'status_id') &&
67 CRM_Core_DAO::checkFieldExists('civicrm_pcp', 'goal_amount') &&
68 CRM_Core_DAO::checkFieldExists('civicrm_contribution_soft', 'pcp_display_in_roll') &&
69 CRM_Core_DAO::checkFieldExists('civicrm_contribution_soft', 'amount')
70 ) {
71
72 $errorMessage = ts('Database check failed - it looks like you have already upgraded to the latest version (v2.2) of the database.');
73 return FALSE;
74 }
75
76 if (!CRM_Core_DAO::checkTableExists('civicrm_cache') ||
77 !CRM_Core_DAO::checkTableExists('civicrm_group_contact_cache') ||
78 !CRM_Core_DAO::checkTableExists('civicrm_menu') ||
79 !CRM_Core_DAO::checkTableExists('civicrm_discount') ||
80 !CRM_Core_DAO::checkTableExists('civicrm_pledge') ||
81 !CRM_Core_DAO::checkTableExists('civicrm_pledge_block') ||
82 !CRM_Core_DAO::checkTableExists('civicrm_pledge_payment')
83 ) {
84 $errorMessage .= ' Few important tables were found missing.';
85 return FALSE;
86 }
87
88 // check fields which MUST be present if a proper 2.1 db
89 if (!CRM_Core_DAO::checkFieldExists('civicrm_cache', 'group_name') ||
90 !CRM_Core_DAO::checkFieldExists('civicrm_cache', 'created_date') ||
91 !CRM_Core_DAO::checkFieldExists('civicrm_cache', 'expired_date') ||
92 !CRM_Core_DAO::checkFieldExists('civicrm_discount', 'option_group_id') ||
93 !CRM_Core_DAO::checkFieldExists('civicrm_discount', 'end_date') ||
94 !CRM_Core_DAO::checkFieldExists('civicrm_group_contact_cache', 'contact_id') ||
95 !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'path_arguments') ||
96 !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'is_exposed') ||
97 !CRM_Core_DAO::checkFieldExists('civicrm_menu', 'page_type') ||
98 !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'component_id') ||
99 !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'id') ||
100 !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'name')
101 ) {
102 // db looks to have stuck somewhere between 2.0 & 2.1
103 $errorMessage .= ' Few important fields were found missing in some of the tables.';
104 return FALSE;
105 }
106
107 return TRUE;
108 }
109
110 function upgrade() {
111 $currentDir = dirname(__FILE__);
112
113 $sqlFile = implode(DIRECTORY_SEPARATOR,
114 array($currentDir, '../sql', 'two_one_two.mysql')
115 );
116 $this->source($sqlFile);
117
118 // CRM-3707, Price Set Export has zeros in all columns
119 $query = "SELECT distinct(price_field_id) FROM civicrm_line_item";
120 $lineItem = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
121 while ($lineItem->fetch()) {
122 $grpName = "civicrm_price_field.amount." . $lineItem->price_field_id;
123 $query = "SELECT id FROM civicrm_option_group WHERE name='$grpName'";
124 $optGrp = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
125 if ($optGrp->fetch()) {
126 // update line_item table
127 $query = "UPDATE civicrm_line_item SET option_group_id={$optGrp->id} WHERE price_field_id={$lineItem->price_field_id}";
128 CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
129 }
130 }
131
132 // CRM-3796, fix null values of fee amount in participant table
133 $query = '
134 UPDATE civicrm_participant,civicrm_option_group, civicrm_option_value, civicrm_event_page, civicrm_event
135 SET civicrm_participant.fee_amount = civicrm_option_value.value
136 WHERE civicrm_option_value.option_group_id = civicrm_option_group.id
137 AND civicrm_event_page.id = substring( civicrm_option_group.name FROM 27 )
138 AND civicrm_option_group.name LIKE "civicrm_event_page.amount.%"
139 AND civicrm_participant.event_id = civicrm_event.id
140 AND civicrm_event.id = civicrm_event_page.event_id
141 AND civicrm_option_value.label = civicrm_participant.fee_level
142 ';
143
144 CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
145
146 $this->setVersion($this->latestVersion);
147 }
148
149 /**
150 * @param $errorMessage
151 *
152 * @return bool
153 */
154 function verifyPostDBState(&$errorMessage) {
155 $errorMessage = ts('Post-condition failed for upgrade to 2.1.2.');
156 return $this->checkVersion($this->latestVersion);
157 }
158 }
159