From fa2581edcfa52c847db93a9421de5216fb0072f6 Mon Sep 17 00:00:00 2001 From: Dries Buytaert Date: Wed, 1 Oct 2003 05:18:03 +0000 Subject: [PATCH] - Modifies path.module to get rid of pgsql reserved word. Patch by Adrian. - Updates database.pgsql and database.mysql to work with current cvs. Patch by Adrian. - Updates update.php to be able to update postgres from 4.2 to current. Patch by Adrian. - Small fixes by me. --- database/database.mysql | 8 +++--- database/database.pgsql | 19 +++++++++++--- includes/common.inc | 2 +- includes/database.inc | 1 + modules/path.module | 56 ++++++++++++++++++++-------------------- modules/path/path.module | 56 ++++++++++++++++++++-------------------- update.php | 48 +++++++++++++++++++++++----------- 7 files changed, 110 insertions(+), 80 deletions(-) diff --git a/database/database.mysql b/database/database.mysql index ce823b2c19b..3f262af343b 100644 --- a/database/database.mysql +++ b/database/database.mysql @@ -307,11 +307,11 @@ CREATE TABLE page ( CREATE TABLE path ( pid int(10) unsigned NOT NULL auto_increment, - old varchar(128) NOT NULL default '', - new varchar(128) NOT NULL default '', + src varchar(128) NOT NULL default '', + dst varchar(128) NOT NULL default '', PRIMARY KEY (pid), - UNIQUE KEY new (new), - UNIQUE KEY old (old) + UNIQUE KEY dst (dst), + UNIQUE KEY src (src) ) TYPE=MyISAM; -- diff --git a/database/database.pgsql b/database/database.pgsql index 3e2d3183b97..fd1ef5f862e 100644 --- a/database/database.pgsql +++ b/database/database.pgsql @@ -263,7 +263,6 @@ CREATE TABLE node ( nid SERIAL, type varchar(16) NOT NULL default '', title varchar(128) NOT NULL default '', - path varchar(250) NULL default '', score integer NOT NULL default '0', votes integer NOT NULL default '0', uid integer NOT NULL default '0', @@ -281,12 +280,11 @@ CREATE TABLE node ( static integer NOT NULL default '0', PRIMARY KEY (nid) ); -CREATE INDEX node_type_idx ON node(type(4)); -CREATE INDEX node_title_idx ON node(title,type(4)); +CREATE INDEX node_type_idx ON node(type); +CREATE INDEX node_title_idx ON node(title,type); CREATE INDEX node_status_idx ON node(status); CREATE INDEX node_uid_idx ON node(uid); CREATE INDEX node_moderate_idx ON node (moderate); -CREATE INDEX node_path_idx ON node (path(8)); CREATE INDEX node_promote_status_idx ON node (promote, status); -- @@ -302,6 +300,19 @@ CREATE TABLE page ( ); CREATE INDEX page_nid_idx ON page(nid); +-- +-- Table structure for table 'path' +-- + +CREATE TABLE path ( + pid integer NOT NULL default '0', + dst varchar(128) NOT NULL default '', + src varchar(128) NOT NULL default '', + PRIMARY KEY (pid) +); +CREATE INDEX path_src_idx ON path(src); +CREATE INDEX path_dst_idx ON path(dst); + -- -- Table structure for permission -- diff --git a/includes/common.inc b/includes/common.inc index a1ad701aa85..475c72c2b49 100644 --- a/includes/common.inc +++ b/includes/common.inc @@ -34,7 +34,7 @@ function get_url_map() { if (empty($map)) { $result = db_query("SELECT * FROM {path}"); while ($data = db_fetch_object($result)) { - $map[$data->new] = $data->old; + $map[$data->dst] = $data->src; } } diff --git a/includes/database.inc b/includes/database.inc index db6e4e17f0a..52851a6b730 100644 --- a/includes/database.inc +++ b/includes/database.inc @@ -29,4 +29,5 @@ else { db_connect($db_url); + ?> diff --git a/modules/path.module b/modules/path.module index df599eb6890..fdd597d9b38 100644 --- a/modules/path.module +++ b/modules/path.module @@ -23,7 +23,7 @@ function path_admin() { case t("delete"): if ($edit["confirm"]) { if (path_delete($edit['pid'])) { - $output .= status("Deleted path '". $edit['new'] ."'"); + $output .= status("Deleted path '". $edit['dst'] ."'"); } } else { @@ -36,7 +36,7 @@ function path_admin() { // fall-through default: - $output = path_overview(); + $output .= path_overview(); } return $output; @@ -85,12 +85,12 @@ function path_confirm_delete($id) { $form .= form_hidden("confirm", 1); $form .= form_hidden("pid", $id); - $form .= form_hidden("old", $path->old); - $form .= form_hidden("new", $path->new); + $form .= form_hidden("src", $path->src); + $form .= form_hidden("dst", $path->dst); $form .= form_submit(t("Delete")); $form .= form_submit(t("Cancel")); - return form(form_item(t("Delete alias '%new' that maps to '%old'", array("%new" => $path->new, "%old" => $path->old)), $form, t("Are you sure you want to delete this alias?"))); + return form(form_item(t("Delete alias '%dst' that maps to '%src'", array("%dst" => $path->dst, "%src" => $path->src)), $form, t("Are you sure you want to delete this alias?"))); } function path_delete($pid) { @@ -114,8 +114,8 @@ function path_help($section = "admin/path/help") { } function path_form($edit = "") { - $form .= form_textfield(t("Existing path"), "old", $edit["old"], 50, 64, t("Specify the existing path you wish to alias. For example: node/view/28, forum/1, taxonomy/page/or/1,2.")); - $form .= form_textfield(t("New path alias"), "new", $edit["new"], 50, 64, t("Specify an alternative path by which this data can be accessed. For example, type 'about' when writing an about page.")); + $form .= form_textfield(t("Existing path"), "src", $edit["src"], 50, 64, t("Specify the existing path you wish to alias. For example: node/view/28, forum/1, taxonomy/page/or/1,2.")); + $form .= form_textfield(t("New path alias"), "dst", $edit["dst"], 50, 64, t("Specify an alternative path by which this data can be accessed. For example, type 'about' when writing an about page.")); $form .= form_hidden("pid", $edit["pid"]); $form .= form_submit(t("Create new alias")); @@ -127,15 +127,15 @@ function path_form($edit = "") { } function path_insert($edit) { - return db_query("INSERT INTO {path} SET old = '%s', new = '%s'", $edit["old"], $edit["new"]); + return db_query("INSERT INTO {path} SET src = '%s', dst = '%s'", $edit["src"], $edit["dst"]); } # DELETE function path_is_unique($path, $type) { - if ($type == "new") { - return !(get_old_url($path)); + if ($type == "dst") { + return !(get_src_url($path)); } - elseif ($type == "old") { + elseif ($type == "src") { return !(get_url_alias($path)); } } @@ -154,15 +154,15 @@ function path_perm() { function path_overview() { $sql = "SELECT * FROM {path}"; $header = array( - array ("data" => t("alias"), "field" => "new", "sort" => "asc"), - array ("data" => t("maps to"), "field" => "old"), + array ("data" => t("alias"), "field" => "dst", "sort" => "asc"), + array ("data" => t("maps to"), "field" => "src"), array("data" => t("operations"), "colspan" => 2) ); $sql .= tablesort_sql($header); $result = pager_query($sql, 50); while ($data = db_fetch_object($result)) { - $rows[] = array($data->new, $data->old, l(t("edit"), "admin/path/edit/$data->pid"), l(t("delete"), "admin/path/delete/$data->pid")); + $rows[] = array($data->dst, $data->src, l(t("edit"), "admin/path/edit/$data->pid"), l(t("delete"), "admin/path/delete/$data->pid")); } $pager = pager_display(NULL, 50, 0, "admin", tablesort_pager()); @@ -174,33 +174,33 @@ function path_overview() { } function path_save($edit) { - $new = path_clean($edit["new"]); - $old = path_clean($edit["old"]); + $dst = path_clean($edit["dst"]); + $src = path_clean($edit["src"]); - if ($old == NULL || !valid_url($old)) { - return t("The specified path is not valid."); + if ($src == NULL || !valid_url($src)) { + return t("the specified path is not valid."); } - if (db_result(db_query("SELECT COUNT(old) FROM {path} WHERE old = '%s'", $old))) { - return t("The specified path is already aliased."); + if (db_result(db_query("SELECT COUNT(src) FROM {path} WHERE src = '%s'", $src))) { + return t("the specified path is already aliased."); } - if ($new == NULL || !valid_url($new)) { - return t("The specified path alias is not valid."); + if ($dst == NULL || !valid_url($dst)) { + return t("the specified path alias is not valid."); } - if (db_result(db_query("SELECT COUNT(new) FROM {path} WHERE new = '%s'", $new))) { - return t("The specified alias is already in use."); + if (db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s'", $dst))) { + return t("the specified alias is already in use."); } if ($edit["pid"]) { - path_update($old, $new); + path_update($src, $dst); } else { //Update the path path_insert($edit); } - return t("you may access %old via %new.", array("%old" => url($old), "%new" => l($new, url($new)))); + return t("you may access %src via %dst.", array("%src" => url($src), "%dst" => l($dst, url($dst)))); } function path_system($field) { @@ -212,10 +212,10 @@ function path_system($field) { function path_update($edit) { if ($edit["pid"]) { - return db_query("UPDATE {path} SET old = '%s', new = '%s' WHERE pid = '%d'", $edit["old"], $edit["new"], $edit["pid"]); + return db_query("UPDATE {path} SET src = '%s', dst = '%s' WHERE pid = '%d'", $edit["src"], $edit["dst"], $edit["pid"]); } else { // intended for nodes - return db_query("UPDATE {path} SET new = '%s' WHERE old = '%s'", $edit["new"], $edit["old"]); + return db_query("UPDATE {path} SET dst = '%s' WHERE src = '%s'", $edit["dst"], $edit["src"]); } } diff --git a/modules/path/path.module b/modules/path/path.module index df599eb6890..fdd597d9b38 100644 --- a/modules/path/path.module +++ b/modules/path/path.module @@ -23,7 +23,7 @@ function path_admin() { case t("delete"): if ($edit["confirm"]) { if (path_delete($edit['pid'])) { - $output .= status("Deleted path '". $edit['new'] ."'"); + $output .= status("Deleted path '". $edit['dst'] ."'"); } } else { @@ -36,7 +36,7 @@ function path_admin() { // fall-through default: - $output = path_overview(); + $output .= path_overview(); } return $output; @@ -85,12 +85,12 @@ function path_confirm_delete($id) { $form .= form_hidden("confirm", 1); $form .= form_hidden("pid", $id); - $form .= form_hidden("old", $path->old); - $form .= form_hidden("new", $path->new); + $form .= form_hidden("src", $path->src); + $form .= form_hidden("dst", $path->dst); $form .= form_submit(t("Delete")); $form .= form_submit(t("Cancel")); - return form(form_item(t("Delete alias '%new' that maps to '%old'", array("%new" => $path->new, "%old" => $path->old)), $form, t("Are you sure you want to delete this alias?"))); + return form(form_item(t("Delete alias '%dst' that maps to '%src'", array("%dst" => $path->dst, "%src" => $path->src)), $form, t("Are you sure you want to delete this alias?"))); } function path_delete($pid) { @@ -114,8 +114,8 @@ function path_help($section = "admin/path/help") { } function path_form($edit = "") { - $form .= form_textfield(t("Existing path"), "old", $edit["old"], 50, 64, t("Specify the existing path you wish to alias. For example: node/view/28, forum/1, taxonomy/page/or/1,2.")); - $form .= form_textfield(t("New path alias"), "new", $edit["new"], 50, 64, t("Specify an alternative path by which this data can be accessed. For example, type 'about' when writing an about page.")); + $form .= form_textfield(t("Existing path"), "src", $edit["src"], 50, 64, t("Specify the existing path you wish to alias. For example: node/view/28, forum/1, taxonomy/page/or/1,2.")); + $form .= form_textfield(t("New path alias"), "dst", $edit["dst"], 50, 64, t("Specify an alternative path by which this data can be accessed. For example, type 'about' when writing an about page.")); $form .= form_hidden("pid", $edit["pid"]); $form .= form_submit(t("Create new alias")); @@ -127,15 +127,15 @@ function path_form($edit = "") { } function path_insert($edit) { - return db_query("INSERT INTO {path} SET old = '%s', new = '%s'", $edit["old"], $edit["new"]); + return db_query("INSERT INTO {path} SET src = '%s', dst = '%s'", $edit["src"], $edit["dst"]); } # DELETE function path_is_unique($path, $type) { - if ($type == "new") { - return !(get_old_url($path)); + if ($type == "dst") { + return !(get_src_url($path)); } - elseif ($type == "old") { + elseif ($type == "src") { return !(get_url_alias($path)); } } @@ -154,15 +154,15 @@ function path_perm() { function path_overview() { $sql = "SELECT * FROM {path}"; $header = array( - array ("data" => t("alias"), "field" => "new", "sort" => "asc"), - array ("data" => t("maps to"), "field" => "old"), + array ("data" => t("alias"), "field" => "dst", "sort" => "asc"), + array ("data" => t("maps to"), "field" => "src"), array("data" => t("operations"), "colspan" => 2) ); $sql .= tablesort_sql($header); $result = pager_query($sql, 50); while ($data = db_fetch_object($result)) { - $rows[] = array($data->new, $data->old, l(t("edit"), "admin/path/edit/$data->pid"), l(t("delete"), "admin/path/delete/$data->pid")); + $rows[] = array($data->dst, $data->src, l(t("edit"), "admin/path/edit/$data->pid"), l(t("delete"), "admin/path/delete/$data->pid")); } $pager = pager_display(NULL, 50, 0, "admin", tablesort_pager()); @@ -174,33 +174,33 @@ function path_overview() { } function path_save($edit) { - $new = path_clean($edit["new"]); - $old = path_clean($edit["old"]); + $dst = path_clean($edit["dst"]); + $src = path_clean($edit["src"]); - if ($old == NULL || !valid_url($old)) { - return t("The specified path is not valid."); + if ($src == NULL || !valid_url($src)) { + return t("the specified path is not valid."); } - if (db_result(db_query("SELECT COUNT(old) FROM {path} WHERE old = '%s'", $old))) { - return t("The specified path is already aliased."); + if (db_result(db_query("SELECT COUNT(src) FROM {path} WHERE src = '%s'", $src))) { + return t("the specified path is already aliased."); } - if ($new == NULL || !valid_url($new)) { - return t("The specified path alias is not valid."); + if ($dst == NULL || !valid_url($dst)) { + return t("the specified path alias is not valid."); } - if (db_result(db_query("SELECT COUNT(new) FROM {path} WHERE new = '%s'", $new))) { - return t("The specified alias is already in use."); + if (db_result(db_query("SELECT COUNT(dst) FROM {path} WHERE dst = '%s'", $dst))) { + return t("the specified alias is already in use."); } if ($edit["pid"]) { - path_update($old, $new); + path_update($src, $dst); } else { //Update the path path_insert($edit); } - return t("you may access %old via %new.", array("%old" => url($old), "%new" => l($new, url($new)))); + return t("you may access %src via %dst.", array("%src" => url($src), "%dst" => l($dst, url($dst)))); } function path_system($field) { @@ -212,10 +212,10 @@ function path_system($field) { function path_update($edit) { if ($edit["pid"]) { - return db_query("UPDATE {path} SET old = '%s', new = '%s' WHERE pid = '%d'", $edit["old"], $edit["new"], $edit["pid"]); + return db_query("UPDATE {path} SET src = '%s', dst = '%s' WHERE pid = '%d'", $edit["src"], $edit["dst"], $edit["pid"]); } else { // intended for nodes - return db_query("UPDATE {path} SET new = '%s' WHERE old = '%s'", $edit["new"], $edit["old"]); + return db_query("UPDATE {path} SET dst = '%s' WHERE src = '%s'", $edit["dst"], $edit["src"]); } } diff --git a/update.php b/update.php index d2737518774..f954524a2c0 100644 --- a/update.php +++ b/update.php @@ -454,28 +454,46 @@ function update_65() { update_sql("CREATE FUNCTION \"rand\"() RETURNS float AS ' BEGIN RETURN random(); - END;' LANGUAGE 'plpgsql';"); + END;' LANGUAGE 'plpgsql'"); } } function update_66() { - update_sql("CREATE TABLE path ( - pid int(10) unsigned NOT NULL auto_increment, - old varchar(128) NOT NULL default '', - new varchar(128) NOT NULL default '', - PRIMARY KEY (pid), - UNIQUE KEY old (old), - UNIQUE KEY new (new) - )"); + if ($GLOBALS["db_type"] == "pgsql") { + update_sql("CREATE TABLE {path} ( + pid integer NOT NULL default '0', + src varchar(128) NOT NULL default '', + dst varchar(128) NOT NULL default '', + PRIMARY KEY (pid) + )"); + update_sql("CREATE INDEX path_src_idx ON {path}(src)"); + update_sql("CREATE INDEX path_dst_idx ON {path}(dst)"); + $result = db_query("SELECT nid, path FROM {node} WHERE path != ''"); + while ($node = db_fetch_object($result)) { + update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')"); + } + + /* most versions of pgsql are incapable of dropping columns */ - // Migrate the existing paths: - $result = db_query("SELECT nid, path FROM {node} WHERE path != ''"); - while ($node = db_fetch_object($result)) { - update_sql("INSERT INTO {path} (old, new) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')"); } + else { + update_sql("CREATE TABLE {path} ( + pid int(10) unsigned NOT NULL auto_increment, + src varchar(128) NOT NULL default '', + dst varchar(128) NOT NULL default '', + PRIMARY KEY (pid), + UNIQUE KEY src (src), + UNIQUE KEY dst (dst) + )"); + // Migrate the existing paths: + $result = db_query("SELECT nid, path FROM {node} WHERE path != ''"); + while ($node = db_fetch_object($result)) { + update_sql("INSERT INTO {path} (src, dst) VALUES ('node/view/$node->nid', '". check_query($node->path) ."')"); + } - update_sql("ALTER TABLE {node} DROP path"); - } + update_sql("ALTER TABLE {node} DROP path"); + } +} /* ** System functions