Rename the CommentNotify table to PackageNotifications

As a preparatory step to adding support for package notifications on
events other than comments, rename the database table accordingly.

Signed-off-by: Lukas Fleischer <lfleischer@archlinux.org>
This commit is contained in:
Lukas Fleischer 2015-11-10 19:26:57 +01:00
parent daee000604
commit 3412de21d3
8 changed files with 27 additions and 21 deletions

View file

@ -81,7 +81,7 @@ def create_pkgbase(pkgbase, user):
"UNIX_TIMESTAMP(), %s, %s)", [pkgbase, userid, userid]) "UNIX_TIMESTAMP(), %s, %s)", [pkgbase, userid, userid])
pkgbase_id = cur.lastrowid pkgbase_id = cur.lastrowid
cur.execute("INSERT INTO CommentNotify (PackageBaseID, UserID) " + cur.execute("INSERT INTO PackageNotifications (PackageBaseID, UserID) " +
"VALUES (%s, %s)", [pkgbase_id, userid]) "VALUES (%s, %s)", [pkgbase_id, userid])
db.commit() db.commit()

View file

@ -160,11 +160,11 @@ def save_metadata(metadata, db, cur, user):
# Add user to notification list on adoption. # Add user to notification list on adoption.
if was_orphan: if was_orphan:
cur.execute("SELECT COUNT(*) FROM CommentNotify WHERE " + cur.execute("SELECT COUNT(*) FROM PackageNotifications WHERE " +
"PackageBaseID = %s AND UserID = %s", "PackageBaseID = %s AND UserID = %s",
[pkgbase_id, user_id]) [pkgbase_id, user_id])
if cur.fetchone()[0] == 0: if cur.fetchone()[0] == 0:
cur.execute("INSERT INTO CommentNotify (PackageBaseID, UserID) " + cur.execute("INSERT INTO PackageNotifications (PackageBaseID, UserID) " +
"VALUES (%s, %s)", [pkgbase_id, user_id]) "VALUES (%s, %s)", [pkgbase_id, user_id])
db.commit() db.commit()

View file

@ -284,15 +284,15 @@ CREATE TABLE PackageComaintainers (
FOREIGN KEY (PackageBaseID) REFERENCES PackageBases(ID) ON DELETE CASCADE FOREIGN KEY (PackageBaseID) REFERENCES PackageBases(ID) ON DELETE CASCADE
) ENGINE = InnoDB; ) ENGINE = InnoDB;
-- Comment addition notifications -- Package base notifications
-- --
CREATE TABLE CommentNotify ( CREATE TABLE PackageNotifications (
PackageBaseID INTEGER UNSIGNED NOT NULL, PackageBaseID INTEGER UNSIGNED NOT NULL,
UserID INTEGER UNSIGNED NOT NULL, UserID INTEGER UNSIGNED NOT NULL,
FOREIGN KEY (PackageBaseID) REFERENCES PackageBases(ID) ON DELETE CASCADE, FOREIGN KEY (PackageBaseID) REFERENCES PackageBases(ID) ON DELETE CASCADE,
FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE FOREIGN KEY (UserID) REFERENCES Users(ID) ON DELETE CASCADE
) ENGINE = InnoDB; ) ENGINE = InnoDB;
CREATE UNIQUE INDEX NotifyUserIDPkgID ON CommentNotify (UserID, PackageBaseID); CREATE UNIQUE INDEX NotifyUserIDPkgID ON PackageNotifications (UserID, PackageBaseID);
-- Package name blacklist -- Package name blacklist
-- --

View file

@ -88,10 +88,10 @@ def get_maintainer_email(cur, pkgbase_id):
def get_recipients(cur, pkgbase_id, uid): def get_recipients(cur, pkgbase_id, uid):
cur.execute('SELECT DISTINCT Users.Email FROM Users ' + cur.execute('SELECT DISTINCT Users.Email FROM Users ' +
'INNER JOIN CommentNotify ' + 'INNER JOIN PackageNotifications ' +
'ON CommentNotify.UserID = Users.ID WHERE ' + 'ON PackageNotifications.UserID = Users.ID WHERE ' +
'CommentNotify.UserID != %s AND ' + 'PackageNotifications.UserID != %s AND ' +
'CommentNotify.PackageBaseID = %s', [uid, pkgbase_id]) 'PackageNotifications.PackageBaseID = %s', [uid, pkgbase_id])
return [row[0] for row in cur.fetchall()] return [row[0] for row in cur.fetchall()]

View file

@ -41,3 +41,9 @@ ALTER TABLE PackageRequests ADD COLUMN ClosureComment TEXT NOT NULL DEFAULT '';
---- ----
ALTER TABLE PackageBases MODIFY COLUMN FlaggerComment TEXT NOT NULL DEFAULT ''; ALTER TABLE PackageBases MODIFY COLUMN FlaggerComment TEXT NOT NULL DEFAULT '';
---- ----
7. Rename the CommentNotify table to PackageNotifications:
----
ALTER TABLE CommentNotify RENAME TO PackageNotifications;
----

View file

