10 sub translateLoc( $ ) {
12 $loc =~ s/(.{8})(.+)/$1\/$2/;
13 $loc =~ s/(.{4})(.+)/$1\/$2/;
17 my $dbh = connectDb();
18 my $clearHist = $dbh->prepare( 'DELETE FROM history WHERE location = ?' );
20 my $com = $dbh->prepare( 'INSERT INTO history (owner, location, time, nodename, nodenote) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?)' );
21 my $user = $dbh->prepare( 'SELECT id FROM users WHERE email = ?' );
22 my $delHis = $dbh->prepare( 'DELETE FROM history WHERE id = ?' );
23 my $markMain = $dbh->prepare( 'UPDATE locations SET
25 name = ( SELECT nodename FROM history WHERE id = ? ),
26 note = ( SELECT nodenote FROM history WHERE id = ? )
29 my $markSeen = $dbh->prepare( "UPDATE history SET seen = '1' WHERE id = ?" );
32 $user->execute( shift );
33 if( my( $id ) = $user->fetchrow_array ) {
45 print "Parsing and importing log\n";
48 my( $time, $who, $ip, $command, $id, $location, $name, $description, $email );
49 if( ( $time, $who, $ip, $command, $id, $location, $name, $description, $email ) = /^(\d+) (\S+) ([0-9.]+) (Create|Batch submit:) (\d+) ([0-9a-f]+) '(.*)(?<!\\)' '(.*)(?<!\\)' '(.*)(?<!\\)'/ ) {
50 my $translated = translateLoc( $location );
51 unless( $tracked{$location} ) {#From now on, it is restored from the log
52 $tracked{$location} = 1;
53 $clearHist->execute( $translated );
55 $name =~ s/\\(.)/$1/g;
56 $description =~ s/\\(.)/$1/g;
57 $name = undef if( $name eq '' );
58 $description = undef if( $description eq '' );
59 eval {#If the item is not here at all, it was deleted -> no need to add it here
60 $com->execute( getUser( $email ), $translated, $time, $name, $description );
61 $coms{$id} = $dbh->last_insert_id( undef, undef, undef, undef );
67 } elsif( ( $time, $who, $ip, $command, $id, $location, $description, $email ) = /^(\d+) (\S+) ([0-9.]+) (Approve|Delete|Overriden) (\d+) ([0-9a-f]+) '(.*)(?<!\\)' '(.*)(?<!\\)'/ ) {
68 next unless( defined( $coms{$id} ) );#This one not tracked yet
69 if( $command eq 'Approve' ) {
71 $markMain->execute( $i, $i, $i, translateLoc( $location ) );
72 $markSeen->execute( $i );
74 } elsif( $command eq 'Delete' ) {
75 $delHis->execute( $coms{$id} );
78 $markSeen->execute( $coms{$id} );
81 print "Unparsed line: $_";