3 # This script will convert a database into the newer, proper
8 # Copyright 2000-2002 Katipo Communications
10 # This file is part of Koha.
12 # Koha is free software; you can redistribute it and/or modify it under the
13 # terms of the GNU General Public License as published by the Free Software
14 # Foundation; either version 2 of the License, or (at your option) any later
17 # Koha is distributed in the hope that it will be useful, but WITHOUT ANY
18 # WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
19 # A PARTICULAR PURPOSE. See the GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License along with
22 # Koha; if not, write to the Free Software Foundation, Inc., 59 Temple Place,
23 # Suite 330, Boston, MA 02111-1307 USA
28 my $dbh = C4::Context->dbh;
30 my $query = "Select * from categories where (categorycode like 'L%' or categorycode like 'F%'
31 or categorycode like 'S%' or categorycode like 'O%' or categorycode like 'H%') and (categorycode <>'HR'
32 and categorycode <> 'ST')";
34 my $sth=$dbh->prepare($query);
37 while (my $data=$sth->fetchrow_hashref){
38 #update borrowers corresponding
41 my $temp=substr($data->{'categorycode'},0,1);
42 $query="update borrowers set area='$temp' where categorycode='$data->{'categorycode'}'";
43 my $sth2=$dbh->prepare($query);
47 $temp=substr($data->{'categorycode'},1,1);
48 $query="update borrowers set categorycode='$temp' where categorycode='$data->{'categorycode'}'";
49 $sth2=$dbh->prepare($query);
53 $query="delete from categories where categorycode='$data->{'categorycode'}'";
54 $sth2=$dbh->prepare($query);
60 $query = "Select * from categories where (categorycode like 'V%') and (categorycode <>'HR'
61 and categorycode <> 'ST')";
63 my $sth=$dbh->prepare($query); # FIXME - There's already a $sth in this scope
66 while (my $data=$sth->fetchrow_hashref){
67 #update borrowers corresponding
69 # my $temp=substr($data->{'categorycode'},0,1);
70 $query="update borrowers set area='V' where categorycode='$data->{'categorycode'}'";
71 my $sth2=$dbh->prepare($query);
75 my $temp=substr($data->{'categorycode'},1,1);
76 $query="update borrowers set categorycode='$temp' where categorycode='$data->{'categorycode'}'";
77 $sth2=$dbh->prepare($query);
81 $query="delete from categories where categorycode='$data->{'categorycode'}'";
82 $sth2=$dbh->prepare($query);
88 my $query = "Select * from categories where categorycode = 'ST'"; # FIXME - There's already a $query in this scope
89 my $sth=$dbh->prepare($query); # FIXME - There's already a $sth in this scope
92 while (my $data=$sth->fetchrow_hashref){
93 #update borrowers corresponding
95 $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
96 my $sth2=$dbh->prepare($query);
100 $query="update borrowers set categorycode='W' where categorycode='$data->{'categorycode'}'";
101 $sth2=$dbh->prepare($query);
105 $query="delete from categories where categorycode='$data->{'categorycode'}'";
106 $sth2=$dbh->prepare($query);
112 my $query = "Select * from categories where categorycode = 'BR' or categorycode='CO' or categorycode='IS'"; # FIXME - There's already a $query in this scope
113 my $sth=$dbh->prepare($query); # FIXME - There's already a $sth in this scope
116 while (my $data=$sth->fetchrow_hashref){
117 #update borrowers corresponding
119 $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
120 my $sth2=$dbh->prepare($query);
124 $query="update borrowers set categorycode='I' where categorycode='$data->{'categorycode'}'";
125 $sth2=$dbh->prepare($query);
129 $query="delete from categories where categorycode='$data->{'categorycode'}'";
130 $sth2=$dbh->prepare($query);
136 my $query = "Select * from categories where categorycode = 'TD' or categorycode='TR'"; # FIXME - There's already a $query in this scope
137 my $sth=$dbh->prepare($query); # FIXME - There's already a $sth in this scope
140 while (my $data=$sth->fetchrow_hashref){
141 #update borrowers corresponding
143 $query="update borrowers set area='X' where categorycode='$data->{'categorycode'}'";
144 my $sth2=$dbh->prepare($query);
148 $query="update borrowers set categorycode='A' where categorycode='$data->{'categorycode'}'";
149 $sth2=$dbh->prepare($query);
153 $query="delete from categories where categorycode='$data->{'categorycode'}'";
154 $sth2=$dbh->prepare($query);
160 my $query = "Select * from categories where categorycode = 'HR'"; # FIXME - There's already a $query in this scope
161 my $sth=$dbh->prepare($query); # FIXME - There's already a $sth in this scope
164 while (my $data=$sth->fetchrow_hashref){
165 #update borrowers corresponding
167 $query="update borrowers set area='K' where categorycode='$data->{'categorycode'}'";
168 my $sth2=$dbh->prepare($query);
172 $query="update borrowers set categorycode='A' where categorycode='$data->{'categorycode'}'";
173 $sth2=$dbh->prepare($query);
177 $query="delete from categories where categorycode='$data->{'categorycode'}'";
178 $sth2=$dbh->prepare($query);
184 my $query = "Select * from categories where categorycode = 'IL'"; # FIXME - There's already a $query in this scope
185 my $sth=$dbh->prepare($query); # FIXME - There's already a $sth in this scope
188 while (my $data=$sth->fetchrow_hashref){
189 #update borrowers corresponding
191 $query="update borrowers set area='Z' where categorycode='$data->{'categorycode'}'";
192 my $sth2=$dbh->prepare($query);
196 $query="update borrowers set categorycode='L' where categorycode='$data->{'categorycode'}'";
197 $sth2=$dbh->prepare($query);
201 $query="delete from categories where categorycode='$data->{'categorycode'}'";
202 $sth2=$dbh->prepare($query);
208 my $query = "Select * from categories where categorycode = 'TB'"; # FIXME - There's already a $query in this scope
209 my $sth=$dbh->prepare($query); # FIXME - There's already a $sth in this scope
211 while (my $data=$sth->fetchrow_hashref){
212 #update borrowers corresponding
215 $query="update borrowers set area='' where categorycode='$data->{'categorycode'}'";
216 my $sth2=$dbh->prepare($query);
220 $query="update borrowers set categorycode='P' where categorycode='$data->{'categorycode'}'";
221 $sth2=$dbh->prepare($query);
225 $query="delete from categories where categorycode='$data->{'categorycode'}'";
226 $sth2=$dbh->prepare($query);
235 ("insert into categories values ('E','Senior Citizen',5,99,0,'A',0,0,0,99,1)",
236 "insert into categories values ('A','Adult',5,99,0,'A',0,0,0,99,1)",
237 "insert into categories values ('C','Child',5,16,0,'A',0,0,0,99,0)",
238 "insert into categories values ('B','Housebound',5,99,0,'E',0,0,0,99,0)",
239 "insert into categories values ('F','Family',5,99,0,'A',0,0,0,99,1)",
240 "insert into categories values ('W','Workers',5,99,0,'A',0,0,0,99,0)",
241 "insert into categories values ('I','Institution',5,99,0,'A',0,0,0,99,0)",
242 "insert into categories values ('P','Privileged',5,99,0,'A',0,0,0,99,0)",
243 "insert into categories values ('L','Library',5,99,0,'A',0,0,0,99,0)"
246 foreach $query (@queryValues) {
247 $sth=$dbh->prepare($query);