Project

General

Profile

Download (5.92 KB) Statistics
| Branch: | Tag: | Revision:
1 6657531f Andreas Kohlbecker
<?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 661b79ac Andreas Kohlbecker
}
30 ba706bf0 Andreas Kohlbecker
31 661b79ac Andreas Kohlbecker
/*
32
 * update functions:
33
 *
34
 * - 1 digit for Drupal core compatibility.
35 9438ad3a Andreas Kohlbecker
 * - 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 661b79ac Andreas Kohlbecker
 *
38
 * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_update_N/7
39
 */
40 ba706bf0 Andreas Kohlbecker
41 bfb2b81a Andreas Kohlbecker
/**
42 661b79ac Andreas Kohlbecker
 * update for RELEASE 3.1.3:
43
 *  - reset edit_map_server variable to default
44
 */
45 8f886253 Andreas Kohlbecker
function cdm_dataportal_update_7301() {
46 661b79ac Andreas Kohlbecker
  // reset edit_map_server variable to default
47
   return _remove_variable('edit_map_server');
48 ba706bf0 Andreas Kohlbecker
}
49
50
/**
51
 * update for RELEASE 3.1.4:
52
 *  - reset edit_map_server variable to default
53 9438ad3a Andreas Kohlbecker
 */
54
function cdm_dataportal_update_7302() {
55
56
  return
57 ba706bf0 Andreas Kohlbecker
  _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 3e36c87c Andreas Kohlbecker
}
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 711242b7 Andreas Kohlbecker
    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 fa40a4af Andreas Kohlbecker
90 711242b7 Andreas Kohlbecker
  if(module_exists('extlinks')){
91
    $extlinks_permissions = array(
92
        'access extlinks content',
93 fa40a4af Andreas Kohlbecker
        'administer extlinks',
94 711242b7 Andreas Kohlbecker
    );
95
    user_role_grant_permissions($role->rid, $extlinks_permissions);
96
    $tasks_performed[] = 'permissions for extlinks';
97
  }
98
99 fa40a4af Andreas Kohlbecker
  foreach (filter_formats() as $key=>$format){
100 711242b7 Andreas Kohlbecker
    if($key == 'full_html' || $format->format == "Full HTML"){
101
      $formats_permissions = array(
102 fa40a4af Andreas Kohlbecker
          'use text format full_html'
103 711242b7 Andreas Kohlbecker
      );
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 fa40a4af Andreas Kohlbecker
    $tasks_performed[] = 'module path enabled';
113 3e36c87c Andreas Kohlbecker
  }
114
  $other_permissions = array(
115
      'create url aliases',
116 711242b7 Andreas Kohlbecker
      'delete revisions',
117
      'revert revisions',
118 3e36c87c Andreas Kohlbecker
      'view own unpublished content',
119 fa40a4af Andreas Kohlbecker
      'flush caches'
120 711242b7 Andreas Kohlbecker
  );
121 3e36c87c Andreas Kohlbecker
  user_role_grant_permissions($role->rid, $other_permissions);
122 711242b7 Andreas Kohlbecker
  $tasks_performed[] = 'and other permissions';
123 3e36c87c Andreas Kohlbecker
124
  return "adding missing permissions for role CDM Admin: " . join(', ', $tasks_performed);
125
}
126 9c92cd84 Andreas Kohlbecker
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
 */
133
function cdm_dataportal_update_7304() {
134
135
    module_enable(array('file'), TRUE);
136
    $tasks_performed[] = 'module file enabled';
137
138
    $cdm_taxon_profile_image_settings = unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT);
139
    $cdm_taxon_profile_image_settings['show'] = variable_get('cdm_dataportal_show_default_image', 0);
140
    variable_set(CDM_TAXON_PROFILE_IMAGE, $cdm_taxon_profile_image_settings);
141
    variable_del('cdm_dataportal_show_default_image');
142
    $tasks_performed[] = 'migrating variable cdm_dataportal_show_default_image to cdm_taxon_profile_image[\'show\']';
143
144 3e36c87c Andreas Kohlbecker
    return  join(', ',$tasks_performed);
145
}
146 6657531f Andreas Kohlbecker
147 9438ad3a Andreas Kohlbecker
148
/**
149
 * Renames a persistent variable.
150
 *
151 6657531f Andreas Kohlbecker
 * @return
152
 *   A message string of the performed operation.
153
 */
154
function _rename_variable($old_name, $new_name) {
155
  $success = FALSE;
156
  $value = variable_get($old_name, FALSE);
157
  variable_del($old_name);
158
  if ($value !== FALSE) {
159
    variable_set($new_name, $value);
160
    $success = variable_get($new_name, FALSE) === $value;
161
  }
162
  else {
163
    $success = TRUE;
164 9438ad3a Andreas Kohlbecker
  }
165 6657531f Andreas Kohlbecker
166
  return "Variable \'$old_name\' to \'$new_name\' renamed. ";
167
}
168 9438ad3a Andreas Kohlbecker
169
/**
170
 * Unsets a persistent variable.
171
 *
172
 * Calls variable_del() and returns a message string.
173
 *
174 6657531f Andreas Kohlbecker
 * @return
175
 *   A message string of the performed operation.
176
 */
177 9438ad3a Andreas Kohlbecker
function _remove_variable($name) {
178 6657531f Andreas Kohlbecker
  variable_del($name);
179
  return "Variable \'$name\' removed. ";
180
}
181 9438ad3a Andreas Kohlbecker
182
/**
183
 * Sets a persistent variable.
184
 *
185
 * Calls variable_set() and returns a message string.
186
 *
187 6657531f Andreas Kohlbecker
 * @return
188
 *   A message string of the performed operation.
189
 */
190 9438ad3a Andreas Kohlbecker
function _create_variable($name, $value) {
191 6657531f Andreas Kohlbecker
  variable_set($name, $value);
192
  return "Variable \'$name\' created with value: \'$value\'. ";
193
}
194 9438ad3a Andreas Kohlbecker
195
/**
196
 * Overwrites a persistent variable.
197
 *
198
 * Calls _create_variable() and returns a message string.
199
 *
200 6657531f Andreas Kohlbecker
 * @return
201
 *   A message string of the performed operation.
202
 */
203
function _modify_variable($name, $value_override) {
204
  /*
205
   * FIXME take care for correct handling of tree variables
206
   * for example description_gallery contains the array:
207
   * Array
208
   (
209
   [cdm_dataportal_show_thumbnail_captions] => 1
210
   [cdm_dataportal_media_maxextend] => 120
211
   [cdm_dataportal_media_cols] => 4
212
   )
213
   * -----> solutions merge arrays !!!
214
   */
215 661b79ac Andreas Kohlbecker
  return _create_variable($name, $value_override);
216
}
217