Project

General

Profile

Statistics
| Branch: | Tag: | Revision:

cdm-dataportal / 7.x / modules / cdm_dataportal / cdm_dataportal.install @ 72032ea6

History | View | Annotate | Download (12.7 KB)

1
<?php
2
/**
3
 * @file
4
 * Install, update and uninstall functions for the cdm_dataportal module.
5
 */
6

    
7
/**
8
 * Implements hook_install().
 */
9
function cdm_dataportal_install() {
10
  db_update('system')
11
    ->fields(array(
12
      'weight' => 20,
13
    ))
14
    ->condition('name', 'cdm_dataportal')
15
    ->execute();
16
}
17

    
18
/**
19
 * Implements hook_uninstall().
 */
20
function cdm_dataportal_uninstall() {
21
  // Delete all nodes with a cdm content type from the node table.
22
  // Comment @WA: you also may want to delete these content types from the
23
  // node_type table.
24
  db_delete('node')
25
    ->condition('type', 'cdm_%')
26
    ->execute();
27
}
28

    
29
/*
30
 * update functions:
31
 *
32
 * - 1 digit for Drupal core compatibility.
33
 * - 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.
34
 * - 2 digits for sequential counting, starting with 00.
35
 *
36
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_update_N/7
37
 */
38

    
39
/**
40
 * update for RELEASE 3.1.3:
41
 *  - reset edit_map_server variable to default
42
 */
43
function cdm_dataportal_update_7301() {
44
  // reset edit_map_server variable to default
45
   return _remove_variable('edit_map_server');
46
}
47

    
48
/**
49
 * update for RELEASE 3.1.4:
50
 *  - reset edit_map_server variable to default
51
 */
52
function cdm_dataportal_update_7302() {
53

    
54
  return
55
  _remove_variable('edit_map_server') . // once again reset edit_map_server variable to default
56
  _rename_variable('cdm_dataportal_show_media', 'cdm_images_include_children');
57
}
58

    
59
/**
60
 * update for RELEASE 3.2.1:
61
 *  - adding missing permissions for role CDM Admin
62
 */
63
function cdm_dataportal_update_7303() {
64
  $role = user_role_load_by_name('CDM admin');
65
  if(!$role){
66
    return "Role CDM admin not found, so the update is skipped.";
67
  }
68

    
69
  $tasks_performed = array();
70

    
71
  // permissions for node types
72
  $node_type_names = node_type_get_names();
73
  $types_to_update = array('page', 'story', 'article');
74
  foreach ($types_to_update as $name){
75
    if(in_array($name, $node_type_names)) {
76
      $node_type_permissions = array(
77
          'create ' . $name . ' content',
78
          'edit any ' . $name . ' content',
79
          'edit own ' . $name . ' content',
80
          'delete any ' . $name . ' content',
81
          'delete own ' . $name . ' content',
82
      );
83
      user_role_grant_permissions($role->rid, $node_type_permissions);
84
      $tasks_performed[] = "node type " . $name;
85
    }
86
  }
87

    
88
  if(module_exists('extlinks')){
89
    $extlinks_permissions = array(
90
        'access extlinks content',
91
        'administer extlinks',
92
    );
93
    user_role_grant_permissions($role->rid, $extlinks_permissions);
94
    $tasks_performed[] = 'permissions for extlinks';
95
  }
96

    
97
  foreach (filter_formats() as $key=>$format){
98
    if($key == 'full_html' || $format->format == "Full HTML"){
99
      $formats_permissions = array(
100
          'use text format full_html'
101
      );
102
      user_role_grant_permissions($role->rid, $formats_permissions);
103
      $tasks_performed[] = 'use text format full_html';
104
    }
105
  }
106

    
107
  // assure  'create url aliases' can be set
108
  if(!module_exists('path')){
109
    module_enable(array('path'), TRUE);
110
    $tasks_performed[] = 'module path enabled';
111
  }
112
  $other_permissions = array(
113
      'create url aliases',
114
      'delete revisions',
115
      'revert revisions',
116
      'view own unpublished content',
117
      'flush caches'
118
  );
119
  user_role_grant_permissions($role->rid, $other_permissions);
120
  $tasks_performed[] = 'and other permissions';
121

    
122
  return "adding missing permissions for role CDM Admin: " . join(', ', $tasks_performed);
123
}
124

    
125

    
126
/**
127
 * update for RELEASE 3.2.2:
128
 *  - migrating variable cdm_dataportal_show_default_image to cdm_taxon_profile_image['show']
129
 *  - enabling required module file
130
 *  - enable new debug block for all dataportals
131
 *  - migrating variables for map settings
132
 */
133
function cdm_dataportal_update_7304() {
134

    
135
    module_enable(array('file'), TRUE);
136
    $tasks_performed[] = 'module file enabled';
137

    
138
    if(!variable_get(CDM_TAXON_PROFILE_IMAGE, FALSE)){
139
      $cdm_taxon_profile_image_settings = unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT);
140
      $cdm_taxon_profile_image_settings['show'] = variable_get('cdm_dataportal_show_default_image', 0);
141
      variable_set(CDM_TAXON_PROFILE_IMAGE, $cdm_taxon_profile_image_settings);
142
      variable_del('cdm_dataportal_show_default_image');
143
      $tasks_performed[] = 'migrating variable cdm_dataportal_show_default_image to cdm_taxon_profile_image[\'show\']';
144
    }
