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