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
31 my $newdb = connectDb();
32 my( $user, $passwd ) = confList( [ "dbuser", "dbpasswd" ] );
33 my $olddb = DBI->connect( "dbi:mysql:$orig", $user, $passwd, { 'RaiseError' => 1 } );
35 print "Submiting ordinary users\n";
36 my $uquery = $olddb->prepare( "SELECT DISTINCT author FROM ids WHERE author like '%@%'" );
37 my $upush = $newdb->prepare( "INSERT INTO users (email, passwd) VALUES (?, '')" );
39 my %users = ( '' => undef );
41 while( my( $author ) = $uquery->fetchrow_array ) {
42 $upush->execute( $author );
43 $users{$author} = $newdb->last_insert_id( undef, undef, undef, undef );
46 my $clean = $newdb->prepare( "DELETE FROM locations WHERE id like 'PC/%'" );
47 print "Cleaning old PCI devices to make place for new ones\n";
49 print "Submiting items from database\n";
51 my $itemq = $olddb->prepare( "SELECT id, name, comment, author, status, type FROM ids ORDER BY LENGTH(id), id" );
52 my $itemp = $newdb->prepare( "INSERT INTO locations (id, parent) VALUES (?, ?)" );
53 my $comp = $newdb->prepare( "INSERT INTO history (owner, location, nodename, nodenote, seen, time) VALUES (?, ?, ?, ?, ?, '2000-01-01 00:00:00')" );
54 my $setMain = $newdb->prepare( 'UPDATE locations SET
56 name = ( SELECT nodename FROM history WHERE id = ? ),
57 note = ( SELECT nodenote FROM history WHERE id = ? )
68 $i =~ s/(.{4,4})(.*)/PC\/$1\/$2/;
73 $i =~ s/(.{4,4})(.{4,4})(.*)/PC\/$1\/$2\/$3/;
79 while( my( $id, $name, $description, $author, $status, $type ) = $itemq->fetchrow_array ) {
80 $id = &{$rex{$type}}( $id );
82 $parent =~ s/\/[^\/]+$//;
83 eval {#Add it if not present yet
84 $itemp->execute( $id, $parent );
86 $author = '' unless( defined $author );
87 $comp->execute( $users{$author} ? $users{$author} : undef, $id, $name, $description, !$status );
89 my $last = $newdb->last_insert_id( undef, undef, undef, undef );
90 $setMain->execute( $last, $last, $last, $id );