'',
1 => 'Mid 4.6 upgrade -- Merge location_user and location_node tables into location',
2 => "Mid 4.6 upgrade II -- Rename column 'exact' to 'source'",
3 => "Correction to zipcode data"
);
if (!ini_get("safe_mode")) {
set_time_limit(180);
}
function location_upgrade_page_header($title) {
$output = "
$title";
$output .= <<
EOF;
$output .= "";
$output .= "";
$output .= "$title
";
return $output;
}
function location_upgrade_page_footer() {
return "";
}
function location_upgrade_page() {
global $user, $sql_updates;
if (isset($_POST['edit'])) {
$edit = $_POST['edit'];
}
if (isset($_POST['op'])) {
$op = $_POST['op'];
}
switch ($op) {
case "Update":
$edit = $_POST['edit'];
if (!isset($edit['location_update_version']) || $edit['location_update_version'] == 0) {
//*****************************
$form = form_select('Select the update after your most recent update', 'location_update_version', '', $sql_updates, 'Please select what you think was the last update for this module. If you\'re not sure of what your last update was, it is better to select one that is older than what you think than to select one that is newer. Updates that are too old for you will fail while the newer ones will still execute.');
$form .= form_submit('Update');
$form = form($form);
print location_upgrade_page_header('location.module database update');
print location_upgrade_info();
print 'You need to select your last update first!'."
\n";
print $form;
print location_upgrade_page_footer();
break;
//*****************************
}
else {
// make sure we have updates to run.
print location_upgrade_page_header("location.module database update");
$links[] = "main page";
$links[] = "administration pages";
print theme("item_list", $links);
location_upgrade($edit['location_update_version']);
print location_upgrade_page_footer();
}
break;
default:
$form = form_select('Select the update after your most recent update.', 'location_update_version', '', array_merge(array('' => ''), $sql_updates), 'Please select what you think was the last update for this module. If you\'re not sure of what your last update was, it is better to select one that is older than what you think than to select one that is newer. Updates that are too old for you will fail while the newer ones will still execute.');
$form .= form_submit('Update');
$form = form($form);
print location_upgrade_page_header('location.module database update');
print location_upgrade_info();
print $form;
print location_upgrade_page_footer();
break;
}
}
function location_upgrade($update_n) {
global $base_url, $sql_updates;
$update_keys = array_keys($sql_updates);
$number = $update_n;
while (in_array($number, $update_keys)) {
print "PERFORMING UPDATE:
\n";
print ' '. $sql_updates[$number] ."
\n
\n";
$function = 'location_update_'. $number;
$function();
$number++;
}
}
function location_upgrade_info() {
$output = "\n";
$output .= "- Use this script to update the database schema for changes to the location module. You don't need this script when installing the location.module from scratch.
"."\n";
$output .= "
"."\n";
return $output;
}
if (isset($_GET["op"])) {
// Access check:
if (($access_check == 0) || ($user->uid == 1)) {
location_upgrade_page();
}
else {
print location_upgrade_page_header("Access denied");
print "Access denied. You are not authorized to access to this page. Please log in as the user with user ID #1. If you cannot log-in, you will have to edit modules/location/location_upgrade.php
to by-pass this access check; in that case, open modules/location/location_upgrade.php
in a text editor and follow the instructions at the top.";
print location_upgrade_page_footer();
}
}
else {
//location_upgrade_info();
location_upgrade_page();
}
function location_update_1() {
db_query("ALTER TABLE {location_node} ADD type varchar(6) NOT NULL DEFAULT ''");
db_query("UPDATE {location_node} SET type = 'node'");
db_query("ALTER TABLE {location_node} DROP PRIMARY KEY");
db_query("ALTER TABLE {location_node} CHANGE nid oid int(10) unsigned NOT NULL default '0'");
db_query("ALTER TABLE {location_node} ADD PRIMARY KEY (type, oid)");
$result = db_query("SELECT * FROM {location_user}");
while ($row = db_fetch_object($result)) {
db_query("INSERT INTO {location_node} (oid, name, street, additional, city, province, postal_code, country, latitude, longitude, exact, type) VALUES (%d, '%s', '%s', '%s', '%s', '%s', '%s', '%s', '%f', '%f', %d, 'user')", $row->uid, $row->name, $row->street, $row->additional, $row->city, $row->province, $row->postal_code, $row->country, $row->latitude, $row->longitude, $row->exact, $row->type);
}
db_query("RENAME TABLE {location_node} TO {location}");
}
function location_update_2() {
db_query("ALTER TABLE {location} CHANGE COLUMN exact source tinyint(4) default '0'");
}
function location_update_3() {
db_query("UPDATE {zipcodes} SET city = 'North Plainfield' WHERE country = 'us' AND zip = '07060'");
}
?>