Line 0
Link Here
|
|
|
1 |
#! /usr/bin/perl |
2 |
|
3 |
use strict; |
4 |
use warnings; |
5 |
use Data::Dumper; |
6 |
use C4::Context; |
7 |
|
8 |
my $dbh = C4::Context->dbh(); |
9 |
$dbh->do("SET FOREIGN_KEY_CHECKS=0"); |
10 |
$dbh->do("ALTER TABLE overduerules RENAME old_overduerules"); |
11 |
$dbh->do("CREATE TABLE overduerules ( |
12 |
`overduerules_id` mediumint NOT NULL AUTO_INCREMENT, |
13 |
`branchcode` varchar(10) NOT NULL DEFAULT '', |
14 |
`categorycode` varchar(10) NOT NULL DEFAULT '', |
15 |
`delay1` int(4) DEFAULT NULL, |
16 |
`letter1` varchar(20) DEFAULT NULL, |
17 |
`debarred1` varchar(1) DEFAULT '0', |
18 |
`delay2` int(4) DEFAULT NULL, |
19 |
`debarred2` varchar(1) DEFAULT '0', |
20 |
`letter2` varchar(20) DEFAULT NULL, |
21 |
`delay3` int(4) DEFAULT NULL, |
22 |
`letter3` varchar(20) DEFAULT NULL, |
23 |
`debarred3` int(1) DEFAULT '0', |
24 |
PRIMARY KEY (`overduerules_id`) |
25 |
) ENGINE=InnoDB DEFAULT CHARSET=utf8;"); |
26 |
$dbh->do("INSERT INTO overduerules(branchcode, categorycode, delay1, letter1, debarred1, delay2, debarred2, letter2, delay3, letter3, debarred3) SELECT * FROM old_overduerules"); |
27 |
$dbh->do("DROP TABLE old_overduerules"); |
28 |
$dbh->do("ALTER TABLE overduerules_transport_types |
29 |
ADD COLUMN overduerules_id mediumint NOT NULL"); |
30 |
my $update = $dbh->prepare("update overduerules_transport_types set overduerules_id = (select overduerules_id from overduerules where branchcode=? and categorycode=? limit 1) where id=?"); |
31 |
my $mtts = $dbh->selectall_arrayref("select * from overduerules_transport_types", { Slice => {} }); |
32 |
$dbh->do("DELETE FROM overduerules_transport_types"); |
33 |
$dbh->do("ALTER TABLE overduerules_transport_types |
34 |
DROP FOREIGN KEY overduerules_fk, |
35 |
ADD FOREIGN KEY overduerules_fk (overduerules_id) REFERENCES overduerules (overduerules_id) ON DELETE CASCADE ON UPDATE CASCADE, |
36 |
DROP COLUMN branchcode, |
37 |
DROP COLUMN categorycode"); |
38 |
my $s = $dbh->prepare("insert into overduerules_transport_types (id, overduerules_id, letternumber, message_transport_type) values(?,?,?,?)"); |
39 |
foreach my $mtt(@$mtts){ |
40 |
$s->execute($mtt->{id}, 1, $mtt->{letternumber}, $mtt->{message_transport_type} ); |
41 |
$update->execute($mtt->{branchcode}, $mtt->{categorycode}, $mtt->{id}); |
42 |
} |
43 |
$dbh->do("SET FOREIGN_KEY_CHECKS=1"); |