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