From d6fadc26427c313080d7693c4a28ed8f0ec559c4 Mon Sep 17 00:00:00 2001 From: rohieb Date: Sun, 13 Jul 2008 22:09:49 +0200 Subject: [PATCH] database conversion, removed needless comments and code --- update-iserv1-iserv2.pl | 63 +++++++++++++---------------------------- 1 file changed, 19 insertions(+), 44 deletions(-) diff --git a/update-iserv1-iserv2.pl b/update-iserv1-iserv2.pl index 3105f77..500ac56 100755 --- a/update-iserv1-iserv2.pl +++ b/update-iserv1-iserv2.pl @@ -6,8 +6,7 @@ use IServ::DB; use Time::Local; my $OLDCFG = "/old/opt/iserv/idesk/rooms/admin/config.inc.rpmsave"; -# FIXME insert real path -my $NEWCFG = "test.inc"; +my $NEWCFG = "/usr/share/iserv/www/inc/mod_room-reservation/config.inc"; my @tsbegin; my @tsend; @@ -24,13 +23,9 @@ open IN, "<", $OLDCFG or die "ERROR: old config file could not be opened: $!"; while() { # skip unused variables if(/\$cfgRooms\[(\"LogOnInsert\"|\'LogOnInsert\')\]/) { - #print "NOTICE: config variable \"LogOnInsert\" is no longer used.\n"; } elsif(/\$cfgRooms\[(\"OldBookings\"|\'OldBookings\')\]/) { - #print "NOTICE: config variable \"OldBookings\" is no longer used.\n"; } elsif(/\$cfgRooms\[(\"ShowClassEdit\"|\'ShowClassEdit\')\]/) { - #print "NOTICE: config variable \"ShowClassEdit\" is no longer used.\n"; } elsif(/\$cfgRooms\[(\"ClassEditText\"|\'ClassEditText\')\]/) { - #print "NOTICE: config variable \"ClassEditText\" is no longer used.\n"; # AbsTime is now named ShowLessons } elsif(/\$cfgRooms\[(\"AbsTime\"|\'AbsTime\')\]\s*=\s*(true|false|0|1)\s*/) { @@ -94,7 +89,6 @@ while() { # convert old user rights to privileges } elsif(/\$cfgRooms\[(\"RestrictAccess\"|\'RestrictAccess\')\]\s*=\s*(false|true|0|1)/) { - #print "config variable \"RestrictAccess\" is no longer used.\n"; $restrictaccess = ($2 eq "true" or $2 eq "1") ? 1 : 0; } elsif(/\$cfgRooms\[(\"AllowedGroups\"|\'AllowedGroups\')\]\s*=\s*array\s*\(/) { @@ -116,7 +110,6 @@ while() { } } elsif(/\$cfgRooms\[(\"GroupsAdmin\"|\'GroupsAdmin\')\]\s*=\s*array\s*\(/) { - #print "config variable AdminGroups is not longer used\n" print "processing admin groups...\n"; while() { if(/\);/) { @@ -191,9 +184,8 @@ print OUT "?>"; close OUT; close IN; -print "\nconverting the database. Have a lot of fun...\n"; +print "\nconverting the database, have a lot of fun...\n"; open IN, "cat /old/rooms.sql | iconv -f utf8 -t utf8 |" or die -#open IN, " "timeslice" ("15:00:00" => "3") @@ -210,45 +202,28 @@ foreach (@tsendold) { $i++; } -#my ($key, $val); -#while(($key, $val) = each(%tsbeginoldkeys)) { -# print "$key => $val\n"; -#} -#while(($key, $val) = each(%tsendoldkeys)) { -# print "$ke:y => $val\n"; -#} - -# FIXME database conversion -print "Importing old bookings...\n"; +# database conversion +# insert old data and then convert them +print "importing old bookings...\n"; IServ::DB::Exec "CREATE TABLE mod_roomreservation_bookings_old (id INT NOT NULL PRIMARY KEY, room TEXT NOT NULL, date DATE NOT NULL, timebegin TIME NOT NULL, timeend TIME NOT NULL, act TEXT REFERENCES users(Act) ON DELETE CASCADE ON UPDATE CASCADE NOT NULL, class TEXT, reason TEXT NOT NULL, fixed BOOL);"; while() { + # rename the table $_ =~ s/INSERT INTO rooms/INSERT INTO mod_roomreservation_bookings_old/; - #print "$_"; IServ::DB::Exec($_); } -#IServ::DB::Exec "INSERT INTO mod_roomreservation_bookings"; + +print "converting the database...\n"; +foreach(IServ::DB::GetArr("SELECT * FROM mod_roomreservation_bookings_old;")) { + my %row = %{$_}; + IServ::DB::Put "mod_roomreservation_bookings", { "rrb_room" => $row{"room"}, + "rrb_date" => $row{"date"}, "rrb_tsfirst" => + $tsbeginoldkeys{$row{"timebegin"}}, "rrb_tslast" => + $tsendoldkeys{$row{"timeend"}}, "rrb_act" => $row{"act"}, "rrb_reason" => + $row{"reason"}, "rrb_interval" => $row{"fixed"} }; +} + +# delete old table IServ::DB::Exec "DROP TABLE mod_roomreservation_bookings_old;"; -die 333; -$i = 0; +print "done.\n"; -my $maxid = 0; -while() { - if(/COPY \"rooms\" FROM stdin;/) { - while() { - if(/\\\./) { - last; - } elsif(/(\d+)\t([^\t]*)\t(\d{4}-\d\d-\d\d)\t(\d\d:\d\d:\d\d)\t(\d\d:\d\d:\d\d)\t([a-zA-Z0-9\.-]+)\t([^\t]*)\t([^\t]*)\t(t|f)/) { - $i++; - # FIXME convert the timeslices!!! - # FIXME insert the right table name and rs_weekly - # ignore uid, it is serial, also class is not used anymore - # print $tsbeginoldkeys{$4}; print "\n"; - IServ::DB::Put "roomschedule", { "rs_room" => $2, "rs_date" => $3, - "rs_tsfirst" => $tsbeginoldkeys{$4}, "rs_tslast" => $tsendoldkeys{$5}, - "rs_act" => $6, "rs_reason" => $8, "rs_weekly" => $9 }; - } - } - } -} -print "$i datasets converted.\ndone!\n"; -- 2.20.1