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

(-)a/C4/Letters.pm (+5 lines)
Lines 953-958 sub EnqueueLetter { Link Here
953
        return;
953
        return;
954
    }
954
    }
955
955
956
    my $branchcode = $params->{borrowernumber} ? Koha::Patrons->find( $params->{borrowernumber} )->branchcode : undef;
957
956
    # If we have any attachments we should encode then into the body.
958
    # If we have any attachments we should encode then into the body.
957
    if ( $params->{'attachments'} ) {
959
    if ( $params->{'attachments'} ) {
958
        $params->{'letter'} = _add_attachments(
960
        $params->{'letter'} = _add_attachments(
Lines 984-989 sub EnqueueLetter { Link Here
984
            reply_address          => $params->{reply_address},
986
            reply_address          => $params->{reply_address},
985
            content_type           => $params->{letter}->{'content-type'},
987
            content_type           => $params->{letter}->{'content-type'},
986
            failure_code           => $params->{failure_code} || q{},
988
            failure_code           => $params->{failure_code} || q{},
989
            branchcode             => $params->{branchcode},
987
        }
990
        }
988
    )->store();
991
    )->store();
989
    return $message->id;
992
    return $message->id;
Lines 1017-1022 sub SendQueuedMessages { Link Here
1017
    my $params = shift;
1020
    my $params = shift;
1018
    my $limit = $params->{limit};
1021
    my $limit = $params->{limit};
1019
    my $where = $params->{where};
1022
    my $where = $params->{where};
1023
    my $branchcode = $params->{branchcode};
1020
1024
1021
    Koha::Exceptions::BadParameter->throw("Parameter message_id cannot be empty if passed.")
1025
    Koha::Exceptions::BadParameter->throw("Parameter message_id cannot be empty if passed.")
1022
        if ( exists( $params->{message_id} ) && !$params->{message_id} );
1026
        if ( exists( $params->{message_id} ) && !$params->{message_id} );
Lines 1025-1030 sub SendQueuedMessages { Link Here
1025
1029
1026
    my $count_messages = 0;
1030
    my $count_messages = 0;
1027
    my $unsent_messages = Koha::Notice::Messages->search({
1031
    my $unsent_messages = Koha::Notice::Messages->search({
1032
        $params->{branchcode} ? ( branchcode => $params->{branchcode} ) : (),
1028
        status  => 'pending',
1033
        status  => 'pending',
1029
        $params->{message_id} ? ( message_id => $params->{message_id} ) : (),
1034
        $params->{message_id} ? ( message_id => $params->{message_id} ) : (),
1030
        $params->{borrowernumber} ? ( borrowernumber => $params->{borrowernumber} ) : (),
1035
        $params->{borrowernumber} ? ( borrowernumber => $params->{borrowernumber} ) : (),
(-)a/installer/data/mysql/atomicupdate/bug_37968.pl (+22 lines)
Line 0 Link Here
1
use Modern::Perl;
2
use Koha::Installer::Output qw(say_warning say_failure say_success say_info);
3
4
return {
5
    bug_number  => "37968",
6
    description => "Add ability to store branchcode for messages in the queue",
7
    up          => sub {
8
        my ($args) = @_;
9
        my ( $dbh, $out ) = @$args{qw(dbh out)};
10
11
        try {
12
            $dbh->do(q{
13
                ALTER TABLE message_queue
14
                ADD COLUMN `branchcode` varchar(10) DEFAULT NULL COMMENT 'branch that "owns" this message' AFTER failure_code,
15
                ADD CONSTRAINT `mq_borrowernumber` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE;
16
            });
17
            say_success( $out, "Added column message_queue.branchcode" );
18
        } catch {
19
            say_failure( $out, "Failed to add column message_queue.branchcode: $_" );
20
        };
21
    },
22
};
(-)a/installer/data/mysql/kohastructure.sql (+2 lines)
Lines 4679-4684 CREATE TABLE `message_queue` ( Link Here
4679
  `reply_address` longtext DEFAULT NULL,
4679
  `reply_address` longtext DEFAULT NULL,
4680
  `content_type` mediumtext DEFAULT NULL,
4680
  `content_type` mediumtext DEFAULT NULL,
4681
  `failure_code` mediumtext DEFAULT NULL,
4681
  `failure_code` mediumtext DEFAULT NULL,
4682
  `branchcode` varchar(10) DEFAULT NULL COMMENT 'branch that "owns" this message',
4682
  PRIMARY KEY (`message_id`),
4683
  PRIMARY KEY (`message_id`),
4683
  KEY `borrowernumber` (`borrowernumber`),
4684
  KEY `borrowernumber` (`borrowernumber`),
4684
  KEY `message_transport_type` (`message_transport_type`),
4685
  KEY `message_transport_type` (`message_transport_type`),
Lines 4686-4691 CREATE TABLE `message_queue` ( Link Here
4686
  CONSTRAINT `letter_fk` FOREIGN KEY (`letter_id`) REFERENCES `letter` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
4687
  CONSTRAINT `letter_fk` FOREIGN KEY (`letter_id`) REFERENCES `letter` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
4687
  CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4688
  CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4688
  CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON UPDATE CASCADE
4689
  CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON UPDATE CASCADE
4690
  CONSTRAINT `mq_borrowernumber` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
4689
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4691
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
4690
/*!40101 SET character_set_client = @saved_cs_client */;
4692
/*!40101 SET character_set_client = @saved_cs_client */;
4691
4693
(-)a/misc/cronjobs/process_message_queue.pl (-1 / +3 lines)
Lines 29-34 use Try::Tiny qw( catch try ); Link Here
29
my $username = undef;
29
my $username = undef;
30
my $password = undef;
30
my $password = undef;
31
my $limit    = undef;
31
my $limit    = undef;
32
my $branchcode = undef;
32
my $method = 'LOGIN';
33
my $method = 'LOGIN';
33
my $help = 0;
34
my $help = 0;
34
my $verbose = 0;
35
my $verbose = 0;
Lines 43-48 GetOptions( Link Here
43
    'u|username:s'      => \$username,
44
    'u|username:s'      => \$username,
44
    'p|password:s'      => \$password,
45
    'p|password:s'      => \$password,
45
    'l|limit:s'         => \$limit,
46
    'l|limit:s'         => \$limit,
47
    'b|branchcode:s'    => \$branchcode,
46
    'm|method:s'        => \$method,
48
    'm|method:s'        => \$method,
47
    'h|help|?'          => \$help,
49
    'h|help|?'          => \$help,
48
    'v|verbose'         => \$verbose,
50
    'v|verbose'         => \$verbose,
Lines 128-133 C4::Letters::SendQueuedMessages( Link Here
128
        type        => \@type,
130
        type        => \@type,
129
        letter_code => \@letter_code,
131
        letter_code => \@letter_code,
130
        where       => $where,
132
        where       => $where,
133
        branchcode => $branchcode,
131
    }
134
    }
132
);
135
);
133
136
134
- 

Return to bug 37968