Project

General

Profile

Download (3.12 KB) Statistics
| Branch: | Tag: | Revision:
1
<?php
2
// $Id$
3

    
4
/**
5
 * Implementation of hook_install().
6
 */
7
function cdm_dataportal_install(){
8
   db_query(_get_sql_fix_module_weight());
9
}
10

    
11
/**
12
 * Implementation of hook_uninstall().
13
 */
14
function cdm_dataportal_uninstall(){
15

    
16
   cdm_delete_all_cdm_nodes();
17
}
18

    
19

    
20
/**
21
 * Implementation of hook_api_update_N().
22
 *
23
 * Database updates consist of 3 parts:
24
 *    1 digit for Drupal core compatibility
25
 *    1 digit for your module's major release version (e.g. is this the 5.x-1.* (1) or 5.x-2.* (2) series of your module?)
26
 *    2 digits for sequential counting starting with 00
27
 * The 2nd digit should be 0 for initial porting of your module to a new Drupal core API.
28
 *
29
 * Update 1 for version 5.x-1.0
30
 */
31
function cdm_dataportal_update_5101() {
32
	$items = array();
33
	$items[] = update_sql(_get_sql_fix_module_weight());
34
	return $items;
35
}
36

    
37
/**
38
 * Implementation of hook_api_update_N().
39
 *
40
 * Database updates consist of 3 parts:
41
 *    1 digit for Drupal core compatibility
42
 *    1 digit for your module's major release version (e.g. is this the 5.x-1.* (1) or 5.x-2.* (2) series of your module?)
43
 *    2 digits for sequential counting starting with 00
44
 * The 2nd digit should be 0 for initial porting of your module to a new Drupal core API.
45
 *
46
 * Update 1 for version 5.x-1.0
47
 */
48
function cdm_dataportal_update_5102() {
49
  $items = array();
50
  $items[] = _remove_variable('cdm_currentSecRef');
51

    
52
  if(variable_get('distribution_sort', false) == 1){
53
	  $items[] = _modify_variable('distribution_sort', 'HIDE_TDWG2');
54
  } else {
55
  	$items[] = _modify_variable('distribution_sort', 'NO_SORT');
56
  }
57

    
58
  $items[] = _create_variable('cdm_dataportal_geoservice_distributionOpacity', '1.0');
59
  $items[] = _create_variable('cdm_dataportal_geoservice_legendOpacity', '0.75');
60

    
61
  return $items;
62
}
63

    
64
// ------------------------- SQL  Scripts ------------------------ //
65

    
66

    
67
function _get_sql_fix_module_weight() {
68
	return  "UPDATE {system} SET weight = 20 WHERE name = 'cdm_dataportal'";
69
}
70

    
71
function _rename_variable($old_name, $new_name) {
72
	$success = FALSE;
73
	$value = variable_get($old_name, FALSE);
74
	variable_del($old_name);
75
	if($value !== FALSE){
76
		variable_set($new_name, $value);
77
		$success = variable_get($new_name, FALSE) === $value;
78
	} else {
79
		$success = TRUE;
80
	}
81

    
82
	return array('success' => $success, 'query' => "Renaming variable $old_name to $new_name");
83
}
84

    
85
function _remove_variable($name) {
86
  variable_del($name);
87
  return array('success' => TRUE, 'query' => "Removing variable $name");
88
}
89

    
90

    
91
function _create_variable($name, $value) {
92
  variable_set($name, $value);
93
  return array('success' => TRUE, 'query' => "Creating variable $name new value: $value");
94
}
95

    
96
function _modify_variable($name, $value_override) {
97

    
98
  /*
99
   * FIXME take care for correct handling of tree variables
100
   * for example description_gallery contains the array:
101
   * Array
102
			(
103
			    [cdm_dataportal_show_thumbnail_captions] => 1
104
			    [cdm_dataportal_media_maxextend] => 120
105
			    [cdm_dataportal_media_cols] => 4
106
			)
107
	 * -----> solutions merge arrays !!!
108
   */
109

    
110
  return _create_variable($name, $value_override);
111
}
(5-5/12)