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, nodenote, discussion) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?, ?)' );
16 my $mismatch = $dbh->prepare( "INSERT INTO history (location, nodename, nodenote, 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 = "" unless defined $email;
50 $email =~ s/.*<([^<>]*)>.*/$1/;
51 my( $mailCheck ) = emailCheck( $email, undef );
52 if( defined $mailCheck ) {
53 print "Invalid email $email\n";
56 my $result = $db->query( 'email', [ $email ] );
57 if( scalar @{$result} ) {
58 return $result->[0]->[0];
60 $db->command( 'adduser-null', [ $email, '' ] );
65 sub addComment( $$$$$ ) {
66 my( $email, $time, $name, $comment, $discussion ) = @_;
67 my $user = getUser( $email );
68 $name = undef if( ( defined $name ) && $name !~ /\S/ && $name ne '' );
69 $comment = undef if( ( defined $comment ) && $comment !~ /\S/ );
70 $discussion = undef if( ( defined $discussion ) && $discussion !~ /\S/ );
71 $newcomment->execute( $user, $addr->get(), $time, $name, $comment, $discussion );
73 $comment = "" unless defined $comment;
74 $name = "" unless defined $name;
75 $ids{"$name\t$comment"} = $id;
81 $db->markChecked( $_ ) foreach( @toMark );
86 $db->setMainHistory( $addr->get(), shift );
91 while( defined( $_ = <> ) ) {
93 if( my( $lid ) = /^### ([0-9a-f]+) ###$/ ) {
96 $id = translateLoc( $lid );
98 } elsif( /^(|#.*)$/ ) {
101 my( $command, @params ) = split( /\t/ );
103 if( $command eq "CREATE" ) {
104 my( $time, $email, $name, $comment, $discussion ) = @params;
105 my $hid = addComment( $email, $time, $name, $comment, $discussion );
106 } elsif ( $command eq "APPROVE" ) {
107 my( $time, $email, $name, $comment ) = @params;
108 $comment = "" if( !defined $comment || $comment !~ /\S/ );
109 $name = "" if( !defined $name || $name !~ /\S/ );
110 my $hid = $ids{"$name\t$comment"};
111 $hid = addComment( $email, $time, $name, $comment, undef ) unless defined $hid;
114 } elsif ( $command eq "COMMENT" ) {# Comments are from admins -> they mark as seen too
115 my( $time, $email, $discussion ) = @params;
116 addComment( $email, $time, undef, undef, $discussion );
118 } elsif ( $command eq "MISMATCH" ) {
119 my( $name, $comment ) = @params;
120 $mismatch->execute( $addr->get(), $name, $comment );
121 setMain( $db->last() );
123 die "Unknow command $command\n";