3105f770e83a81363442aad990ef0a90f40c0a44
8 my $OLDCFG = "/old/opt/iserv/idesk/rooms/admin/config.inc.rpmsave";
9 # FIXME insert real path
10 my $NEWCFG = "test.inc";
18 my $restrictaccess = 0;
22 # convert the config file
23 open IN
, "<", $OLDCFG or die "ERROR: old config file could not be opened: $!";
25 # skip unused variables
26 if(/\$cfgRooms\[(\"LogOnInsert\"|\'LogOnInsert\')\]/) {
27 #print "NOTICE: config variable \"LogOnInsert\" is no longer used.\n";
28 } elsif(/\$cfgRooms\[(\"OldBookings\"|\'OldBookings\')\]/) {
29 #print "NOTICE: config variable \"OldBookings\" is no longer used.\n";
30 } elsif(/\$cfgRooms\[(\"ShowClassEdit\"|\'ShowClassEdit\')\]/) {
31 #print "NOTICE: config variable \"ShowClassEdit\" is no longer used.\n";
32 } elsif(/\$cfgRooms\[(\"ClassEditText\"|\'ClassEditText\')\]/) {
33 #print "NOTICE: config variable \"ClassEditText\" is no longer used.\n";
35 # AbsTime is now named ShowLessons
36 } elsif(/\$cfgRooms\[(\"AbsTime\"|\'AbsTime\')\]\s*=\s*(true|false|0|1)\s*/) {
37 print "AbsTime is $2\n";
38 $showlessons = ($2 eq "true" or $2 eq "1") ?
1 : 0;
41 } elsif(/\$cfgRooms\[(\"ShowWeekend\"|\'ShowWeekend\')\]\s*=\s*(true|false|0|1)/) {
42 print "ShowWeekend is $2\n";
43 $showweekend = ($2 eq "true" or $2 eq "1") ?
1 : 0;
45 # timeslice beginnings
46 } elsif(/\$cfgRooms\[(\"TimeslicesBegin\"|\'TimeslicesBegin\')\]\s*=\s*array\s*\(/) {
47 print "processing timeslice beginnings...\n";
52 /\s*(\d)\s*=>\s*[\'\"](\d\d?):(\d\d)[\'\"]\s*/;
54 $hr = "0$hr" if length $hr < 2;
55 push @tsbeginold, "$hr:$3:00";
56 push @tsbegin, Time
::Local
::timelocal
0, $3, $hr, 1, 0, 1970;
57 print " found beginning: $hr:$3\n";
62 } elsif(/\$cfgRooms\[(\"TimeslicesEnd\"|\'TimeslicesEnd\')\]\s*=\s*array\s*\(/) {
63 print "processing timeslice endings...\n";
68 /\s*(\d)\s*=>\s*[\'\"](\d\d?):(\d\d)[\'\"]\s*/;
70 $hr = "0$hr" if length $hr < 2;
71 push @tsendold, "$hr:$3:00";
72 push @tsend, Time
::Local
::timelocal
0, $3, $hr, 1, 0, 1970;
73 print " found ending: $hr:$3\n";
77 # add rooms to the database, if they do not exist yet
78 } elsif(/\$cfgRooms\[(\"Rooms\"|\'Rooms\')\]\s*=\s*array\s*\(/) {
79 print "processing rooms...\n";
84 /\s*\d\s*=>\s*((\'([^\']*)\')|(\"([^\"]*)\"))\s*/;
85 my $sqlval = IServ
::DB
::Val
$3;
86 if(IServ
::DB
::Rows
"SELECT * FROM rooms WHERE name = $sqlval;") {
87 print " room '$3' found in database.\n";
89 print "NOTICE: room '$3' not found in database, adding it.\n";
90 IServ
::DB
::Put
"rooms", { "name" => $3 } or die $!;
95 # convert old user rights to privileges
96 } elsif(/\$cfgRooms\[(\"RestrictAccess\"|\'RestrictAccess\')\]\s*=\s*(false|true|0|1)/) {
97 #print "config variable \"RestrictAccess\" is no longer used.\n";
98 $restrictaccess = ($2 eq "true" or $2 eq "1") ?
1 : 0;
100 } elsif(/\$cfgRooms\[(\"AllowedGroups\"|\'AllowedGroups\')\]\s*=\s*array\s*\(/) {
101 print "processing allowed groups...\n";
106 /\s*\d\s*=>\s*((\'([^\']*)\')|(\"([^\"]*)\"))\s*/;
107 my $name = IServ
::DB
::Val
$3;
108 my @act = IServ
::DB
::GetArr
"SELECT act FROM groups WHERE name=$name;";
110 print " found group $name.\n";
111 push @allowedgroups, $act[0]{"act"};
113 print "NOTICE: group $name not found in database, ignoring it.\n";
118 } elsif(/\$cfgRooms\[(\"GroupsAdmin\"|\'GroupsAdmin\')\]\s*=\s*array\s*\(/) {
119 #print "config variable AdminGroups is not longer used\n"
120 print "processing admin groups...\n";
125 /\s*\d\s*=>\s*((\'([^\']*)\')|(\"([^\"]*)\"))\s*/;
126 my $name = IServ
::DB
::Val
$3;
127 my @act = IServ
::DB
::GetArr
"SELECT act FROM groups WHERE name=$name;";
129 print " found group $name.\n";
130 push @admingroups, $act[0]{"act"};
132 print "NOTICE: group $name not found in database, ignoring it.\n";
139 print "converting old user rights to privileges...\n";
140 # change the privilege names to the right ones
141 if($restrictaccess) {
142 foreach(@allowedgroups) {
143 my $priv = "mod_roomreservation_view";
145 my @act = IServ
::DB
::GetArr
"SELECT act FROM privileges_assign ".
146 "WHERE privilege='$priv' AND act='$act';";
148 print " group $_ is already allowed to see the bookings, ignoring it.\n";
150 IServ
::DB
::Put
"privileges_assign", { "act" => $_,
151 "privilege" => $priv } or die $!;
152 print " allowed viewing for group '$_'\n";
155 $priv = "mod_roomreservation_book";
156 @act = "SELECT act FROM privileges_assign ".
157 "WHERE privilege='$priv' AND act='$act';";
159 print " group $_ is already allowed to book, ignoring it.\n";
161 IServ
::DB
::Put
"privileges_assign", { "act" => $_,
162 "privilege" => $priv } or die $!;
163 print " allowed booking for group '$_'\n";
167 foreach(@admingroups) {
168 my $priv = "mod_roomreservation_admin";
170 my @act = IServ
::DB
::GetArr
"SELECT act FROM privileges_assign ".
171 "WHERE privilege='$priv' AND act='$act';";
173 print " group $_ has already adminship, ignoring it.\n";
175 IServ
::DB
::Put
"privileges_assign", { "act" => $_,
176 "privilege" => $priv } or die $!;
177 print " allowed administration for group '$_'\n";
181 print "writing config file...\n";
182 system "touch $NEWCFG";
183 open OUT
, ">", $NEWCFG or die "ERROR: new config file could not be opened: $!";
184 print OUT
"<?php\n\$this->flushTimeslices();\n";
185 for(my $i = 0; $i <= $#tsbegin; $i++) {
186 print OUT
"\$this->addTimeslice(new rsTimeslice($tsbegin[$i],$tsend[$i]));\n";
188 print OUT
"\$this->setShowWeekend($showweekend);\n";
189 print OUT
"\$this->setShowLessons($showlessons);\n";
194 print "\nconverting the database. Have a lot of fun...\n";
195 open IN
, "cat /old/rooms.sql | iconv -f utf8 -t utf8 |" or die
196 #open IN, "</old/pgdump.sql" or die
197 "ERROR: the database dump could not be opened: $!\n";
199 # build hashes of the form "timestamp" => "timeslice" ("15:00:00" => "3")
203 foreach (@tsbeginold) {
204 $tsbeginoldkeys{$_} = $i;
208 foreach (@tsendold) {
209 $tsendoldkeys{$_} = $i;
214 #while(($key, $val) = each(%tsbeginoldkeys)) {
215 # print "$key => $val\n";
217 #while(($key, $val) = each(%tsendoldkeys)) {
218 # print "$ke:y => $val\n";
221 # FIXME database conversion
222 print "Importing old bookings...\n";
223 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);";
225 $_ =~ s/INSERT INTO rooms/INSERT INTO mod_roomreservation_bookings_old/;
229 #IServ::DB::Exec "INSERT INTO mod_roomreservation_bookings";
230 IServ
::DB
::Exec
"DROP TABLE mod_roomreservation_bookings_old;";
237 if(/COPY \"rooms\" FROM stdin;/) {
241 } 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)/) {
243 # FIXME convert the timeslices!!!
244 # FIXME insert the right table name and rs_weekly
245 # ignore uid, it is serial, also class is not used anymore
246 # print $tsbeginoldkeys{$4}; print "\n";
247 IServ
::DB
::Put
"roomschedule", { "rs_room" => $2, "rs_date" => $3,
248 "rs_tsfirst" => $tsbeginoldkeys{$4}, "rs_tslast" => $tsendoldkeys{$5},
249 "rs_act" => $6, "rs_reason" => $8, "rs_weekly" => $9 };
254 print "$i datasets converted.\ndone!\n";
This page took 0.077769 seconds and 3 git commands to generate.