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
29 sub translateLoc( $ ) {
31 $loc =~ s/(.{8})(.+)/$1\/$2/;
32 $loc =~ s/(.{4})(.+)/$1\/$2/;
36 my $dbh = connectDb();
37 my $clearHist = $dbh->prepare( 'DELETE FROM history WHERE location = ?' );
39 my $com = $dbh->prepare( 'INSERT INTO history (owner, location, time, nodename, nodenote) VALUES (?, ?, FROM_UNIXTIME(?), ?, ?)' );
40 my $user = $dbh->prepare( 'SELECT id FROM users WHERE email = ?' );
41 my $delHis = $dbh->prepare( 'DELETE FROM history WHERE id = ?' );
42 my $markMain = $dbh->prepare( 'UPDATE locations SET
44 name = ( SELECT nodename FROM history WHERE id = ? ),
45 note = ( SELECT nodenote FROM history WHERE id = ? )
48 my $markSeen = $dbh->prepare( "UPDATE history SET seen = '1' WHERE id = ?" );
51 $user->execute( shift );
52 if( my( $id ) = $user->fetchrow_array ) {
64 print "Parsing and importing log\n";
67 my( $time, $who, $ip, $command, $id, $location, $name, $description, $email );
68 if( ( $time, $who, $ip, $command, $id, $location, $name, $description, $email ) = /^(\d+) (\S+) ([0-9.]+) (Create|Batch submit:) (\d+) ([0-9a-f]+) '(.*)(?<!\\)' '(.*)(?<!\\)' '(.*)(?<!\\)'/ ) {
69 my $translated = translateLoc( $location );
70 unless( $tracked{$location} ) {#From now on, it is restored from the log
71 $tracked{$location} = 1;
72 $clearHist->execute( $translated );
74 $name =~ s/\\(.)/$1/g;
75 $description =~ s/\\(.)/$1/g;
76 $name = undef if( $name eq '' );
77 $description = undef if( $description eq '' );
78 eval {#If the item is not here at all, it was deleted -> no need to add it here
79 $com->execute( getUser( $email ), $translated, $time, $name, $description );
80 $coms{$id} = $dbh->last_insert_id( undef, undef, undef, undef );
86 } elsif( ( $time, $who, $ip, $command, $id, $location, $description, $email ) = /^(\d+) (\S+) ([0-9.]+) (Approve|Delete|Overriden) (\d+) ([0-9a-f]+) '(.*)(?<!\\)' '(.*)(?<!\\)'/ ) {
87 next unless( defined( $coms{$id} ) );#This one not tracked yet
88 if( $command eq 'Approve' ) {
90 $markMain->execute( $i, $i, $i, translateLoc( $location ) );
91 $markSeen->execute( $i );
93 } elsif( $command eq 'Delete' ) {
94 $delHis->execute( $coms{$id} );
97 $markSeen->execute( $coms{$id} );
100 print "Unparsed line: $_";