13 my $newdb = connectDb();
14 my( $user, $passwd ) = confList( [ "dbuser", "dbpasswd" ] );
15 my $olddb = DBI->connect( "dbi:mysql:$orig", $user, $passwd, { 'RaiseError' => 1 } );
17 print "Submiting ordinary users\n";
18 my $uquery = $olddb->prepare( "SELECT DISTINCT author FROM ids WHERE author like '%@%'" );
19 my $upush = $newdb->prepare( "INSERT INTO users (email, passwd) VALUES (?, '')" );
21 my %users = ( '' => undef );
23 while( my( $author ) = $uquery->fetchrow_array ) {
24 $upush->execute( $author );
25 $users{$author} = $newdb->last_insert_id( undef, undef, undef, undef );
28 my $clean = $newdb->prepare( "DELETE FROM locations WHERE id like 'PC/%'" );
29 print "Cleaning old PCI devices to make place for new ones\n";
31 print "Submiting items from database\n";
33 my $itemq = $olddb->prepare( "SELECT id, name, comment, author, status, type FROM ids ORDER BY LENGTH(id), id" );
34 my $itemp = $newdb->prepare( "INSERT INTO locations (id, parent) VALUES (?, ?)" );
35 my $comp = $newdb->prepare( "INSERT INTO history (owner, location, nodename, nodenote, seen, time) VALUES (?, ?, ?, ?, ?, '2000-01-01 00:00:00')" );
36 my $setMain = $newdb->prepare( 'UPDATE locations SET
38 name = ( SELECT nodename FROM history WHERE id = ? ),
39 note = ( SELECT nodenote FROM history WHERE id = ? )
50 $i =~ s/(.{4,4})(.*)/PC\/$1\/$2/;
55 $i =~ s/(.{4,4})(.{4,4})(.*)/PC\/$1\/$2\/$3/;
61 while( my( $id, $name, $description, $author, $status, $type ) = $itemq->fetchrow_array ) {
62 $id = &{$rex{$type}}( $id );
64 $parent =~ s/\/[^\/]+$//;
65 eval {#Add it if not present yet
66 $itemp->execute( $id, $parent );
68 $author = '' unless( defined $author );
69 $comp->execute( $users{$author} ? $users{$author} : undef, $id, $name, $description, !$status );
71 my $last = $newdb->last_insert_id( undef, undef, undef, undef );
72 $setMain->execute( $last, $last, $last, $id );