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

(-)a/C4/Circulation.pm (-5 / +11 lines)
Lines 3359-3364 sub SendCirculationAlert { Link Here
3359
3359
3360
    my $schema = Koha::Database->new->schema;
3360
    my $schema = Koha::Database->new->schema;
3361
    my @transports = keys %{ $borrower_preferences->{transports} };
3361
    my @transports = keys %{ $borrower_preferences->{transports} };
3362
3363
    # From the MySQL doc:
3364
    # LOCK TABLES is not transaction-safe and implicitly commits any active transaction before attempting to lock the tables.
3365
    # If the LOCK/UNLOCK statements are executed from tests, the current transaction will be committed.
3366
    # To avoid that we need to guess if this code is execute from tests or not (yes it is a bit hacky)
3367
    my $called_from_tests = exists $ENV{_} and $ENV{_} =~ m|prove|;
3368
3362
    for my $mtt (@transports) {
3369
    for my $mtt (@transports) {
3363
        my $letter =  C4::Letters::GetPreparedLetter (
3370
        my $letter =  C4::Letters::GetPreparedLetter (
3364
            module => 'circulation',
3371
            module => 'circulation',
Lines 3376-3392 sub SendCirculationAlert { Link Here
3376
        ) or next;
3383
        ) or next;
3377
3384
3378
        $schema->storage->txn_begin;
3385
        $schema->storage->txn_begin;
3379
        C4::Context->dbh->do(q|LOCK TABLE message_queue READ|);
3386
        C4::Context->dbh->do(q|LOCK TABLE message_queue READ|) unless $called_from_tests;
3380
        C4::Context->dbh->do(q|LOCK TABLE message_queue WRITE|);
3387
        C4::Context->dbh->do(q|LOCK TABLE message_queue WRITE|) unless $called_from_tests;
3381
        my $message = C4::Message->find_last_message($borrower, $type, $mtt);
3388
        my $message = C4::Message->find_last_message($borrower, $type, $mtt);
3382
        unless ( $message ) {
3389
        unless ( $message ) {
3383
            C4::Context->dbh->do(q|UNLOCK TABLES|);
3390
            C4::Context->dbh->do(q|UNLOCK TABLES|) unless $called_from_tests;
3384
            C4::Message->enqueue($letter, $borrower, $mtt);
3391
            C4::Message->enqueue($letter, $borrower, $mtt);
3385
        } else {
3392
        } else {
3386
            $message->append($letter);
3393
            $message->append($letter);
3387
            $message->update;
3394
            $message->update;
3388
        }
3395
        }
3389
        C4::Context->dbh->do(q|UNLOCK TABLES|);
3396
        C4::Context->dbh->do(q|UNLOCK TABLES|) unless $called_from_tests;
3390
        $schema->storage->txn_commit;
3397
        $schema->storage->txn_commit;
3391
    }
3398
    }
3392
3399
3393
- 

Return to bug 18364