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