Import from SVN (r45945, r596)
[civicrm-core.git] / CRM / Upgrade / TwoTwo / Form / Step1.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.3 |
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 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-2013
32 * $Id$
33 *
34 */
35 class CRM_Upgrade_TwoTwo_Form_Step1 extends CRM_Upgrade_Form {
36 function verifyPreDBState(&$errorMessage) {
37 // check if log file is writable
38 $config = CRM_Core_Config::singleton();
39
40 if (!is_writable($config->uploadDir . 'CiviCRM.log') &&
41 !is_writable($config->uploadDir . 'CiviCRM.log.' .
42 md5($config->dsn . $config->userFrameworkResourceURL)
43 )
44 ) {
45 $errorMessage = ts('Log file CiviCRM.log is not writable. Make sure files directory is writable.',
46 array(1 => $config->uploadDir)
47 );
48 return FALSE;
49 }
50
51 $errorMessage = ts('Database check failed - the current database is not v2.1.');
52 $is21db = TRUE;
53
54 // abort if partial upgraded db found.
55 if ($this->checkVersion('2.1.101') ||
56 $this->checkVersion('2.1.102') ||
57 $this->checkVersion('2.1.103')
58 ) {
59 $errorMessage = ts('Corrupt / Partial Upgraded database found. Looks like upgrade wizard failed to complete all the required steps to convert your database to v2.2. Please fix any errors and start the upgrade process again with a clean v2.1 database.');
60 return FALSE;
61 }
62
63 // abort if already 2.2
64 if ($this->checkVersion('2.2')) {
65 $errorMessage = ts('Database check failed - looks like you have already upgraded to the latest version (v2.2) of the database.');
66 return FALSE;
67 }
68
69 // check if 2.1 version
70 if (!$this->checkVersion('2.1.2') ||
71 !$this->checkVersion('2.1.3') ||
72 !$this->checkVersion('2.1.4')
73 ) {
74 $is21db = FALSE;
75 }
76
77 // check if 2.1 tables exists
78 if (!CRM_Core_DAO::checkTableExists('civicrm_pledge') ||
79 !CRM_Core_DAO::checkTableExists('civicrm_cache') ||
80 !CRM_Core_DAO::checkTableExists('civicrm_group_contact_cache') ||
81 !CRM_Core_DAO::checkTableExists('civicrm_discount') ||
82 !CRM_Core_DAO::checkTableExists('civicrm_menu') ||
83 !CRM_Core_DAO::checkTableExists('civicrm_pledge') ||
84 !CRM_Core_DAO::checkTableExists('civicrm_pledge_block') ||
85 !CRM_Core_DAO::checkTableExists('civicrm_case_contact')
86 ) {
87 // db is not 2.1
88 $errorMessage .= ' Few 2.1 tables were found missing.';
89 $is21db = FALSE;
90 }
91
92 // check fields which MUST be present if a proper 2.1 db
93 if ($is21db) {
94 if (!CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'is_recur_interval') ||
95 !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'recur_frequency_unit') ||
96 !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'for_organization') ||
97 !CRM_Core_DAO::checkFieldExists('civicrm_contribution_page', 'is_for_organization') ||
98 !CRM_Core_DAO::checkFieldExists('civicrm_contribution', 'is_pay_later') ||
99 !CRM_Core_DAO::checkFieldExists('civicrm_membership', 'is_pay_later') ||
100 !CRM_Core_DAO::checkFieldExists('civicrm_membership_status', 'is_reserved') ||
101 !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'is_pay_later') ||
102 !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'fee_amount') ||
103 !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'registered_by_id') ||
104 !CRM_Core_DAO::checkFieldExists('civicrm_participant', 'discount_id') ||
105 !CRM_Core_DAO::checkFieldExists('civicrm_contact', 'employer_id') ||
106 !CRM_Core_DAO::checkFieldExists('civicrm_domain', 'locales') ||
107 !CRM_Core_DAO::checkFieldExists('civicrm_mapping', 'mapping_type_id') ||
108 !CRM_Core_DAO::checkFieldExists('civicrm_custom_field', 'is_view') ||
109 !CRM_Core_DAO::checkFieldExists('civicrm_group', 'cache_date') ||
110 !CRM_Core_DAO::checkFieldExists('civicrm_group', 'parents') ||
111 !CRM_Core_DAO::checkFieldExists('civicrm_group', 'children') ||
112 !CRM_Core_DAO::checkFieldExists('civicrm_preferences', 'editor_id') ||
113 !CRM_Core_DAO::checkFieldExists('civicrm_uf_group', 'group_type') ||
114 !CRM_Core_DAO::checkFieldExists('civicrm_address', 'name') ||
115 !CRM_Core_DAO::checkFieldExists('civicrm_uf_match', 'language')
116 ) {
117 // db looks to have stuck somewhere between 2.1 & 2.2
118 $errorMessage .= ' Few important fields were found missing in some of the tables.';
119 $is21db = FALSE;
120 }
121 }
122
123 // check if the db is 2.2
124 if (!CRM_Core_DAO::checkTableExists('civicrm_event_page') &&
125 CRM_Core_DAO::checkFieldExists('civicrm_participant', 'registered_by_id') &&
126 CRM_Core_DAO::checkFieldExists('civicrm_event', 'intro_text') &&
127 CRM_Core_DAO::checkFieldExists('civicrm_event', 'is_multiple_registrations') &&
128 CRM_Core_DAO::checkTableExists('civicrm_pcp_block') &&
129 CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'tellfriend_limit') &&
130 CRM_Core_DAO::checkFieldExists('civicrm_pcp_block', 'supporter_profile_id') &&
131 CRM_Core_DAO::checkTableExists('civicrm_pcp') &&
132 CRM_Core_DAO::checkFieldExists('civicrm_pcp', 'status_id') &&
133 CRM_Core_DAO::checkFieldExists('civicrm_pcp', 'goal_amount') &&
134 CRM_Core_DAO::checkTableExists('civicrm_contribution_soft') &&
135 CRM_Core_DAO::checkFieldExists('civicrm_contribution_soft', 'pcp_display_in_roll') &&
136 CRM_Core_DAO::checkFieldExists('civicrm_contribution_soft', 'amount')
137 ) {
138
139 $errorMessage = ts('Database check failed - it looks like you have already upgraded to the latest version (v2.2) of the database.');
140 return FALSE;
141 }
142
143
144 // check tables which should not exist for v2.x
145 if (CRM_Core_DAO::checkTableExists('civicrm_custom_option') ||
146 CRM_Core_DAO::checkTableExists('civicrm_custom_value') ||
147 CRM_Core_DAO::checkTableExists('civicrm_email_history') ||
148 CRM_Core_DAO::checkTableExists('civicrm_geo_coord') ||
149 CRM_Core_DAO::checkTableExists('civicrm_individual') ||
150 CRM_Core_DAO::checkTableExists('civicrm_location') ||
151 CRM_Core_DAO::checkTableExists('civicrm_meeting') ||
152 CRM_Core_DAO::checkTableExists('civicrm_organization') ||
153 CRM_Core_DAO::checkTableExists('civicrm_phonecall') ||
154 CRM_Core_DAO::checkTableExists('civicrm_sms_history') ||
155 CRM_Core_DAO::checkTableExists('civicrm_validation')
156 ) {
157 // table(s) found in the db which are no longer required
158 // for v2.x, though would not do any harm it's recommended
159 // to remove them.
160 CRM_Core_Session::setStatus(ts("Table(s) found in your db which are no longer required for v2.x, though would not do any harm it's recommended to remove them"), ts('Redundant Tables'), 'info');
161 }
162
163 // show error if any of the tables, use 'MyISAM' storage engine.
164 // just check the first 10 civicrm tables, rather than checking all 106!
165 if (CRM_Core_DAO::isDBMyISAM(10)) {
166 $errorMessage = ts('Your database is configured to use the MyISAM database engine. CiviCRM requires InnoDB. You will need to convert any MyISAM tables in your database to InnoDB before proceeding.');
167 return FALSE;
168 }
169
170 return TRUE;
171 }
172
173 function upgrade() {
174 $this->setVersion('2.1.101');
175 }
176
177 function verifyPostDBState(&$errorMessage) {
178 $errorMessage = ts('Post-condition failed for upgrade step %1.', array(1 => '1'));
179 return $this->checkVersion('2.1.101');
180 }
181
182 function getTitle() {
183 return ts('CiviCRM 2.2 Upgrade: Step One (Check Version)');
184 }
185
186 function getTemplateMessage() {
187 $msg = '<p><strong>' . ts('This process will upgrade your v2.1 CiviCRM database to the v2.2 database format.') . '</strong></p><div class="messsages status"><ul><li><strong>' . ts('Make sure you have a current and complete backup of your CiviCRM database and codebase files before starting the upgrade process.') . '</strong></li><li>' . '</li></ul></div><p>' . ts('Click <strong>Begin Upgrade</strong> to begin the process.') . '</p>';
188
189 return $msg;
190 }
191
192 function getButtonTitle() {
193 return ts('Begin Upgrade');
194 }
195 }
196