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

(-)a/Koha/Preservation/Processing.pm (+20 lines)
Lines 21-26 use Koha::Database; Link Here
21
21
22
use base qw(Koha::Object);
22
use base qw(Koha::Object);
23
23
24
use Koha::Preservation::Trains;
25
use Koha::Preservation::Train::Items;
24
use Koha::Preservation::Processing::Attributes;
26
use Koha::Preservation::Processing::Attributes;
25
27
26
=head1 NAME
28
=head1 NAME
Lines 80-85 sub attributes { Link Here
80
    return Koha::Preservation::Processing::Attributes->_new_from_dbic($attributes_rs);
82
    return Koha::Preservation::Processing::Attributes->_new_from_dbic($attributes_rs);
81
}
83
}
82
84
85
=head3 can_be_deleted
86
87
A processing can be deleted if it is not used from any trains or items.
88
Note that we do not enforce that in ->delete, the callers are supposed to deal with that correctly.
89
90
=cut
91
92
sub can_be_deleted {
93
    my ($self) = @_;
94
95
    my $trains_using_it = Koha::Preservation::Trains->search(
96
        { default_processing_id => $self->processing_id } )->count;
97
    my $items_using_it = Koha::Preservation::Train::Items->search(
98
        { processing_id => $self->processing_id } )->count;
99
100
    return ( $trains_using_it || $items_using_it ) ? 0 : 1;
101
}
102
83
=head2 Internal methods
103
=head2 Internal methods
84
104
85
=head3 _type
105
=head3 _type
(-)a/Koha/REST/V1/Preservation/Processings.pm (-1 / +8 lines)
Lines 227-233 sub update { Link Here
227
sub delete {
227
sub delete {
228
    my $c = shift->openapi->valid_input or return;
228
    my $c = shift->openapi->valid_input or return;
229
229
230
    my $processing = Koha::Preservation::Processings->find( $c->validation->param('processing_id') );
230
    my $processing_id = $c->validation->param('processing_id');
231
    my $processing = Koha::Preservation::Processings->find( $processing_id );
231
    unless ($processing) {
232
    unless ($processing) {
232
        return $c->render(
233
        return $c->render(
233
            status  => 404,
234
            status  => 404,
Lines 235-240 sub delete { Link Here
235
        );
236
        );
236
    }
237
    }
237
238
239
    unless ($processing->can_be_deleted) {
240
        return $c->render(
241
            status => 409,
242
            openapi => { error => "Processing is already used" },
243
        );
244
    }
238
    return try {
245
    return try {
239
        $processing->delete;
246
        $processing->delete;
240
        return $c->render(
247
        return $c->render(
(-)a/koha-tmpl/intranet-tmpl/prog/js/vue/components/Preservation/SettingsProcessings.vue (-3 / +13 lines)
Lines 44-51 import { APIClient } from "../../fetch/api-client.js" Link Here
44
44
45
export default {
45
export default {
46
    setup() {
46
    setup() {
47
        const { setConfirmationDialog, setMessage } = inject("mainStore")
47
        const { setConfirmationDialog, setMessage, setError } =
48
        return { setConfirmationDialog, setMessage }
48
            inject("mainStore")
49
        return { setConfirmationDialog, setMessage, setError }
49
    },
50
    },
50
    data() {
51
    data() {
51
        return {
52
        return {
Lines 90-96 export default { Link Here
90
                                error => {}
91
                                error => {}
91
                            )
92
                            )
92
                        },
93
                        },
93
                        error => {}
94
                        error => {
95
                            // FIXME We need a better way to do that
96
                            if (error.toString().match(/409/)) {
97
                                this.setError(
98
                                    this.$__(
99
                                        "This processing cannot be deleted, it is already in used."
100
                                    )
101
                                )
102
                            }
103
                        }
94
                    )
104
                    )
95
                }
105
                }
96
            )
106
            )
(-)a/t/db_dependent/Koha/Preservation/Processings.t (-2 / +36 lines)
Lines 17-23 Link Here
17
17
18
use Modern::Perl;
18
use Modern::Perl;
19
19
20
use Test::More tests => 1;
20
use Test::More tests => 2;
21
use Test::Exception;
21
use Test::Exception;
22
use Test::Warn;
22
use Test::Warn;
23
23
Lines 56-58 subtest 'attributes' => sub { Link Here
56
56
57
    $schema->storage->txn_rollback;
57
    $schema->storage->txn_rollback;
58
};
58
};
59
- 
59
60
subtest 'can_be_deleted' => sub {
61
62
    plan tests => 5;
63
64
    $schema->storage->txn_begin;
65
66
    my $processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
67
    my $another_processing = $builder->build_object( { class => 'Koha::Preservation::Processings' } );
68
69
    is( $processing->can_be_deleted, 1, 'processing is not used, it can be deleted' );
70
71
    my $train = $builder->build_object(
72
        {
73
            class => 'Koha::Preservation::Trains',
74
            value => {
75
                not_for_loan => 42,
76
                default_processing_id => $processing->processing_id,
77
                closed_on    => undef,
78
                sent_on      => undef,
79
                received_on  => undef
80
            }
81
        }
82
    );
83
84
    is( $processing->can_be_deleted, 0, 'processing is used, it cannot be deleted' );
85
    is( $another_processing->can_be_deleted, 1, 'processing is not used, it can be deleted' );
86
87
    my $item = $builder->build_sample_item;
88
    $train->add_item( { item_id => $item->itemnumber, processing_id => $another_processing->processing_id }, { skip_waiting_list_check => 1 } );
89
    is( $processing->can_be_deleted, 0, 'processing is used, it cannot be deleted' );
90
    is( $another_processing->can_be_deleted, 0, 'processing is used, it cannot be deleted' );
91
92
    $schema->storage->txn_rollback;
93
};

Return to bug 30708