From ed9e8f34c786b7ceba6459c763ef8206eec0fd0d Mon Sep 17 00:00:00 2001 From: Michal Vaner Date: Fri, 29 Aug 2008 20:23:24 +0200 Subject: [PATCH] New terminology, part 1 (database) comment -> discussion description -> note --- PciIds/DBQ.pm | 36 ++++++++++++++++++------------------ scripts/export.pl | 2 +- scripts/feeddb.pl | 6 +++--- scripts/importil.pl | 4 ++-- scripts/importlog.pl | 6 +++--- scripts/init | 5 +++-- scripts/mailbot | 2 +- scripts/transfer.pl | 6 +++--- tables | 24 ++++++++++++------------ 9 files changed, 46 insertions(+), 45 deletions(-) diff --git a/PciIds/DBQ.pm b/PciIds/DBQ.pm index 02ca5c1..7d4e6ef 100644 --- a/PciIds/DBQ.pm +++ b/PciIds/DBQ.pm @@ -5,8 +5,8 @@ use base 'PciIds::DBQAny'; sub new( $ ) { my( $dbh ) = @_; - my $node = 'SELECT id, name, description, maincomment FROM locations WHERE parent = ? ORDER BY '; - my $noder = 'SELECT id, name, description, maincomment FROM locations WHERE parent = ? AND id LIKE ? ORDER BY '; + my $node = 'SELECT id, name, note, mainhistory FROM locations WHERE parent = ? ORDER BY '; + my $noder = 'SELECT id, name, note, mainhistory FROM locations WHERE parent = ? AND id LIKE ? ORDER BY '; return bless PciIds::DBQAny::new( $dbh, { 'nodes-id' => $node.'id', 'nodes-name' => $node.'name', @@ -16,7 +16,7 @@ sub new( $ ) { 'nodes-name-r' => $noder.'name', 'nodes-rid-r' => $noder.'id DESC', 'nodes-rname-r' => $noder.'name DESC', - 'item' => 'SELECT parent, name, description, maincomment FROM locations WHERE id = ?', + 'item' => 'SELECT parent, name, note, mainhistory FROM locations WHERE id = ?', 'login' => 'SELECT id FROM users WHERE login = ?', 'email' => 'SELECT id FROM users WHERE email = ?', 'adduser' => 'INSERT INTO users (login, email, passwd) VALUES(?, ?, ?)', @@ -28,25 +28,25 @@ sub new( $ ) { 'setlastlog' => 'UPDATE users SET logtime = now(), lastlog = ? WHERE id = ?', 'rights' => 'SELECT rightId FROM rights WHERE userId = ?', 'newitem' => 'INSERT INTO locations (id, parent) VALUES(?, ?)', - 'newcomment' => 'INSERT INTO history (location, owner, text, nodename, nodedescription) VALUES(?, ?, ?, ?, ?)', - 'history' => 'SELECT history.id, history.text, history.time, history.nodename, history.nodedescription, history.seen, users.login FROM history LEFT OUTER JOIN users ON history.owner = users.id WHERE history.location = ? ORDER BY history.time', + 'newcomment' => 'INSERT INTO history (location, owner, discussion, nodename, nodenote) VALUES(?, ?, ?, ?, ?)', + 'history' => 'SELECT history.id, history.discussion, history.time, history.nodename, history.nodenote, history.seen, users.login FROM history LEFT OUTER JOIN users ON history.owner = users.id WHERE history.location = ? ORDER BY history.time', 'admindump' => 'SELECT - locations.id, locations.name, locations.description, locations.maincomment, musers.login, main.text, - history.id, history.text, history.nodename, history.nodedescription, users.login + locations.id, locations.name, locations.note, locations.mainhistory, musers.login, main.discussion, + history.id, history.discussion, history.nodename, history.nodenote, users.login FROM locations INNER JOIN history ON history.location = locations.id LEFT OUTER JOIN users ON history.owner = users.id - LEFT OUTER JOIN history AS main ON locations.maincomment = main.id + LEFT OUTER JOIN history AS main ON locations.mainhistory = main.id LEFT OUTER JOIN users AS musers ON main.owner = musers.id WHERE history.seen = "0" ORDER BY locations.id, history.id - LIMIT 15',#Dumps all new comments with their senders and corresponding main comments and names + LIMIT 15',#Dumps new comments with their senders and corresponding main comments and names 'delete-hist' => 'DELETE FROM history WHERE id = ?', 'mark-checked' => 'UPDATE history SET seen = 1 WHERE id = ?', 'delete-item' => 'DELETE FROM locations WHERE id = ?', 'set-maincomment' => 'UPDATE locations SET - maincomment = ?, + mainhistory = ?, name = ( SELECT nodename FROM history WHERE id = ? ), - description = ( SELECT nodedescription FROM history WHERE id = ? ) + note = ( SELECT nodenote FROM history WHERE id = ? ) WHERE id = ?', 'profiledata' => 'SELECT email, xmpp, login, mailgather, xmppgather FROM users WHERE id = ?', @@ -56,17 +56,17 @@ sub new( $ ) { 'notifdata' => 'SELECT recursive, type, notification FROM notifications WHERE user = ? AND location = ?', 'drop-notif' => 'DELETE FROM notifications WHERE user = ? AND location = ?', 'new-notif' => 'INSERT INTO notifications (user, location, recursive, type, notification) VALUES (?, ?, ?, ?, ?)', - 'notify' => 'INSERT INTO pending (user, comment, notification, reason) SELECT DISTINCT user, ?, ?, ? FROM notifications WHERE ( notification = 2 OR notification = ? ) AND type <= ? AND ( location = ? OR ( SUBSTR( ?, 1, LENGTH( location ) ) = location ) )', + 'notify' => 'INSERT INTO pending (user, history, notification, reason) SELECT DISTINCT user, ?, ?, ? FROM notifications WHERE ( notification = 2 OR notification = ? ) AND type <= ? AND ( location = ? OR ( SUBSTR( ?, 1, LENGTH( location ) ) = location ) )', 'newtime-mail' => 'UPDATE users SET nextmail = FROM_UNIXTIME( UNIX_TIMESTAMP( NOW() ) + 60 * mailgather ) WHERE nextmail < NOW() AND EXISTS ( SELECT 1 FROM notifications WHERE ( notification = 0 OR notification = 2 ) AND type <= ? AND ( location = ? OR ( SUBSTR( ?, 1, LENGTH( location ) ) = location ) ) )', 'newtime-xmpp' => 'UPDATE users SET nextxmpp = FROM_UNIXTIME( UNIX_TIMESTAMP( NOW() ) + 60 * xmppgather ) WHERE nextxmpp < NOW() AND EXISTS ( SELECT 1 FROM notifications WHERE ( notification = 1 OR notification = 2 ) AND type <= ? AND ( location = ? OR ( SUBSTR( ?, 1, LENGTH( location ) ) = location ) ) )', 'mailout' => 'SELECT pending.user, users.email, - pending.reason, history.text, history.nodename, history.nodedescription, history.time, - auth.login, history.location, locations.name, locations.description + pending.reason, history.discussion, history.nodename, history.nodenote, history.time, + auth.login, history.location, locations.name, locations.note FROM pending INNER JOIN users ON users.id = pending.user - INNER JOIN history ON history.id = pending.comment + INNER JOIN history ON history.id = pending.history INNER JOIN locations ON history.location = locations.id INNER JOIN users AS auth ON auth.id = history.owner WHERE @@ -76,12 +76,12 @@ sub new( $ ) { pending.user, pending.reason, history.time, history.location', 'xmppout' => 'SELECT pending.user, users.xmpp, - pending.reason, history.text, history.nodename, history.nodedescription, history.time, - auth.login, history.location, locations.name, locations.description + pending.reason, history.discussion, history.nodename, history.nodenote, history.time, + auth.login, history.location, locations.name, locations.note FROM pending INNER JOIN users ON users.id = pending.user - INNER JOIN history ON history.id = pending.comment + INNER JOIN history ON history.id = pending.history INNER JOIN locations ON history.location = locations.id INNER JOIN users AS auth ON auth.id = history.owner WHERE diff --git a/scripts/export.pl b/scripts/export.pl index 1acf068..ac55810 100755 --- a/scripts/export.pl +++ b/scripts/export.pl @@ -9,7 +9,7 @@ use PciIds::Db; use PciIds::DBQAny; my $db = PciIds::DBQAny::new( connectDb(), { - 'list' => 'SELECT id, name, description FROM locations WHERE name IS NOT NULL ORDER BY id' + 'list' => 'SELECT id, name, note FROM locations WHERE name IS NOT NULL ORDER BY id' } ); foreach( @{$db->query( 'list', [] )} ) { diff --git a/scripts/feeddb.pl b/scripts/feeddb.pl index e3a71ca..66d17dd 100755 --- a/scripts/feeddb.pl +++ b/scripts/feeddb.pl @@ -9,9 +9,9 @@ use PciIds::Db; use DBI; my $dbh = connectDb(); -my $query = $dbh->prepare( "INSERT INTO locations (id, name, description, parent) VALUES(?, ?, ?, ?);" ) or die "Could not create the query (".DBI->errstr.")\n"; -my $comment = $dbh->prepare( "INSERT INTO history (location, nodename, nodedescription, seen) VALUES(?, ?, ?, '1')" ) or die "Could not create query (".DBI->errstr.")\n"; -my $update = $dbh->prepare( "UPDATE locations SET maincomment = ? WHERE id = ?" ) or die "Could not create query (".DBI->errstr.")\n"; +my $query = $dbh->prepare( "INSERT INTO locations (id, name, note, parent) VALUES(?, ?, ?, ?);" ) or die "Could not create the query (".DBI->errstr.")\n"; +my $comment = $dbh->prepare( "INSERT INTO history (location, nodename, nodenote, seen) VALUES(?, ?, ?, '1')" ) or die "Could not create query (".DBI->errstr.")\n"; +my $update = $dbh->prepare( "UPDATE locations SET mainhistory = ? WHERE id = ?" ) or die "Could not create query (".DBI->errstr.")\n"; my( $vendor, $type, $sub, $description, $name ); $query->execute( "PC", undef, undef, undef ) or die "Could not add toplevel node\n"; diff --git a/scripts/importil.pl b/scripts/importil.pl index c149567..add02d1 100755 --- a/scripts/importil.pl +++ b/scripts/importil.pl @@ -12,8 +12,8 @@ use PciIds::Users; my $dbh = connectDb(); print "Deleting all PCI devices\n"; $dbh->prepare( "DELETE FROM locations WHERE id like 'PC/%'" )->execute(); -my $newcomment = $dbh->prepare( 'INSERT INTO history (owner, location, time, nodename, nodedescription, text) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?, ?)' ); -my $mismatch = $dbh->prepare( "INSERT INTO history (location, nodename, nodedescription, seen) VALUES(?, ?, ?, '1')" ); +my $newcomment = $dbh->prepare( 'INSERT INTO history (owner, location, time, nodename, nodenote, discussion) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?, ?)' ); +my $mismatch = $dbh->prepare( "INSERT INTO history (location, nodename, nodenote, seen) VALUES(?, ?, ?, '1')" ); my $db = PciIds::DBQ::new( $dbh ); my @toMark; my %ids; diff --git a/scripts/importlog.pl b/scripts/importlog.pl index df75d92..edb40a6 100755 --- a/scripts/importlog.pl +++ b/scripts/importlog.pl @@ -17,13 +17,13 @@ sub translateLoc( $ ) { my $dbh = connectDb(); my $clearHist = $dbh->prepare( 'DELETE FROM history WHERE location = ?' ); my %coms; -my $com = $dbh->prepare( 'INSERT INTO history (owner, location, time, nodename, nodedescription) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?)' ); +my $com = $dbh->prepare( 'INSERT INTO history (owner, location, time, nodename, nodenote) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?)' ); my $user = $dbh->prepare( 'SELECT id FROM users WHERE email = ?' ); my $delHis = $dbh->prepare( 'DELETE FROM history WHERE id = ?' ); my $markMain = $dbh->prepare( 'UPDATE locations SET - maincomment = ?, + mainhistory = ?, name = ( SELECT nodename FROM history WHERE id = ? ), - description = ( SELECT nodedescription FROM history WHERE id = ? ) + note = ( SELECT nodenote FROM history WHERE id = ? ) WHERE id = ?' ); my $markSeen = $dbh->prepare( "UPDATE history SET seen = '1' WHERE id = ?" ); diff --git a/scripts/init b/scripts/init index 30cc1a9..6bc8df3 100755 --- a/scripts/init +++ b/scripts/init @@ -1,6 +1,7 @@ ./scripts/initdb.pl ./scripts/feeddb.pl pci.ids -./scripts/transfer.pl pciidsold -./scripts/importlog.pl iii.log +#./scripts/transfer.pl pciidsold +#./scripts/importlog.pl iii.log +./scripts/importil.pl ~/iii.out echo 'Database is prepared, but it does not contain admins. Add them manually, please.' echo 'Just register like ordinary user and run ./scripts/rights.pl + username validate' diff --git a/scripts/mailbot b/scripts/mailbot index e8a4a3b..9b6bcfc 100755 --- a/scripts/mailbot +++ b/scripts/mailbot @@ -37,7 +37,7 @@ my $hasAuth = $tables->dbh()->prepare( 'SELECT id FROM users WHERE email = ?' ); my $addAuth = $tables->dbh()->prepare( "INSERT INTO users (email, passwd) VALUES(?, '')" ); my $hasItem = $tables->dbh()->prepare( "SELECT 1 FROM locations WHERE id = ?" ); my $addItem = $tables->dbh()->prepare( "INSERT INTO locations (id, parent) VALUES (?, ?)" ); -my $addComment = $tables->dbh()->prepare( "INSERT INTO history (owner, location, text, nodename, nodedescription) VALUES (?, ?, ?, ?, ?)" ); +my $addComment = $tables->dbh()->prepare( "INSERT INTO history (owner, location, discussion, nodename, nodenote) VALUES (?, ?, ?, ?, ?)" ); sub getAuthor( $ ) { my( $mail ) = @_; diff --git a/scripts/transfer.pl b/scripts/transfer.pl index 14c5a9a..fde17ff 100755 --- a/scripts/transfer.pl +++ b/scripts/transfer.pl @@ -32,11 +32,11 @@ print "Submiting items from database\n"; my $itemq = $olddb->prepare( "SELECT id, name, comment, author, status, type FROM ids ORDER BY LENGTH(id), id" ); my $itemp = $newdb->prepare( "INSERT INTO locations (id, parent) VALUES (?, ?)" ); -my $comp = $newdb->prepare( "INSERT INTO history (owner, location, nodename, nodedescription, seen, time) VALUES (?, ?, ?, ?, ?, '2000-01-01 00:00:00')" ); +my $comp = $newdb->prepare( "INSERT INTO history (owner, location, nodename, nodenote, seen, time) VALUES (?, ?, ?, ?, ?, '2000-01-01 00:00:00')" ); my $setMain = $newdb->prepare( 'UPDATE locations SET - maincomment = ?, + mainhistory = ?, name = ( SELECT nodename FROM history WHERE id = ? ), - description = ( SELECT nodedescription FROM history WHERE id = ? ) + note = ( SELECT nodenote FROM history WHERE id = ? ) WHERE id = ?' ); diff --git a/tables b/tables index f42c611..680780a 100644 --- a/tables +++ b/tables @@ -28,9 +28,9 @@ nextxmpp TIMESTAMP#When do we send pending xmpp notifications? # id VARCHAR(50) <> NOT NULL UNIQUE PRIMARY KEY,#The name of the location, must be just node, no / at the end parent VARCHAR(50) <>,#To allow selecting of all node's children -maincomment INT UNSIGNED,#Reference for the main comment -name TINYTEXT <>,#Should match the one of main comment, if any (if no main comment, name can be set too) -description TEXT <>,#Should match the one of main comment (if no main comment, can be set too) +mainhistory INT UNSIGNED,#Reference for the main history +name TINYTEXT <>,#Should match the one of main history, if any (if no main history, name can be set too) +note TEXT <>,#Should match the one of main history (if no main history, can be set too) CONSTRAINT parent_ref FOREIGN KEY (parent) REFERENCES locations(id) ON DELETE CASCADE @rights @@ -42,14 +42,14 @@ CONSTRAINT right_user FOREIGN KEY (userId) REFERENCES users(id) ON DELETE CASCAD PRIMARY KEY (userId, rightId) @history -#Contains the comments in the discussion +#Contains the discussion and history of items id INT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE PRIMARY KEY, owner INT UNSIGNED,#Who posted it? location VARCHAR(50) <> NOT NULL,#Where it belongs -text TEXT <>, +discussion TEXT <>, time TIMESTAMP NOT NULL DEFAULT NOW(),#When this was added nodename TINYTEXT <>,#Modification of the location name -nodedescription TEXT <>,#Modification of the location comment +nodenote TEXT <>,#Modification of the location note seen BOOLEAN NOT NULL DEFAULT '0', #Did some admin see this, or is it still unseen? CONSTRAINT history_location FOREIGN KEY (location) REFERENCES locations(id) ON DELETE CASCADE, CONSTRAINT history_owner FOREIGN KEY (owner) REFERENCES users(id) ON DELETE SET NULL @@ -60,9 +60,9 @@ user INT UNSIGNED NOT NULL,#Who wants it location VARCHAR(50) <> NOT NULL,#Where recursive BOOLEAN NOT NULL DEFAULT '0', type SMALLINT NOT NULL,#When to send -#0: Comment -- When a new comment is posted -#1: Description -- Name or comment changed -#2: MainComment -- The main comment changed +#0: History -- When a new discussion is posted +#1: Description -- Name or note changed +#2: MainHistory -- The main history changed #All contains the less common events notification SMALLINT NOT NULL, #0: mail only @@ -75,14 +75,14 @@ PRIMARY KEY (user, location) @pending #Contains the pending notifications user INT UNSIGNED NOT NULL, -comment INT UNSIGNED NOT NULL, +history INT UNSIGNED NOT NULL, notification SMALLINT NOT NULL, #0: mail #1: xmpp #If a notification generates both, it splits to 2 of them reason SMALLINT NOT NULL, #0: New item -#1: New comment +#1: New history #2: Changed main article -CONSTRAINT pending_comment FOREIGN KEY (comment) REFERENCES history(id) ON DELETE CASCADE, +CONSTRAINT pending_history FOREIGN KEY (history) REFERENCES history(id) ON DELETE CASCADE, CONSTRAINT pending_user FOREIGN KEY (user) REFERENCES users(id) ON DELETE CASCADE -- 2.39.5