database conversion, removed needless comments and code
authorrohieb <devnull@localhost>
Sun, 13 Jul 2008 20:09:49 +0000 (22:09 +0200)
committerrohieb <devnull@localhost>
Sun, 13 Jul 2008 20:09:49 +0000 (22:09 +0200)
update-iserv1-iserv2.pl

index 3105f77..500ac56 100755 (executable)
@@ -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(<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*/) {
@@ -94,7 +89,6 @@ while(<IN>) {
 
   # 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(<IN>) {
     }
   
   } 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(/\);/) {
@@ -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, "</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")
@@ -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(<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 table
 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.033554 seconds and 4 git commands to generate.