summary refs log tree commit diff stats
path: root/pages
diff options
context:
space:
mode:
authorStarla Insigna <hatkirby@fourisland.com>2009-01-05 21:48:01 -0500
committerStarla Insigna <hatkirby@fourisland.com>2009-01-05 21:48:01 -0500
commit1cb945e201704062e9940f327464f4b31a861f20 (patch)
treee2e8ddc9d4681c605621ed1132168cdb7b9eb93b /pages
parent9ba37f4643f825052c002bda16884ccc73f57ebc (diff)
downloadfourisland-1cb945e201704062e9940f327464f4b31a861f20.tar.gz
fourisland-1cb945e201704062e9940f327464f4b31a861f20.tar.bz2
fourisland-1cb945e201704062e9940f327464f4b31a861f20.zip
Changed comments' user index
Previously, the comments table referenced users by username. However, if user ever changed their username, everything would become messed up. To fix
this, the index has been changed to the user ID. This change obviously requires maintenance:

This SQL must be run: "ALTER TABLE `comments` ADD `user_id` INT( 11 ) NOT NULL AFTER `page_id`;"

This PHP will generate some SQL that must be run:

<?php

$getusers = "SELECT DISTINCT username FROM comments WHERE is_anon = 0";
$getusers2 = mysql_query($getusers);
while ($getusers3 = mysql_fetch_array($getusers2))
{
        $getuser = "SELECT * FROM phpbb_users WHERE username = \"" . $getusers3['username'] . "\"";
        $getuser2 = mysql_query($getuser);
        $getuser3 = mysql_fetch_array($getuser2);

        echo("UPDATE comments SET user_id = " . $getuser3['user_id'] . " WHERE username = \"" . $getuser3['username'] . "\" AND is_anon = 0;<BR>");
}

$getusers = "SELECT * FROM anon_commenters";
$getusers2 = mysql_query($getusers);
while ($getusers3 = mysql_fetch_array($getusers2))
{
        echo("UPDATE comments SET user_id = " . $getusers3['id'] . " WHERE username = \"" . $getusers3['username'] . "\" AND is_anon = 1;<BR>");
}

?>

This SQL must be run: "ALTER TABLE `comments` DROP `username`;"
Diffstat (limited to 'pages')
-rwxr-xr-xpages/admin.php2
-rwxr-xr-xpages/post.php4
2 files changed, 3 insertions, 3 deletions
diff --git a/pages/admin.php b/pages/admin.php index fda03c3..12a2d01 100755 --- a/pages/admin.php +++ b/pages/admin.php
@@ -563,7 +563,7 @@ if (isLoggedIn())
563 $insanon = "INSERT INTO anon_commenters (username,email,website) VALUES (\"" . $getcomment3['author'] . "\",\"" . $getcomment3['email'] . "\",\"" . $getcomment3['website'] . "\")"; 563 $insanon = "INSERT INTO anon_commenters (username,email,website) VALUES (\"" . $getcomment3['author'] . "\",\"" . $getcomment3['email'] . "\",\"" . $getcomment3['website'] . "\")";
564 $insanon2 = mysql_query($insanon); 564 $insanon2 = mysql_query($insanon);
565 565
566 $inscomment = "INSERT INTO comments (page_id,username,comment,is_anon) VALUES (\"" . $getcomment3['page_id'] . "\",\"" . $getcomment3['author'] . "\",\"" . $getcomment3['comment'] . "\",1)"; 566 $inscomment = "INSERT INTO comments (page_id,user_id,comment,is_anon) VALUES (\"" . $getcomment3['page_id'] . "\"," . mysql_insert_id() . ",\"" . $getcomment3['comment'] . "\",1)";
567 $inscomment2 = mysql_query($inscomment); 567 $inscomment2 = mysql_query($inscomment);
568 568
569 $delcomment = "DELETE FROM moderation WHERE id = " . $getcomment3['id']; 569 $delcomment = "DELETE FROM moderation WHERE id = " . $getcomment3['id'];
diff --git a/pages/post.php b/pages/post.php index 7d6dd08..87413e8 100755 --- a/pages/post.php +++ b/pages/post.php
@@ -56,7 +56,7 @@ if (!isset($_GET['id']))
56 { 56 {
57 if ($getanon3['email'] == $_POST['email']) 57 if ($getanon3['email'] == $_POST['email'])
58 { 58 {
59 $setcomment = "INSERT INTO comments SET page_id = \"" . $_GET['id'] . "\", username = \"" . $_POST['username'] . "\", comment = \"" . $_POST['comment'] . "\", is_anon = 1"; 59 $setcomment = "INSERT INTO comments SET page_id = \"" . $_GET['id'] . "\", user_id = " . $getanon3['id'] . ", comment = \"" . $_POST['comment'] . "\", is_anon = 1";
60 $setcomment2 = mysql_query($setcomment); 60 $setcomment2 = mysql_query($setcomment);
61 61
62 $page_id = $_GET['id']; 62 $page_id = $_GET['id'];
@@ -84,7 +84,7 @@ if (!isset($_GET['id']))
84 } 84 }
85 } 85 }
86 } else { 86 } else {
87 $setcomment = "INSERT INTO comments SET page_id = \"" . $_GET['id'] . "\", username = \"" . getSessionUsername() . "\", comment = \"" . $_POST['comment'] . "\", is_anon = 0"; 87 $setcomment = "INSERT INTO comments SET page_id = \"" . $_GET['id'] . "\", user_id = " . getSessionUserID() . ", comment = \"" . $_POST['comment'] . "\", is_anon = 0";
88 $setcomment2 = mysql_query($setcomment); 88 $setcomment2 = mysql_query($setcomment);
89 89
90 mail('hatkirby@fourisland.com', 'New comment on Four Island!', getSessionUsername() . ' has posted a comment on Four Island under the "page id" ' . $_GET['id']); 90 mail('hatkirby@fourisland.com', 'New comment on Four Island!', getSessionUsername() . ' has posted a comment on Four Island under the "page id" ' . $_GET['id']);