1
|
<?php
|
2
|
/**
|
3
|
* @file
|
4
|
* Install, update and uninstall functions for the cdm_dataportal module.
|
5
|
*/
|
6
|
|
7
|
/**
|
8
|
* Implements hook_install().
|
9
|
*/
|
10
|
function cdm_dataportal_install() {
|
11
|
db_update('system')
|
12
|
->fields(array(
|
13
|
'weight' => 20,
|
14
|
))
|
15
|
->condition('name', 'cdm_dataportal')
|
16
|
->execute();
|
17
|
}
|
18
|
|
19
|
/**
|
20
|
* Implements hook_uninstall().
|
21
|
*/
|
22
|
function cdm_dataportal_uninstall() {
|
23
|
// Delete all nodes with a cdm content type from the node table.
|
24
|
// Comment @WA: you also may want to delete these content types from the
|
25
|
// node_type table.
|
26
|
db_delete('node')
|
27
|
->condition('type', 'cdm_%')
|
28
|
->execute();
|
29
|
}
|
30
|
|
31
|
/*
|
32
|
* update functions:
|
33
|
*
|
34
|
* - 1 digit for Drupal core compatibility.
|
35
|
* - 1 digit for your module's major release version (e.g., is this the 7.x-1.* (1) or 7.x-2.* (2) series of your module?). This digit should be 0 for initial porting of your module to a new Drupal core API.
|
36
|
* - 2 digits for sequential counting, starting with 00.
|
37
|
*
|
38
|
* @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_update_N/7
|
39
|
*/
|
40
|
|
41
|
/**
|
42
|
* update for RELEASE 3.1.3:
|
43
|
* - reset edit_map_server variable to default
|
44
|
*/
|
45
|
function cdm_dataportal_update_7301() {
|
46
|
// reset edit_map_server variable to default
|
47
|
return _remove_variable('edit_map_server');
|
48
|
}
|
49
|
|
50
|
/**
|
51
|
* update for RELEASE 3.1.4:
|
52
|
* - reset edit_map_server variable to default
|
53
|
*/
|
54
|
function cdm_dataportal_update_7302() {
|
55
|
|
56
|
return
|
57
|
_remove_variable('edit_map_server') . // once again reset edit_map_server variable to default
|
58
|
_rename_variable('cdm_dataportal_show_media', 'cdm_images_include_children');
|
59
|
}
|
60
|
|
61
|
/**
|
62
|
* update for RELEASE 3.2.1:
|
63
|
* - adding missing permissions for role CDM Admin
|
64
|
*/
|
65
|
function cdm_dataportal_update_7303() {
|
66
|
$role = user_role_load_by_name('CDM admin');
|
67
|
if(!$role){
|
68
|
return "Role CDM admin not found, so the update is skipped.";
|
69
|
}
|
70
|
|
71
|
$tasks_performed = array();
|
72
|
|
73
|
// permissions for node types
|
74
|
$node_type_names = node_type_get_names();
|
75
|
$types_to_update = array('page', 'story', 'article');
|
76
|
foreach ($types_to_update as $name){
|
77
|
if(in_array($name, $node_type_names)) {
|
78
|
$node_type_permissions = array(
|
79
|
'create ' . $name . ' content',
|
80
|
'edit any ' . $name . ' content',
|
81
|
'edit own ' . $name . ' content',
|
82
|
'delete any ' . $name . ' content',
|
83
|
'delete own ' . $name . ' content',
|
84
|
);
|
85
|
user_role_grant_permissions($role->rid, $node_type_permissions);
|
86
|
$tasks_performed[] = "node type " . $name;
|
87
|
}
|
88
|
}
|
89
|
|
90
|
if(module_exists('extlinks')){
|
91
|
$extlinks_permissions = array(
|
92
|
'access extlinks content',
|
93
|
'administer extlinks',
|
94
|
);
|
95
|
user_role_grant_permissions($role->rid, $extlinks_permissions);
|
96
|
$tasks_performed[] = 'permissions for extlinks';
|
97
|
}
|
98
|
|
99
|
foreach (filter_formats() as $key=>$format){
|
100
|
if($key == 'full_html' || $format->format == "Full HTML"){
|
101
|
$formats_permissions = array(
|
102
|
'use text format full_html'
|
103
|
);
|
104
|
user_role_grant_permissions($role->rid, $formats_permissions);
|
105
|
$tasks_performed[] = 'use text format full_html';
|
106
|
}
|
107
|
}
|
108
|
|
109
|
// assure 'create url aliases' can be set
|
110
|
if(!module_exists('path')){
|
111
|
module_enable(array('path'), TRUE);
|
112
|
$tasks_performed[] = 'module path enabled';
|
113
|
}
|
114
|
$other_permissions = array(
|
115
|
'create url aliases',
|
116
|
'delete revisions',
|
117
|
'revert revisions',
|
118
|
'view own unpublished content',
|
119
|
'flush caches'
|
120
|
);
|
121
|
user_role_grant_permissions($role->rid, $other_permissions);
|
122
|
$tasks_performed[] = 'and other permissions';
|
123
|
|
124
|
return "adding missing permissions for role CDM Admin: " . join(', ', $tasks_performed);
|
125
|
}
|
126
|
|
127
|
|
128
|
/**
|
129
|
* update for RELEASE 3.2.2:
|
130
|
* - migrating variable cdm_dataportal_show_default_image to cdm_taxon_profile_image['show']
|
131
|
* - enabling required module file
|
132
|
* - enable new debug block for all dataportals
|
133
|
*/
|
134
|
function cdm_dataportal_update_7304() {
|
135
|
|
136
|
module_enable(array('file'), TRUE);
|
137
|
$tasks_performed[] = 'module file enabled';
|
138
|
|
139
|
if(!variable_get(CDM_TAXON_PROFILE_IMAGE, FALSE)){
|
140
|
$cdm_taxon_profile_image_settings = unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT);
|
141
|
$cdm_taxon_profile_image_settings['show'] = variable_get('cdm_dataportal_show_default_image', 0);
|
142
|
variable_set(CDM_TAXON_PROFILE_IMAGE, $cdm_taxon_profile_image_settings);
|
143
|
variable_del('cdm_dataportal_show_default_image');
|
144
|
$tasks_performed[] = 'migrating variable cdm_dataportal_show_default_image to cdm_taxon_profile_image[\'show\']';
|
145
|
}
|
146
|
|
147
|
|
148
|
// CDM web service debug block
|
149
|
$cdm_ws_debug_block = array(
|
150
|
'block' => array(
|
151
|
'module' => 'cdm_api',
|
152
|
'delta' => 'cdm_ws_debug',
|
153
|
'theme' => NULL,
|
154
|
'status' => 1,
|
155
|
'weight' => -50,
|
156
|
'region' => 'sidebar_first',
|
157
|
'pages' => '',
|
158
|
'cache' => -1,
|
159
|
),
|
160
|
'block_role' =>
|
161
|
array(
|
162
|
|
163
|
)
|
164
|
);
|
165
|
|
166
|
$admin_user = user_load(1);
|
167
|
|
168
|
// harmonize cdm admin role names if needed
|
169
|
$cdm_admin_role = user_role_load_by_name('CDM Admin');
|
170
|
if(is_object($cdm_admin_role) && $cdm_admin_role->name !== 'CDM admin'){
|
171
|
$cdm_admin_role->name = 'CDM admin';
|
172
|
user_role_save($cdm_admin_role);
|
173
|
$tasks_performed[] = $cdm_admin_role->name . ' role name harmonized';
|
174
|
}
|
175
|
$cdm_admin_role = user_role_load_by_name('CDM admin');
|
176
|
|
177
|
if(is_object($cdm_admin_role)) {
|
178
|
// make sure admin is member of role CDM admin
|
179
|
if (!isset($admin_user->roles[$admin_role->rid])) {
|
180
|
user_multiple_role_edit(array(1), 'add_role', $cdm_admin_role->rid);
|
181
|
$tasks_performed[] = 'admin user (uid=1) added to role ' . $cdm_admin_role->name;
|
182
|
}
|
183
|
$cdm_ws_debug_block['block_role'][] = array(
|
184
|
'module' => 'cdm_api',
|
185
|
'delta' => 'cdm_ws_debug',
|
186
|
'rid' => $cdm_admin_role->rid
|
187
|
);
|
188
|
}
|
189
|
|
190
|
$admin_role = user_role_load_by_name("admin"); // Drupal 5
|
191
|
|
192
|
if(is_object($admin_role)){
|
193
|
$admin_role->name == 'administrator';
|
194
|
user_role_save($admin_role);
|
195
|
$tasks_performed[] = 'administrator role name harmonized';
|
196
|
} else {
|
197
|
$admin_role = user_role_load_by_name("administrator"); // Drupal 7
|
198
|
}
|
199
|
if(is_object($admin_role)){
|
200
|
// make sure admin is member of role admin
|
201
|
if (!isset($admin_user->roles[$admin_role->rid])) {
|
202
|
user_multiple_role_edit(array(1), 'add_role', $admin_role->rid);
|
203
|
$tasks_performed[] = 'admin user (uid=1) added to role ' . $admin_role->name;
|
204
|
}
|
205
|
$cdm_ws_debug_block['block_role'][] = array(
|
206
|
'module' => 'cdm_api',
|
207
|
'delta' => 'cdm_ws_debug',
|
208
|
'rid' => $admin_role->rid
|
209
|
);
|
210
|
}
|
211
|
|
212
|
// clean up existing block configuration which might be set by drupal automatically, we need to override this
|
213
|
db_delete('block')->condition('module', 'cdm_api')->execute();
|
214
|
db_delete('block_role')->condition('module', 'cdm_api')->execute();
|
215
|
// insert
|
216
|
$block_insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
|
217
|
$block_role_insert = db_insert('block_role')->fields(array('module', 'delta', 'rid'));
|
218
|
|
219
|
$themes = system_list('theme');
|
220
|
foreach ($themes as $theme) {
|
221
|
if($theme->status == "1"){ // only for enabled themes
|
222
|
$cdm_ws_debug_block['block']['theme'] = $theme->name;
|
223
|
$block_insert->values($cdm_ws_debug_block['block']);
|
224
|
}
|
225
|
}
|
226
|
foreach($cdm_ws_debug_block['block_role'] as $block_role){
|
227
|
$block_role_insert->values($block_role);
|
228
|
}
|
229
|
$block_insert->execute();
|
230
|
$block_role_insert->execute();
|
231
|
$tasks_performed[] = 'CDM web service debug block enabled for \'CDM admin\' users in all themes';
|
232
|
$tasks_performed[] = _remove_variable('cdm_webservice_debug');
|
233
|
$tasks_performed[] = _remove_variable('cdm_webservice_isStub');
|
234
|
|
235
|
return join(', ',$tasks_performed);
|
236
|
}
|
237
|
|
238
|
|
239
|
/**
|
240
|
* Renames a persistent variable.
|
241
|
*
|
242
|
* @return
|
243
|
* A message string of the performed operation.
|
244
|
*/
|
245
|
function _rename_variable($old_name, $new_name) {
|
246
|
$success = FALSE;
|
247
|
$value = variable_get($old_name, FALSE);
|
248
|
variable_del($old_name);
|
249
|
if ($value !== FALSE) {
|
250
|
variable_set($new_name, $value);
|
251
|
$success = variable_get($new_name, FALSE) === $value;
|
252
|
}
|
253
|
else {
|
254
|
$success = TRUE;
|
255
|
}
|
256
|
|
257
|
return "Variable '$old_name' to '$new_name' renamed. ";
|
258
|
}
|
259
|
|
260
|
/**
|
261
|
* Unsets a persistent variable.
|
262
|
*
|
263
|
* Calls variable_del() and returns a message string.
|
264
|
*
|
265
|
* @return
|
266
|
* A message string of the performed operation.
|
267
|
*/
|
268
|
function _remove_variable($name) {
|
269
|
variable_del($name);
|
270
|
return "Variable '$name' removed. ";
|
271
|
}
|
272
|
|
273
|
/**
|
274
|
* Sets a persistent variable.
|
275
|
*
|
276
|
* Calls variable_set() and returns a message string.
|
277
|
*
|
278
|
* @return
|
279
|
* A message string of the performed operation.
|
280
|
*/
|
281
|
function _create_variable($name, $value) {
|
282
|
variable_set($name, $value);
|
283
|
return "Variable '$name' created with value: '$value'. ";
|
284
|
}
|
285
|
|
286
|
/**
|
287
|
* Overwrites a persistent variable.
|
288
|
*
|
289
|
* Calls _create_variable() and returns a message string.
|
290
|
*
|
291
|
* @return
|
292
|
* A message string of the performed operation.
|
293
|
*/
|
294
|
function _modify_variable($name, $value_override) {
|
295
|
/*
|
296
|
* FIXME take care for correct handling of tree variables
|
297
|
* for example description_gallery contains the array:
|
298
|
* Array
|
299
|
(
|
300
|
[cdm_dataportal_show_thumbnail_captions] => 1
|
301
|
[cdm_dataportal_media_maxextend] => 120
|
302
|
[cdm_dataportal_media_cols] => 4
|
303
|
)
|
304
|
* -----> solutions merge arrays !!!
|
305
|
*/
|
306
|
return _create_variable($name, $value_override);
|
307
|
}
|
308
|
|
309
|
|