function location_update_4 in Location 7.3
Same name and namespace in other branches
- 5.3 location.install \location_update_4()
- 5 location.install \location_update_4()
- 6.3 location.install \location_update_4()
- 7.5 location.install \location_update_4()
- 7.4 location.install \location_update_4()
Legacy update 4.
Add "lid" as the new location key.
File
- ./
location.install, line 381 - Install, update and uninstall functions for the location module.
Code
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);
}
}