This repository has been archived by the owner on Aug 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
simple_geo.install
221 lines (200 loc) · 5.5 KB
/
simple_geo.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
<?php
// $Id$
/**
* @file
* Install file for the simple geo module
*/
/**
* Implementation of hook_install().
* We have to add our spatial columns manually in the install because the are unsupported by
* the schema api
*
* @return void
*/
function simple_geo_install() {
drupal_install_schema('simple_geo');
db_query("ALTER TABLE {simple_geo_area} ENGINE=MyISAM");
db_query("ALTER TABLE {simple_geo_position} ENGINE=MyISAM");
db_query("ALTER TABLE {simple_geo_area}
ADD COLUMN area POLYGON NOT NULL,
ADD SPATIAL INDEX area_index(area)");
db_query("ALTER TABLE {simple_geo_position}
ADD COLUMN position POINT NOT NULL,
ADD SPATIAL INDEX position_index(position)");
}
/**
* Implementation of hook_uninstall().
*
* @return void
*/
function simple_geo_uninstall() {
$type_vars = array(
'simple_geo_allow_area_',
'simple_geo_allow_position_',
'simple_geo_sync_translations_',
'simple_geo_show_in_form',
);
$types = node_get_types();
foreach ($type_vars as $var) {
foreach ($types as $type) {
variable_del($var . $type->type);
}
}
$vars = array(
'simple_geo_default_position',
'simple_geo_geocoding_suffix',
'simple_geo_micromap_parent',
'simple_geo_micromap_add_mode',
'simple_geo_use_microformat_map',
'simple_geo_add_google_jsapi',
'simple_geo_position_users',
'simple_geo_search_address',
'simple_geo_search_address_icon',
'simple_geo_show_map_link',
'simple_geo_add_microformat_tag',
'simple_geo_min_zoom',
'simple_geo_max_zoom',
'simple_geo_overview_map_show',
'simple_geo_overview_map_size',
'simple_geo_manually_load',
);
foreach ($vars as $var) {
variable_del($var);
}
drupal_uninstall_schema('simple_geo');
}
/**
* Implementation of hook_scheme().
* We have to add our spatial columns manually in the install because the are unsupported by
* the schema api
*
* @return array The database schema for simple_geo
*/
function simple_geo_schema() {
$schema['simple_geo_position'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'type' => array(
'type' => 'varchar',
'length' => 32,
'default' => 'node',
'not null' => TRUE,
)
),
'primary key' => array('nid', 'type'),
);
$schema['simple_geo_area'] = array(
'fields' => array(
'nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'type' => array(
'type' => 'varchar',
'length' => 32,
'default' => 'node',
'not null' => TRUE,
)
),
'primary key' => array('nid', 'type'),
);
$schema['simple_geo_in_area'] = array(
'fields' => array(
'point_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'point_type' => array(
'type' => 'varchar',
'length' => 32,
'default' => 'node',
'not null' => TRUE,
),
'area_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'area_type' => array(
'type' => 'varchar',
'length' => 32,
'default' => 'node',
'not null' => TRUE,
)
),
'indexes' => array(
'point' => array('point_nid', 'point_type'),
'area' => array('area_nid', 'area_type'),
),
'primary key' => array('point_nid', 'point_type', 'area_nid', 'area_type'),
);
return $schema;
}
function simple_geo_update_1() {
$ret = array();
//Update position table
db_drop_primary_key($ret, 'simple_geo_position');
db_add_field($ret, 'simple_geo_position', 'type', array(
'type' => 'varchar',
'length' => 32,
'default' => 'node',
'not null' => TRUE,
));
db_add_primary_key($ret, 'simple_geo_position', array('nid', 'type'));
//Update area table
db_drop_primary_key($ret, 'simple_geo_area');
db_add_field($ret, 'simple_geo_area', 'type', array(
'type' => 'varchar',
'length' => 32,
'default' => 'node',
'not null' => TRUE,
));
db_add_primary_key($ret, 'simple_geo_area', array('nid', 'type'));
//Update simple_geo_in_area table
db_drop_primary_key($ret, 'simple_geo_in_area');
db_drop_index($ret, 'simple_geo_in_area', 'point');
db_drop_index($ret, 'simple_geo_in_area', 'area');
db_add_field($ret, 'simple_geo_in_area', 'point_type', array(
'type' => 'varchar',
'length' => 32,
'default' => 'node',
'not null' => TRUE,
));
db_add_field($ret, 'simple_geo_in_area', 'area_type', array(
'type' => 'varchar',
'length' => 32,
'default' => 'node',
'not null' => TRUE,
));
db_add_index($ret, 'simple_geo_in_area', 'point', array('point_nid', 'point_type'));
db_add_index($ret, 'simple_geo_in_area', 'area', array('area_nid', 'area_type'));
db_add_primary_key($ret, 'simple_geo_in_area', array('point_nid', 'point_type', 'area_nid', 'area_type'));
return $ret;
}
//For upcoming 6.x-0.5
function simple_geo_update_2() {
$type_vars = array(
'allow_area_' => 'simple_geo_allow_area_',
'allow_position_' => 'simple_geo_allow_position_',
);
$types = node_get_types();
foreach ($type_vars as $key => $var) {
foreach ($types as $type) {
$tmp = variable_get($key . $type->type, NULL);
if ($tmp !== NULL) {
variable_set($var . $type->type, $tmp);
}
}
}
return array();
}