[geeklog-hg] geeklog: Optimize Geeklog 2.0.0 Topic upgrade script for article...
geeklog-cvs at lists.geeklog.net
geeklog-cvs at lists.geeklog.net
Mon Jan 21 11:17:05 EST 2013
changeset 8925:bf988cbbf0f7
url: http://project.geeklog.net/cgi-bin/hgwebdir.cgi/geeklog/rev/bf988cbbf0f7
user: Tom <websitemaster at cogeco.net>
date: Mon Jan 21 11:16:26 2013 -0500
description:
Optimize Geeklog 2.0.0 Topic upgrade script for articles and blocks (feature request #0001544)
diffstat:
sql/updates/mssql_1.8.2_to_2.0.0.php | 29 ++++++++---------------------
sql/updates/mysql_1.8.2_to_2.0.0.php | 32 ++++++++++----------------------
sql/updates/pgsql_1.8.2_to_2.0.0.php | 29 ++++++++---------------------
3 files changed, 26 insertions(+), 64 deletions(-)
diffs (145 lines):
diff -r 44b55b16dea8 -r bf988cbbf0f7 sql/updates/mssql_1.8.2_to_2.0.0.php
--- a/sql/updates/mssql_1.8.2_to_2.0.0.php Mon Jan 21 22:49:35 2013 +0900
+++ b/sql/updates/mssql_1.8.2_to_2.0.0.php Mon Jan 21 11:16:26 2013 -0500
@@ -41,16 +41,10 @@
$story_tables[] = $_TABLES['storysubmission'];
foreach ($story_tables as $story_table) {
- $sql = "SELECT * FROM $story_table";
- $result = DB_query($sql);
- $nrows = DB_numRows($result);
-
- for ($i = 0; $i < $nrows; $i++) {
- $A = DB_fetchArray($result);
-
- $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault) VALUES ('{$A['tid']}', 'article', '{$A['sid']}', 1, 1)";
- DB_query($sql);
- }
+ $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault)
+ SELECT tid, 'article' AS type, sid, 1 AS inherit, 1 AS tdefault
+ FROM $story_table";
+ DB_query($sql);
// Remove tid from table
$sql = "ALTER TABLE $story_table DROP tid";
@@ -67,17 +61,10 @@
{
global $_TABLES;
-
- $sql = "SELECT * FROM {$_TABLES['blocks']}";
- $result = DB_query($sql);
- $nrows = DB_numRows($result);
-
- for ($i = 0; $i < $nrows; $i++) {
- $A = DB_fetchArray($result);
-
- $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault) VALUES ('{$A['tid']}', 'block', '{$A['bid']}', 1, 0)";
- DB_query($sql);
- }
+ $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault)
+ SELECT tid, 'block' AS type, bid, 1 AS inherit, 0 AS tdefault
+ FROM {$_TABLES['blocks']}";
+ DB_query($sql);
// Remove Topic Id from blocks table
$sql = "ALTER TABLE {$_TABLES['blocks']} DROP tid";
diff -r 44b55b16dea8 -r bf988cbbf0f7 sql/updates/mysql_1.8.2_to_2.0.0.php
--- a/sql/updates/mysql_1.8.2_to_2.0.0.php Mon Jan 21 22:49:35 2013 +0900
+++ b/sql/updates/mysql_1.8.2_to_2.0.0.php Mon Jan 21 11:16:26 2013 -0500
@@ -39,18 +39,12 @@
$story_tables[] = $_TABLES['stories'];
$story_tables[] = $_TABLES['storysubmission'];
-
+
foreach ($story_tables as $story_table) {
- $sql = "SELECT * FROM $story_table";
- $result = DB_query($sql);
- $nrows = DB_numRows($result);
-
- for ($i = 0; $i < $nrows; $i++) {
- $A = DB_fetchArray($result);
-
- $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault) VALUES ('{$A['tid']}', 'article', '{$A['sid']}', 1, 1)";
- DB_query($sql);
- }
+ $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault)
+ SELECT tid, 'article' AS type, sid, 1 AS inherit, 1 AS tdefault
+ FROM $story_table";
+ DB_query($sql);
// Remove tid from table
$sql = "ALTER TABLE $story_table DROP tid";
@@ -66,20 +60,14 @@
function update_BlockTopicAssignmentsFor200()
{
global $_TABLES;
-
- $sql = "SELECT * FROM {$_TABLES['blocks']}";
- $result = DB_query($sql);
- $nrows = DB_numRows($result);
- for ($i = 0; $i < $nrows; $i++) {
- $A = DB_fetchArray($result);
-
- $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault) VALUES ('{$A['tid']}', 'block', '{$A['bid']}', 1, 0)";
- DB_query($sql);
- }
+ $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault)
+ SELECT tid, 'block' AS type, bid, 1 AS inherit, 0 AS tdefault
+ FROM {$_TABLES['blocks']}";
+ DB_query($sql);
// Remove Topic Id from blocks table
- $sql = "ALTER TABLE {$_TABLES['blocks']} DROP `tid`";
+ $sql = "ALTER TABLE {$_TABLES['blocks']} DROP tid";
DB_query($sql);
}
diff -r 44b55b16dea8 -r bf988cbbf0f7 sql/updates/pgsql_1.8.2_to_2.0.0.php
--- a/sql/updates/pgsql_1.8.2_to_2.0.0.php Mon Jan 21 22:49:35 2013 +0900
+++ b/sql/updates/pgsql_1.8.2_to_2.0.0.php Mon Jan 21 11:16:26 2013 -0500
@@ -50,16 +50,10 @@
$story_tables[] = $_TABLES['storysubmission'];
foreach ($story_tables as $story_table) {
- $sql = "SELECT * FROM $story_table";
- $result = DB_query($sql);
- $nrows = DB_numRows($result);
-
- for ($i = 0; $i < $nrows; $i++) {
- $A = DB_fetchArray($result);
-
- $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault) VALUES ('{$A['tid']}', 'article', '{$A['sid']}', 1, 1)";
- DB_query($sql);
- }
+ $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault)
+ SELECT tid, 'article' AS type, sid, 1 AS inherit, 1 AS tdefault
+ FROM $story_table";
+ DB_query($sql);
// Remove tid from table
$sql = "ALTER TABLE $story_table DROP tid";
@@ -76,17 +70,10 @@
{
global $_TABLES;
-
- $sql = "SELECT * FROM {$_TABLES['blocks']}";
- $result = DB_query($sql);
- $nrows = DB_numRows($result);
-
- for ($i = 0; $i < $nrows; $i++) {
- $A = DB_fetchArray($result);
-
- $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault) VALUES ('{$A['tid']}', 'block', '{$A['bid']}', 1, 0)";
- DB_query($sql);
- }
+ $sql = "INSERT INTO {$_TABLES['topic_assignments']} (tid, type, id, inherit, tdefault)
+ SELECT tid, 'block' AS type, bid, 1 AS inherit, 0 AS tdefault
+ FROM {$_TABLES['blocks']}";
+ DB_query($sql);
// Remove Topic Id from blocks table
$sql = "ALTER TABLE {$_TABLES['blocks']} DROP tid";
More information about the geeklog-cvs
mailing list