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

(-)a/Koha/Item.pm (-35 / +38 lines)
Lines 2293-2341 sub add_to_bundle { Link Here
2293
2293
2294
    my $BundleNotLoanValue = C4::Context->preference('BundleNotLoanValue');
2294
    my $BundleNotLoanValue = C4::Context->preference('BundleNotLoanValue');
2295
2295
2296
    try {
2296
    $schema->txn_do(
2297
        $schema->txn_do(
2297
        sub {
2298
            sub {
2298
            try {
2299
                $schema->safe_do(
2300
                    sub {
2299
2301
2300
                Koha::Exceptions::Item::Bundle::BundleIsCheckedOut->throw if $self->checkout;
2302
                        Koha::Exceptions::Item::Bundle::BundleIsCheckedOut->throw if $self->checkout;
2301
2303
2302
                my $checkout = $bundle_item->checkout;
2304
                        my $checkout = $bundle_item->checkout;
2303
                if ($checkout) {
2305
                        if ($checkout) {
2304
                    unless ( $options->{force_checkin} ) {
2306
                            unless ( $options->{force_checkin} ) {
2305
                        Koha::Exceptions::Item::Bundle::ItemIsCheckedOut->throw();
2307
                                Koha::Exceptions::Item::Bundle::ItemIsCheckedOut->throw();
2306
                    }
2308
                            }
2307
2309
2308
                    my $branchcode = C4::Context->userenv->{'branch'};
2310
                            my $branchcode = C4::Context->userenv->{'branch'};
2309
                    my ($success) = C4::Circulation::AddReturn( $bundle_item->barcode, $branchcode );
2311
                            my ($success) = C4::Circulation::AddReturn( $bundle_item->barcode, $branchcode );
2310
2312
2311
                    if ($success) {
2313
                            if ($success) {
2312
2314
2313
                        # HoldsQueue doesn't seem to mind bundles, not sure if this is correct, but rebuild for now
2315
                                # HoldsQueue doesn't seem to mind bundles, not sure if this is correct, but rebuild for now
2314
                        Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
2316
                                Koha::BackgroundJob::BatchUpdateBiblioHoldsQueue->new->enqueue(
2315
                            { biblio_ids => [ $self->biblionumber ] } )
2317
                                    { biblio_ids => [ $self->biblionumber ] } )
2316
                            if C4::Context->preference('RealTimeHoldsQueue');
2318
                                    if C4::Context->preference('RealTimeHoldsQueue');
2317
                    } else {
2319
                            } else {
2318
                        Koha::Exceptions::Checkin::FailedCheckin->throw();
2320
                                Koha::Exceptions::Checkin::FailedCheckin->throw();
2319
                    }
2321
                            }
2320
                }
2322
                        }
2321
2323
2322
                my $holds = $bundle_item->current_holds;
2324
                        my $holds = $bundle_item->current_holds;
2323
                if ( $holds->count ) {
2325
                        if ( $holds->count ) {
2324
                    unless ( $options->{ignore_holds} ) {
2326
                            unless ( $options->{ignore_holds} ) {
2325
                        Koha::Exceptions::Item::Bundle::ItemHasHolds->throw();
2327
                                Koha::Exceptions::Item::Bundle::ItemHasHolds->throw();
2326
                    }
2328
                            }
2327
                }
2329
                        }
2328
2330
2329
                $self->_result->add_to_item_bundles_hosts( { item => $bundle_item->itemnumber } );
2331
                        $self->_result->add_to_item_bundles_hosts( { item => $bundle_item->itemnumber } );
2330
2332
2331
                $bundle_item->notforloan($BundleNotLoanValue)->store();
2333
                        $bundle_item->notforloan($BundleNotLoanValue)->store();
2332
            }
2334
                    }
2333
        );
2335
                );
2334
    } catch {
2336
            } catch {
2335
2337
2336
        # Use centralized exception translation instead of duplicated code
2338
                # Propagate any exception (already translated by safe_do if needed)
2337
        $schema->translate_exception($_);
2339
                $_->rethrow();
2338
    };
2340
            };
2341
        }
2342
    );
2339
}
2343
}
2340
2344
2341
=head3 remove_from_bundle
2345
=head3 remove_from_bundle
2342
- 

Return to bug 19871