| 1 |
<?php
|
| 2 |
// $Id: location.install,v 1.42 2009/02/24 22:54:38 bdragon Exp $
|
| 3 |
|
| 4 |
/**
|
| 5 |
* @file
|
| 6 |
* Installation / uninstallation routines.
|
| 7 |
*/
|
| 8 |
|
| 9 |
/**
|
| 10 |
* Implementation of hook_install().
|
| 11 |
*/
|
| 12 |
function location_install() {
|
| 13 |
drupal_install_schema('location');
|
| 14 |
}
|
| 15 |
|
| 16 |
/**
|
| 17 |
* Implentation of hook_uninstall().
|
| 18 |
*/
|
| 19 |
function location_uninstall() {
|
| 20 |
drupal_uninstall_schema('location');
|
| 21 |
|
| 22 |
// Delete variables.
|
| 23 |
variable_del('location_default_country');
|
| 24 |
variable_del('location_display_location');
|
| 25 |
variable_del('location_usegmap');
|
| 26 |
variable_del('location_locpick_macro');
|
| 27 |
|
| 28 |
// Delete geocoder settings.
|
| 29 |
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_geocode_%'")->fetchCol();
|
| 30 |
foreach ($result as $var) {
|
| 31 |
variable_del($var);
|
| 32 |
}
|
| 33 |
}
|
| 34 |
|
| 35 |
/**
|
| 36 |
* Implementation of hook_schema().
|
| 37 |
*/
|
| 38 |
function location_schema() {
|
| 39 |
$schema['location'] = array(
|
| 40 |
'description' => 'Locational data managed by location.module.',
|
| 41 |
'fields' => array(
|
| 42 |
'lid' => array(
|
| 43 |
'description' => 'Primary Key: Unique location ID.',
|
| 44 |
'type' => 'serial',
|
| 45 |
'unsigned' => TRUE,
|
| 46 |
'not null' => TRUE,
|
| 47 |
),
|
| 48 |
'name' => array(
|
| 49 |
'description' => 'Place Name.',
|
| 50 |
'type' => 'varchar',
|
| 51 |
'length' => 255,
|
| 52 |
'default' => '',
|
| 53 |
'not null' => TRUE,
|
| 54 |
),
|
| 55 |
'street' => array(
|
| 56 |
'description' => 'Street address, line 1.',
|
| 57 |
'type' => 'varchar',
|
| 58 |
'length' => 255,
|
| 59 |
'default' => '',
|
| 60 |
'not null' => TRUE,
|
| 61 |
),
|
| 62 |
'additional' => array(
|
| 63 |
'description' => 'Street address, line 2.',
|
| 64 |
'type' => 'varchar',
|
| 65 |
'length' => 255,
|
| 66 |
'default' => '',
|
| 67 |
'not null' => TRUE,
|
| 68 |
),
|
| 69 |
'city' => array(
|
| 70 |
'description' => 'City.',
|
| 71 |
'type' => 'varchar',
|
| 72 |
'length' => 255,
|
| 73 |
'default' => '',
|
| 74 |
'not null' => TRUE,
|
| 75 |
),
|
| 76 |
'province' => array(
|
| 77 |
'description' => 'State / Province code.',
|
| 78 |
'type' => 'varchar',
|
| 79 |
'length' => 16,
|
| 80 |
'default' => '',
|
| 81 |
'not null' => TRUE,
|
| 82 |
),
|
| 83 |
'postal_code' => array(
|
| 84 |
'description' => 'Postal / ZIP code.',
|
| 85 |
'type' => 'varchar',
|
| 86 |
'length' => 16,
|
| 87 |
'default' => '',
|
| 88 |
'not null' => TRUE,
|
| 89 |
),
|
| 90 |
'country' => array(
|
| 91 |
'description' => 'Two letter ISO country code.',
|
| 92 |
'type' => 'char',
|
| 93 |
'length' => 2,
|
| 94 |
'not null' => TRUE,
|
| 95 |
'default' => '',
|
| 96 |
),
|
| 97 |
'latitude' => array(
|
| 98 |
'description' => 'Location latitude (decimal degrees).',
|
| 99 |
'type' => 'numeric',
|
| 100 |
'precision' => 10,
|
| 101 |
'scale' => 6, // @@@ Shouldn't these all be 7?
|
| 102 |
'not null' => TRUE,
|
| 103 |
'default' => 0.0,
|
| 104 |
),
|
| 105 |
'longitude' => array(
|
| 106 |
'description' => 'Location longitude (decimal degrees).',
|
| 107 |
'type' => 'numeric',
|
| 108 |
'precision' => 10,
|
| 109 |
'scale' => 6,
|
| 110 |
'not null' => TRUE,
|
| 111 |
'default' => 0.0,
|
| 112 |
),
|
| 113 |
'source' => array(
|
| 114 |
'description' => 'Source of the latitude and longitude data (Geocoder, user entered, invalid, etc.)',
|
| 115 |
'type' => 'int',
|
| 116 |
'size' => 'tiny',
|
| 117 |
'default' => 0,
|
| 118 |
'not null' => TRUE,
|
| 119 |
),
|
| 120 |
// @@@ Historical civicrm field that isn't applicable to location, I think..
|
| 121 |
'is_primary' => array(
|
| 122 |
'description' => 'Is this the primary location of an object? (unused, civicrm legacy field?).',
|
| 123 |
'type' => 'int',
|
| 124 |
'size' => 'tiny',
|
| 125 |
'default' => 0,
|
| 126 |
'not null' => TRUE,
|
| 127 |
),
|
| 128 |
),
|
| 129 |
'primary key' => array('lid'),
|
| 130 |
);
|
| 131 |
$schema['location_instance'] = array(
|
| 132 |
'description' => 'N:M join table to join locations to other tables.',
|
| 133 |
'fields' => array(
|
| 134 |
'nid' => array(
|
| 135 |
'description' => 'Reference to {node}.nid.',
|
| 136 |
'type' => 'int',
|
| 137 |
'unsigned' => TRUE,
|
| 138 |
'not null' => TRUE,
|
| 139 |
'default' => 0,
|
| 140 |
),
|
| 141 |
'vid' => array(
|
| 142 |
'description' => 'Reference to {node_revisions}.vid.',
|
| 143 |
'type' => 'int',
|
| 144 |
'unsigned' => TRUE,
|
| 145 |
'not null' => TRUE,
|
| 146 |
'default' => 0,
|
| 147 |
),
|
| 148 |
'uid' => array(
|
| 149 |
'description' => 'Reference to {users}.uid.',
|
| 150 |
'type' => 'int',
|
| 151 |
'unsigned' => TRUE,
|
| 152 |
'not null' => TRUE,
|
| 153 |
'default' => 0,
|
| 154 |
),
|
| 155 |
'genid' => array(
|
| 156 |
'description' => 'Generic reference key.',
|
| 157 |
'type' => 'varchar',
|
| 158 |
'length' => 255,
|
| 159 |
'not null' => TRUE,
|
| 160 |
'default' => '',
|
| 161 |
),
|
| 162 |
'lid' => array(
|
| 163 |
'description' => 'Reference to {location}.lid.',
|
| 164 |
'type' => 'int',
|
| 165 |
'unsigned' => TRUE,
|
| 166 |
'not null' => TRUE,
|
| 167 |
'default' => 0,
|
| 168 |
),
|
| 169 |
),
|
| 170 |
'indexes' => array(
|
| 171 |
'nid' => array('nid'),
|
| 172 |
'vid' => array('vid'),
|
| 173 |
'uid' => array('uid'),
|
| 174 |
'genid' => array('genid'),
|
| 175 |
'lid' => array('lid'),
|
| 176 |
),
|
| 177 |
);
|
| 178 |
$schema['zipcodes'] = array(
|
| 179 |
'description' => 'Location.module zipcode database.',
|
| 180 |
'fields' => array(
|
| 181 |
'zip' => array(
|
| 182 |
'description' => 'Postal / ZIP code.',
|
| 183 |
'type' => 'varchar',
|
| 184 |
'length' => 16,
|
| 185 |
'not null' => TRUE,
|
| 186 |
'default' => '0', // @@@ Why?
|
| 187 |
),
|
| 188 |
'city' => array(
|
| 189 |
'description' => 'City.',
|
| 190 |
'type' => 'varchar',
|
| 191 |
'length' => 30,
|
| 192 |
'not null' => TRUE,
|
| 193 |
'default' => '',
|
| 194 |
),
|
| 195 |
'state' => array(
|
| 196 |
'description' => 'Province / State.',
|
| 197 |
'type' => 'varchar',
|
| 198 |
'length' => 30,
|
| 199 |
'not null' => TRUE,
|
| 200 |
'default' => '',
|
| 201 |
),
|
| 202 |
'latitude' => array(
|
| 203 |
'description' => 'Location latitude (decimal degrees).',
|
| 204 |
'type' => 'numeric',
|
| 205 |
'precision' => 10,
|
| 206 |
'scale' => 6,
|
| 207 |
'not null' => TRUE,
|
| 208 |
'default' => 0.0,
|
| 209 |
),
|
| 210 |
'longitude' => array(
|
| 211 |
'description' => 'Location longitude (decimal degrees).',
|
| 212 |
'type' => 'numeric',
|
| 213 |
'precision' => 10,
|
| 214 |
'scale' => 6,
|
| 215 |
'not null' => TRUE,
|
| 216 |
'default' => 0.0,
|
| 217 |
),
|
| 218 |
// @@@ Not used, an artifact of the original data dump format.
|
| 219 |
'timezone' => array(
|
| 220 |
'description' => 'Timezone (unused).',
|
| 221 |
'type' => 'int',
|
| 222 |
'size' => 'tiny',
|
| 223 |
'not null' => TRUE,
|
| 224 |
'default' => 0,
|
| 225 |
),
|
| 226 |
// @@@ Not used, an artifact of the original data dump format.
|
| 227 |
'dst' => array(
|
| 228 |
'description' => 'Daylight Savings Time (unused).',
|
| 229 |
'type' => 'int',
|
| 230 |
'size' => 'tiny',
|
| 231 |
'not null' => TRUE,
|
| 232 |
'default' => 0,
|
| 233 |
),
|
| 234 |
'country' => array(
|
| 235 |
'description' => 'Two letter ISO country code.',
|
| 236 |
'type' => 'char',
|
| 237 |
'length' => 2,
|
| 238 |
'not null' => TRUE,
|
| 239 |
'default' => '',
|
| 240 |
),
|
| 241 |
),
|
| 242 |
// @@@ This pk is invalid, see issue queue.
|
| 243 |
//'primary key' => array('country', 'zip'),
|
| 244 |
// @@@ These need reworked.
|
| 245 |
'indexes' => array(
|
| 246 |
'pc' => array('country', 'zip'),
|
| 247 |
'zip' => array('zip'),
|
| 248 |
// @@@ No combined one?
|
| 249 |
'latitude' => array('latitude'),
|
| 250 |
'longitude' => array('longitude'),
|
| 251 |
'country' => array('country'),
|
| 252 |
),
|
| 253 |
);
|
| 254 |
// Copied from system.module.
|
| 255 |
$schema['cache_location'] = array(
|
| 256 |
'description' => t('Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.'),
|
| 257 |
'fields' => array(
|
| 258 |
'cid' => array(
|
| 259 |
'description' => t('Primary Key: Unique cache ID.'),
|
| 260 |
'type' => 'varchar',
|
| 261 |
'length' => 255,
|
| 262 |
'not null' => TRUE,
|
| 263 |
'default' => ''),
|
| 264 |
'data' => array(
|
| 265 |
'description' => t('A collection of data to cache.'),
|
| 266 |
'type' => 'blob',
|
| 267 |
'not null' => FALSE,
|
| 268 |
'size' => 'big'),
|
| 269 |
'expire' => array(
|
| 270 |
'description' => t('A Unix timestamp indicating when the cache entry should expire, or 0 for never.'),
|
| 271 |
'type' => 'int',
|
| 272 |
'not null' => TRUE,
|
| 273 |
'default' => 0),
|
| 274 |
'created' => array(
|
| 275 |
'description' => t('A Unix timestamp indicating when the cache entry was created.'),
|
| 276 |
'type' => 'int',
|
| 277 |
'not null' => TRUE,
|
| 278 |
'default' => 0),
|
| 279 |
'headers' => array(
|
| 280 |
'description' => t('Any custom HTTP headers to be added to cached data.'),
|
| 281 |
'type' => 'text',
|
| 282 |
'not null' => FALSE),
|
| 283 |
'serialized' => array(
|
| 284 |
'description' => t('A flag to indicate whether content is serialized (1) or not (0).'),
|
| 285 |
'type' => 'int',
|
| 286 |
'size' => 'small',
|
| 287 |
'not null' => TRUE,
|
| 288 |
'default' => 0)
|
| 289 |
),
|
| 290 |
'indexes' => array('expire' => array('expire')),
|
| 291 |
'primary key' => array('cid'),
|
| 292 |
);
|
| 293 |
|
| 294 |
return $schema;
|
| 295 |
}
|
| 296 |
|
| 297 |
/**
|
| 298 |
* Legacy update 1.
|
| 299 |
* Convert tables to utf8.
|
| 300 |
*/
|
| 301 |
function location_update_1() {
|
| 302 |
// return _system_update_utf8(array('location', 'zipcodes'));
|
| 303 |
}
|
| 304 |
|
| 305 |
/**
|
| 306 |
* Legacy update 2.
|
| 307 |
* Fix a bug with the "us" entry in the "location_configured_countries" var.
|
| 308 |
*/
|
| 309 |
function location_update_2() {
|
| 310 |
$configured_countries = variable_get('location_configured_countries', array());
|
| 311 |
if ($configured_countries['us']) {
|
| 312 |
$configured_countries['us'] = 'us';
|
| 313 |
variable_set('location_configured_countries', $configured_countries);
|
| 314 |
}
|
| 315 |
return array();
|
| 316 |
}
|
| 317 |
|
| 318 |
/**
|
| 319 |
* Legacy update 3.
|
| 320 |
* Allow for postgresql support by renaming the oid column, which is a reserved
|
| 321 |
* name on postgresql.
|
| 322 |
*/
|
| 323 |
function location_update_3() {
|
| 324 |
$ret = array();
|
| 325 |
|
| 326 |
switch ($GLOBALS['db_type']) {
|
| 327 |
case 'mysql':
|
| 328 |
case 'mysqli':
|
| 329 |
$ret[] = update_sql("ALTER TABLE {location} CHANGE oid eid int unsigned NOT NULL default '0'");
|
| 330 |
break;
|
| 331 |
}
|
| 332 |
|
| 333 |
drupal_set_message("The schema for location module has been updated. The update is such that you may want to re-resave any views you have that may include locations.");
|
| 334 |
|
| 335 |
if (module_exists('views')) {
|
| 336 |
views_invalidate_cache();
|
| 337 |
}
|
| 338 |
return $ret;
|
| 339 |
}
|
| 340 |
|
| 341 |
/***************************************************************
|
| 342 |
PostgreSQL must be supported in all updates after this comment
|
| 343 |
***************************************************************/
|
| 344 |
|
| 345 |
/**
|
| 346 |
* Legacy update 4.
|
| 347 |
* Add "lid" as the new location key.
|
| 348 |
*/
|
| 349 |
function location_update_4() {
|
| 350 |
$ret = array();
|
| 351 |
|
| 352 |
switch ($GLOBALS['db_type']) {
|
| 353 |
case 'mysql':
|
| 354 |
case 'mysqli':
|
| 355 |
$ret[] = update_sql("ALTER TABLE {location} ADD COLUMN lid int(10) unsigned NOT NULL default '0' AFTER eid");
|
| 356 |
|
| 357 |
$result = db_query("SELECT eid, type FROM {location}");
|
| 358 |
$next_id = 0;
|
| 359 |
while ($row = db_fetch_object($result)) {
|
| 360 |
$next_id++;
|
| 361 |
db_query("UPDATE {location} SET lid = %d WHERE eid = %d AND type = '%s'", $next_id, $row->eid, $row->type);
|
| 362 |
}
|
| 363 |
|
| 364 |
$ret[] = update_sql("ALTER TABLE {location} DROP PRIMARY KEY");
|
| 365 |
$ret[] = update_sql("ALTER TABLE {location} ADD PRIMARY KEY (lid)");
|
| 366 |
|
| 367 |
db_query("INSERT INTO {sequences} (name, id) VALUES ('{location}_lid', %d)", $next_id);
|
| 368 |
$ret[] = update_sql("ALTER TABLE {location} ADD COLUMN is_primary tinyint NOT NULL default '0'");
|
| 369 |
$ret[] = update_sql("UPDATE {location} SET is_primary = 1 WHERE type = 'user'");
|
| 370 |
|
| 371 |
break;
|
| 372 |
case 'pgsql':
|
| 373 |
// help me
|
| 374 |
break;
|
| 375 |
}
|
| 376 |
|
| 377 |
foreach (node_get_types() as $type => $name) {
|
| 378 |
$new_setting = variable_get('location_'. $type, 0) ? 1 : 0;
|
| 379 |
variable_del('location_'. $type);
|
| 380 |
variable_set('location_maxnum_'. $type, $new_setting);
|
| 381 |
variable_set('location_defaultnum_'. $type, $new_setting);
|
| 382 |
}
|
| 383 |
return $ret;
|
| 384 |
}
|
| 385 |
|
| 386 |
/**
|
| 387 |
* Legacy update 5.
|
| 388 |
* Postgresql support that was missing from previous update.
|
| 389 |
*/
|
| 390 |
function location_update_5() {
|
| 391 |
$ret = array();
|
| 392 |
|
| 393 |
switch ($GLOBALS['db_type']) {
|
| 394 |
case 'pgsql':
|
| 395 |
$ret[] = update_sql("ALTER TABLE {location} DROP CONSTRAINT {location}_pkey");
|
| 396 |
$ret[] = update_sql("ALTER TABLE {location} RENAME TO {location}_old");
|
| 397 |
$ret[] = update_sql("CREATE TABLE {location} (
|
| 398 |
lid serial CHECK (lid >= 0),
|
| 399 |
eid int NOT NULL default '0' CHECK (eid >= 0),
|
| 400 |
type varchar(6) NOT NULL default '',
|
| 401 |
name varchar(255) default NULL,
|
| 402 |
street varchar(255) default NULL,
|
| 403 |
additional varchar(255) default NULL,
|
| 404 |
city varchar(255) default NULL,
|
| 405 |
province varchar(16) default NULL,
|
| 406 |
postal_code varchar(16) default NULL,
|
| 407 |
country char(2) default NULL,
|
| 408 |
latitude decimal(10,6) default NULL,
|
| 409 |
longitude decimal(10,6) default NULL,
|
| 410 |
source smallint default '0',
|
| 411 |
is_primary smallint default '0',
|
| 412 |
PRIMARY KEY (lid)
|
| 413 |
)");
|
| 414 |
$ret[] = update_sql("INSERT INTO {location}
|
| 415 |
(eid, type, name, street, additional, city, province, postal_code, country, latitude,
|
| 416 |
longitude, source) SELECT eid, type, name, street, additional, city, province,
|
| 417 |
postal_code, country, latitude, longitude, source FROM {location}_old");
|
| 418 |
$ret[] = update_sql("DROP TABLE {location}_old");
|
| 419 |
$ret[] = update_sql("UPDATE {location} SET is_primary = 1 WHERE type = 'user'");
|
| 420 |
break;
|
| 421 |
}
|
| 422 |
return $ret;
|
| 423 |
}
|
| 424 |
|
| 425 |
/**
|
| 426 |
* Legacy update 6.
|
| 427 |
* Use correct country code for Sweeden.
|
| 428 |
*/
|
| 429 |
function location_update_6() {
|
| 430 |
$ret = array();
|
| 431 |
|
| 432 |
switch ($GLOBALS['db_type']) {
|
| 433 |
case 'mysql':
|
| 434 |
case 'mysqli':
|
| 435 |
$ret[] = update_sql("UPDATE {location} SET country = 'se' WHERE country = 'sw'");
|
| 436 |
|
| 437 |
break;
|
| 438 |
case 'pgsql':
|
| 439 |
$ret[] = update_sql("UPDATE {location} SET country = 'se' WHERE country = 'sw'");
|
| 440 |
|
| 441 |
break;
|
| 442 |
}
|
| 443 |
return $ret;
|
| 444 |
}
|
| 445 |
|
| 446 |
/**
|
| 447 |
* Update 7 (Location 2.x)
|
| 448 |
* Generalize google geocoding so you don't have to enter the api key over and over.
|
| 449 |
*/
|
| 450 |
function location_update_7() {
|
| 451 |
$ret = array();
|
| 452 |
|
| 453 |
$services = array('google');
|
| 454 |
$general_geocoders_in_use = array();
|
| 455 |
|
| 456 |
switch ($GLOBALS['db_type']) {
|
| 457 |
case 'mysql':
|
| 458 |
case 'mysqli':
|
| 459 |
$result = db_query('SELECT * FROM {variable} WHERE name REGEXP \'^location_geocode_[a-z][a-z]$\'');
|
| 460 |
|
| 461 |
while ($row = db_fetch_object($result)) {
|
| 462 |
$value_decoded = unserialize($row->value);
|
| 463 |
if (!in_array($value_decoded, $services)) {
|
| 464 |
$ret[] = update_sql('UPDATE {variable} SET value = \''. serialize($value_decoded .'|'. substr($row->name, 17)) .'\' WHERE name = \''. $row->name .'\'');
|
| 465 |
}
|
| 466 |
else {
|
| 467 |
$general_geocoders_in_use[$value_decoded] = $value_decoded;
|
| 468 |
}
|
| 469 |
}
|
| 470 |
|
| 471 |
$key = db_result(db_query('SELECT value FROM {variable} WHERE name REGEXP \'^location_geocode_[a-z][a-z]_google_apikey$\' LIMIT 1'));
|
| 472 |
|
| 473 |
$ret[] = update_sql('DELETE FROM {variable} WHERE name REGEXP \'^location_geocode_[a-z][a-z]_google_apikey$\'');
|
| 474 |
$ret[] = update_sql('INSERT INTO {variable} (name, value) VALUES (\'location_geocode_google_apikey\', \''. $key .'\')');
|
| 475 |
$ret[] = update_sql('DELETE FROM {cache} WHERE cid = \'variables\'');
|
| 476 |
|
| 477 |
variable_set('location_general_geocoders_in_use', $general_geocoders_in_use);
|
| 478 |
break;
|
| 479 |
case 'pgsql':
|
| 480 |
$result = db_query('SELECT * FROM {variable} WHERE name REGEXP \'^location_geocode_[a-z][a-z]$\'');
|
| 481 |
|
| 482 |
while ($row = db_fetch_object($result)) {
|
| 483 |
$value_decoded = unserialize($row->value);
|
| 484 |
if (!in_array($value_decoded, $services)) {
|
| 485 |
$ret[] = update_sql('UPDATE {variable} SET value = \''. serialize($value_decoded .'|'. substr($row->name, 17)) .'\' WHERE name = \''. $row->name .'\'');
|
| 486 |
}
|
| 487 |
else {
|
| 488 |
$general_geocoders_in_use[$value_decoded] = $value_decoded;
|
| 489 |
}
|
| 490 |
}
|
| 491 |
|
| 492 |
$key = db_result(db_query('SELECT value FROM {variable} WHERE name REGEXP \'^location_geocode_[a-z][a-z]_google_apikey$\' LIMIT 1'));
|
| 493 |
|
| 494 |
$ret[] = update_sql('DELETE FROM {variable} WHERE name REGEXP \'^location_geocode_[a-z][a-z]_google_apikey$\'');
|
| 495 |
$ret[] = update_sql('INSERT INTO {variable} (name, value) VALUES (\'location_geocode_google_apikey\', \''. $key .'\')');
|
| 496 |
$ret[] = update_sql('DELETE FROM {cache} WHERE cid = \'variables\'');
|
| 497 |
|
| 498 |
variable_set('location_general_geocoders_in_use', $general_geocoders_in_use);
|
| 499 |
break;
|
| 500 |
}
|
| 501 |
return $ret;
|
| 502 |
}
|
| 503 |
|
| 504 |
/**
|
| 505 |
* Location 3.x update 1.
|
| 506 |
* Add location specific cache table.
|
| 507 |
*/
|
| 508 |
function location_update_5300() {
|
| 509 |
$ret = array();
|
| 510 |
switch ($GLOBALS['db_type']) {
|
| 511 |
case 'mysql':
|
| 512 |
case 'mysqli':
|
| 513 |
$ret[] = update_sql("CREATE TABLE {cache_location} (
|
| 514 |
cid varchar(255) NOT NULL default '',
|
| 515 |
data longblob,
|
| 516 |
expire int NOT NULL default '0',
|
| 517 |
created int NOT NULL default '0',
|
| 518 |
headers text,
|
| 519 |
PRIMARY KEY (cid),
|
| 520 |
INDEX expire (expire)
|
| 521 |
) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
|
| 522 |
break;
|
| 523 |
case 'pgsql':
|
| 524 |
$ret[] = update_sql("CREATE TABLE {cache_location} (
|
| 525 |
cid varchar(255) NOT NULL default '',
|
| 526 |
data bytea,
|
| 527 |
expire int NOT NULL default '0',
|
| 528 |
created int NOT NULL default '0',
|
| 529 |
headers text,
|
| 530 |
PRIMARY KEY (cid)
|
| 531 |
)");
|
| 532 |
$ret[] = update_sql("CREATE INDEX {cache_location}_expire_idx ON {cache_location} (expire)");
|
| 533 |
break;
|
| 534 |
}
|
| 535 |
return $ret;
|
| 536 |
}
|
| 537 |
|
| 538 |
/**
|
| 539 |
* Location 3.x update 2.
|
| 540 |
* Normalize the location table.
|
| 541 |
* This allows:
|
| 542 |
* - Making the loading and saving code cleaner.
|
| 543 |
* - Fixing a longstanding bug with revisions.
|
| 544 |
* - Having the same location on multiple nodes/users/both.
|
| 545 |
* - Garbage collecting unused locations periodically.
|
| 546 |
* - Having full support for deletions.
|
| 547 |
* - Full revisions support.
|
| 548 |
* Note that the location_instance table does NOT have a primary key.
|
| 549 |
* This is on purpose. It's a N:M join table.
|
| 550 |
*/
|
| 551 |
function location_update_5301() {
|
| 552 |
$ret = array();
|
| 553 |
switch ($GLOBALS['db_type']) {
|
| 554 |
case 'mysql':
|
| 555 |
case 'mysqli':
|
| 556 |
db_query("
|
| 557 |
CREATE TABLE {location_instance} (
|
| 558 |
nid int UNSIGNED DEFAULT NULL,
|
| 559 |
vid int UNSIGNED DEFAULT NULL,
|
| 560 |
uid int UNSIGNED DEFAULT NULL,
|
| 561 |
genid varchar(255) NOT NULL default '',
|
| 562 |
lid int UNSIGNED NOT NULL DEFAULT '0',
|
| 563 |
INDEX {location_instance}_nid_idx (nid),
|
| 564 |
INDEX {location_instance}_vid_idx (vid),
|
| 565 |
INDEX {location_instance}_uid_idx (uid),
|
| 566 |
INDEX {location_instance}_genid_idx (genid),
|
| 567 |
INDEX {location_instance}_lid_idx (lid)
|
| 568 |
) /*!40100 DEFAULT CHARACTER SET utf8 */");
|
| 569 |
break;
|
| 570 |
case 'pgsql':
|
| 571 |
$ret[] = update_sql("
|
| 572 |
CREATE TABLE {location_instance} (
|
| 573 |
nid int DEFAULT NULL CHECK (nid >= 0 OR nid IS NULL),
|
| 574 |
vid int DEFAULT NULL CHECK (vid >= 0 OR vid IS NULL),
|
| 575 |
uid int DEFAULT NULL CHECK (uid >= 0 OR uid IS NULL),
|
| 576 |
genid varchar(255) NOT NULL default '',
|
| 577 |
lid int NOT NULL DEFAULT '0' CHECK (lid >= 0)
|
| 578 |
)");
|
| 579 |
$ret[] = update_sql('CREATE INDEX {location_instance}_nid_idx ON {location_instance} (nid)');
|
| 580 |
$ret[] = update_sql('CREATE INDEX {location_instance}_vid_idx ON {location_instance} (vid)');
|
| 581 |
$ret[] = update_sql('CREATE INDEX {location_instance}_uid_idx ON {location_instance} (uid)');
|
| 582 |
$ret[] = update_sql('CREATE INDEX {location_instance}_lid_idx ON {location_instance} (lid)');
|
| 583 |
$ret[] = update_sql('CREATE INDEX {location_instance}_genid_idx ON {location_instance} (genid)');
|
| 584 |
break;
|
| 585 |
}
|
| 586 |
|
| 587 |
// Synthesise node location data based on what we have.
|
| 588 |
// Storage of locations was previously stored against node revision, BUT the
|
| 589 |
// data was not properly duplicated by revision (i.e. only the latest revision
|
| 590 |
// carried the data.)
|
| 591 |
// Joining like this allows us to backfill all the old revisions with the current
|
| 592 |
// data, which is not nice but better than having no data at all when viewing
|
| 593 |
// old revisions.
|
| 594 |
$ret[] = update_sql("INSERT INTO {location_instance} (nid,vid,lid) (SELECT nr.nid, nr.vid, l.lid FROM {node_revisions} nr INNER JOIN {node_revisions} nr2 ON nr.nid = nr2.nid INNER JOIN {location} l ON nr2.vid = l.eid AND l.type = 'node')");
|
| 595 |
|
| 596 |
// Users is much simpler.
|
| 597 |
$ret[] = update_sql("INSERT INTO {location_instance} (uid,lid) (SELECT eid, lid FROM {location} WHERE type = 'user')");
|
| 598 |
|
| 599 |
// Aug 18 2008:
|
| 600 |
// Save everything else in genid.
|
| 601 |
switch ($GLOBALS['db_type']) {
|
| 602 |
case 'mysql':
|
| 603 |
case 'mysqli':
|
| 604 |
$ret[] = update_sql("INSERT INTO {location_instance} (genid, lid) (SELECT CONCAT(type, ':', eid), lid FROM {location} WHERE type <> 'user' AND type <> 'node')");
|
| 605 |
break;
|
| 606 |
case 'pgsql':
|
| 607 |
$ret[] = update_sql("INSERT INTO {location_instance} (genid, lid) (SELECT type||':'||eid, lid FROM {location} WHERE type <> 'user' AND type <> 'node')");
|
| 608 |
break;
|
| 609 |
}
|
| 610 |
|
| 611 |
// Remove now unused columns.
|
| 612 |
$ret[] = update_sql("ALTER TABLE {location} DROP COLUMN type");
|
| 613 |
$ret[] = update_sql("ALTER TABLE {location} DROP COLUMN eid");
|
| 614 |
|
| 615 |
// General cleanup.
|
| 616 |
variable_del('location_user'); // Removed in favor of permission check.
|
| 617 |
|
| 618 |
// Variable consolidation (as part of the element based system)
|
| 619 |
// We're doing this "raw" so we can be sure we got everything moved over,
|
| 620 |
// INCLUDING content types that were deleted in the past.
|
| 621 |
// This will let us do better cleanup sometime in the future.
|
| 622 |
$data = array();
|
| 623 |
$todelete = array();
|
| 624 |
foreach(array('name', 'street', 'additional', 'city', 'province', 'postal_code', 'country', 'phone', 'fax') as $field) {
|
| 625 |
$result = db_query("SELECT name, value FROM {variable} WHERE name LIKE 'location_%s%%'", $field);
|
| 626 |
while ($row = db_fetch_object($result)) {
|
| 627 |
$data[substr($row->name, strlen($field) + 10)][$field] = (string)(int)unserialize($row->value);
|
| 628 |
$todelete[] = $row->name;
|
| 629 |
}
|
| 630 |
}
|
| 631 |
foreach ($data as $type => $value) {
|
| 632 |
// We aren't going to trust that hook_locationapi is operational.
|
| 633 |
// So, stick with some conservative defaults.
|
| 634 |
$value = array_merge(array(
|
| 635 |
'name' => '1',
|
| 636 |
'street' => '1',
|
| 637 |
// additional is left out of this list intentionally.
|
| 638 |
'city' => '0',
|
| 639 |
'province' => '0',
|
| 640 |
'postal_code' => '0',
|
| 641 |
'country' => '1',
|
| 642 |
), $value);
|
| 643 |
if (!isset($value['additional'])) {
|
| 644 |
// Initialize additional to match street.
|
| 645 |
$value['additional'] = $value['street'];
|
| 646 |
}
|
| 647 |
variable_set('location_fields_'. $type, $value);
|
| 648 |
}
|
| 649 |
foreach ($todelete as $key) {
|
| 650 |
variable_del($key);
|
| 651 |
}
|
| 652 |
|
| 653 |
// This update was retrofitted on Aug 18, 2008. Set a flag for use by
|
| 654 |
// the next update in order to handle the case where someone has already
|
| 655 |
// updated to EXACTLY schema revision 5301 before the retrofit took effect.
|
| 656 |
// People who migrated past this point before that date may have the following
|
| 657 |
// inconsistencies:
|
| 658 |
// A) location_{field}_{type} variables were not collected for content types
|
| 659 |
// that had been deleted in the past.
|
| 660 |
// B) Any locations with the 'type' field set to something other than 'node'
|
| 661 |
// or 'user' did not get entries in {location_instance}.
|
| 662 |
variable_set('location_update_5301_retrofit', TRUE);
|
| 663 |
return $ret;
|
| 664 |
}
|
| 665 |
|
| 666 |
/**
|
| 667 |
* Location 3.x update 3.
|
| 668 |
* Add genid to {location_instance}.
|
| 669 |
*/
|
| 670 |
function location_update_5302() {
|
| 671 |
$ret = array();
|
| 672 |
// OK, here's the deal. I retrofitted 5301 on Aug 18 2008 to integrate the genid.
|
| 673 |
// This was needed to fix the pre location 3.x todo item regarding keeping non
|
| 674 |
// user, non node data intact. People doing an update after Aug 18 will already
|
| 675 |
// have the genid column in place, so it can be safely skipped.
|
| 676 |
if (!variable_get('location_update_5301_retrofit', FALSE)) {
|
| 677 |
switch ($GLOBALS['db_type']) {
|
| 678 |
case 'mysql':
|
| 679 |
case 'mysqli':
|
| 680 |
$ret[] = update_sql("ALTER TABLE {location_instance} ADD COLUMN genid varchar(255) NOT NULL default '' AFTER uid");
|
| 681 |
$ret[] = update_sql('CREATE INDEX {location_instance}_genid_idx ON {location_instance} (genid)');
|
| 682 |
break;
|
| 683 |
case 'pgsql':
|
| 684 |
db_add_column($ret, 'location_instance', 'genid', 'varchar(255)', array('not null' => TRUE, 'default' => "''"));
|
| 685 |
$ret[] = update_sql('CREATE INDEX {location_instance}_genid_idx ON {location_instance} (genid)');
|
| 686 |
break;
|
| 687 |
}
|
| 688 |
}
|
| 689 |
return $ret;
|
| 690 |
}
|
| 691 |
|
| 692 |
/**
|
| 693 |
* Location 3.x update 4.
|
| 694 |
* Shuffle more variables around.
|
| 695 |
*/
|
| 696 |
function location_update_5303() {
|
| 697 |
$ret = array();
|
| 698 |
|
| 699 |
$types = array();
|
| 700 |
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_display_teaser_%'");
|
| 701 |
while ($row = db_fetch_object($result)) {
|
| 702 |
$type = substr($row->name, 24);
|
| 703 |
$types[$type]['teaser'] = variable_get('location_display_teaser_'. $type, TRUE);
|
| 704 |
$types[$type]['full'] = variable_get('location_display_full_'. $type, TRUE);
|
| 705 |
$types[$type]['weight'] = variable_get('location_display_weight_'. $type, 0);
|
| 706 |
// @@@ Combine location_suppress_country and country require settings to set this up?
|
| 707 |
$types[$type]['hide'] = array();
|
| 708 |
}
|
| 709 |
foreach ($types as $type => $value) {
|
| 710 |
variable_set("location_display_$type", $value);
|
| 711 |
variable_del("location_display_teaser_$type");
|
| 712 |
variable_del("location_display_full_$type");
|
| 713 |
variable_del("location_display_weight_$type");
|
| 714 |
}
|
| 715 |
|
| 716 |
return $ret;
|
| 717 |
}
|
| 718 |
|
| 719 |
// @@@ Does 5303 need rerun in some circumstances?
|
| 720 |
|
| 721 |
/**
|
| 722 |
* Drupal 6 location 3.x update.
|
| 723 |
*/
|
| 724 |
function location_update_6301() {
|
| 725 |
$t = get_t();
|
| 726 |
drupal_set_message($t('Note: Location.module update 6301 will generate several warnings/failures regarding indexes and primary keys if you are upgrading from one of the 6.x test releases. These warnings can be safely disregarded in this case.'));
|
| 727 |
|
| 728 |
$ret = array();
|
| 729 |
|
| 730 |
// Update cache table.
|
| 731 |
db_drop_table($ret, 'cache_location');
|
| 732 |
|
| 733 |
$schema['cache_location'] = array(
|
| 734 |
'description' => t('Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.'),
|
| 735 |
'fields' => array(
|
| 736 |
'cid' => array(
|
| 737 |
'description' => t('Primary Key: Unique cache ID.'),
|
| 738 |
'type' => 'varchar',
|
| 739 |
'length' => 255,
|
| 740 |
'not null' => TRUE,
|
| 741 |
'default' => ''),
|
| 742 |
'data' => array(
|
| 743 |
'description' => t('A collection of data to cache.'),
|
| 744 |
'type' => 'blob',
|
| 745 |
'not null' => FALSE,
|
| 746 |
'size' => 'big'),
|
| 747 |
'expire' => array(
|
| 748 |
'description' => t('A Unix timestamp indicating when the cache entry should expire, or 0 for never.'),
|
| 749 |
'type' => 'int',
|
| 750 |
'not null' => TRUE,
|
| 751 |
'default' => 0),
|
| 752 |
'created' => array(
|
| 753 |
'description' => t('A Unix timestamp indicating when the cache entry was created.'),
|
| 754 |
'type' => 'int',
|
| 755 |
'not null' => TRUE,
|
| 756 |
'default' => 0),
|
| 757 |
'headers' => array(
|
| 758 |
'description' => t('Any custom HTTP headers to be added to cached data.'),
|
| 759 |
'type' => 'text',
|
| 760 |
'not null' => FALSE),
|
| 761 |
'serialized' => array(
|
| 762 |
'description' => t('A flag to indicate whether content is serialized (1) or not (0).'),
|
| 763 |
'type' => 'int',
|
| 764 |
'size' => 'small',
|
| 765 |
'not null' => TRUE,
|
| 766 |
'default' => 0)
|
| 767 |
),
|
| 768 |
'indexes' => array('expire' => array('expire')),
|
| 769 |
'primary key' => array('cid'),
|
| 770 |
);
|
| 771 |
|
| 772 |
db_create_table($ret, 'cache_location', $schema['cache_location']);
|
| 773 |
|
| 774 |
// LID 0 causes all sorts of issues, and will break our update routine
|
| 775 |
// unless we handle it beforehand.
|
| 776 |
// Since we're so nice, we're gonna renumber it for the user.
|
| 777 |
if (db_result(db_query('SELECT COUNT(*) FROM {location} WHERE lid = 0'))) {
|
| 778 |
$lid = 1 + db_result(db_query('SELECT MAX(lid) FROM {location}'));
|
| 779 |
drupal_set_message(t('Note: A location with lid 0 was found in your database. It has been moved to lid %lid. You may wish to verify it manually, as lid 0 is usually a corrupt entry.', array('%lid' => $lid)));
|
| 780 |
// $lid is safe to inject here.
|
| 781 |
$ret[] = update_sql("UPDATE {location} SET lid = $lid WHERE lid = 0");
|
| 782 |
$ret[] = update_sql("UPDATE {location_instance} SET lid = $lid WHERE lid = 0");
|
| 783 |
}
|
| 784 |
|
| 785 |
// Field changes
|
| 786 |
|
| 787 |
// {location}
|
| 788 |
|
| 789 |
// {location}.lid -- Becomes a serial.
|
| 790 |
db_drop_primary_key($ret, 'location');
|
| 791 |
db_change_field($ret, 'location', 'lid', 'lid',
|
| 792 |
array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
|
| 793 |
array('primary key' => array('lid')));
|
| 794 |
|
| 795 |
// (The rest of the changes to this table were moved to update 6302 due to a bug.)
|
| 796 |
|
| 797 |
// {location_instance}
|
| 798 |
|
| 799 |
// Fix oddly named indexes -- Was using the postgresql method for both.
|
| 800 |
switch ($GLOBALS['db_type']) {
|
| 801 |
case 'mysql':
|
| 802 |
case 'mysqli':
|
| 803 |
db_drop_index($ret, 'location_instance', '{location_instance}_nid_idx');
|
| 804 |
db_drop_index($ret, 'location_instance', '{location_instance}_vid_idx');
|
| 805 |
db_drop_index($ret, 'location_instance', '{location_instance}_uid_idx');
|
| 806 |
db_drop_index($ret, 'location_instance', '{location_instance}_genid_idx');
|
| 807 |
db_drop_index($ret, 'location_instance', '{location_instance}_lid_idx');
|
| 808 |
break;
|
| 809 |
case 'pgsql':
|
| 810 |
db_drop_index($ret, 'location_instance', 'nid');
|
| 811 |
db_drop_index($ret, 'location_instance', 'vid');
|
| 812 |
db_drop_index($ret, 'location_instance', 'uid');
|
| 813 |
db_drop_index($ret, 'location_instance', 'genid');
|
| 814 |
db_drop_index($ret, 'location_instance', 'lid');
|
| 815 |
}
|
| 816 |
|
| 817 |
// Fill in nulls.
|
| 818 |
$ret[] = update_sql('UPDATE {location_instance} SET nid = 0 WHERE nid IS NULL');
|
| 819 |
$ret[] = update_sql('UPDATE {location_instance} SET vid = 0 WHERE vid IS NULL');
|
| 820 |
$ret[] = update_sql('UPDATE {location_instance} SET uid = 0 WHERE uid IS NULL');
|
| 821 |
$ret[] = update_sql("UPDATE {location_instance} SET genid = '' WHERE genid IS NULL");
|
| 822 |
|
| 823 |
// {location_instance}.nid
|
| 824 |
db_change_field($ret, 'location_instance', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 825 |
// {location_instance}.vid
|
| 826 |
db_change_field($ret, 'location_instance', 'vid', 'vid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 827 |
// {location_instance}.uid
|
| 828 |
db_change_field($ret, 'location_instance', 'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 829 |
// {location_instance}.genid
|
| 830 |
db_change_field($ret, 'location_instance', 'genid', 'genid', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 831 |
|
| 832 |
// {location_instance}.lid
|
| 833 |
db_change_field($ret, 'location_instance', 'lid', 'lid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
|
| 834 |
|
| 835 |
// Readd indexes.
|
| 836 |
db_add_index($ret, 'location_instance', 'nid', array('nid'));
|
| 837 |
db_add_index($ret, 'location_instance', 'vid', array('vid'));
|
| 838 |
db_add_index($ret, 'location_instance', 'uid', array('uid'));
|
| 839 |
db_add_index($ret, 'location_instance', 'genid', array('genid'));
|
| 840 |
db_add_index($ret, 'location_instance', 'lid', array('lid'));
|
| 841 |
|
| 842 |
// {zipcodes}
|
| 843 |
// Drop primary key.
|
| 844 |
db_drop_primary_key($ret, 'zipcodes');
|
| 845 |
|
| 846 |
return $ret;
|
| 847 |
}
|
| 848 |
|
| 849 |
/**
|
| 850 |
* Drupal 6 location 3.x update, part 2.
|
| 851 |
*/
|
| 852 |
function location_update_6302() {
|
| 853 |
$ret = array();
|
| 854 |
|
| 855 |
// OK, here's the update to fix the previous update which had a few problems
|
| 856 |
// when upgrading from pre-rc 6.x versions.
|
| 857 |
|
| 858 |
// The "mismatch between mysql and postgresql" was actually applicable to
|
| 859 |
// 6.x-3.0 pre-rc1 as well, but I didn't notice because I accidentally added
|
| 860 |
// the not null when reformatting the schema.
|
| 861 |
$ret[] = update_sql('UPDATE {location} SET is_primary = 0 WHERE is_primary IS NULL');
|
| 862 |
db_change_field($ret, 'location', 'is_primary', 'is_primary', array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'not null' => TRUE));
|
| 863 |
|
| 864 |
// Fix zipcode mismatches caused by the same problem.
|
| 865 |
|
| 866 |
// There shouldn't be any rows like this, but it doesn't hurt to be sure.
|
| 867 |
$ret[] = update_sql('UPDATE {zipcodes} SET zip = 0 WHERE zip IS NULL');
|
| 868 |
|
| 869 |
// Set not null.
|
| 870 |
db_change_field($ret, 'zipcodes', 'zip', 'zip', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => '0'));
|
| 871 |
|
| 872 |
// Prepare latitude and longitude for the same.
|
| 873 |
$ret[] = update_sql('UPDATE {zipcodes} SET latitude = 0.0 WHERE latitude IS NULL');
|
| 874 |
$ret[] = update_sql('UPDATE {zipcodes} SET longitude = 0.0 WHERE longitude IS NULL');
|
| 875 |
|
| 876 |
// Set not null.
|
| 877 |
db_change_field($ret, 'zipcodes', 'latitude', 'latitude', array('type' => 'numeric', 'not null' => TRUE, 'default' => 0, 'precision' => 10, 'scale' => 6));
|
| 878 |
db_change_field($ret, 'zipcodes', 'longitude', 'longitude', array('type' => 'numeric', 'not null' => TRUE, 'default' => 0, 'precision' => 10, 'scale' => 6));
|
| 879 |
|
| 880 |
// Prepare country.
|
| 881 |
$ret[] = update_sql("UPDATE {zipcodes} SET country = '' WHERE country IS NULL");
|
| 882 |
|
| 883 |
// Set not null.
|
| 884 |
db_change_field($ret, 'zipcodes', 'country', 'country', array('type' => 'char', 'length' => 2, 'not null' => TRUE, 'default' => ''));
|
| 885 |
|
| 886 |
// Fix up possible {location} problems from previous update that could be caused if you had NULLed fields.
|
| 887 |
|
| 888 |
// Set defaults
|
| 889 |
$ret[] = update_sql("UPDATE {location} SET name = '' WHERE name IS NULL");
|
| 890 |
$ret[] = update_sql("UPDATE {location} SET street = '' WHERE street IS NULL");
|
| 891 |
$ret[] = update_sql("UPDATE {location} SET additional = '' WHERE additional IS NULL");
|
| 892 |
$ret[] = update_sql("UPDATE {location} SET city = '' WHERE city IS NULL");
|
| 893 |
$ret[] = update_sql("UPDATE {location} SET province = '' WHERE province IS NULL");
|
| 894 |
$ret[] = update_sql("UPDATE {location} SET postal_code = '' WHERE postal_code IS NULL");
|
| 895 |
$ret[] = update_sql("UPDATE {location} SET country = '' WHERE country IS NULL");
|
| 896 |
$ret[] = update_sql('UPDATE {location} SET latitude = 0.0 WHERE latitude IS NULL');
|
| 897 |
$ret[] = update_sql('UPDATE {location} SET longitude = 0.0 WHERE longitude IS NULL');
|
| 898 |
$ret[] = update_sql('UPDATE {location} SET source = 0 WHERE source IS NULL');
|
| 899 |
|
| 900 |
// {location}.name -- NOT NULL
|
| 901 |
db_change_field($ret, 'location', 'name', 'name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 902 |
// {location}.street -- NOT NULL
|
| 903 |
db_change_field($ret, 'location', 'street', 'street', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 904 |
// {location}.additional -- NOT NULL
|
| 905 |
db_change_field($ret, 'location', 'additional', 'additional', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 906 |
// {location}.city -- NOT NULL
|
| 907 |
db_change_field($ret, 'location', 'city', 'city', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
|
| 908 |
// {location}.province -- NOT NULL
|
| 909 |
db_change_field($ret, 'location', 'province', 'province', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''));
|
| 910 |
// {location}.postal_code -- NOT NULL
|
| 911 |
db_change_field($ret, 'location', 'postal_code', 'postal_code', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''));
|
| 912 |
// {location}.country -- NOT NULL
|
| 913 |
db_change_field($ret, 'location', 'country', 'country', array('type' => 'char', 'length' => 2, 'not null' => TRUE, 'default' => ''));
|
| 914 |
|
| 915 |
// {location}.latitude
|
| 916 |
db_change_field($ret, 'location', 'latitude', 'latitude', array('type' => 'numeric', 'precision' => 10, 'scale' => 6, 'not null' => TRUE, 'default' => 0.0));
|
| 917 |
// {location}.longitude
|
| 918 |
db_change_field($ret, 'location', 'longitude', 'longitude', array('type' => 'numeric', 'precision' => 10, 'scale' => 6, 'not null' => TRUE, 'default' => 0.0));
|
| 919 |
|
| 920 |
// {location}.source
|
| 921 |
db_change_field($ret, 'location', 'source', 'source', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
|
| 922 |
|
| 923 |
return $ret;
|
| 924 |
}
|
| 925 |
|
| 926 |
/**
|
| 927 |
* Drupal 6 location 3.x update, part 3.
|
| 928 |
*/
|
| 929 |
function location_update_6303() {
|
| 930 |
$ret = array();
|
| 931 |
if (!variable_get('location_update_5304_done', FALSE)) {
|
| 932 |
// Do the same updates as 5304.
|
| 933 |
|
| 934 |
// Delete unused variables.
|
| 935 |
variable_del('location_configured_countries');
|
| 936 |
variable_del('location_garbagecollect');
|
| 937 |
|
| 938 |
// Update province code for Italy/Forlì-Cesena.
|
| 939 |
$ret[] = update_sql("UPDATE {location} SET province = 'FC' WHERE country = 'it' AND province = 'FO'");
|
| 940 |
// Update province code for Italy/Pesaro e Urbino.
|
| 941 |
$ret[] = update_sql("UPDATE {location} SET province = 'PU' WHERE country = 'it' AND province = 'PS'");
|
| 942 |
|
| 943 |
// Do one final garbage collection by hand.
|
| 944 |
$ret[] = update_sql('DELETE FROM {location} WHERE lid NOT IN (SELECT lid FROM {location_instance})');
|
| 945 |
|
| 946 |
// Garbage collect {location_phone} by hand.
|
| 947 |
if (db_table_exists('location_phone')) {
|
| 948 |
$ret[] = update_sql('DELETE FROM {location_phone} WHERE lid NOT IN (SELECT lid FROM {location})');
|
| 949 |
}
|
| 950 |
|
| 951 |
// Garbage collect {location_fax} by hand.
|
| 952 |
if (db_table_exists('location_fax')) {
|
| 953 |
$ret[] = update_sql('DELETE FROM {location_fax} WHERE lid NOT IN (SELECT lid FROM {location})');
|
| 954 |
}
|
| 955 |
|
| 956 |
variable_del('location_update_5304_done');
|
| 957 |
}
|
| 958 |
return $ret;
|
| 959 |
}
|
| 960 |
|
| 961 |
/**
|
| 962 |
* Upgrade all of the settings variables to the new unified system.
|
| 963 |
*/
|
| 964 |
function location_update_6304() {
|
| 965 |
// Skip this update if it was already done on the 5.x side.
|
| 966 |
if (variable_get('location_update_5305_done', FALSE)) {
|
| 967 |
variable_del('location_update_5305_done');
|
| 968 |
return array();
|
| 969 |
}
|
| 970 |
|
| 971 |
$ret = array();
|
| 972 |
|
| 973 |
$variables = array();
|
| 974 |
$todelete = array();
|
| 975 |
|
| 976 |
$base = array(
|
| 977 |
'multiple' => array(
|
| 978 |
'min' => 0,
|
| 979 |
'max' => 0,
|
| 980 |
'add' => 3,
|
| 981 |
),
|
| 982 |
'form' => array(
|
| 983 |
'weight' => 0,
|
| 984 |
'collapsible' => TRUE,
|
| 985 |
'collapsed' => TRUE,
|
| 986 |
'fields' => array(),
|
| 987 |
),
|
| 988 |
'display' => array(
|
| 989 |
'weight' => 0,
|
| 990 |
'hide' => array(),
|
| 991 |
),
|
| 992 |
);
|
| 993 |
|
| 994 |
// Pull in user settings.
|
| 995 |
$variables['location_settings_user'] = $base;
|
| 996 |
$tmp = &$variables['location_settings_user'];
|
| 997 |
// Users previously could not have multiple locations, initialize with those
|
| 998 |
// settings.
|
| 999 |
$tmp['multiple'] = array(
|
| 1000 |
'min' => 0,
|
| 1001 |
'max' => 1,
|
| 1002 |
'add' => 3,
|
| 1003 |
);
|
| 1004 |
$tmp['form']['weight'] = variable_get('location_user_weight', 9);
|
| 1005 |
$tmp['form']['collapsible'] = variable_get('location_user_collapsible', TRUE);
|
| 1006 |
$tmp['form']['collapased'] = variable_get('location_user_collapsed', TRUE);
|
| 1007 |
$tmp['form']['fields'] = variable_get('location_user_fields', array());
|
| 1008 |
|
| 1009 |
|
| 1010 |
// Pull in node settings.
|
| 1011 |
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_maxnum_%'");
|
| 1012 |
while ($row = db_fetch_object($result)) {
|
| 1013 |
$type = substr($row->name, 16);
|
| 1014 |
$todelete[] = $type;
|
| 1015 |
|
| 1016 |
$variables["location_settings_node_$type"] = $base;
|
| 1017 |
$tmp = &$variables["location_settings_node_$type"];
|
| 1018 |
|
| 1019 |
$tmp['multiple']['min'] = 1; // Old behavior was to have the first one be required.
|
| 1020 |
$tmp['multiple']['max'] = variable_get("location_maxnum_$type", 0);
|
| 1021 |
$tmp['multiple']['add'] = variable_get("location_defaultnum_$type", 3);
|
| 1022 |
$tmp['form']['weight'] = variable_get("location_weight_$type", 9);
|
| 1023 |
$tmp['form']['collapsible'] = variable_get("location_collapsible_$type", TRUE);
|
| 1024 |
$tmp['form']['collapsed'] = variable_get("location_collapsed_$type", TRUE);
|
| 1025 |
$tmp['form']['fields'] = variable_get("location_fields_$type", array());
|
| 1026 |
$tmp['rss']['mode'] = variable_get("location_rss_$type", 'simple');
|
| 1027 |
$tmp['display'] = variable_get("location_display_$type", array(
|
| 1028 |
'teaser' => TRUE,
|
| 1029 |
'full' => TRUE,
|
| 1030 |
'weight' => 0,
|
| 1031 |
'hide' => array(),
|
| 1032 |
));
|
| 1033 |
}
|
| 1034 |
|
| 1035 |
foreach ($variables as $name => $value) {
|
| 1036 |
variable_set($name, $value);
|
| 1037 |
}
|
| 1038 |
|
| 1039 |
// Delete old node variables.
|
| 1040 |
foreach ($todelete as $key) {
|
| 1041 |
// variable_del("location_maxnum_$key");
|
| 1042 |
// variable_del("location_defaultnum_$key");
|
| 1043 |
variable_del("location_weight_$key");
|
| 1044 |
variable_del("location_collapsible_$key");
|
| 1045 |
variable_del("location_collapsed_$key");
|
| 1046 |
variable_del("location_fields_$key");
|
| 1047 |
variable_del("location_rss_$key");
|
| 1048 |
variable_del("location_display_$key");
|
| 1049 |
}
|
| 1050 |
|
| 1051 |
// Delete old user variables.
|
| 1052 |
variable_del('location_user_weight');
|
| 1053 |
variable_del('location_user_collapsible');
|
| 1054 |
variable_del('location_user_collapsed');
|
| 1055 |
variable_del('location_user_fields');
|
| 1056 |
|
| 1057 |
return $ret;
|
| 1058 |
}
|
| 1059 |
|
| 1060 |
/**
|
| 1061 |
* Disabled due to some typos, moved to 6306.
|
| 1062 |
*/
|
| 1063 |
function location_update_6305() {
|
| 1064 |
return array();
|
| 1065 |
}
|
| 1066 |
|
| 1067 |
/**
|
| 1068 |
* Add per-location-field weights and defaults.
|
| 1069 |
*/
|
| 1070 |
function location_update_6306() {
|
| 1071 |
// Skip this update if it was already done on the 5.x side.
|
| 1072 |
if (variable_get('location_update_5306_done', FALSE)) {
|
| 1073 |
variable_del('location_update_5306_done');
|
| 1074 |
return array();
|
| 1075 |
}
|
| 1076 |
$ret = array();
|
| 1077 |
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_settings_%'");
|
| 1078 |
while ($row = db_fetch_object($result)) {
|
| 1079 |
$var = variable_get($row->name, array());
|
| 1080 |
$collect = $var['form']['fields'];
|
| 1081 |
$var['form']['fields'] = array();
|
| 1082 |
foreach ($collect as $k => $v) {
|
| 1083 |
$var['form']['fields'][$k]['collect'] = $v;
|
| 1084 |
}
|
| 1085 |
// Country 3 has changed to 4 to make requirements code easier.
|
| 1086 |
if (isset($var['form']['fields']['country']['collect']) && $var['form']['fields']['country']['collect'] == 3) {
|
| 1087 |
$var['form']['fields']['country']['collect'] = 4;
|
| 1088 |
}
|
| 1089 |
// Weight and default values don't need to get set for now.
|
| 1090 |
variable_set($row->name, $var);
|
| 1091 |
}
|
| 1092 |
return $ret;
|
| 1093 |
}
|
| 1094 |
|
| 1095 |
/**
|
| 1096 |
* I hate to waste a whole update on this, but people will need to know.
|
| 1097 |
*/
|
| 1098 |
function location_update_6307() {
|
| 1099 |
$ret = array();
|
| 1100 |
drupal_set_message(t("Note: Location module has now split off user location support into a seperate module, called <em>User Locations</em>. It has been enabled for you. If you don't want user locations, visit the <a href='!url'>modules page</a> and disable it.", array('!url' => url('admin/build/modules'))));
|
| 1101 |
if (module_exists('location')) {
|
| 1102 |
module_enable(array('location_user'));
|
| 1103 |
}
|
| 1104 |
else {
|
| 1105 |
drupal_set_message(t("Note: Refusing to enable location_user.module, as location.module is not currently enabled."));
|
| 1106 |
}
|
| 1107 |
return $ret;
|
| 1108 |
}
|
| 1109 |
|
| 1110 |
/**
|
| 1111 |
* Well, I do have 99 updates to use :P
|
| 1112 |
*/
|
| 1113 |
function location_update_6308() {
|
| 1114 |
$ret = array();
|
| 1115 |
drupal_set_message(t("Note: Location module has now split off node location support into a seperate module, called <em>Node Locations</em>. It has been enabled for you. If you don't want node locations, visit the <a href='!url'>modules page</a> and disable it.", array('!url' => url('admin/build/modules'))));
|
| 1116 |
if (module_exists('location')) {
|
| 1117 |
module_enable(array('location_node'));
|
| 1118 |
}
|
| 1119 |
else {
|
| 1120 |
drupal_set_message(t("Note: Refusing to enable location_node.module, as location.module is not currently enabled."));
|
| 1121 |
}
|
| 1122 |
return $ret;
|
| 1123 |
}
|
| 1124 |
|
| 1125 |
/**
|
| 1126 |
* 7.x update 1
|
| 1127 |
*/
|
| 1128 |
/*
|
| 1129 |
function location_update_7000() {
|
| 1130 |
$ret = array();
|
| 1131 |
// This went away because core now has site_default_country.
|
| 1132 |
variable_del('location_default_country');
|
| 1133 |
|
| 1134 |
return $ret;
|
| 1135 |
}
|
| 1136 |
*/
|