8 my $OLDCFG = "/old/opt/iserv/idesk/rooms/admin/config.inc.rpmsave";
9 my $NEWCFG = "/usr/share/iserv/www/inc/mod_room-reservation/config.inc";
17 my $restrictaccess = 0;
21 # convert the config file
22 open IN
, "<", $OLDCFG or die "ERROR: old config file could not be opened: $!";
24 # skip unused variables
25 if(/\$cfgRooms\[(\"LogOnInsert\"|\'LogOnInsert\')\]/) {
26 } elsif(/\$cfgRooms\[(\"OldBookings\"|\'OldBookings\')\]/) {
27 } elsif(/\$cfgRooms\[(\"ShowClassEdit\"|\'ShowClassEdit\')\]/) {
28 } elsif(/\$cfgRooms\[(\"ClassEditText\"|\'ClassEditText\')\]/) {
30 # AbsTime is now named ShowLessons
31 } elsif(/\$cfgRooms\[(\"AbsTime\"|\'AbsTime\')\]\s*=\s*(true|false|0|1)\s*/) {
32 print "AbsTime is $2\n";
33 $showlessons = ($2 eq "true" or $2 eq "1") ?
1 : 0;
36 } elsif(/\$cfgRooms\[(\"ShowWeekend\"|\'ShowWeekend\')\]\s*=\s*(true|false|0|1)/) {
37 print "ShowWeekend is $2\n";
38 $showweekend = ($2 eq "true" or $2 eq "1") ?
1 : 0;
40 # timeslice beginnings
41 } elsif(/\$cfgRooms\[(\"TimeslicesBegin\"|\'TimeslicesBegin\')\]\s*=\s*array\s*\(/) {
42 print "processing timeslice beginnings...\n";
47 /\s*(\d)\s*=>\s*[\'\"](\d\d?):(\d\d)[\'\"]\s*/;
49 $hr = "0$hr" if length $hr < 2;
50 push @tsbeginold, "$hr:$3:00";
51 push @tsbegin, Time
::Local
::timegm
0, $3, $hr, 1, 0, 1970;
52 print " found beginning: $hr:$3\n";
57 } elsif(/\$cfgRooms\[(\"TimeslicesEnd\"|\'TimeslicesEnd\')\]\s*=\s*array\s*\(/) {
58 print "processing timeslice endings...\n";
63 /\s*(\d)\s*=>\s*[\'\"](\d\d?):(\d\d)[\'\"]\s*/;
65 $hr = "0$hr" if length $hr < 2;
66 push @tsendold, "$hr:$3:00";
67 push @tsend, Time
::Local
::timegm
0, $3, $hr, 1, 0, 1970;
68 print " found ending: $hr:$3\n";
72 # add rooms to the database, if they do not exist yet
73 } elsif(/\$cfgRooms\[(\"Rooms\"|\'Rooms\')\]\s*=\s*array\s*\(/) {
74 print "processing rooms...\n";
79 /\s*\d\s*=>\s*((\'([^\']*)\')|(\"([^\"]*)\"))\s*/;
80 my $sqlval = IServ
::DB
::Val
$3;
81 if(IServ
::DB
::Rows
"SELECT * FROM rooms WHERE name = $sqlval;") {
82 print " room '$3' found in database.\n";
84 print "NOTICE: room '$3' not found in database, adding it.\n";
85 IServ
::DB
::Put
"rooms", { "name" => $3 } or die $!;
90 # convert old user rights to privileges
91 } elsif(/\$cfgRooms\[(\"RestrictAccess\"|\'RestrictAccess\')\]\s*=\s*(false|true|0|1)/) {
92 $restrictaccess = ($2 eq "true" or $2 eq "1") ?
1 : 0;
94 } elsif(/\$cfgRooms\[(\"AllowedGroups\"|\'AllowedGroups\')\]\s*=\s*array\s*\(/) {
95 print "processing allowed groups...\n";
100 /\s*\d\s*=>\s*((\'([^\']*)\')|(\"([^\"]*)\"))\s*/;
101 my $name = IServ
::DB
::Val
$3;
102 my @act = IServ
::DB
::GetArr
"SELECT act FROM groups WHERE name=$name;";
104 print " found group $name.\n";
105 push @allowedgroups, $act[0]{"act"};
107 print "NOTICE: group $name not found in database, ignoring it.\n";
112 } elsif(/\$cfgRooms\[(\"GroupsAdmin\"|\'GroupsAdmin\')\]\s*=\s*array\s*\(/) {
113 print "processing admin groups...\n";
118 /\s*\d\s*=>\s*((\'([^\']*)\')|(\"([^\"]*)\"))\s*/;
119 my $name = IServ
::DB
::Val
$3;
120 my @act = IServ
::DB
::GetArr
"SELECT act FROM groups WHERE name=$name;";
122 print " found group $name.\n";
123 push @admingroups, $act[0]{"act"};
125 print "NOTICE: group $name not found in database, ignoring it.\n";
132 print "converting old user rights to privileges...\n";
133 # change the privilege names to the right ones
134 if($restrictaccess) {
135 foreach(@allowedgroups) {
136 my $priv = "mod_roomreservation_view";
138 my @act = IServ
::DB
::GetArr
"SELECT act FROM privileges_assign ".
139 "WHERE privilege='$priv' AND act='$act';";
141 print " group $_ is already allowed to see the bookings, ignoring it.\n";
143 IServ
::DB
::Put
"privileges_assign", { "act" => $_,
144 "privilege" => $priv } or die $!;
145 print " allowed viewing for group '$_'\n";
148 $priv = "mod_roomreservation_book";
149 @act = "SELECT act FROM privileges_assign ".
150 "WHERE privilege='$priv' AND act='$act';";
152 print " group $_ is already allowed to book, ignoring it.\n";
154 IServ
::DB
::Put
"privileges_assign", { "act" => $_,
155 "privilege" => $priv } or die $!;
156 print " allowed booking for group '$_'\n";
160 foreach(@admingroups) {
161 my $priv = "mod_roomreservation_admin";
163 my @act = IServ
::DB
::GetArr
"SELECT act FROM privileges_assign ".
164 "WHERE privilege='$priv' AND act='$act';";
166 print " group $_ has already adminship, ignoring it.\n";
168 IServ
::DB
::Put
"privileges_assign", { "act" => $_,
169 "privilege" => $priv } or die $!;
170 print " allowed administration for group '$_'\n";
174 print "writing config file...\n";
175 system "touch $NEWCFG";
176 open OUT
, ">", $NEWCFG or die "ERROR: new config file could not be opened: $!";
177 print OUT
"<?php\n\$this->flushTimeslices();\n";
178 for(my $i = 0; $i <= $#tsbegin; $i++) {
179 print OUT
"\$this->addTimeslice(new mod_roomReservationTimeslice($tsbegin[$i],$tsend[$i]));\n";
181 print OUT
"\$this->setShowWeekend($showweekend);\n";
182 print OUT
"\$this->setShowLessons($showlessons);\n";
187 print "\nconverting the database, have a lot of fun...\n";
188 open IN
, "cat /old/rooms.sql | iconv -f utf8 -t utf8 |" or die
189 "ERROR: the database dump could not be opened: $!\n";
191 # build hashes of the form "timestamp" => "timeslice" ("15:00:00" => "3")
195 foreach (@tsbeginold) {
196 $tsbeginoldkeys{$_} = $i;
200 foreach (@tsendold) {
201 $tsendoldkeys{$_} = $i;
205 # database conversion
206 # insert old data and then convert them
207 print "importing old bookings...\n";
208 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);";
211 $_ =~ s/INSERT INTO rooms /INSERT INTO mod_roomreservation_bookings_old /;
215 print "converting the database...\n";
216 foreach(IServ
::DB
::GetArr
("SELECT * FROM mod_roomreservation_bookings_old;")) {
218 IServ
::DB
::Put
"mod_roomreservation_bookings", { "rrb_room" => $row{"room"},
219 "rrb_date" => $row{"date"}, "rrb_tsfirst" =>
220 $tsbeginoldkeys{$row{"timebegin"}}, "rrb_tslast" =>
221 $tsendoldkeys{$row{"timeend"}}, "rrb_act" => $row{"act"}, "rrb_reason" =>
222 $row{"reason"}, "rrb_interval" => $row{"fixed"} };
226 IServ
::DB
::Exec
"DROP TABLE mod_roomreservation_bookings_old;";
227 IServ
::DB
::Exec
"DROP TABLE rooms_archive;";
This page took 0.068162 seconds and 5 git commands to generate.