View | Details | Raw Unified | Return to bug 13624
Collapse All | Expand All

(-)a/C4/Overdues.pm (-2 / +5 lines)
Lines 937-944 sub GetOverdueMessageTransportTypes { Link Here
937
    return unless $categorycode and $letternumber;
937
    return unless $categorycode and $letternumber;
938
    my $dbh = C4::Context->dbh;
938
    my $dbh = C4::Context->dbh;
939
    my $sth = $dbh->prepare("
939
    my $sth = $dbh->prepare("
940
        SELECT message_transport_type FROM overduerules_transport_types
940
        SELECT message_transport_type 
941
        WHERE branchcode = ? AND categorycode = ? AND letternumber = ?
941
        FROM overduerules odr LEFT JOIN overduerules_transport_types ott USING (overduerules_id) 
942
        WHERE branchcode = ? 
943
          AND categorycode = ? 
944
          AND letternumber = ?
942
    ");
945
    ");
943
    $sth->execute( $branchcode, $categorycode, $letternumber );
946
    $sth->execute( $branchcode, $categorycode, $letternumber );
944
    my @mtts;
947
    my @mtts;
(-)a/installer/data/mysql/atomicupdate/bug_13624_overduerules_transport_types.pl (+43 lines)
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");
(-)a/t/db_dependent/Overdues.t (-19 / +17 lines)
Lines 24-49 $dbh->do(q| Link Here
24
|);
24
|);
25
25
26
$dbh->do(q|
26
$dbh->do(q|
27
    INSERT INTO overduerules ( branchcode, categorycode ) VALUES
27
    INSERT INTO overduerules ( overduerules_id, branchcode, categorycode ) VALUES
28
    ('CPL', 'PT'),
28
    (1, 'CPL', 'PT'),
29
    ('CPL', 'YA'),
29
    (2, 'CPL', 'YA'),
30
    ('', 'PT'),
30
    (3, '', 'PT'),
31
    ('', 'YA')
31
    (4, '', 'YA')
32
|);
32
|);
33
33
34
$dbh->do(q|
34
$dbh->do(q|INSERT INTO overduerules_transport_types (overduerules_id, letternumber, message_transport_type) VALUES 
35
    INSERT INTO overduerules_transport_types( branchcode, categorycode, letternumber, message_transport_type ) VALUES
35
    (1, 1, 'email'),
36
    ('CPL', 'PT', 1, 'email'),
36
    (1, 2, 'sms'),
37
    ('CPL', 'PT', 2, 'sms'),
37
    (1, 3, 'email'),
38
    ('CPL', 'PT', 3, 'email'),
38
    (2, 3, 'print'),
39
    ('CPL', 'YA', 3, 'print'),
39
    (3, 1, 'email'),
40
    ('', 'PT', 1, 'email'),
40
    (3, 2, 'email'),
41
    ('', 'PT', 2, 'email'),
41
    (3, 2, 'sms'),
42
    ('', 'PT', 2, 'sms'),
42
    (3, 3, 'sms'),
43
    ('', 'PT', 3, 'sms'),
43
    (3, 3, 'email'),
44
    ('', 'PT', 3, 'email'),
44
    (3, 3, 'print'),
45
    ('', 'PT', 3, 'print'),
45
    (4, 2, 'sms')
46
    ('', 'YA', 2, 'sms')
47
|);
46
|);
48
47
49
my $mtts;
48
my $mtts;
50
- 

Return to bug 13624