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;
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')
});
('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',''),
-
- "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
};
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,