Project

General

Profile

Download (3.16 KB) Statistics
| Branch: | Tag: | Revision:
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
48
  _remove_variable('edit_map_server');
49
}
50

    
51
/**
52
 * update for RELEASE 3.1.4:
53
 *  - reset edit_map_server variable to default
54
 */
55
function cdm_dataportal_update_7302() {
56

    
57
  return
58
  _remove_variable('edit_map_server') . // once again reset edit_map_server variable to default
59
  _rename_variable('cdm_dataportal_show_media', 'cdm_images_include_children');
60
}
61

    
62
/**
63
 * Renames a persistent variable.
64
 *
65
 * @return
66
 *   A message string of the performed operation.
67
 */
68
function _rename_variable($old_name, $new_name) {
69
  $success = FALSE;
70
  $value = variable_get($old_name, FALSE);
71
  variable_del($old_name);
72
  if ($value !== FALSE) {
73
    variable_set($new_name, $value);
74
    $success = variable_get($new_name, FALSE) === $value;
75
  }
76
  else {
77
    $success = TRUE;
78
  }
79

    
80
  return "Variable \'$old_name\' to \'$new_name\' renamed. ";
81
}
82

    
83
/**
84
 * Unsets a persistent variable.
85
 *
86
 * Calls variable_del() and returns a message string.
87
 *
88
 * @return
89
 *   A message string of the performed operation.
90
 */
91
function _remove_variable($name) {
92
  variable_del($name);
93
  return "Variable \'$name\' removed. ";
94
}
95

    
96
/**
97
 * Sets a persistent variable.
98
 *
99
 * Calls variable_set() and returns a message string.
100
 *
101
 * @return
102
 *   A message string of the performed operation.
103
 */
104
function _create_variable($name, $value) {
105
  variable_set($name, $value);
106
  return "Variable \'$name\' created with value: \'$value\'. ";
107
}
108

    
109
/**
110
 * Overwrites a persistent variable.
111
 *
112
 * Calls _create_variable() and returns a message string.
113
 *
114
 * @return
115
 *   A message string of the performed operation.
116
 */
117
function _modify_variable($name, $value_override) {
118
  /*
119
   * FIXME take care for correct handling of tree variables
120
   * for example description_gallery contains the array:
121
   * Array
122
   (
123
   [cdm_dataportal_show_thumbnail_captions] => 1
124
   [cdm_dataportal_media_maxextend] => 120
125
   [cdm_dataportal_media_cols] => 4
126
   )
127
   * -----> solutions merge arrays !!!
128
   */
129
  return _create_variable($name, $value_override);
130
}
131

    
132

    
(5-5/13)