View | Details | Raw Unified | Return to bug 5770
Collapse All | Expand All

(-)a/C4/Suggestions.pm (-27 / +32 lines)
Lines 456-488 sub NewSuggestion { Link Here
456
    my $rs = Koha::Database->new->schema->resultset('Suggestion');
456
    my $rs = Koha::Database->new->schema->resultset('Suggestion');
457
    my $new_id = $rs->create($suggestion)->id;
457
    my $new_id = $rs->create($suggestion)->id;
458
458
459
    my $full_suggestion = GetSuggestion( $new_id );
459
    my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions");
460
    if (
460
    if ($emailpurchasesuggestions) {
461
        my $letter = C4::Letters::GetPreparedLetter(
461
        my $full_suggestion = GetSuggestion( $new_id );
462
            module      => 'suggestions',
462
        if (
463
            letter_code => 'NEW_SUGGESTION',
463
            my $letter = C4::Letters::GetPreparedLetter(
464
            tables      => {
464
                module      => 'suggestions',
465
                'branches'    => $full_suggestion->{branchcode},
465
                letter_code => 'NEW_SUGGESTION',
466
                'borrowers'   => $full_suggestion->{suggestedby},
466
                tables      => {
467
                'suggestions' => $full_suggestion,
467
                    'branches'    => $full_suggestion->{branchcode},
468
            },
468
                    'borrowers'   => $full_suggestion->{suggestedby},
469
        )
469
                    'suggestions' => $full_suggestion,
470
    ){
470
                },
471
        my $emailpurchasesuggestions = C4::Context->preference("EmailPurchaseSuggestions");
471
            )
472
472
        ){
473
        my $toaddress = ( $emailpurchasesuggestions eq "BranchEmailAddress" )
473
474
                ? ( Koha::Libraries->find($full_suggestion->{branchcode})->branchemail || C4::Context->preference('KohaAdminEmailAddress') )
474
            my $toaddress =
475
                : C4::Context->preference( $emailpurchasesuggestions ) ;
475
              ( $emailpurchasesuggestions eq "BranchEmailAddress" )
476
476
              ? ( Koha::Libraries->find( $full_suggestion->{branchcode} )
477
        C4::Letters::EnqueueLetter(
477
                  ->branchemail
478
            {
478
                  || C4::Context->preference('KohaAdminEmailAddress') )
479
                letter         => $letter,
479
              : C4::Context->preference($emailpurchasesuggestions);
480
                borrowernumber => $full_suggestion->{suggestedby},
480
481
                suggestionid   => $full_suggestion->{suggestionid},
481
            C4::Letters::EnqueueLetter(
482
                to_address     => $toaddress,
482
                {
483
                message_transport_type => 'email',
483
                    letter         => $letter,
484
            }
484
                    borrowernumber => $full_suggestion->{suggestedby},
485
        ) or warn "can't enqueue letter $letter";
485
                    suggestionid   => $full_suggestion->{suggestionid},
486
                    to_address     => $toaddress,
487
                    message_transport_type => 'email',
488
                }
489
            ) or warn "can't enqueue letter $letter";
490
        }
486
    }
491
    }
487
492
488
    return $new_id;
493
    return $new_id;
(-)a/installer/data/mysql/atomicupdate/bug_5770.perl (-1 / +1 lines)
Lines 2-8 $DBversion = '18.12.00.XXX'; # will be replaced by the RM Link Here
2
if( CheckVersion( $DBversion ) ) {
2
if( CheckVersion( $DBversion ) ) {
3
    $dbh->do( q{
3
    $dbh->do( q{
4
            INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES
4
            INSERT IGNORE INTO systempreferences (variable,value,options,explanation,type) VALUES
5
            ('EmailPurchaseSuggestions','KohaAdminEmailAddress','EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that will be sent new purchase suggestions','Choice'),
5
            ('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that will be sent new purchase suggestions','Choice'),
6
            ('EmailAddressForSuggestions','','','If you choose EmailAddressForSuggestions you should enter a valid email address','free')
6
            ('EmailAddressForSuggestions','','','If you choose EmailAddressForSuggestions you should enter a valid email address','free')
7
    });
7
    });
8
8
(-)a/installer/data/mysql/sysprefs.sql (-1 / +1 lines)
Lines 160-166 INSERT INTO systempreferences ( `variable`, `value`, `options`, `explanation`, ` Link Here
160
('ElasticsearchIndexStatus_biblios', '0', 'Biblios index status', NULL, NULL),
160
('ElasticsearchIndexStatus_biblios', '0', 'Biblios index status', NULL, NULL),
161
('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'),
161
('EmailAddressForSuggestions','','',' If you choose EmailAddressForSuggestions you have to enter a valid email address: ','free'),
162
('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'),
162
('emailLibrarianWhenHoldIsPlaced','0',NULL,'If ON, emails the librarian whenever a hold is placed','YesNo'),
163
('EmailPurchaseSuggestions','KohaAdminEmailAddress','EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'),
163
('EmailPurchaseSuggestions','0','0|EmailAddressForSuggestions|BranchEmailAddress|KohaAdminEmailAddress','Choose email address that new purchase suggestions will be sent to: ','Choice'),
164
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
164
('EnableAdvancedCatalogingEditor','0','','Enable the Rancor advanced cataloging editor','YesNo'),
165
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
165
('EnableBorrowerFiles','0',NULL,'If enabled, allows librarians to upload and attach arbitrary files to a borrower record.','YesNo'),
166
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
166
('EnableOpacSearchHistory','1','YesNo','Enable or disable opac search history',''),
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/admin/preferences/admin.pref (-1 / +2 lines)
Lines 9-16 Administration: Link Here
9
        -
9
        -
10
            - "Choose email address that new purchase suggestions will be sent to: "
10
            - "Choose email address that new purchase suggestions will be sent to: "
11
            - pref: EmailPurchaseSuggestions
11
            - pref: EmailPurchaseSuggestions
12
              default: KohaAdminEmailAddress
12
              default: 0
13
              choices:
13
              choices:
14
                  0: None
14
                  EmailAddressForSuggestions: EmailAddressForSuggestions
15
                  EmailAddressForSuggestions: EmailAddressForSuggestions
15
                  BranchEmailAddress: email address of branch
16
                  BranchEmailAddress: email address of branch
16
                  KohaAdminEmailAddress: KohaAdminEmailAddress
17
                  KohaAdminEmailAddress: KohaAdminEmailAddress
(-)a/t/db_dependent/Suggestions.t (-3 / +11 lines)
Lines 469-483 subtest 'DelSuggestionsOlderThan' => sub { Link Here
469
};
469
};
470
470
471
subtest 'EmailPurchaseSuggestions' => sub {
471
subtest 'EmailPurchaseSuggestions' => sub {
472
    plan tests => 5;
472
    plan tests => 6;
473
473
474
    $dbh->do(q|DELETE FROM message_queue|);
474
    $dbh->do(q|DELETE FROM message_queue|);
475
475
476
    Koha::Libraries->find('CPL')->update({ branchemail => 'branchemail@b.c' });
476
    Koha::Libraries->find('CPL')->update({ branchemail => 'branchemail@b.c' });
477
    t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", 'root@localhost');
477
    t::lib::Mocks::mock_preference( "KohaAdminEmailAddress", 'root@localhost');
478
    t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", 'a@b.c');
478
    t::lib::Mocks::mock_preference( "EmailAddressForSuggestions", 'a@b.c');
479
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress"); # EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress
480
479
480
    # EmailAddressForSuggestions or BranchEmailAddress or KohaAdminEmailAddress or 0
481
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "0");
482
    NewSuggestion($my_suggestion);
483
    my $newsuggestions_messages = C4::Letters::GetQueuedMessages({
484
            borrowernumber => $borrowernumber
485
        });
486
487
    is( @$newsuggestions_messages, 0, 'NewSuggestions does not send an email when disabled' );
488
489
    t::lib::Mocks::mock_preference( "EmailPurchaseSuggestions", "KohaAdminEmailAddress");
481
    NewSuggestion($my_suggestion);
490
    NewSuggestion($my_suggestion);
482
    my $newsuggestions_messages = C4::Letters::GetQueuedMessages({
491
    my $newsuggestions_messages = C4::Letters::GetQueuedMessages({
483
            borrowernumber => $borrowernumber,
492
            borrowernumber => $borrowernumber,
484
- 

Return to bug 5770