CRM/Upgrade add missing comment blocks
[civicrm-core.git] / CRM / Upgrade / TwoOne / Form / Step2.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_Step2 extends CRM_Upgrade_Form {
36 /**
37 * @param $errorMessage
38 *
39 * @return bool
40 */
41 function verifyPreDBState(&$errorMessage) {
42 $errorMessage = ts('Pre-condition failed for upgrade step %1.', array(1 => '2'));
43
44 return $this->checkVersion('2.01');
45 }
46
47 function upgrade() {
48 $currentDir = dirname(__FILE__);
49
50 // 1. remove domain_ids from the entire db
51 $sqlFile = implode(DIRECTORY_SEPARATOR,
52 array($currentDir, '../sql', 'group_values.mysql')
53 );
54 $this->source($sqlFile);
55
56 // 2. Add option group "safe_file_extension" and its option
57 // values to db, if not already present. CRM-3238
58 $query = "
59 SELECT id FROM civicrm_option_group WHERE name = 'safe_file_extension'";
60 $sfeGroup = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
61 $sfeGroup->fetch();
62 if (!isset($sfeGroup->id)) {
63 $query = "
64 INSERT INTO civicrm_option_group (name, description, is_reserved, is_active)
65 VALUES ('safe_file_extension', 'Safe File Extension', 0, 1)";
66 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
67
68 $query = "
69 SELECT id FROM civicrm_option_group WHERE name = 'safe_file_extension'";
70 $dao = CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray);
71 $dao->fetch();
72 if ($dao->id) {
73 $query = "
74 INSERT INTO `civicrm_option_value` (`option_group_id`, `label`, `value`, `name`, `grouping`, `filter`, `is_default`, `weight`, `description`, `is_optgroup`, `is_reserved`, `is_active`, `component_id`)
75 VALUES
76 ( %1, 'jpg', 1, NULL, NULL, 0, 0, 1, NULL, 0, 0, 1, NULL),
77 ( %1, 'jpeg', 2, NULL, NULL, 0, 0, 2, NULL, 0, 0, 1, NULL),
78 ( %1, 'png', 3, NULL, NULL, 0, 0, 3, NULL, 0, 0, 1, NULL),
79 ( %1, 'gif', 4, NULL, NULL, 0, 0, 4, NULL, 0, 0, 1, NULL),
80 ( %1, 'txt', 5, NULL, NULL, 0, 0, 5, NULL, 0, 0, 1, NULL),
81 ( %1, 'pdf', 6, NULL, NULL, 0, 0, 6, NULL, 0, 0, 1, NULL),
82 ( %1, 'doc', 7, NULL, NULL, 0, 0, 7, NULL, 0, 0, 1, NULL),
83 ( %1, 'xls', 8, NULL, NULL, 0, 0, 8, NULL, 0, 0, 1, NULL),
84 ( %1, 'rtf', 9, NULL, NULL, 0, 0, 9, NULL, 0, 0, 1, NULL),
85 ( %1, 'csv', 10, NULL, NULL, 0, 0, 10, NULL, 0, 0, 1, NULL),
86 ( %1, 'ppt', 11, NULL, NULL, 0, 0, 11, NULL, 0, 0, 1, NULL)
87 ";
88 $params = array(1 => array($dao->id, 'Integer'));
89 $dao = CRM_Core_DAO::executeQuery($query, $params);
90 }
91 }
92 else {
93 //fix for CRM-3252
94 //delete records from db.
95
96 $query = "
97 DELETE
98 FROM `civicrm_option_value`
99 WHERE `option_group_id` = %1
100 AND `label` IN ('html', 'htm')
101 ";
102 $params = array(1 => array($sfeGroup->id, 'Integer'));
103 $dao = CRM_Core_DAO::executeQuery($query, $params);
104 }
105
106 $this->setVersion('2.02');
107 }
108
109 /**
110 * @param $errorMessage
111 *
112 * @return bool
113 */
114 function verifyPostDBState(&$errorMessage) {
115 // check if Option Group & Option Values tables exists
116 if (!CRM_Core_DAO::checkTableExists('civicrm_option_group') ||
117 !CRM_Core_DAO::checkTableExists('civicrm_option_value')
118 ) {
119 $errorMessage .= ' option group or option value table is missing.';
120 return FALSE;
121 }
122 // check fields which MUST be present civicrm_option_group & civicrm_option_value
123 if (!CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'id') ||
124 !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'name') ||
125 !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'label') ||
126 !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'description') ||
127 !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'is_reserved') ||
128 !CRM_Core_DAO::checkFieldExists('civicrm_option_group', 'is_active')
129 ) {
130 $errorMessage .= ' Few important fields were found missing in civicrm_option_group table.';
131 return FALSE;
132 }
133 if (!CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'id') ||
134 !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'option_group_id') ||
135 !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'name') ||
136 !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'label') ||
137 !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'description') ||
138 !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'component_id') ||
139 !CRM_Core_DAO::checkFieldExists('civicrm_option_value', 'is_active')
140 ) {
141 $errorMessage .= ' Few important fields were found missing in civicrm_option_value table.';
142 return FALSE;
143 }
144 $errorMessage = ts('Post-condition failed for upgrade step %1.', array(1 => '1'));
145
146 return $this->checkVersion('2.02');
147 }
148
149 /**
150 * @return string
151 */
152 function getTitle() {
153 return ts('CiviCRM 2.1 Upgrade: Step Two (Option Group And Values)');
154 }
155
156 /**
157 * @return string
158 */
159 function getTemplateMessage() {
160 return '<p>' . ts('Step Two will upgrade the Option Group And Values in your database.') . '</p>';
161 }
162
163 /**
164 * @return string
165 */
166 function getButtonTitle() {
167 return ts('Upgrade & Continue');
168 }
169 }
170