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

(-)a/C4/Letters.pm (-1 / +3 lines)
Lines 1061-1069 sub SendQueuedMessages { Link Here
1061
    my $unsent_messages = _get_unsent_messages( $which_unsent_messages );
1061
    my $unsent_messages = _get_unsent_messages( $which_unsent_messages );
1062
    MESSAGE: foreach my $message ( @$unsent_messages ) {
1062
    MESSAGE: foreach my $message ( @$unsent_messages ) {
1063
        my $message_object = Koha::Notice::Messages->find( $message->{message_id} );
1063
        my $message_object = Koha::Notice::Messages->find( $message->{message_id} );
1064
        $message_object->status('processing');
1064
1065
        # If this fails the database is unwritable and we won't manage to send a message that continues to be marked 'pending'
1065
        # If this fails the database is unwritable and we won't manage to send a message that continues to be marked 'pending'
1066
        $message_object->status('processing'); # enum: same as empty string
1066
        return unless $message_object->store();
1067
        return unless $message_object->store();
1068
        $message_object->status('pending')->store; # We need to restore the original status in order to prevent possible loss, but this implicitly assumes that the second store worked too.
1067
1069
1068
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
1070
        # warn Data::Dumper->Dump( [ $message ], [ 'message' ] );
1069
        warn sprintf( 'sending %s message to patron: %s',
1071
        warn sprintf( 'sending %s message to patron: %s',
(-)a/t/db_dependent/Letters.t (-9 / +17 lines)
Lines 18-24 Link Here
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
18
# along with Koha; if not, see <http://www.gnu.org/licenses>.
19
19
20
use Modern::Perl;
20
use Modern::Perl;
21
use Test::More tests => 77;
21
use Test::More tests => 78;
22
use Test::MockModule;
22
use Test::MockModule;
23
use Test::Warn;
23
use Test::Warn;
24
24
Lines 48-53 use Koha::Acquisition::Bookseller::Contacts; Link Here
48
use Koha::Acquisition::Orders;
48
use Koha::Acquisition::Orders;
49
use Koha::Libraries;
49
use Koha::Libraries;
50
use Koha::Notice::Templates;
50
use Koha::Notice::Templates;
51
use Koha::Notice::Messages;
52
51
my $schema = Koha::Database->schema;
53
my $schema = Koha::Database->schema;
52
$schema->storage->txn_begin();
54
$schema->storage->txn_begin();
53
55
Lines 753-759 subtest 'Test limit parameter for SendQueuedMessages' => sub { Link Here
753
};
755
};
754
756
755
subtest 'Test canary call for SendQueuedMessages' => sub {
757
subtest 'Test canary call for SendQueuedMessages' => sub {
756
    plan tests => 2;
758
    plan tests => 4;
757
759
758
    my $letter = {
760
    my $letter = {
759
        'letter' => {
761
        'letter' => {
Lines 768-781 subtest 'Test canary call for SendQueuedMessages' => sub { Link Here
768
        'message_transport_type' => 'email',
770
        'message_transport_type' => 'email',
769
        'from_address'           => 'from@example.com'
771
        'from_address'           => 'from@example.com'
770
    };
772
    };
771
    C4::Letters::EnqueueLetter($letter);
773
    my $queued_msg = Koha::Notice::Messages->find(
774
        C4::Letters::EnqueueLetter($letter),
775
    );
776
    is( $queued_msg->status, 'pending', 'Status should be pending now' );
772
777
773
    my $mocked_storing = Test::MockModule->new('Koha::Object');
778
    my $mocked_storing = Test::MockModule->new('Koha::Object');
774
    $mocked_storing->mock('store' => sub { return; });
779
    $mocked_storing->mock('store' => sub { return; });
775
    $messages_processed = C4::Letters::SendQueuedMessages();
780
    is( C4::Letters::SendQueuedMessages(), undef, 'Bad store should prevent handling any messages.' );
776
    is( $messages_processed, undef, 'Bad store should prevent sending any.');
781
    $queued_msg->discard_changes; # refresh
782
    is( $queued_msg->status, 'pending', 'Status still pending' );
783
777
    $mocked_storing->unmock('store');
784
    $mocked_storing->unmock('store');
778
    $messages_processed = C4::Letters::SendQueuedMessages();
785
    C4::Letters::SendQueuedMessages();
779
    is( $messages_processed, 1, 'Good store should send.');
786
    $queued_msg->discard_changes; # refresh again
787
    is( $queued_msg->status, 'failed', 'Good store and mocked sendmail should trigger status change.' );
788
};
780
789
781
}
790
$schema->storage->txn_rollback;
782
- 

Return to bug 18725