From a404b314b2787f223348158bcbab4a295d383396 Mon Sep 17 00:00:00 2001 From: Martin Renvoize Date: Wed, 1 May 2019 14:14:38 +0100 Subject: [PATCH] Bug 5770: (QA follow-up) Allow feature to be disable This patch adds 'None' to the available options for the feature so it may be disabled entirely (and sets that as default) Signed-off-by: Martin Renvoize Signed-off-by: Nick Clemens --- C4/Suggestions.pm | 59 ++++++++++--------- .../data/mysql/atomicupdate/bug_5770.perl | 2 +- installer/data/mysql/sysprefs.sql | 2 +- .../en/modules/admin/preferences/admin.pref | 3 +- t/db_dependent/Suggestions.t | 13 +++- 5 files changed, 47 insertions(+), 32 deletions(-) diff --git a/C4/Suggestions.pm b/C4/Suggestions.pm index 6958967d9d..25328d0982 100644 --- a/C4/Suggestions.pm +++ b/C4/Suggestions.pm @@ -456,33 +456,38 @@ sub NewSuggestion { my $rs = Koha::Database->new->schema->resultset('Suggestion'); my $new_id = $rs->create($suggestion)->id; - my $full_suggestion = GetSuggestion( $new_id ); - if ( - my $letter = C4::Letters::GetPreparedLetter( - module => 'suggestions', - letter_code => 'NEW_SUGGESTION', - tables => { - 'branches' => $full_suggestion->{branchcode}, - 'borrowers' => $full_suggestion->{suggestedby}, - 'suggestions' => $full_suggestion, - }, - ) - ){ - my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions"); - - my $toaddress = ( $emailpurchasesuggestions eq "BranchEmailAddress" ) - ? ( Koha::Libraries->find($full_suggestion->{branchcode})->branchemail || C4::Context->preference('KohaAdminEmailAddress') ) - : C4::Context->preference( $emailpurchasesuggestions ) ; - - C4::Letters::EnqueueLetter( - { - letter => $letter, - borrowernumber => $full_suggestion->{suggestedby}, - suggestionid => $full_suggestion->{suggestionid}, - to_address => $toaddress, - message_transport_type => 'email', - } - ) or warn "can't enqueue letter $letter"; + my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions"); + if ($emailpurchasesuggestions) { + my $full_suggestion = GetSuggestion( $new_id ); + if ( + my $letter = C4::Letters::GetPreparedLetter( + module => 'suggestions', + letter_code => 'NEW_SUGGESTION', + tables => { + 'branches' => $full_suggestion->{branchcode}, + 'borrowers' => $full_suggestion->{suggestedby}, + 'suggestions' => $full_suggestion, + }, + ) + ){ + + my $toaddress = + ( $emailpurchasesuggestions eq "BranchEmailAddress" ) + ? ( Koha::Libraries->find( $full_suggestion->{branchcode} ) + ->branchemail + || C4::Context->preference('KohaAdminEmailAddress') ) + : C4::Context->preference($emailpurchasesuggestions); + + C4::Letters::EnqueueLetter( + { + letter => $letter, + borrowernumber => $full_suggestion->{suggestedby}, + suggestionid => $full_suggestion->{suggestionid}, + to_address => $toaddress, + message_transport_type => 'email', + } + ) or warn "can't enqueue letter $letter"; + } } return $new_id; diff --git a/installer/data/mysql/atomicupdate/bug_5770.perl b/installer/data/mysql/atomicupdate/bug_5770.perl index 12e0d09c9c..627415ac55 100644 --- a/installer/data/mysql/atomicupdate/bug_5770.perl +++ b/installer/data/mysql/atomicupdate/bug_5770.perl @@ -2,7 +2,7 @@ $DBversion = '18.12.00.XXX'; # will be replaced by the RM if( CheckVersion( $DBversion ) ) { $dbh->do( q{ INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES - ('EmailPurchaseSuggestions','KohaAdminEmailAddress','EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that will be sent new purchase suggestions','Choice'), + ('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that will be sent new purchase suggestions','Choice'), ('EmailAddressForSuggestions','','','If you choose EmailAddressForSuggestions you should enter a valid email address','free') }); diff --git a/installer/data/mysql/sysprefs.sql b/installer/data/mysql/sysprefs.sql index 06144ed773..c8086043c9 100644 --- a/installer/data/mysql/sysprefs.sql +++ b/installer/data/mysql/sysprefs.sql @@ -161,7 +161,7 @@ INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` ('ElasticsearchIndexStatus_biblios', '0', 'Biblios index status', NULL, NULL), ('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'), ('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'), -('EmailPurchaseSuggestions','KohaAdminEmailAddress','EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'), +('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'), ('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'), ('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'), ('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''), diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref index 5347f270a0..adf86d77fb 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref @@ -9,8 +9,9 @@ Administration: - - "Choose email address that new purchase suggestions will be sent to: " - pref: EmailPurchaseSuggestions - default: KohaAdminEmailAddress + default: 0 choices: + 0: None EmailAddressForSuggestions: EmailAddressForSuggestions BranchEmailAddress: email address of branch KohaAdminEmailAddress: KohaAdminEmailAddress diff --git a/t/db_dependent/Suggestions.t b/t/db_dependent/Suggestions.t index 56e7d2240e..816786a2f8 100644 --- a/t/db_dependent/Suggestions.t +++ b/t/db_dependent/Suggestions.t @@ -469,15 +469,24 @@ subtest 'DelSuggestionsOlderThan' => sub { }; subtest 'EmailPurchaseSuggestions' => sub { - plan tests => 5; + plan tests => 6; $dbh->do(q|DELETE FROM message_queue|); Koha::Libraries->find('CPL')->update({ branchemail => 'branchemail@b.c' }); t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", 'root@localhost'); t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", 'a@b.c'); - t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); # EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress + # EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress or 0 + t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0"); + NewSuggestion($my_suggestion); + my $newsuggestions_messages = C4::Letters::GetQueuedMessages({ + borrowernumber => $borrowernumber + }); + + is( @$newsuggestions_messages, 0, 'NewSuggestions does not send an email when disabled' ); + + t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); NewSuggestion($my_suggestion); my $newsuggestions_messages = C4::Letters::GetQueuedMessages({ borrowernumber => $borrowernumber, -- 2.39.5