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',
'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(?, ?, ?)',
'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 = ?',
'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
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
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', [] )} ) {
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";
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;
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 = ?" );
./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'
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 ) = @_;
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 = ?' );
#
id VARCHAR(50) <<CHARSET>> NOT NULL UNIQUE PRIMARY KEY,#The name of the location, must be just node, no / at the end
parent VARCHAR(50) <<CHARSET>>,#To allow selecting of all node's children
-maincomment INT UNSIGNED,#Reference for the main comment
-name TINYTEXT <<CHARSET>>,#Should match the one of main comment, if any (if no main comment, name can be set too)
-description TEXT <<CHARSET>>,#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 <<CHARSET>>,#Should match the one of main history, if any (if no main history, name can be set too)
+note TEXT <<CHARSET>>,#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
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) <<CHARSET>> NOT NULL,#Where it belongs
-text TEXT <<CHARSET>>,
+discussion TEXT <<CHARSET>>,
time TIMESTAMP NOT NULL DEFAULT NOW(),#When this was added
nodename TINYTEXT <<CHARSET>>,#Modification of the location name
-nodedescription TEXT <<CHARSET>>,#Modification of the location comment
+nodenote TEXT <<CHARSET>>,#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
location VARCHAR(50) <<CHARSET>> 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
@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