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;
while(<IN>) {
# 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*/) {
my $hr = $2;
$hr = "0$hr" if length $hr < 2;
push @tsbeginold, "$hr:$3:00";
- push @tsbegin, Time::Local::timelocal 0, $3, $hr, 1, 0, 1970;
+ push @tsbegin, Time::Local::timegm 0, $3, $hr, 1, 0, 1970;
print " found beginning: $hr:$3\n";
}
}
my $hr = $2;
$hr = "0$hr" if length $hr < 2;
push @tsendold, "$hr:$3:00";
- push @tsend, Time::Local::timelocal 0, $3, $hr, 1, 0, 1970;
+ push @tsend, Time::Local::timegm 0, $3, $hr, 1, 0, 1970;
print " found ending: $hr:$3\n";
}
}
# 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*\(/) {
}
} elsif(/\$cfgRooms\[(\"GroupsAdmin\"|\'GroupsAdmin\')\]\s*=\s*array\s*\(/) {
- #print "config variable AdminGroups is not longer used\n"
print "processing admin groups...\n";
while(<IN>) {
if(/\);/) {
open OUT, ">", $NEWCFG or die "ERROR: new config file could not be opened: $!";
print OUT "<?php\n\$this->flushTimeslices();\n";
for(my $i = 0; $i <= $#tsbegin; $i++) {
- print OUT "\$this->addTimeslice(new rsTimeslice($tsbegin[$i],$tsend[$i]));\n";
+ print OUT "\$this->addTimeslice(new mod_roomReservationTimeslice($tsbegin[$i],$tsend[$i]));\n";
}
print OUT "\$this->setShowWeekend($showweekend);\n";
print OUT "\$this->setShowLessons($showlessons);\n";
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, "</old/pgdump.sql" or die
"ERROR: the database dump could not be opened: $!\n";
# build hashes of the form "timestamp" => "timeslice" ("15:00:00" => "3")
$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(<IN>) {
+ # 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 tables
IServ::DB::Exec "DROP TABLE mod_roomreservation_bookings_old;";
+IServ::DB::Exec "DROP TABLE rooms_archive;";
-die 333;
-$i = 0;
+print "done.\n";
-my $maxid = 0;
-while(<IN>) {
- if(/COPY \"rooms\" FROM stdin;/) {
- while(<IN>) {
- 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";