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/installer/data/mysql/kohastructure.sql (-4 / +4 lines)
Lines 1700-1705 CREATE TABLE `opac_news` ( -- data from the news tool Link Here
1700
1700
1701
DROP TABLE IF EXISTS `overduerules`;
1701
DROP TABLE IF EXISTS `overduerules`;
1702
CREATE TABLE `overduerules` ( -- overdue notice status and triggers
1702
CREATE TABLE `overduerules` ( -- overdue notice status and triggers
1703
  `overduerules_id` mediumint NOT NULL AUTO_INCREMENT,
1703
  `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table to define which branch this rule is for (if blank it's all libraries)
1704
  `branchcode` varchar(10) NOT NULL default '', -- foreign key from the branches table to define which branch this rule is for (if blank it's all libraries)
1704
  `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table to define which patron category this rule is for
1705
  `categorycode` varchar(10) NOT NULL default '', -- foreign key from the categories table to define which patron category this rule is for
1705
  `delay1` int(4) default NULL, -- number of days after the item is overdue that the first notice is sent
1706
  `delay1` int(4) default NULL, -- number of days after the item is overdue that the first notice is sent
Lines 1711-1717 CREATE TABLE `overduerules` ( -- overdue notice status and triggers Link Here
1711
  `delay3` int(4) default NULL, -- number of days after the item is overdue that the third notice is sent
1712
  `delay3` int(4) default NULL, -- number of days after the item is overdue that the third notice is sent
1712
  `letter3` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the third notice
1713
  `letter3` varchar(20) default NULL, -- foreign key from the letter table to define which notice should be sent as the third notice
1713
  `debarred3` int(1) default 0, -- is the patron restricted when the third notice is sent (1 for yes, 0 for no)
1714
  `debarred3` int(1) default 0, -- is the patron restricted when the third notice is sent (1 for yes, 0 for no)
1714
  PRIMARY KEY  (`branchcode`,`categorycode`)
1715
  PRIMARY KEY  (`overduerules_id`)
1715
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1716
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
1716
1717
1717
--
1718
--
Lines 2595-2606 CREATE TABLE `message_transport_types` ( Link Here
2595
DROP TABLE IF EXISTS `overduerules_transport_types`;
2596
DROP TABLE IF EXISTS `overduerules_transport_types`;
2596
CREATE TABLE overduerules_transport_types(
2597
CREATE TABLE overduerules_transport_types(
2597
    `id` INT(11) NOT NULL AUTO_INCREMENT,
2598
    `id` INT(11) NOT NULL AUTO_INCREMENT,
2598
    `branchcode` varchar(10) NOT NULL DEFAULT '',
2599
    `overduerules_id` mediumint NOT NULL,
2599
    `categorycode` VARCHAR(10) NOT NULL DEFAULT '',
2600
    `letternumber` INT(1) NOT NULL DEFAULT 1,
2600
    `letternumber` INT(1) NOT NULL DEFAULT 1,
2601
    `message_transport_type` VARCHAR(20) NOT NULL DEFAULT 'email',
2601
    `message_transport_type` VARCHAR(20) NOT NULL DEFAULT 'email',
2602
    PRIMARY KEY (id),
2602
    PRIMARY KEY (id),
2603
    CONSTRAINT overduerules_fk FOREIGN KEY (branchcode, categorycode) REFERENCES overduerules (branchcode, categorycode) ON DELETE CASCADE ON UPDATE CASCADE,
2603
    CONSTRAINT overduerules_fk FOREIGN KEY (overduerules_id) REFERENCES overduerules (overduerules_id) ON DELETE CASCADE ON UPDATE CASCADE,
2604
    CONSTRAINT mtt_fk FOREIGN KEY (message_transport_type) REFERENCES message_transport_types (message_transport_type) ON DELETE CASCADE ON UPDATE CASCADE
2604
    CONSTRAINT mtt_fk FOREIGN KEY (message_transport_type) REFERENCES message_transport_types (message_transport_type) ON DELETE CASCADE ON UPDATE CASCADE
2605
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2605
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
2606
2606
(-)a/t/db_dependent/Overdues.t (-18 / +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;
(-)a/tools/overduerules.pl (-3 / +2 lines)
Lines 89-100 if ($op eq 'save') { Link Here
89
        INSERT INTO overduerules_transport_types(
89
        INSERT INTO overduerules_transport_types(
90
            branchcode, categorycode, letternumber, message_transport_type
90
            branchcode, categorycode, letternumber, message_transport_type
91
        ) VALUES (
91
        ) VALUES (
92
            ?, ?, ?, ?
92
            (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?), ?, ?
93
        )
93
        )
94
    ");
94
    ");
95
    my $sth_delete_mtt = $dbh->prepare("
95
    my $sth_delete_mtt = $dbh->prepare("
96
        DELETE FROM overduerules_transport_types
96
        DELETE FROM overduerules_transport_types
97
        WHERE branchcode = ? AND categorycode = ?
97
        WHERE overduerules_id = (SELECT overduerules_id FROM overduerules WHERE branchcode = ? AND categorycode = ?)
98
    ");
98
    ");
99
99
100
    foreach my $key (@names){
100
    foreach my $key (@names){
101
- 

Return to bug 13624