Bug 18925: Move maxissueqty and maxonsiteissueqty to circulation_rules
[koha.git] / installer / data / mysql / atomicupdate / bug_18925.perl
1 $DBversion = 'XXX';  # will be replaced by the RM
2 if( CheckVersion( $DBversion ) ) {
3     if ( column_exists( 'branch_borrower_circ_rules', 'maxissueqty' ) ) {
4         $dbh->do("
5             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
6             SELECT categorycode, branchcode, NULL, 'maxissueqty', maxissueqty
7             FROM branch_borrower_circ_rules
8         ");
9         $dbh->do("
10             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
11             SELECT categorycode, branchcode, NULL, 'maxonsiteissueqty', maxonsiteissueqty
12             FROM branch_borrower_circ_rules
13         ");
14         $dbh->do("DROP TABLE branch_borrower_circ_rules");
15     }
16
17     if ( column_exists( 'default_borrower_circ_rules', 'maxissueqty' ) ) {
18         $dbh->do("
19             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
20             SELECT categorycode, NULL, NULL, 'maxissueqty', maxissueqty
21             FROM default_borrower_circ_rules
22         ");
23         $dbh->do("
24             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
25             SELECT categorycode, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
26             FROM default_borrower_circ_rules
27         ");
28         $dbh->do("DROP TABLE default_borrower_circ_rules");
29     }
30
31     if ( column_exists( 'default_circ_rules', 'maxissueqty' ) ) {
32         $dbh->do("
33             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
34             SELECT NULL, NULL, NULL, 'maxissueqty', maxissueqty
35             FROM default_circ_rules
36         ");
37         $dbh->do("
38             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
39             SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
40             FROM default_circ_rules
41         ");
42         $dbh->do("ALTER TABLE default_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
43     }
44
45     if ( column_exists( 'default_branch_circ_rules', 'maxissueqty' ) ) {
46         $dbh->do("
47             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
48             SELECT NULL, branchcode, NULL, 'maxissueqty', maxissueqty
49             FROM default_branch_circ_rules
50         ");
51         $dbh->do("
52             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
53             SELECT NULL, NULL, NULL, 'maxonsiteissueqty', maxonsiteissueqty
54             FROM default_branch_circ_rules
55         ");
56         $dbh->do("ALTER TABLE default_branch_circ_rules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
57     }
58
59     if ( column_exists( 'issuingrules', 'maxissueqty' ) ) {
60         $dbh->do("
61             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
62             SELECT categorycode, branchcode, itemtype, 'maxissueqty', maxissueqty
63             FROM issuingrules
64         ");
65         $dbh->do("
66             INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
67             SELECT categorycode, branchcode, itemtype, 'maxonsiteissueqty', maxonsiteissueqty
68             FROM issuingrules
69         ");
70         $dbh->do("ALTER TABLE issuingrules DROP COLUMN maxissueqty, DROP COLUMN maxonsiteissueqty");
71     }
72
73     SetVersion( $DBversion );
74     print "Upgrade to $DBversion done (Bug 18925 - Move maxissueqty and maxonsiteissueqty to circulation_rules)\n";
75 }