3 # script to fix all the branch settings in the items table of the koha database.
9 # This script makes the following substitutions.
10 # on homebranch field:
11 my $home_default = 'C';
12 my %home = ( 'F' => 'FP' ,
27 # on holdingbranch field:
28 my $hold_default = 'L';
29 my %hold = ( 'F' => 'F' ,
45 # do the substitutions.....
46 my $dbh = C4::Context->dbh;
48 my $sth = $dbh->prepare("SELECT barcode, holdingbranch, homebranch FROM items");
51 my $today = localtime(time());
52 print "Output from fixBranches.pl $today \n\n";
54 while (my $item = $sth->fetchrow_hashref) {
55 my $oldhold = $item->{'holdingbranch'};
56 my $newhold = $hold{$oldhold} ? $hold{$oldhold} : $hold_default ;
57 if ($oldhold ne $newhold) {
58 my $uth = $dbh->prepare("UPDATE items SET holdingbranch = ? WHERE barcode = ?");
59 $uth->execute($newhold, $item->{'barcode'});
60 print "$item->{'barcode'} : Holding branch setting changed from $oldhold -> $newhold \n";
63 my $oldhome = $item->{'homebranch'};
64 my $newhome = $home{$oldhome} ? $home{$oldhome} : $home_default ;
65 if ($oldhome ne $newhome) {
66 my $uth = $dbh->prepare("UPDATE items SET homebranch = ? WHERE barcode = ?");
67 $uth->execute($newhome, $item->{'barcode'});
68 print "$item->{'barcode'} : Home branch setting changed from $oldhome -> $newhome \n";
73 print "\nFinished output from fixbranches.pl\n";