Skip to content

Commit

Permalink
Updated update_CombineUserTables222
Browse files Browse the repository at this point in the history
For issue #1128
  • Loading branch information
eSilverStrike committed Jun 13, 2022
1 parent 476f377 commit 3b170a2
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 15 deletions.
31 changes: 23 additions & 8 deletions sql/updates/mysql_2.2.1_to_2.2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -231,14 +231,6 @@ function update_CombineUserTables222()
VALUES (1, 'nested', 'ASC', 100)
SQL;

$sql3 = <<<SQL
SELECT c.*, x.*, f.*, p.*
FROM {$_TABLES['usercomment']} AS c
LEFT JOIN {$_TABLES['userindex']} AS x ON c.uid = x.uid
LEFT JOIN {$_TABLES['userinfo']} AS f ON c.uid = f.uid
LEFT JOIN {$_TABLES['userprefs']} AS p ON c.uid = p.uid
SQL;

// Create $_TABLES['user_attributes'] table
DB_query($sql1);

Expand All @@ -255,6 +247,28 @@ function update_CombineUserTables222()
$sql = "DELETE uc FROM {$_TABLES['userprefs']} uc WHERE uid NOT IN (SELECT uid FROM {$_TABLES['users']} u WHERE uc.uid = u.uid)";
DB_query($sql);

// Retrieve data from old tables and insert into new attributes table
$sql = "INSERT INTO {$_TABLES['user_attributes']}
SELECT f.uid,
IFNULL(c.commentmode, 'nested'), IFNULL(c.commentorder, 'ASC'), IFNULL(c.commentlimit, 100),
IFNULL(x.etids, '-'), IFNULL(x.noboxes, 0), IFNULL(x.maxstories, 0),
IFNULL(f.about, ''), IFNULL(f.location, ''), IFNULL(f.pgpkey, ''), IFNULL(f.tokens, 0), IFNULL(f.lastgranted, 0), IFNULL(f.lastlogin, 0),
IFNULL(p.dfid, 0), IFNULL(p.advanced_editor, 1), IFNULL(p.tzid, ''), IFNULL(p.emailfromadmin, 1), IFNULL(p.emailfromuser, 1), IFNULL(p.showonline, 1)
FROM {$_TABLES['usercomment']} AS c
LEFT JOIN {$_TABLES['userindex']} AS x ON c.uid = x.uid
LEFT JOIN {$_TABLES['userinfo']} AS f ON c.uid = f.uid
LEFT JOIN {$_TABLES['userprefs']} AS p ON c.uid = p.uid";
DB_query($sql);

/* Converted commented code to above SQL query to improve speed
$sql3 = <<<SQL
SELECT c.*, x.*, f.*, p.*
FROM {$_TABLES['usercomment']} AS c
LEFT JOIN {$_TABLES['userindex']} AS x ON c.uid = x.uid
LEFT JOIN {$_TABLES['userinfo']} AS f ON c.uid = f.uid
LEFT JOIN {$_TABLES['userprefs']} AS p ON c.uid = p.uid
SQL;
// Collect data from old tables
$result = DB_query($sql3);
if (DB_error()) {
Expand All @@ -268,6 +282,7 @@ function update_CombineUserTables222()
$entity = UserAttributeEntity::fromArray($A);
$userAttributeDAO->create($entity);
}
*/

// Drop old tables
DB_query("DROP TABLE {$_TABLES['usercomment']}");
Expand Down
32 changes: 25 additions & 7 deletions sql/updates/pgsql_2.2.1_to_2.2.2.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,13 +229,7 @@ function update_CombineUserTables222()
VALUES (1, 'nested', 'ASC', 100)
SQL;

$sql3 = <<<SQL
SELECT c.*, x.*, f.*, p.*
FROM {$_TABLES['usercomment']} AS c
LEFT JOIN {$_TABLES['userindex']} AS x ON c.uid = x.uid
LEFT JOIN {$_TABLES['userinfo']} AS f ON c.uid = f.uid
LEFT JOIN {$_TABLES['userprefs']} AS p ON c.uid = p.uid
SQL;


// Clean user tables that may have orphan records
$sql = "DELETE uc FROM {$_TABLES['usercomment']} uc WHERE uid NOT IN (SELECT uid FROM {$_TABLES['users']} u WHERE uc.uid = u.uid)";
Expand Down Expand Up @@ -264,6 +258,29 @@ function update_CombineUserTables222()

return false;
}

// Retrieve data from old tables and insert into new attributes table
$sql = "INSERT INTO {$_TABLES['user_attributes']}
SELECT f.uid,
IFNULL(c.commentmode, 'nested'), IFNULL(c.commentorder, 'ASC'), IFNULL(c.commentlimit, 100),
IFNULL(x.etids, '-'), IFNULL(x.noboxes, 0), IFNULL(x.maxstories, 0),
IFNULL(f.about, ''), IFNULL(f.location, ''), IFNULL(f.pgpkey, ''), IFNULL(f.tokens, 0), IFNULL(f.lastgranted, 0), IFNULL(f.lastlogin, 0),
IFNULL(p.dfid, 0), IFNULL(p.advanced_editor, 1), IFNULL(p.tzid, ''), IFNULL(p.emailfromadmin, 1), IFNULL(p.emailfromuser, 1), IFNULL(p.showonline, 1)
FROM {$_TABLES['usercomment']} AS c
LEFT JOIN {$_TABLES['userindex']} AS x ON c.uid = x.uid
LEFT JOIN {$_TABLES['userinfo']} AS f ON c.uid = f.uid
LEFT JOIN {$_TABLES['userprefs']} AS p ON c.uid = p.uid";
DB_query($sql);


/* Converted commented code to above SQL query to improve speed
$sql3 = <<<SQL
SELECT c.*, x.*, f.*, p.*
FROM {$_TABLES['usercomment']} AS c
LEFT JOIN {$_TABLES['userindex']} AS x ON c.uid = x.uid
LEFT JOIN {$_TABLES['userinfo']} AS f ON c.uid = f.uid
LEFT JOIN {$_TABLES['userprefs']} AS p ON c.uid = p.uid
SQL;
// Collect data from old tables
$result = DB_query($sql3);
Expand All @@ -280,6 +297,7 @@ function update_CombineUserTables222()
$entity = UserAttributeEntity::fromArray($A);
$userAttributeDAO->create($entity);
}
*/

// Drop old tables
DB_query("DROP TABLE {$_TABLES['usercomment']}");
Expand Down

0 comments on commit 3b170a2

Please sign in to comment.