Bug 31626: Add letter id to the message queue table
It can be useful to know exactly what template was used to generate a notice. To this end, it would be useful to store the letter id as a foreign key in the message queue table. Test Plan: 1) Apply this patch 2) Run updatedatabase.pl 3) Restart all the things! 4) Run an action that will send a notice to a patron 5) Note the letter id is now in the message_queue table for that notice! Signed-off-by: Andrew Fuerste-Henry <andrewfh@dubcolib.org> Signed-off-by: Katrin Fischer <katrin.fischer.83@web.de> Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
This commit is contained in:
parent
6fc1ddd144
commit
9bc996be91
|
|
@ -922,13 +922,13 @@ sub EnqueueLetter {
|
|||
my $dbh = C4::Context->dbh();
|
||||
my $statement = << 'ENDSQL';
|
||||
INSERT INTO message_queue
|
||||
( borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, reply_address, content_type, failure_code )
|
||||
VALUES
|
||||
( ?, ?, ?, ?, ?, ?, ?, CAST(NOW() AS DATETIME), ?, ?, ?, ?, ? )
|
||||
( letter_id, borrowernumber, subject, content, metadata, letter_code, message_transport_type, status, time_queued, to_address, from_address, reply_address, content_type, failure_code )
|
||||
VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, CAST(NOW() AS DATETIME), ?, ?, ?, ?, ? )
|
||||
ENDSQL
|
||||
|
||||
my $sth = $dbh->prepare($statement);
|
||||
my $result = $sth->execute(
|
||||
$params->{letter}->{id} || undef, # letter.id
|
||||
$params->{'borrowernumber'}, # borrowernumber
|
||||
$params->{'letter'}->{'title'}, # subject
|
||||
$params->{'letter'}->{'content'}, # content
|
||||
|
|
|
|||
|
|
@ -0,0 +1,15 @@
|
|||
use Modern::Perl;
|
||||
|
||||
return {
|
||||
bug_number => "31626",
|
||||
description => "Add letter id to the message queue table",
|
||||
up => sub {
|
||||
my ($args) = @_;
|
||||
my ($dbh, $out) = @$args{qw(dbh out)};
|
||||
$dbh->do(q{
|
||||
ALTER TABLE message_queue
|
||||
ADD COLUMN letter_id INT(11) NULL DEFAULT NULL AFTER message_id,
|
||||
ADD CONSTRAINT letter_fk FOREIGN KEY (letter_id) REFERENCES letter(id) ON DELETE SET NULL ON UPDATE CASCADE
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
@ -3847,6 +3847,7 @@ DROP TABLE IF EXISTS `message_queue`;
|
|||
/*!40101 SET character_set_client = utf8 */;
|
||||
CREATE TABLE `message_queue` (
|
||||
`message_id` int(11) NOT NULL AUTO_INCREMENT,
|
||||
`letter_id` int(11) DEFAULT NULL,
|
||||
`borrowernumber` int(11) DEFAULT NULL,
|
||||
`subject` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
`content` mediumtext COLLATE utf8mb4_unicode_ci DEFAULT NULL,
|
||||
|
|
@ -3864,6 +3865,7 @@ CREATE TABLE `message_queue` (
|
|||
PRIMARY KEY (`message_id`),
|
||||
KEY `borrowernumber` (`borrowernumber`),
|
||||
KEY `message_transport_type` (`message_transport_type`),
|
||||
CONSTRAINT `letter_fk` FOREIGN KEY (`letter_id`) REFERENCES `letter` (`id`) ON DELETE SET NULL ON UPDATE CASCADE,
|
||||
CONSTRAINT `messageq_ibfk_1` FOREIGN KEY (`borrowernumber`) REFERENCES `borrowers` (`borrowernumber`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||
CONSTRAINT `messageq_ibfk_2` FOREIGN KEY (`message_transport_type`) REFERENCES `message_transport_types` (`message_transport_type`) ON UPDATE CASCADE
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
|
||||
|
|
|
|||
|
|
@ -781,7 +781,7 @@ subtest 'TranslateNotices' => sub {
|
|||
|
||||
subtest 'Test SMS handling in SendQueuedMessages' => sub {
|
||||
|
||||
plan tests => 13;
|
||||
plan tests => 14;
|
||||
|
||||
t::lib::Mocks::mock_preference( 'SMSSendDriver', 'Email' );
|
||||
t::lib::Mocks::mock_preference('EmailSMSSendDriverFromAddress', '');
|
||||
|
|
@ -808,6 +808,7 @@ subtest 'Test SMS handling in SendQueuedMessages' => sub {
|
|||
status => 'sent'
|
||||
})->next();
|
||||
|
||||
is( $message->letter_id, $messages->[0]->{id}, "Message letter_id is set correctly" );
|
||||
is( $message->to_address(), '5555555555@kidclamp.rocks', 'SendQueuedMessages populates the to address correctly for SMS by email when to_address not set' );
|
||||
is(
|
||||
$message->from_address(),
|
||||
|
|
|
|||
Loading…
Reference in New Issue