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/;
+ $_ =~ s/INSERT INTO rooms /INSERT INTO mod_roomreservation_bookings_old /;
IServ::DB::Exec($_);
}
print "converting the database...\n";
foreach(IServ::DB::GetArr("SELECT * FROM mod_roomreservation_bookings_old;")) {
my %row = %{$_};
+
+ # test if room exists, if not, create it
+ my @room = IServ::DB::GetArr "SELECT * FROM rooms WHERE name='".$row{"room"}."';";
+ if(!@room) {
+ print "NOTICE: room $_ was found in old database but not in current, creating it.\n";
+ IServ::DB::Put "rooms", { "name" => $row{"room"} };
+ }
+
IServ::DB::Put "mod_roomreservation_bookings", { "rrb_room" => $row{"room"},
"rrb_date" => $row{"date"}, "rrb_tsfirst" =>
$tsbeginoldkeys{$row{"timebegin"}}, "rrb_tslast" =>