145

    
146

    
147
    // CDM web service debug block
148
    $cdm_ws_debug_block = array(
149
        'block' => array(
150
            'module' => 'cdm_api',
151
            'delta' => 'cdm_ws_debug',
152
            'theme' => NULL,
153
            'status' => 1,
154
            'weight' => -50,
155
            'region' => 'sidebar_first',
156
            'pages' => '',
157
            'cache' => -1,
158
        ),
159
        'block_role' =>
160
            array(
161

    
162
        )
163
    );
164

    
165
    $admin_user = user_load(1);
166

    
167
    // harmonize cdm admin role names if needed
168
    $cdm_admin_role = user_role_load_by_name('CDM Admin');
169
    if(is_object($cdm_admin_role) && $cdm_admin_role->name !== 'CDM admin'){
170
      $cdm_admin_role->name = 'CDM admin';
171
      user_role_save($cdm_admin_role);
172
      $tasks_performed[] = $cdm_admin_role->name . ' role name harmonized';
173
    }
174
    $cdm_admin_role = user_role_load_by_name('CDM admin');
175

    
176
    if(is_object($cdm_admin_role)) {
177
      // make sure admin is member of role CDM admin
178
      if (!isset($admin_user->roles[$admin_role->rid])) {
179
        user_multiple_role_edit(array(1), 'add_role', $cdm_admin_role->rid);
180
        $tasks_performed[] = 'admin user (uid=1) added to role ' . $cdm_admin_role->name;
181
      }
182
      $cdm_ws_debug_block['block_role'][] =  array(
183
        'module' => 'cdm_api',
184
        'delta' => 'cdm_ws_debug',
185
        'rid' => $cdm_admin_role->rid
186
      );
187
    }
188

    
189
    $admin_role = user_role_load_by_name("admin"); // Drupal 5
190

    
191
    if(is_object($admin_role)){
192
      $admin_role->name == 'administrator';
193
      user_role_save($admin_role);
194
      $tasks_performed[] = 'administrator role name harmonized';
195
    } else {
196
      $admin_role = user_role_load_by_name("administrator"); // Drupal 7
197
    }
198
    if(is_object($admin_role)){
199
      // make sure admin is member of role admin
200
      if (!isset($admin_user->roles[$admin_role->rid])) {
201
        user_multiple_role_edit(array(1), 'add_role', $admin_role->rid);
202
        $tasks_performed[] = 'admin user (uid=1) added to role ' . $admin_role->name;
203
      }
204
      $cdm_ws_debug_block['block_role'][] =  array(
205
          'module' => 'cdm_api',
206
          'delta' => 'cdm_ws_debug',
207
          'rid' => $admin_role->rid
208
      );
209
    }
210

    
211
    // clean up existing block configuration which might be set by drupal automatically, we need to override this
212
    db_delete('block')->condition('module', 'cdm_api')->execute();
213
    db_delete('block_role')->condition('module', 'cdm_api')->execute();
214
    // insert
215
    $block_insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache'));
216
    $block_role_insert = db_insert('block_role')->fields(array('module', 'delta', 'rid'));
217

    
218
    $themes = system_list('theme');
219
    foreach ($themes as $theme) {
220
      if($theme->status == "1"){ // only for enabled themes
221
        $cdm_ws_debug_block['block']['theme'] = $theme->name;
222
        $block_insert->values($cdm_ws_debug_block['block']);
223
      }
224
    }
225
    foreach($cdm_ws_debug_block['block_role'] as $block_role){
226
      $block_role_insert->values($block_role);
227
    }
228
    $block_insert->execute();
229
    $block_role_insert->execute();
230
    $tasks_performed[] = 'CDM web service debug block enabled for \'CDM admin\' users in all themes';
231
    $tasks_performed[] = _remove_variable('cdm_webservice_debug');
232
    $tasks_performed[] = _remove_variable('cdm_webservice_isStub');
233

    
234
    /*
235
     *  migrating variables for map settings
236
     */
237
    $cdm_map_distribution = array();
238

    
239
    $cdm_map_distribution['width'] = variable_get('cdm_dataportal_geoservice_display_width', 390);
240
    $cdm_map_distribution['height'] = $cdm_map_distribution['width'] / 2;
241
    _remove_variable('cdm_dataportal_geoservice_display_width');
242

    
243
    $cdm_map_distribution['bbox'] = variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90');
244
    _remove_variable('cdm_dataportal_geoservice_bounding_box');
245

    
246
    $cdm_map_distribution['show_labels'] = variable_get('cdm_dataportal_geoservice_labels_on', FALSE);
247
    _remove_variable('cdm_dataportal_geoservice_labels_on');
248

    
249
    $cdm_map_distribution['caption'] = variable_get('cdm_dataportal_geoservice_map_caption', '');
250
    _remove_variable('cdm_dataportal_geoservice_map_caption');