@ -897,7 +897,7 @@ function user_delete($id) {
$fields_delete = array( $fields_delete = array(
array("Sessions", "UsersID"), array("Sessions", "UsersID"),
array("PackageVotes", "UsersID"), array("PackageVotes", "UsersID"),
array("CommentNotify", "UsersID") array("PackageNotifications", "UsersID")
); );
$fields_set_null = array( $fields_set_null = array(

View file

@ -542,15 +542,15 @@ function pkgbase_delete ($base_ids, $merge_base_id, $via, $grant=false) {
$dbh->exec($q); $dbh->exec($q);
/* Merge notifications */ /* Merge notifications */
$q = "SELECT DISTINCT UserID FROM CommentNotify cn "; $q = "SELECT DISTINCT UserID FROM PackageNotifications cn ";
$q.= "WHERE PackageBaseID IN (" . implode(",", $base_ids) . ") "; $q.= "WHERE PackageBaseID IN (" . implode(",", $base_ids) . ") ";
$q.= "AND NOT EXISTS (SELECT * FROM CommentNotify cn2 "; $q.= "AND NOT EXISTS (SELECT * FROM PackageNotifications cn2 ";
$q.= "WHERE cn2.PackageBaseID = " . intval($merge_base_id) . " "; $q.= "WHERE cn2.PackageBaseID = " . intval($merge_base_id) . " ";
$q.= "AND cn2.UserID = cn.UserID)"; $q.= "AND cn2.UserID = cn.UserID)";
$result = $dbh->query($q); $result = $dbh->query($q);
while ($notify_uid = $result->fetch(PDO::FETCH_COLUMN, 0)) { while ($notify_uid = $result->fetch(PDO::FETCH_COLUMN, 0)) {
$q = "INSERT INTO CommentNotify (UserID, PackageBaseID) "; $q = "INSERT INTO PackageNotifications (UserID, PackageBaseID) ";
$q.= "VALUES (" . intval($notify_uid) . ", " . intval($merge_base_id) . ")"; $q.= "VALUES (" . intval($notify_uid) . ", " . intval($merge_base_id) . ")";
$dbh->exec($q); $dbh->exec($q);
} }
@ -840,7 +840,7 @@ function pkgbase_user_voted($uid, $base_id) {
function pkgbase_user_notify($uid, $base_id) { function pkgbase_user_notify($uid, $base_id) {
$dbh = DB::connect(); $dbh = DB::connect();
$q = "SELECT * FROM CommentNotify WHERE UserID = " . $dbh->quote($uid); $q = "SELECT * FROM PackageNotifications WHERE UserID = " . $dbh->quote($uid);
$q.= " AND PackageBaseID = " . $dbh->quote($base_id); $q.= " AND PackageBaseID = " . $dbh->quote($base_id);
$result = $dbh->query($q); $result = $dbh->query($q);
@ -898,20 +898,20 @@ function pkgbase_notify ($base_ids, $action=true) {
if ($action) { if ($action) {
$q = "SELECT COUNT(*) FROM CommentNotify WHERE "; $q = "SELECT COUNT(*) FROM PackageNotifications WHERE ";
$q .= "UserID = $uid AND PackageBaseID = $bid"; $q .= "UserID = $uid AND PackageBaseID = $bid";
/* Notification already added. Don't add again. */ /* Notification already added. Don't add again. */
$result = $dbh->query($q); $result = $dbh->query($q);
if ($result->fetchColumn() == 0) { if ($result->fetchColumn() == 0) {
$q = "INSERT INTO CommentNotify (PackageBaseID, UserID) VALUES ($bid, $uid)"; $q = "INSERT INTO PackageNotifications (PackageBaseID, UserID) VALUES ($bid, $uid)";
$dbh->exec($q); $dbh->exec($q);
} }
$output .= $basename; $output .= $basename;
} }
else { else {
$q = "DELETE FROM CommentNotify WHERE PackageBaseID = $bid "; $q = "DELETE FROM PackageNotifications WHERE PackageBaseID = $bid ";
$q .= "AND UserID = $uid"; $q .= "AND UserID = $uid";
$dbh->exec($q); $dbh->exec($q);

View file

@ -716,7 +716,7 @@ function pkg_search_page($SID="") {
/* Build the package search query. */ /* Build the package search query. */
$q_select = "SELECT "; $q_select = "SELECT ";
if ($SID) { if ($SID) {
$q_select .= "CommentNotify.UserID AS Notify, $q_select .= "PackageNotifications.UserID AS Notify,
PackageVotes.UsersID AS Voted, "; PackageVotes.UsersID AS Voted, ";
} }
$q_select .= "Users.Username AS Maintainer, $q_select .= "Users.Username AS Maintainer,
@ -731,8 +731,8 @@ function pkg_search_page($SID="") {
/* This is not needed for the total row count query. */ /* This is not needed for the total row count query. */
$q_from_extra = "LEFT JOIN PackageVotes $q_from_extra = "LEFT JOIN PackageVotes
ON (PackageBases.ID = PackageVotes.PackageBaseID AND PackageVotes.UsersID = $myuid) ON (PackageBases.ID = PackageVotes.PackageBaseID AND PackageVotes.UsersID = $myuid)
LEFT JOIN CommentNotify LEFT JOIN PackageNotifications
ON (PackageBases.ID = CommentNotify.PackageBaseID AND CommentNotify.UserID = $myuid) "; ON (PackageBases.ID = PackageNotifications.PackageBaseID AND PackageNotifications.UserID = $myuid) ";
} else { } else {
$q_from_extra = ""; $q_from_extra = "";
} }