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, $discussion ) = @_;
66 my $user = getUser( $email );
67 $name = undef if( ( defined $name ) && $name !~ /\S/ );
68 $comment = undef if( ( defined $comment ) && $comment !~ /\S/ );
69 $discussion = undef if( ( defined $discussion ) && $discussion !~ /\S/ );
70 $newcomment->execute( $user, $addr->get(), $time, $name, $comment, $discussion );
72 $comment = "" unless defined $comment;
73 $name = "" unless defined $name;
74 $ids{"$name\t$comment"} = $id;
80 $db->markChecked( $_ ) foreach( @toMark );
85 $db->setMainComment( $addr->get(), shift );
90 while( defined( $_ = <> ) ) {
91 if( my( $lid ) = /^### ([0-9a-f]+) ###$/ ) {
94 $id = translateLoc( $lid );
96 } elsif( /^(|#.*)$/ ) {
99 my( $command, @params ) = split( /\t/ );
101 if( $command eq "CREATE" ) {
102 my( $time, $email, $name, $comment, $discussion ) = @params;
103 my $hid = addComment( $email, $time, $name, $comment, $discussion );
104 } elsif ( $command eq "APPROVE" ) {
105 my( $time, $email, $name, $comment ) = @params;
106 $comment = "" if( !defined $comment || $comment !~ /\S/ );
107 $name = "" if( !defined $name || $name !~ /\S/ );
108 my $hid = $ids{"$name\t$comment"};
109 $hid = addComment( $email, $time, $name, $comment, undef ) unless defined $hid;
112 } elsif ( $command eq "COMMENT" ) {# Comments are from admins -> they mark as seen too
113 my( $time, $email, $discussion ) = @params;
114 addComment( $email, $time, undef, undef, $discussion );
116 } elsif ( $command eq "MISMATCH" ) {
117 my( $name, $comment ) = @params;
118 $mismatch->execute( $addr->get(), $name, $comment );
119 setMain( $db->last() );
121 die "Unknow command $command\n";