12 my $dbh = connectDb();
13 print "Deleting all PCI devices\n";
14 $dbh->prepare( "DELETE FROM locations WHERE id like 'PC/%'" )->execute();
15 my $newcomment = $dbh->prepare( 'INSERT INTO history (owner, location, time, nodename, nodedescription, text) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?, ?)' );
16 my $mismatch = $dbh->prepare( "INSERT INTO history (location, nodename, nodedescription, seen) VALUES(?, ?, ?, '1')" );
17 my $db = PciIds::DBQ::new( $dbh );
24 sub translateLoc( $ ) {
26 $loc =~ s/(.{8})(.+)/$1\/$2/;
27 $loc =~ s/(.{4})(.+)/$1\/$2/;
35 $db->command( 'newitem', [ $addr->get(), $addr->parent()->get() ] );
42 print "$cnt\n" if( ++ $cnt % 1000 == 0 );
43 $addr = PciIds::Address::new( $id );
49 $email =~ s/.*<([^<>]*)>.*/$1/;
50 my( $mailCheck ) = emailCheck( $email, undef );
51 if( defined $mailCheck ) {
52 print "Invalid email $email\n";
55 my $result = $db->query( 'email', [ $email ] );
56 if( scalar @{$result} ) {
57 return $result->[0]->[0];
59 $db->command( 'adduser-null', [ $email, '' ] );
64 sub addComment( $$$$$ ) {
65 my( $email, $time, $name, $comment, $history ) = @_;
66 my $user = getUser( $email );
67 $newcomment->execute( $user, $addr->get(), $time, $name, $comment, $history );
69 $comment = "" unless defined $comment;
70 $name = "" unless defined $name;
71 $ids{"$name\t$comment"} = $id;
77 $db->markChecked( $_ ) foreach( @toMark );
82 $db->setMainComment( $addr->get(), shift );
87 while( defined( $_ = <> ) ) {
88 if( my( $lid ) = /^### ([0-9a-f]+) ###$/ ) {
91 $id = translateLoc( $lid );
93 } elsif( /^(|#.*)$/ ) {
96 my( $command, @params ) = split( /\t/ );
98 if( $command eq "CREATE" ) {
99 my( $time, $email, $name, $comment, $discussion ) = @params;
100 my $hid = addComment( $email, $time, $name, $comment, $discussion );
101 } elsif ( $command eq "APPROVE" ) {
102 my( $time, $email, $name, $comment ) = @params;
103 $comment = "" unless defined $comment;
104 $name = "" unless defined $name;
105 my $hid = $ids{"$name\t$comment"};
106 $hid = addComment( $email, $time, $name, $comment, undef );
109 } elsif ( $command eq "COMMENT" ) {# Comments are from admins -> they mark as seen too
110 my( $time, $email, $discussion ) = @params;
111 addComment( $email, $time, undef, undef, $discussion );
113 } elsif ( $command eq "MISMATCH" ) {
114 my( $name, $comment ) = @params;
115 $mismatch->execute( $addr->get(), $name, $comment );
116 setMain( $db->last() );
118 die "Unknow command $command\n";