Newer
Older
* Install, update and uninstall functions for the location module.
*/
/**
* Implentation of hook_uninstall().
*/
function location_uninstall() {
// Delete variables.
variable_del('location_default_country');
variable_del('location_display_location');
variable_del('location_usegmap');
Brandon Bergren
committed
variable_del('location_locpick_macro');
// Delete geocoder settings.
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_geocode_%'")->fetchCol();
foreach ($result as $var) {
variable_del($var);
Brandon Bergren
committed
}
/**
* Implementation of hook_schema().
*/
function location_schema() {
$schema['location'] = array(
'description' => 'Locational data managed by location.module.',
'fields' => array(
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
'lid' => array(
'description' => 'Primary Key: Unique location ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'name' => array(
'description' => 'Place Name.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => TRUE,
),
'street' => array(
'description' => 'Street address, line 1.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => TRUE,
),
'additional' => array(
'description' => 'Street address, line 2.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => TRUE,
),
'city' => array(
'description' => 'City.',
'type' => 'varchar',
'length' => 255,
'default' => '',
'not null' => TRUE,
),
'province' => array(
'description' => 'State / Province code.',
'type' => 'varchar',
'length' => 16,
'default' => '',
'not null' => TRUE,
),
'postal_code' => array(
'description' => 'Postal / ZIP code.',
'type' => 'varchar',
'length' => 16,
'default' => '',
'not null' => TRUE,
),
'country' => array(
'description' => 'Two letter ISO country code.',
'type' => 'char',
'length' => 2,
'not null' => TRUE,
'default' => '',
),
'latitude' => array(
'description' => 'Location latitude (decimal degrees).',
'type' => 'numeric',
'precision' => 10,
'scale' => 6, // @@@ Shouldn't these all be 7?
'not null' => TRUE,
'default' => 0.0,
),
'longitude' => array(
'description' => 'Location longitude (decimal degrees).',
'type' => 'numeric',
'precision' => 10,
'scale' => 6,
'not null' => TRUE,
'default' => 0.0,
),
'source' => array(
'description' => 'Source of the latitude and longitude data (Geocoder, user entered, invalid, etc.)',
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
),
// @@@ Historical civicrm field that isn't applicable to location, I think..
'is_primary' => array(
'description' => 'Is this the primary location of an object? (unused, civicrm legacy field?).',
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
),
),
'primary key' => array('lid'),
);
$schema['location_instance'] = array(
'description' => 'N:M join table to join locations to other tables.',
'fields' => array(
'nid' => array(
'description' => 'Reference to {node}.nid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'vid' => array(
Reuben Turk
committed
'description' => 'Reference to {node_revision}.vid.',
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
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => 'Reference to {users}.uid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'genid' => array(
'description' => 'Generic reference key.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'lid' => array(
'description' => 'Reference to {location}.lid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'nid' => array('nid'),
'vid' => array('vid'),
'uid' => array('uid'),
'genid' => array('genid'),
'lid' => array('lid'),
),
);
$schema['zipcodes'] = array(
'description' => 'Location.module zipcode database.',
'fields' => array(
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
222
223
224
225
226
227
228
229
230
'zip' => array(
'description' => 'Postal / ZIP code.',
'type' => 'varchar',
'length' => 16,
'not null' => TRUE,
'default' => '0', // @@@ Why?
),
'city' => array(
'description' => 'City.',
'type' => 'varchar',
'length' => 30,
'not null' => TRUE,
'default' => '',
),
'state' => array(
'description' => 'Province / State.',
'type' => 'varchar',
'length' => 30,
'not null' => TRUE,
'default' => '',
),
'latitude' => array(
'description' => 'Location latitude (decimal degrees).',
'type' => 'numeric',
'precision' => 10,
'scale' => 6,
'not null' => TRUE,
'default' => 0.0,
),
'longitude' => array(
'description' => 'Location longitude (decimal degrees).',
'type' => 'numeric',
'precision' => 10,
'scale' => 6,
'not null' => TRUE,
'default' => 0.0,
),
// @@@ Not used, an artifact of the original data dump format.
'timezone' => array(
'description' => 'Timezone (unused).',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
// @@@ Not used, an artifact of the original data dump format.
'dst' => array(
'description' => 'Daylight Savings Time (unused).',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'country' => array(
'description' => 'Two letter ISO country code.',
'type' => 'char',
'length' => 2,
'not null' => TRUE,
'default' => '',
),
),
// @@@ This pk is invalid, see issue queue.
//'primary key' => array('country', 'zip'),
// @@@ These need reworked.
'indexes' => array(
'pc' => array('country', 'zip'),
'zip' => array('zip'),
// @@@ No combined one?
'latitude' => array('latitude'),
'longitude' => array('longitude'),
'country' => array('country'),
),
);
// Copied from system.module.
$schema['cache_location'] = array(
'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
'fields' => array(
'cid' => array(
'description' => 'Primary Key: Unique cache ID.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''),
'data' => array(
'description' => 'A collection of data to cache.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big'),
'expire' => array(
'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
'type' => 'int',
'not null' => TRUE,
'default' => 0),
'created' => array(
'description' => 'A Unix timestamp indicating when the cache entry was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0),
'headers' => array(
'description' => 'Any custom HTTP headers to be added to cached data.',
'type' => 'text',
'not null' => FALSE),
'serialized' => array(
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0)
),
'indexes' => array('expire' => array('expire')),
'primary key' => array('cid'),
);
return $schema;
}
/**
* Legacy update 1.
* Convert tables to utf8.
*/
// return _system_update_utf8(array('location', 'zipcodes'));
Ankur Rishi
committed
/**
* Legacy update 2.
* Fix a bug with the "us" entry in the "location_configured_countries" var.
*/
Ankur Rishi
committed
function location_update_2() {
$configured_countries = variable_get('location_configured_countries', array());
if ($configured_countries['us']) {
$configured_countries['us'] = 'us';
variable_set('location_configured_countries', $configured_countries);
}
Ankur Rishi
committed
}
/**
* Legacy update 3.
* Allow for postgresql support by renaming the oid column, which is a reserved
* name on postgresql.
*/
function location_update_3() {
db_change_field('location', 'oid', 'eid', array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
));
if (module_exists('views')) {
views_invalidate_cache();
}
return t("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.");
}
/***************************************************************
PostgreSQL must be supported in all updates after this comment
***************************************************************/
/**
* Legacy update 4.
* Add "lid" as the new location key.
*/
function location_update_4() {
db_add_field('location', 'lid', array(
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Primary Key: Unique location ID.',
));
$result = db_query("SELECT eid, type FROM {location}");
$next_id = 0;
foreach ($result as $row) {
$next_id++;
db_update('location')
->fields(array(
'lid' => $next_id,
))
->condition('eid', $row->eid)
->condition('type', $row->type)
->execute();
}
db_drop_primary_key('location');
db_add_primary_key('location', array('lid'));
db_insert('sequences')
->fields(array(
'name' => '{location}_lid',
'id' => $next_id,
))
->execute();
db_add_field('location', 'is_primary', array(
'description' => 'Is this the primary location of an object? (unused, civicrm legacy field?).',
'type' => 'int',
'size' => 'tiny',
'default' => 0,
'not null' => TRUE,
));
db_update('location')
->fields(array(
'is_primary' => 1,
))
->condition('type', 'user')
->execute();
foreach (node_type_get_types() as $type) {
$new_setting = variable_get('location_' . $type->type, 0) ? 1 : 0;
variable_del('location_' . $type->type);
variable_set('location_maxnum_' . $type->type, $new_setting);
variable_set('location_defaultnum_' . $type->type, $new_setting);
}
}
/**
* Legacy update 5.
* Postgresql support that was missing from previous update.
*
* This update is redundant now that we have db api functions
* that are database independant.
function location_update_5() {
}
/**
* Legacy update 6.
* Use correct country code for Sweeden.
*/
function location_update_6() {
db_update('location')
->fields(array(
'country' => 'se',
))
->condition('country', 'sw')
->execute();
/**
* Update 7 (Location 2.x)
* Generalize google geocoding so you don't have to enter the api key over and over.
*/
function location_update_7() {
$services = array('google');
$general_geocoders_in_use = array();
$result = db_query("SELECT * FROM {variable} WHERE name REGEXP '^location_geocode_[a-z][a-z]$'");
foreach ($result as $row) {
$value_decoded = unserialize($row->value);
if (!in_array($value_decoded, $services)) {
db_update('variable')
->fields(array(
'value' => serialize($value_decoded . '|' . substr($row->name, 17)),
))
->condition('name', $row->name)
->execute();
}
else {
$general_geocoders_in_use[$value_decoded] = $value_decoded;
}
}
$key = db_query("SELECT value FROM {variable} WHERE name REGEXP '^location_geocode_[a-z][a-z]_google_apikey$'")->fetchField();
Reuben Turk
committed
->where("name REGEXP '^location_geocode_[a-z][a-z]_google_apikey$'")
db_insert('variable')
->fields(array(
'name' => 'location_geocode_google_apikey',
'value' => $key,
))
->execute();
db_delete('cache')
->condition('cid', 'variables')
->execute();
variable_set('location_general_geocoders_in_use', $general_geocoders_in_use);
/**
* Location 3.x update 1.
* Add location specific cache table.
*/
function location_update_5300() {
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
$schema['cache_location'] = array(
'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
'fields' => array(
'cid' => array(
'description' => 'Primary Key: Unique cache ID.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'data' => array(
'description' => 'A collection of data to cache.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big',
),
'expire' => array(
'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'created' => array(
'description' => 'A Unix timestamp indicating when the cache entry was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
'headers' => array(
'description' => 'Any custom HTTP headers to be added to cached data.',
'type' => 'text',
'not null' => FALSE,
),
),
'indexes' => array('expire' => array('expire')),
'primary key' => array('cid'),
);
db_create_table('cache_location', $schema['cache_location']);
/**
* Location 3.x update 2.
* Normalize the location table.
* This allows:
* - Making the loading and saving code cleaner.
* - Fixing a longstanding bug with revisions.
* - Having the same location on multiple nodes/users/both.
* - Garbage collecting unused locations periodically.
* - Having full support for deletions.
* - Full revisions support.
* Note that the location_instance table does NOT have a primary key.
* This is on purpose. It's a N:M join table.
*/
function location_update_5301() {
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
$schema['location_instance'] = array(
'description' => 'N:M join table to join locations to other tables.',
'fields' => array(
'nid' => array(
'description' => 'Reference to {node}.nid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'vid' => array(
'description' => 'Reference to {node_revision}.vid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'uid' => array(
'description' => 'Reference to {users}.uid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'genid' => array(
'description' => 'Generic reference key.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
),
'lid' => array(
'description' => 'Reference to {location}.lid.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'nid' => array('nid'),
'vid' => array('vid'),
'uid' => array('uid'),
'genid' => array('genid'),
'lid' => array('lid'),
),
);
db_create_table('location_instance', $schema['location_instance']);
// Synthesise node location data based on what we have.
// Storage of locations was previously stored against node revision, BUT the
// data was not properly duplicated by revision (i.e. only the latest revision
// carried the data.)
// Joining like this allows us to backfill all the old revisions with the current
// data, which is not nice but better than having no data at all when viewing
// old revisions.
Reuben Turk
committed
$query = db_select('node_revision', 'nr');
$query->join('node_revision', 'nr2', 'nr.nid = nr2.nid');
$query->join('location', 'l', "nr2.vid = l.eid AND l.type = 'node'");
$query->addField('nr', 'nid');
$query->addField('nr', 'vid');
$query->addField('l', 'lid');
Reuben Turk
committed
db_insert('location_instance')
->fields(array('nid', 'vid', 'lid'))
->from($query)
->execute();
// Users is much simpler.
Reuben Turk
committed
$query = db_select('location', 'l');
$query->addField('l', 'eid');
$query->addField('l', 'lid');
$query->condition('type', 'user');
Reuben Turk
committed
db_insert('location_instance')
->fields(array('uid', 'lid'))
// Aug 18 2008:
// Save everything else in genid.
Reuben Turk
committed
$query = db_select('location', 'l');
$query->addExpression("CONCAT(l.type, ':', l.eid)");
$query->addField('l', 'lid');
$query->condition('type', 'user', '<>');
$query->condition('type', 'node', '<>');
Reuben Turk
committed
db_insert('location_instance')
->fields(array('genid', 'lid'))
->from($query)
->execute();
// Remove now unused columns.
Reuben Turk
committed
db_drop_field('location', 'type');
db_drop_field('location', 'eid');
// General cleanup.
variable_del('location_user'); // Removed in favor of permission check.
// Variable consolidation (as part of the element based system)
// We're doing this "raw" so we can be sure we got everything moved over,
// INCLUDING content types that were deleted in the past.
// This will let us do better cleanup sometime in the future.
$data = array();
$todelete = array();
foreach(array('name', 'street', 'additional', 'city', 'province', 'postal_code', 'country', 'phone', 'fax') as $field) {
Reuben Turk
committed
$result = db_query("SELECT name, value FROM {variable} WHERE name > :name", array(':name' => "location_$field%"));
foreach ($result as $row) {
$data[substr($row->name, strlen($field) + 10)][$field] = (string)(int)unserialize($row->value);
$todelete[] = $row->name;
}
foreach ($data as $type => $value) {
// We aren't going to trust that hook_locationapi is operational.
// So, stick with some conservative defaults.
$value = array_merge(array(
'name' => '1',
'street' => '1',
// additional is left out of this list intentionally.
'city' => '0',
'province' => '0',
'postal_code' => '0',
'country' => '1',
), $value);
if (!isset($value['additional'])) {
// Initialize additional to match street.
$value['additional'] = $value['street'];
variable_set('location_fields_'. $type, $value);
}
foreach ($todelete as $key) {
variable_del($key);
// This update was retrofitted on Aug 18, 2008. Set a flag for use by
// the next update in order to handle the case where someone has already
// updated to EXACTLY schema revision 5301 before the retrofit took effect.
// People who migrated past this point before that date may have the following
// inconsistencies:
// A) location_{field}_{type} variables were not collected for content types
// that had been deleted in the past.
// B) Any locations with the 'type' field set to something other than 'node'
// or 'user' did not get entries in {location_instance}.
variable_set('location_update_5301_retrofit', TRUE);
Brandon Bergren
committed
/**
* Location 3.x update 3.
* Add genid to {location_instance}.
*/
function location_update_5302() {
// OK, here's the deal. I retrofitted 5301 on Aug 18 2008 to integrate the genid.
// This was needed to fix the pre location 3.x todo item regarding keeping non
// user, non node data intact. People doing an update after Aug 18 will already
// have the genid column in place, so it can be safely skipped.
if (!variable_get('location_update_5301_retrofit', FALSE)) {
Reuben Turk
committed
db_add_field('location_instance', 'genid', array(
'description' => 'Generic reference key.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
));
db_add_index('location_instance', 'genid', array('genid'));
Brandon Bergren
committed
}
}
/**
* Location 3.x update 4.
* Shuffle more variables around.
*/
function location_update_5303() {
$types = array();
$result = db_query("SELECT name FROM {variable} WHERE name LIKE 'location_display_teaser_%'");
Reuben Turk
committed
foreach ($result as $row) {
$type = substr($row->name, 24);
$types[$type]['teaser'] = variable_get('location_display_teaser_'. $type, TRUE);
$types[$type]['full'] = variable_get('location_display_full_'. $type, TRUE);
$types[$type]['weight'] = variable_get('location_display_weight_'. $type, 0);
// @@@ Combine location_suppress_country and country require settings to set this up?
$types[$type]['hide'] = array();
}
foreach ($types as $type => $value) {
variable_set("location_display_$type", $value);
variable_del("location_display_teaser_$type");
variable_del("location_display_full_$type");
variable_del("location_display_weight_$type");
}
}
// @@@ Does 5303 need rerun in some circumstances?
/**
* Drupal 6 location 3.x update.
*/
function location_update_6301() {
Reuben Turk
committed
$message = '';
db_drop_table('cache_location');
'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.',
'description' => 'Primary Key: Unique cache ID.',
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => ''),
'data' => array(
'description' => 'A collection of data to cache.',
'type' => 'blob',
'not null' => FALSE,
'size' => 'big'),
'expire' => array(
'description' => 'A Unix timestamp indicating when the cache entry should expire, or 0 for never.',
'type' => 'int',
'not null' => TRUE,
'default' => 0),
'created' => array(
'description' => 'A Unix timestamp indicating when the cache entry was created.',
'type' => 'int',
'not null' => TRUE,
'default' => 0),
'headers' => array(
'description' => 'Any custom HTTP headers to be added to cached data.',
'type' => 'text',
'not null' => FALSE),
'serialized' => array(
'description' => 'A flag to indicate whether content is serialized (1) or not (0).',
'type' => 'int',
'size' => 'small',
'not null' => TRUE,
'default' => 0)
),
'indexes' => array('expire' => array('expire')),
'primary key' => array('cid'),
);
db_create_table('cache_location', $schema['cache_location']);
// LID 0 causes all sorts of issues, and will break our update routine
// unless we handle it beforehand.
// Since we're so nice, we're gonna renumber it for the user.
Reuben Turk
committed
$has_rows = (bool) db_query_range('SELECT 1 FROM {location} WHERE lid = 0', 0, 1)->fetchField();
if ($has_rows) {
$lid = 1 + db_query('SELECT MAX(lid) FROM {location}')->fetchField();
$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));
Reuben Turk
committed
db_update('location')
->fields(array(
'lid' => $lid,
))
->condition('lid', 0)
->execute();
db_update('location_instance')
->fields(array(
'lid' => $lid,
))
->condition('lid', 0)
->execute();
}
// Field changes
// {location}
// {location}.lid -- Becomes a serial.
db_drop_primary_key('location');
db_change_field('location', 'lid', 'lid',
array('type' => 'serial', 'unsigned' => TRUE, 'not null' => TRUE),
array('primary key' => array('lid')));
Brandon Bergren
committed
// (The rest of the changes to this table were moved to update 6302 due to a bug.)
// {location_instance}
// Fix oddly named indexes -- Was using the postgresql method for both.
Reuben Turk
committed
db_drop_index('location_instance', '{location_instance}_nid_idx');
db_drop_index('location_instance', '{location_instance}_vid_idx');
db_drop_index('location_instance', '{location_instance}_uid_idx');
db_drop_index('location_instance', '{location_instance}_genid_idx');
db_drop_index('location_instance', '{location_instance}_lid_idx');
db_drop_index('location_instance', 'nid');
db_drop_index('location_instance', 'vid');
db_drop_index('location_instance', 'uid');
db_drop_index('location_instance', 'genid');
db_drop_index('location_instance', 'lid');
Reuben Turk
committed
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
db_update('location_instance')
->fields(array(
'nid' => 0,
))
->isNull('nid')
->execute();
db_update('location_instance')
->fields(array(
'vid' => 0,
))
->isNull('vid')
->execute();
db_update('location_instance')
->fields(array(
'uid' => 0,
))
->isNull('uid')
->execute();
db_update('location_instance')
->fields(array(
'genid' => 0,
))
->isNull('genid')
->execute();
db_change_field('location_instance', 'nid', 'nid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
db_change_field('location_instance', 'vid', 'vid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
db_change_field('location_instance', 'uid', 'uid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
db_change_field('location_instance', 'genid', 'genid', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
db_change_field('location_instance', 'lid', 'lid', array('type' => 'int', 'unsigned' => TRUE, 'not null' => TRUE, 'default' => 0));
db_add_index('location_instance', 'nid', array('nid'));
db_add_index('location_instance', 'vid', array('vid'));
db_add_index('location_instance', 'uid', array('uid'));
db_add_index('location_instance', 'genid', array('genid'));
db_add_index('location_instance', 'lid', array('lid'));
db_drop_primary_key('zipcodes');
Reuben Turk
committed
if ($message) {
$message .= '<br /><br />';
}
return $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.');
Brandon Bergren
committed
/**
* Drupal 6 location 3.x update, part 2.
*/
function location_update_6302() {
// OK, here's the update to fix the previous update which had a few problems
// when upgrading from pre-rc 6.x versions.
// The "mismatch between mysql and postgresql" was actually applicable to
// 6.x-3.0 pre-rc1 as well, but I didn't notice because I accidentally added
// the not null when reformatting the schema.
Reuben Turk
committed
db_update('location')
->fields(array(
'is_primary' => 0,
))
->isNull('is_primary')
->execute();
db_change_field('location', 'is_primary', 'is_primary', array('type' => 'int', 'size' => 'tiny', 'default' => 0, 'not null' => TRUE));
Brandon Bergren
committed
// Fix zipcode mismatches caused by the same problem.
// There shouldn't be any rows like this, but it doesn't hurt to be sure.
Reuben Turk
committed
db_update('zipcodes')
->fields(array(
'zip' => 0,
))
->isNull('zip')
->execute();
Brandon Bergren
committed
// Set not null.
db_change_field('zipcodes', 'zip', 'zip', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => '0'));
Brandon Bergren
committed
// Prepare latitude and longitude for the same.
Reuben Turk
committed
db_update('zipcodes')
->fields(array(
'latitude' => 0.0,
))
->isNull('latitude')
->execute();
db_update('zipcodes')
->fields(array(
'longitude' => 0.0,
))
->isNull('longitude')
->execute();
Brandon Bergren
committed
// Set not null.
db_change_field('zipcodes', 'latitude', 'latitude', array('type' => 'numeric', 'not null' => TRUE, 'default' => 0, 'precision' => 10, 'scale' => 6));
db_change_field('zipcodes', 'longitude', 'longitude', array('type' => 'numeric', 'not null' => TRUE, 'default' => 0, 'precision' => 10, 'scale' => 6));
Brandon Bergren
committed
// Prepare country.
update_sql("UPDATE {zipcodes} SET country = '' WHERE country IS NULL");
Reuben Turk
committed
db_update('zipcodes')
->fields(array(
'country' => '',
))
->isNull('country')
->execute();
Brandon Bergren
committed
// Set not null.
db_change_field('zipcodes', 'country', 'country', array('type' => 'char', 'length' => 2, 'not null' => TRUE, 'default' => ''));
Brandon Bergren
committed
// Fix up possible {location} problems from previous update that could be caused if you had NULLed fields.
// Set defaults
Reuben Turk
committed
$fields = array(
'name' => '',
'street' => '',
'additional' => '',
'city' => '',
'province' => '',
'postal_code' => '',
'latitude' => 0.0,
'longitude' => 0.0,
'source' => 0,
);
foreach ($fields as $field => $value) {
db_update('location')
->fields(array(
$field => $value,
))
->isNull($field)
->execute();
}
Brandon Bergren
committed
// {location}.name -- NOT NULL
db_change_field('location', 'name', 'name', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
Brandon Bergren
committed
// {location}.street -- NOT NULL
db_change_field('location', 'street', 'street', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
Brandon Bergren
committed
// {location}.additional -- NOT NULL
db_change_field('location', 'additional', 'additional', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
Brandon Bergren
committed
// {location}.city -- NOT NULL
db_change_field('location', 'city', 'city', array('type' => 'varchar', 'length' => 255, 'not null' => TRUE, 'default' => ''));
Brandon Bergren
committed
// {location}.province -- NOT NULL
db_change_field('location', 'province', 'province', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''));
Brandon Bergren
committed
// {location}.postal_code -- NOT NULL
db_change_field('location', 'postal_code', 'postal_code', array('type' => 'varchar', 'length' => 16, 'not null' => TRUE, 'default' => ''));
Brandon Bergren
committed
// {location}.country -- NOT NULL
db_change_field('location', 'country', 'country', array('type' => 'char', 'length' => 2, 'not null' => TRUE, 'default' => ''));
Brandon Bergren
committed
// {location}.latitude
db_change_field('location', 'latitude', 'latitude', array('type' => 'numeric', 'precision' => 10, 'scale' => 6, 'not null' => TRUE, 'default' => 0.0));
Brandon Bergren
committed
// {location}.longitude
db_change_field('location', 'longitude', 'longitude', array('type' => 'numeric', 'precision' => 10, 'scale' => 6, 'not null' => TRUE, 'default' => 0.0));
Brandon Bergren
committed
// {location}.source
db_change_field('location', 'source', 'source', array('type' => 'int', 'size' => 'tiny', 'not null' => TRUE, 'default' => 0));
Brandon Bergren
committed
}
/**
* Drupal 6 location 3.x update, part 3.
*/
function location_update_6303() {
if (!variable_get('location_update_5304_done', FALSE)) {
// Do the same updates as 5304.
// Delete unused variables.
variable_del('location_configured_countries');
variable_del('location_garbagecollect');
// Update province code for Italy/Forlì-Cesena.
Reuben Turk
committed
db_update('location')
->fields(array(
'province' => 'FC',
))
->condition('country', 'it')
->condition('province', 'FO')
->execute();
// Update province code for Italy/Pesaro e Urbino.