From a638d24943c825d3476c7052c807dc65c0ebeb48 Mon Sep 17 00:00:00 2001 From: Kyle M Hall Date: Tue, 12 Sep 2023 14:34:55 -0400 Subject: [PATCH] Bug 25816: (QA follow-up) Add system preference Signed-off-by: Kyle M Hall --- C4/SIP/ILS/Patron.pm | 31 +++++++----- .../data/mysql/atomicupdate/bug_25816.pl | 19 ++++++++ installer/data/mysql/mandatory/sysprefs.sql | 1 + .../admin/preferences/circulation.pref | 7 +++ t/db_dependent/SIP/Patron.t | 47 ++++++++++++------- 5 files changed, 74 insertions(+), 31 deletions(-) create mode 100755 installer/data/mysql/atomicupdate/bug_25816.pl diff --git a/C4/SIP/ILS/Patron.pm b/C4/SIP/ILS/Patron.pm index 7e7746b5768..5365860b7d3 100644 --- a/C4/SIP/ILS/Patron.pm +++ b/C4/SIP/ILS/Patron.pm @@ -152,9 +152,11 @@ sub new { if ( $patron->is_debarred and $patron->debarredcomment ) { $ilspatron{screen_msg} .= " -- " . $patron->debarredcomment; } + if ( $circ_blocked ) { $ilspatron{screen_msg} .= " -- " . "Patron has overdues"; } + for (qw(EXPIRED CHARGES CREDITS GNA LOST NOTES)) { ($flags->{$_}) or next; if ($_ ne 'NOTES' and $flags->{$_}->{message}) { @@ -166,20 +168,23 @@ sub new { } } } - my $patron_messages = Koha::Patron::Messages->search( - { - borrowernumber => $kp->{borrowernumber}, - message_type => 'B', + + if ( C4::Context->preference('SIP2AddOpacMessagesToScreenMessage') ) { + my $patron_messages = Koha::Patron::Messages->search( + { + borrowernumber => $kp->{borrowernumber}, + message_type => 'B', + } + ); + my @messages_array; + while ( my $message = $patron_messages->next ) { + my $messagedt = dt_from_string( $message->message_date, 'iso' ); + my $formatted_date = output_pref( { dt => $messagedt, dateonly => 1 } ); + push @messages_array, $formatted_date . ": " . $message->message; + } + if (@messages_array) { + $ilspatron{screen_msg} .= " Messages for you: " . join( ' / ', @messages_array ); } - ); - my @messages_array; - while ( my $message = $patron_messages->next ) { - my $messagedt = dt_from_string( $message->message_date, 'iso' ); - my $formatted_date = output_pref({ dt => $messagedt, dateonly => 1}); - push @messages_array, $formatted_date . ": " . $message->message; - } - if (@messages_array) { - $ilspatron{screen_msg} .= ". Messages for you: " . join(' / ', @messages_array); } # FIXME: populate fine_items recall_items diff --git a/installer/data/mysql/atomicupdate/bug_25816.pl b/installer/data/mysql/atomicupdate/bug_25816.pl new file mode 100755 index 00000000000..6156d245c49 --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_25816.pl @@ -0,0 +1,19 @@ +use Modern::Perl; + +return { + bug_number => "25816", + description => "Add OPAC messages in SIP display", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do( + q{ + INSERT IGNORE INTO systempreferences ( `variable`, `value`, `options`, `explanation`, `type` ) VALUES + ('SIP2AddOpacMessagesToScreenMessage','0','','If enabled, patron OPAC messages will be included in the SIP2 screen message','YesNo') + } + ); + + say $out "Added new system preference 'SIP2AddOpacMessagesToScreenMessage'"; + }, +}; diff --git a/installer/data/mysql/mandatory/sysprefs.sql b/installer/data/mysql/mandatory/sysprefs.sql index fad32d896e5..932812559f6 100644 --- a/installer/data/mysql/mandatory/sysprefs.sql +++ b/installer/data/mysql/mandatory/sysprefs.sql @@ -678,6 +678,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ShowReviewer','full','none|full|first|surname|firstandinitial|username','Choose how a commenter\'s identity is presented alongside comments in the OPAC','Choice'), ('ShowReviewerPhoto','1','','If ON, photo of reviewer will be shown beside comments in OPAC','YesNo'), ('SIP2SortBinMapping','',NULL,'Use the following mappings to determine the sort_bin of a returned item. The mapping should be on the form \"branchcode:item field:item field value:sort bin number\", with one mapping per line.','free'), +('SIP2AddOpacMessagesToScreenMessage','1','','If enabled, patron OPAC messages will be included in the SIP2 screen message','YesNo'), ('SkipHoldTrapOnNotForLoanValue','',NULL,'If set, Koha will never trap items for hold with this notforloan value','Integer'), ('SlipCSS','',NULL,'Slips CSS url.','free'), ('SMSSendDriver','','','Sets which SMS::Send driver is used to send SMS messages.','free'), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref index 55feb4d4442..6357a067e86 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/circulation.pref @@ -1355,6 +1355,13 @@ Circulation: 1: permanent_location 0: homebranch - for AQ field in SIP protocol. + - + - Use + - pref: SIP2AddOpacMessagesToScreenMessage + choices: + 1: Do + 0: Don't + - send OPAC patron messages in the SIP2 screen message field. Curbside pickup module: - diff --git a/t/db_dependent/SIP/Patron.t b/t/db_dependent/SIP/Patron.t index 56cafc0fe03..560c322bf40 100755 --- a/t/db_dependent/SIP/Patron.t +++ b/t/db_dependent/SIP/Patron.t @@ -407,28 +407,39 @@ subtest "NoIssuesChargeGuarantorsWithGuarantees tests" => sub { }; subtest "Patron messages tests" => sub { - plan tests => 1; + plan tests => 2; $schema->storage->txn_begin; - my $today = output_pref({ dt => dt_from_string(), dateonly => 1}); - my $patron = $builder->build_object({ class => 'Koha::Patrons' }); - my $library = $builder->build_object ({ class => 'Koha::Libraries' }); - my $new_message_1 = Koha::Patron::Message->new( - { borrowernumber => $patron->id, - branchcode => $library->branchcode, - message_type => 'B', - message => 'my message 1', - })->store; - - my $new_message_2 = Koha::Patron::Message->new( - { borrowernumber => $patron->id, - branchcode => $library->branchcode, - message_type => 'B', - message => 'my message 2', - })->store; + my $today = output_pref( { dt => dt_from_string(), dateonly => 1 } ); + my $patron = $builder->build_object( { class => 'Koha::Patrons', value => { opacnote => q{} } } ); + my $library = $builder->build_object( { class => 'Koha::Libraries' } ); + my $new_message_1 = Koha::Patron::Message->new( + { + borrowernumber => $patron->id, + branchcode => $library->branchcode, + message_type => 'B', + message => 'my message 1', + } + )->store; + my $new_message_2 = Koha::Patron::Message->new( + { + borrowernumber => $patron->id, + branchcode => $library->branchcode, + message_type => 'B', + message => 'my message 2', + } + )->store; + t::lib::Mocks::mock_preference( 'SIP2AddOpacMessagesToScreenMessage', 0 ); my $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); - like( $sip_patron->screen_msg, qr/Messages for you: $today: my message 1 \/ $today: my message 2/,"Screen message includes patron messages"); + is( $sip_patron->screen_msg, 'Greetings from Koha. ' ); + + t::lib::Mocks::mock_preference( 'SIP2AddOpacMessagesToScreenMessage', 1 ); + $sip_patron = C4::SIP::ILS::Patron->new( $patron->cardnumber ); + like( + $sip_patron->screen_msg, qr/Messages for you: $today: my message 1 \/ $today: my message 2/, + "Screen message includes patron messages" + ); $schema->storage->txn_rollback; }; -- 2.30.2