Bug 5770: (QA follow-up) Allow feature to be disable
authorMartin Renvoize <martin.renvoize@ptfs-europe.com>
Wed, 1 May 2019 13:14:38 +0000 (14:14 +0100)
committerNick Clemens <nick@bywatersolutions.com>
Fri, 10 May 2019 17:29:31 +0000 (17:29 +0000)
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 <martin.renvoize@ptfs-europe.com>

Signed-off-by: Nick Clemens <nick@bywatersolutions.com>

C4/Suggestions.pm
installer/data/mysql/atomicupdate/bug_5770.perl
installer/data/mysql/sysprefs.sql
koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref
t/db_dependent/Suggestions.t

index 6958967..25328d0 100644 (file)
@@ -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;
index 12e0d09..627415a 100644 (file)
@@ -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')
     });
 
index 06144ed..c808604 100644 (file)
@@ -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',''),
index 5347f27..adf86d7 100644 (file)
@@ -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
index 56e7d22..816786a 100644 (file)
@@ -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,