CRM-12595 fix formatting in CRM/Upgrade files
[civicrm-core.git] / CRM / Upgrade / Incremental / php / ThreeTwo.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. |
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_ThreeTwo {
35 function verifyPreDBstate(&$errors) {
36 return TRUE;
37 }
38
39 function upgrade_3_2_alpha1($rev) {
40 //CRM-5666 -if user already have 'access CiviCase'
41 //give all new permissions and drop access CiviCase.
42 $config = CRM_Core_Config::singleton();
43 if ($config->userSystem->is_drupal) {
44
45 $config->userSystem->replacePermission('access CiviCase', array('access my cases and activities', 'access all cases and activities', 'administer CiviCase'));
46
47 //insert core acls.
48 $casePermissions = array(
49 'delete in CiviCase',
50 'administer CiviCase',
51 'access my cases and activities',
52 'access all cases and activities',
53 );
54 $aclParams = array(
55 'name' => 'Core ACL',
56 'deny' => 0,
57 'acl_id' => NULL,
58 'object_id' => NULL,
59 'acl_table' => NULL,
60 'entity_id' => 1,
61 'operation' => 'All',
62 'is_active' => 1,
63 'entity_table' => 'civicrm_acl_role',
64 );
65 foreach ($casePermissions as $per) {
66 $aclParams['object_table'] = $per;
67 $acl = new CRM_ACL_DAO_ACL();
68 $acl->object_table = $per;
69 if (!$acl->find(TRUE)) {
70 $acl->copyValues($aclParams);
71 $acl->save();
72 }
73 }
74 //drop 'access CiviCase' acl
75 CRM_Core_DAO::executeQuery("DELETE FROM civicrm_acl WHERE object_table = 'access CiviCase'");
76 }
77
78 $upgrade = new CRM_Upgrade_Form();
79 $upgrade->processSQL($rev);
80 }
81
82 function upgrade_3_2_beta4($rev) {
83 $upgrade = new CRM_Upgrade_Form;
84
85 $config = CRM_Core_Config::singleton();
86 $seedLocale = $config->lcMessages;
87
88 //handle missing civicrm_uf_field.help_pre
89 $hasLocalizedPreHelpCols = FALSE;
90
91 // CRM-6451: for multilingual sites we need to find the optimal
92 // locale to use as the final civicrm_membership_status.name column
93 $domain = new CRM_Core_DAO_Domain;
94 $domain->find(TRUE);
95 $locales = array();
96 if ($domain->locales) {
97 $locales = explode(CRM_Core_DAO::VALUE_SEPARATOR, $domain->locales);
98 // optimal: an English locale
99 foreach (array(
100 'en_US', 'en_GB', 'en_AU') as $loc) {
101 if (in_array($loc, $locales)) {
102 $seedLocale = $loc;
103 break;
104 }
105 }
106
107 // if no English and no $config->lcMessages: use the first available
108 if (!$seedLocale) {
109 $seedLocale = $locales[0];
110 }
111
112 $upgrade->assign('seedLocale', $seedLocale);
113 $upgrade->assign('locales', $locales);
114
115 $localizedColNames = array();
116 foreach ($locales as $loc) {
117 $localizedName = "help_pre_{$loc}";
118 $localizedColNames[$localizedName] = $localizedName;
119 }
120 $columns = CRM_Core_DAO::executeQuery('SHOW COLUMNS FROM civicrm_uf_field');
121 while ($columns->fetch()) {
122 if (strpos($columns->Field, 'help_pre') !== FALSE &&
123 in_array($columns->Field, $localizedColNames)
124 ) {
125 $hasLocalizedPreHelpCols = TRUE;
126 break;
127 }
128 }
129 }
130 $upgrade->assign('hasLocalizedPreHelpCols', $hasLocalizedPreHelpCols);
131
132 $upgrade->processSQL($rev);
133
134 // now civicrm_membership_status.name has possibly localised strings, so fix them
135 $i18n = new CRM_Core_I18n($seedLocale);
136 $statuses = array(
137 array(
138 'name' => 'New',
139 'start_event' => 'join_date',
140 'end_event' => 'join_date',
141 'end_event_adjust_unit' => 'month',
142 'end_event_adjust_interval' => '3',
143 'is_current_member' => '1',
144 'is_admin' => '0',
145 'is_default' => '0',
146 'is_reserved' => '0',
147 ),
148 array(
149 'name' => 'Current',
150 'start_event' => 'start_date',
151 'end_event' => 'end_date',
152 'is_current_member' => '1',
153 'is_admin' => '0',
154 'is_default' => '1',
155 'is_reserved' => '0',
156 ),
157 array(
158 'name' => 'Grace',
159 'start_event' => 'end_date',
160 'end_event' => 'end_date',
161 'end_event_adjust_unit' => 'month',
162 'end_event_adjust_interval' => '1',
163 'is_current_member' => '1',
164 'is_admin' => '0',
165 'is_default' => '0',
166 'is_reserved' => '0',
167 ),
168 array(
169 'name' => 'Expired',
170 'start_event' => 'end_date',
171 'start_event_adjust_unit' => 'month',
172 'start_event_adjust_interval' => '1',
173 'is_current_member' => '0',
174 'is_admin' => '0',
175 'is_default' => '0',
176 'is_reserved' => '0',
177 ),
178 array(
179 'name' => 'Pending',
180 'start_event' => 'join_date',
181 'end_event' => 'join_date',
182 'is_current_member' => '0',
183 'is_admin' => '0',
184 'is_default' => '0',
185 'is_reserved' => '1',
186 ),
187 array(
188 'name' => 'Cancelled',
189 'start_event' => 'join_date',
190 'end_event' => 'join_date',
191 'is_current_member' => '0',
192 'is_admin' => '0',
193 'is_default' => '0',
194 'is_reserved' => '0',
195 ),
196 array(
197 'name' => 'Deceased',
198 'is_current_member' => '0',
199 'is_admin' => '1',
200 'is_default' => '0',
201 'is_reserved' => '1',
202 ),
203 );
204
205 $statusIds = array();
206 $insertedNewRecord = FALSE;
207 foreach ($statuses as $status) {
208 $dao = new CRM_Member_DAO_MembershipStatus;
209
210 // try to find an existing English status
211 $dao->name = $status['name'];
212
213 // // if not found, look for translated status name
214 // if (!$dao->find(true)) {
215 // $found = false;
216 // $dao->name = $i18n->translate($status['name']);
217 // }
218
219 // if found, update name and is_reserved
220 if ($dao->find(TRUE)) {
221 $dao->name = $status['name'];
222 $dao->is_reserved = $status['is_reserved'];
223 if ($status['is_reserved']) {
224 $dao->is_active = 1;
225 }
226 // if not found, prepare a new row for insertion
227 }
228 else {
229 $insertedNewRecord = TRUE;
230 foreach ($status as $property => $value) {
231 $dao->$property = $value;
232 }
233 $dao->weight = CRM_Utils_Weight::getDefaultWeight('CRM_Member_DAO_MembershipStatus');
234 }
235
236 // add label (translated name) and save (UPDATE or INSERT)
237 $dao->label = $i18n->translate($status['name']);
238 $dao->save();
239
240 $statusIds[$dao->id] = $dao->id;
241 }
242
243 //disable all status those are customs.
244 if ($insertedNewRecord) {
245 $sql = '
246 UPDATE civicrm_membership_status
247 SET is_active = 0
248 WHERE id NOT IN ( ' . implode(',', $statusIds) . ' )';
249 CRM_Core_DAO::executeQuery($sql);
250 }
251 }
252
253 function upgrade_3_2_1($rev) {
254 //CRM-6565 check if Activity Index is already exists or not.
255 $addActivityTypeIndex = TRUE;
256 $indexes = CRM_Core_DAO::executeQuery('SHOW INDEXES FROM civicrm_activity');
257 while ($indexes->fetch()) {
258 if ($indexes->Key_name == 'UI_activity_type_id') {
259 $addActivityTypeIndex = FALSE;
260 }
261 }
262 // CRM-6563: restrict access to the upload dir, tighten access to the config-and-log dir
263 $config = CRM_Core_Config::singleton();
264 CRM_Utils_File::restrictAccess($config->uploadDir);
265 CRM_Utils_File::restrictAccess($config->configAndLogDir);
266 $upgrade = new CRM_Upgrade_Form;
267 $upgrade->assign('addActivityTypeIndex', $addActivityTypeIndex);
268 $upgrade->processSQL($rev);
269 }
270 }
271