Bug 18928: (QA follow-up) Remove DBIC files and reference to DefaultCircRule
[koha.git] / installer / data / mysql / atomicupdate / bug_18928.perl
1 $DBversion = 'XXX';  # will be replaced by the RM
2 if( CheckVersion( $DBversion ) ) {
3
4     if ( TableExists('default_circ_rules') ) {
5         if ( column_exists( 'default_circ_rules', 'holdallowed' ) ) {
6             $dbh->do("
7                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
8                 SELECT NULL, NULL, NULL, 'holdallowed', holdallowed
9                 FROM default_circ_rules
10             ");
11             $dbh->do("
12                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
13                 SELECT NULL, NULL, NULL, 'hold_fulfillment_policy', hold_fulfillment_policy
14                 FROM default_circ_rules
15             ");
16             $dbh->do("
17                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
18                 SELECT NULL, NULL, NULL, 'returnbranch', returnbranch
19                 FROM default_circ_rules
20             ");
21             $dbh->do("DROP TABLE default_circ_rules");
22         }
23     }
24
25     if ( TableExists('default_branch_circ_rules') ) {
26         if ( column_exists( 'default_branch_circ_rules', 'holdallowed' ) ) {
27             $dbh->do("
28                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
29                 SELECT NULL, branchcode, NULL, 'holdallowed', holdallowed
30                 FROM default_branch_circ_rules
31             ");
32             $dbh->do("
33                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
34                 SELECT NULL, branchcode, NULL, 'hold_fulfillment_policy', hold_fulfillment_policy
35                 FROM default_branch_circ_rules
36             ");
37             $dbh->do("
38                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
39                 SELECT NULL, branchcode, NULL, 'returnbranch', returnbranch
40                 FROM default_branch_circ_rules
41             ");
42             $dbh->do("DROP TABLE default_branch_circ_rules");
43         }
44     }
45
46     if ( TableExists('branch_item_rules') ) {
47         if ( column_exists( 'branch_item_rules', 'holdallowed' ) ) {
48             $dbh->do("
49                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
50                 SELECT NULL, branchcode, itemtype, 'holdallowed', holdallowed
51                 FROM branch_item_rules
52             ");
53             $dbh->do("
54                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
55                 SELECT NULL, branchcode, itemtype, 'hold_fulfillment_policy', hold_fulfillment_policy
56                 FROM branch_item_rules
57             ");
58             $dbh->do("
59                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
60                 SELECT NULL, branchcode, itemtype, 'returnbranch', returnbranch
61                 FROM branch_item_rules
62             ");
63             $dbh->do("DROP TABLE branch_item_rules");
64         }
65     }
66
67     if ( TableExists('default_branch_item_rules') ) {
68         if ( column_exists( 'default_branch_item_rules', 'holdallowed' ) ) {
69             $dbh->do("
70                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
71                 SELECT NULL, NULL, itemtype, 'holdallowed', holdallowed
72                 FROM default_branch_item_rules
73             ");
74             $dbh->do("
75                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
76                 SELECT NULL, NULL, itemtype, 'hold_fulfillment_policy', hold_fulfillment_policy
77                 FROM default_branch_item_rules
78             ");
79             $dbh->do("
80                 INSERT INTO circulation_rules ( categorycode, branchcode, itemtype, rule_name, rule_value )
81                 SELECT NULL, NULL, itemtype, 'returnbranch', returnbranch
82                 FROM default_branch_item_rules
83             ");
84             $dbh->do("DROP TABLE default_branch_item_rules");
85         }
86     }
87
88     SetVersion( $DBversion );
89     print "Upgrade to $DBversion done (Bug 18928 - Move holdallowed, hold_fulfillment_policy, returnbranch to circulation_rules)\n";
90 }