getTimesliceBeginnings(), getTimesliceEndings(): fixed GMT problem here too
[iserv-mod-room-reservation.git] / update-iserv1-iserv2.pl
index 3105f77..76b05dc 100755 (executable)
@@ -6,8 +6,7 @@ use IServ::DB;
 use Time::Local;
 
 my $OLDCFG = "/old/opt/iserv/idesk/rooms/admin/config.inc.rpmsave";
 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;
 
 my @tsbegin;
 my @tsend;
@@ -24,13 +23,9 @@ open IN, "<", $OLDCFG or die "ERROR: old config file could not be opened: $!";
 while(<IN>) {
   # skip unused variables
   if(/\$cfgRooms\[(\"LogOnInsert\"|\'LogOnInsert\')\]/) {
 while(<IN>) {
   # skip unused variables
   if(/\$cfgRooms\[(\"LogOnInsert\"|\'LogOnInsert\')\]/) {
-    #print "NOTICE: config variable \"LogOnInsert\" is no longer used.\n";
   } elsif(/\$cfgRooms\[(\"OldBookings\"|\'OldBookings\')\]/) {
   } elsif(/\$cfgRooms\[(\"OldBookings\"|\'OldBookings\')\]/) {
-    #print "NOTICE: config variable \"OldBookings\" is no longer used.\n";
   } elsif(/\$cfgRooms\[(\"ShowClassEdit\"|\'ShowClassEdit\')\]/) {
   } elsif(/\$cfgRooms\[(\"ShowClassEdit\"|\'ShowClassEdit\')\]/) {
-    #print "NOTICE: config variable \"ShowClassEdit\" is no longer used.\n";
   } elsif(/\$cfgRooms\[(\"ClassEditText\"|\'ClassEditText\')\]/) {
   } 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*/) {
 
   # AbsTime is now named ShowLessons
   } elsif(/\$cfgRooms\[(\"AbsTime\"|\'AbsTime\')\]\s*=\s*(true|false|0|1)\s*/) {
@@ -53,7 +48,7 @@ while(<IN>) {
         my $hr = $2;
         $hr = "0$hr" if length $hr < 2;
         push @tsbeginold, "$hr:$3:00";
         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";
       }
     }
         print "  found beginning: $hr:$3\n";
       }
     }
@@ -69,7 +64,7 @@ while(<IN>) {
         my $hr = $2;
         $hr = "0$hr" if length $hr < 2;
         push @tsendold, "$hr:$3:00";
         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";
       }
     }
         print "  found ending: $hr:$3\n";
       }
     }
@@ -94,7 +89,6 @@ while(<IN>) {
 
   # convert old user rights to privileges
   } elsif(/\$cfgRooms\[(\"RestrictAccess\"|\'RestrictAccess\')\]\s*=\s*(false|true|0|1)/) {
 
   # 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*\(/) {
     $restrictaccess = ($2 eq "true" or $2 eq "1") ? 1 : 0;
 
   } elsif(/\$cfgRooms\[(\"AllowedGroups\"|\'AllowedGroups\')\]\s*=\s*array\s*\(/) {
@@ -116,7 +110,6 @@ while(<IN>) {
     }
   
   } elsif(/\$cfgRooms\[(\"GroupsAdmin\"|\'GroupsAdmin\')\]\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(/\);/) {
     print "processing admin groups...\n";
     while(<IN>) {
       if(/\);/) {
@@ -183,7 +176,7 @@ system "touch $NEWCFG";
 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++) {
 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";
 }
 print OUT "\$this->setShowWeekend($showweekend);\n";
 print OUT "\$this->setShowLessons($showlessons);\n";
@@ -191,9 +184,8 @@ print OUT "?>";
 close OUT;
 close IN;
 
 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, "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")
   "ERROR: the database dump could not be opened: $!\n";
 
 # build hashes of the form "timestamp" => "timeslice" ("15:00:00" => "3")
@@ -210,45 +202,28 @@ foreach (@tsendold) {
   $i++;
 }
 
   $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>) {
 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/;
-  #print "$_";
   IServ::DB::Exec($_);
 }
   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;";
 
 IServ::DB::Exec "DROP TABLE mod_roomreservation_bookings_old;";
 
-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";
This page took 0.0465 seconds and 4 git commands to generate.