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
/**
22
 * Implementation of hook_api_update_N().
23
 *
24
 * Database updates consist of 3 parts:
25
 *    1 digit for Drupal core compatibility
26
 *    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?)
27
 *    2 digits for sequential counting starting with 00
28
 * The 2nd digit should be 0 for initial porting of your module to a new Drupal core API.
29
 *
30
 * Update 1 for version 5.x-1.0
31
 */
32
function cdm_dataportal_update_5101() {
33
	$items = array();
34
	$items[] = update_sql(_get_sql_fix_module_weight());
35
	return $items;
36
}
37

    
38
/**
39
 * Implementation of hook_api_update_N().
40
 *
41
 * Database updates consist of 3 parts:
42
 *    1 digit for Drupal core compatibility
43
 *    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?)
44
 *    2 digits for sequential counting starting with 00
45
 * The 2nd digit should be 0 for initial porting of your module to a new Drupal core API.
46
 *
47
 * Update 1 for version 5.x-1.0
48
 */
49
function cdm_dataportal_update_5102() {
50
  $items = array();
51
  $items[] = _remove_variable('cdm_currentSecRef');
52

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

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

    
62
  return $items;
63
}
64

    
65
// ------------------------- SQL  Scripts ------------------------ //
66

    
67

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

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

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

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

    
91

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

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

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

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