251

    
252
    $cdm_map_distribution['distribution_opacity'] = variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5');
253
    _remove_variable('cdm_dataportal_geoservice_distributionOpacity');
254

    
255
    $cdm_map_distribution['mapType'] = variable_get('cdm_dataportal_map_openlayers', 1);
256
    _remove_variable('cdm_dataportal_map_openlayers');
257

    
258
    // imageMap
259
    $cdm_map_distribution['image_map'] = array();
260
    $cdm_map_distribution['image_map']['base_layer']= variable_get('map_base_layer', 'cyprusdivs');
261
    _remove_variable('map_base_layer');
262

    
263
    $cdm_map_distribution['image_map']['bg_color'] = variable_get('map_bg_color', '1874CD');
264
    _remove_variable('map_bg_color');
265

    
266
    $cdm_map_distribution['image_map']['layer_style'] = variable_get('map_base_layer_style', 'ffffff,606060,,');
267
    _remove_variable('map_base_layer_style');
268

    
269
    // OpenLayers
270
    $cdm_map_distribution['openlayers'] = array();
271
    $cdm_map_distribution['openlayers']['base_layers'] = variable_get('baselayers', array('osgeo_vmap0' => 'osgeo_vmap0', 'PREFERRED' => 'osgeo_vmap0'));
272
    _remove_variable('baselayers');
273

    
274
    $cdm_map_distribution['openlayers']['show_layer_switcher'] = variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE);
275
    _remove_variable('cdm_dataportal_geoservice_showLayerSwitcher');
276

    
277
    $cdm_map_distribution['legend'] = array();
278
    $cdm_map_distribution['legend']['show'] = variable_get('cdm_dataportal_geoservice_legend_on', TRUE);
279
    _remove_variable('cdm_dataportal_geoservice_legend_on');
280

    
281
    $cdm_map_distribution['legend']['opacity'] = variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5');
282
    _remove_variable('cdm_dataportal_geoservice_legendOpacity');
283

    
284
    $cdm_map_distribution['legend']['font_size'] = variable_get('cdm_dataportal_geoservice_legend_font_size', 10);
285
    _remove_variable('cdm_dataportal_geoservice_legend_font_size');
286

    
287
    $cdm_map_distribution['legend']['font_style'] = variable_get('cdm_dataportal_geoservice_legend_font_style', FALSE);
288
    _remove_variable('cdm_dataportal_geoservice_legend_font_style');
289

    
290
    $cdm_map_distribution['legend']['icon_width'] = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35);
291
    _remove_variable('cdm_dataportal_geoservice_legend_icon_width');
292

    
293
    $cdm_map_distribution['legend']['icon_height'] = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15);
294
    _remove_variable('cdm_dataportal_geoservice_legend_icon_height');
295

    
296
    variable_set('cdm_map_distribution', $cdm_map_distribution);
297
    $tasks_performed[] =  'variables for map settings migrated to new variable "cdm_map_distribution"';
298

    
299
    return  join(', ',$tasks_performed);
300
}
301

    
302

    
303
/**
304
 * Renames a persistent variable.
305
 *
306
 * @return
307
 *   A message string of the performed operation.
308
 */
309
function _rename_variable($old_name, $new_name) {
310
  $success = FALSE;
311
  $value = variable_get($old_name, FALSE);
312
  variable_del($old_name);
313
  if ($value !== FALSE) {
314
    variable_set($new_name, $value);
315
    $success = variable_get($new_name, FALSE) === $value;
316
  }
317
  else {
318
    $success = TRUE;
319
  }
320

    
321
  return "Variable '$old_name' to '$new_name' renamed. ";
322
}
323

    
324
/**
325
 * Unsets a persistent variable.
326
 *
327
 * Calls variable_del() and returns a message string.
328
 *
329
 * @return
330
 *   A message string of the performed operation.
331
 */
332
function _remove_variable($name) {
333
  variable_del($name);
334
  return "Variable '$name' removed. ";
335
}
336

    
337
/**
338
 * Sets a persistent variable.
339
 *
340
 * Calls variable_set() and returns a message string.
341
 *
342
 * @return
343
 *   A message string of the performed operation.
344
 */
345
function _create_variable($name, $value) {
346
  variable_set($name, $value);
347
  return "Variable '$name' created with value: '$value'. ";
348
}
349

    
350
/**
351
 * Overwrites a persistent variable.
352
 *
353
 * Calls _create_variable() and returns a message string.
354
 *
355
 * @return
356
 *   A message string of the performed operation.
357
 */
358
function _modify_variable($name, $value_override) {
359
  /*
360
   * FIXME take care for correct handling of tree variables
361
   * for example description_gallery contains the array:
362
   * Array
363
   (
364
   [cdm_dataportal_show_thumbnail_captions] => 1
365
   [cdm_dataportal_media_maxextend] => 120
366
   [cdm_dataportal_media_cols] => 4
367
   )
368
   * -----> solutions merge arrays !!!
369
   */
370
  return _create_variable($name, $value_override);
371
}
372

    
373

    
Add picture from clipboard (Maximum size: 40 MB)