adding printcirculationsplit parameter (already existed, but was not in systempref...
[koha.git] / fixBranches.pl
1 #!/usr/bin/perl
2
3 # script to fix all the branch settings in the items table of the koha database.
4
5 use strict;
6 use DBI;
7 use C4::Context;
8
9 # This script makes the following substitutions.
10 # on homebranch field:
11 my $home_default = 'C';
12 my %home = ( 'F'  => 'FP' ,
13              'FM' => 'FP' ,
14              'M'  => 'C'  ,
15              'P'  => 'C'  ,
16              'S'  => 'SP' ,
17              'T'  => 'C'  ,
18              'TR' => 'C'  ,
19              'I'  => 'C'  ,
20              'D'  => 'C'  ,
21              'L'  => 'LP' ,
22              'FP' => 'FP' ,
23              'SP' => 'SP' ,
24              'LP' => 'LP' ,
25              'C'  => 'C' );
26
27 # on holdingbranch field:
28 my $hold_default = 'L';
29 my %hold = ( 'F'  => 'F' ,
30              'FM' => 'FM' ,
31              'M'  => 'M'  ,
32              'P'  => 'P'  ,
33              'S'  => 'S' ,
34              'T'  => 'T'  ,
35              'TR' => 'TR'  ,
36              'I'  => 'I'  ,
37              'D'  => 'D'  ,
38              'L'  => 'L' ,
39              'FP' => 'F' ,
40              'C'  => 'L' ,
41              'SP' => 'S' ,
42              'LP' => 'L' );
43
44
45 # do the substitutions.....
46 my $dbh = C4::Context->dbh;
47
48 my $sth = $dbh->prepare("SELECT barcode, holdingbranch, homebranch FROM items");
49 $sth->execute();
50
51 my $today = localtime(time());
52 print "Output from fixBranches.pl   $today \n\n";
53
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";
61         $uth->finish;
62     }
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";
69         $uth->finish;
70     }
71 }
72
73 print "\nFinished output from fixbranches.pl\n";