4 # Copyright (C) 2008 Michal Vaner (vorner@ucw.cz)
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # he Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
31 my $dbh = connectDb();
32 print "Deleting all PCI devices\n";
33 $dbh->prepare( "DELETE FROM locations WHERE id like 'PC/%'" )->execute();
34 my $newcomment = $dbh->prepare( 'INSERT INTO history (owner, location, time, nodename, nodenote, discussion) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?, ?)' );
35 my $mismatch = $dbh->prepare( "INSERT INTO history (location, nodename, nodenote, seen) VALUES(?, ?, ?, '1')" );
36 my $db = PciIds::DBQ::new( $dbh );
43 sub translateLoc( $ ) {
45 $loc =~ s/(.{8})(.+)/$1\/$2/;
46 $loc =~ s/(.{4})(.+)/$1\/$2/;
54 $db->command( 'newitem', [ $addr->get(), $addr->parent()->get() ] );
61 print "$cnt\n" if( ++ $cnt % 1000 == 0 );
62 $addr = PciIds::Address::new( $id );
68 $email = "" unless defined $email;
69 $email =~ s/.*<([^<>]*)>.*/$1/;
70 my( $mailCheck ) = emailCheck( $email, undef );
71 if( defined $mailCheck ) {
72 print "Invalid email $email\n";
75 my $result = $db->query( 'email', [ $email ] );
76 if( scalar @{$result} ) {
77 return $result->[0]->[0];
79 $db->command( 'adduser-null', [ $email, '' ] );
84 sub addComment( $$$$$ ) {
85 my( $email, $time, $name, $comment, $discussion ) = @_;
86 my $user = getUser( $email );
87 $name = undef if( ( defined $name ) && $name !~ /\S/ && $name ne '' );
88 $comment = undef if( ( defined $comment ) && $comment !~ /\S/ );
89 $discussion = undef if( ( defined $discussion ) && $discussion !~ /\S/ );
90 $newcomment->execute( $user, $addr->get(), $time, $name, $comment, $discussion );
92 $comment = "" unless defined $comment;
93 $name = "" unless defined $name;
94 $ids{"$name\t$comment"} = $id;
100 $db->markChecked( $_ ) foreach( @toMark );
105 $db->setMainHistory( $addr->get(), shift );
110 while( defined( $_ = <> ) ) {
112 if( my( $lid ) = /^### ([0-9a-f]+) ###$/ ) {
115 $id = translateLoc( $lid );
117 } elsif( /^(|#.*)$/ ) {
120 my( $command, @params ) = split( /\t/ );
122 if( $command eq "CREATE" ) {
123 my( $time, $email, $name, $comment, $discussion ) = @params;
124 my $hid = addComment( $email, $time, $name, $comment, $discussion );
125 } elsif ( $command eq "APPROVE" ) {
126 my( $time, $email, $name, $comment ) = @params;
127 $comment = "" if( !defined $comment || $comment !~ /\S/ );
128 $name = "" if( !defined $name || $name !~ /\S/ );
129 my $hid = $ids{"$name\t$comment"};
130 $hid = addComment( $email, $time, $name, $comment, undef ) unless defined $hid;
133 } elsif ( $command eq "COMMENT" ) {# Comments are from admins -> they mark as seen too
134 my( $time, $email, $discussion ) = @params;
135 addComment( $email, $time, undef, undef, $discussion );
137 } elsif ( $command eq "MISMATCH" ) {
138 my( $name, $comment ) = @params;
139 $mismatch->execute( $addr->get(), $name, $comment );
140 setMain( $db->last() );
142 die "Unknow command $command\n";