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

(-)a/Koha/BackgroundJob/BatchDeleteItem.pm (-2 / +11 lines)
Lines 81-88 sub process { Link Here
81
81
82
    $self->start;
82
    $self->start;
83
83
84
    my @record_ids     = @{ $args->{record_ids} };
84
    my @record_ids           = @{ $args->{record_ids} };
85
    my $delete_biblios = $args->{delete_biblios};
85
    my $delete_biblios       = $args->{delete_biblios};
86
    my $delete_serial_issues = $args->{delete_serial_issues};
86
87
87
    my $report = {
88
    my $report = {
88
        total_records => scalar @record_ids,
89
        total_records => scalar @record_ids,
Lines 104-109 sub process { Link Here
104
105
105
                    my $item = Koha::Items->find($record_id) || next;
106
                    my $item = Koha::Items->find($record_id) || next;
106
107
108
                    if ($delete_serial_issues) {
109
                        my $serial_item = $item->serial_item;
110
                        my $serial      = Koha::Serials->find( $serial_item->serialid );
111
112
                        $serial->delete;
113
                        $serial_item->delete;
114
                    }
115
107
                    my $return = $item->safe_delete({ skip_record_index => 1, skip_holds_queue => 1 });
116
                    my $return = $item->safe_delete({ skip_record_index => 1, skip_holds_queue => 1 });
108
                    unless ( $return ) {
117
                    unless ( $return ) {
109
118
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt (-5 / +14 lines)
Lines 167-178 Link Here
167
167
168
    [% IF ( itemresults ) %]
168
    [% IF ( itemresults ) %]
169
        <div id="cataloguing_additem_newitem" class="item_edit_form">
169
        <div id="cataloguing_additem_newitem" class="item_edit_form">
170
         <input type="hidden" name="op" value="[% op | html %]" />
170
            <input type="hidden" name="op" value="[% op | html %]" />
171
         <p>This will delete [% IF ( too_many_items_display ) %]all the[% ELSE %]the selected[% END %] items.</p>
171
            <p>This will delete [% IF ( too_many_items_display ) %]all the[% ELSE %]the selected[% END %] items.</p>
172
         <input type="hidden" name="del" value="1" />
172
            <input type="hidden" name="del" value="1" />
173
         <input type="checkbox" name="del_records" id="del_records" /> <label for="del_records">Delete records if no items remain.</label>
173
            <div style="display: flex; flex-direction: column; gap: 5px;">
174
                <div>
175
                    <input type="checkbox" name="del_records" id="del_records" />
176
                    <label for="del_records">Delete records if no items remain.</label>
177
                </div>
178
                <div>
179
                    <input type="checkbox" name="del_serial_issues" id="del_serial_issues" />
180
                    <label for="del_serial_issues">Delete serial issues linked to items.</label>
181
                </div>
182
            </div>
174
183
175
         <fieldset class="action">
184
        <fieldset class="action">
176
        [% IF too_many_items_display %]
185
        [% IF too_many_items_display %]
177
            <input type="submit" name="mainformsubmit" class="btn btn-primary" value="Delete ALL submitted items" />
186
            <input type="submit" name="mainformsubmit" class="btn btn-primary" value="Delete ALL submitted items" />
178
        [% ELSE %]
187
        [% ELSE %]
(-)a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t (-1 / +39 lines)
Lines 24-29 use JSON qw( encode_json ); Link Here
24
24
25
use Koha::Database;
25
use Koha::Database;
26
use Koha::BackgroundJob::BatchDeleteItem;
26
use Koha::BackgroundJob::BatchDeleteItem;
27
use Koha::Serial;
28
use Koha::Serial::Items;
27
29
28
use t::lib::Mocks;
30
use t::lib::Mocks;
29
use t::lib::TestBuilder;
31
use t::lib::TestBuilder;
Lines 33-39 my $builder = t::lib::TestBuilder->new; Link Here
33
35
34
subtest "process() tests" => sub {
36
subtest "process() tests" => sub {
35
37
36
    plan tests => 2;
38
    plan tests => 4;
37
39
38
    $schema->storage->txn_begin;
40
    $schema->storage->txn_begin;
39
41
Lines 99-103 subtest "process() tests" => sub { Link Here
99
101
100
    is( $counter, 1, 'Counter untouched with RealTimeHoldsQueue disabled' );
102
    is( $counter, 1, 'Counter untouched with RealTimeHoldsQueue disabled' );
101
103
104
    $biblio = $builder->build_sample_biblio;
105
    my $item_with_serial = $builder->build_sample_item( { biblionumber => $biblio->id } );
106
    my $serial_item =
107
        $builder->build_object(
108
        { class => 'Koha::Serial::Items', value => { itemnumber => $item_with_serial->itemnumber } } );
109
    my $serial =
110
        $builder->build_object( { class => 'Koha::Serials', value => { biblionumber => $biblio->biblionumber } } );
111
112
    $job = Koha::BackgroundJob::BatchDeleteItem->new(
113
        {
114
            status         => 'new',
115
            size           => 2,
116
            borrowernumber => undef,
117
            type           => 'batch_item_record_deletion',
118
            data           => encode_json {
119
                record_ids           => [ $item_with_serial->id ],
120
                delete_biblios       => 1,
121
                delete_serial_issues => 1,
122
            }
123
        }
124
    );
125
126
    $job->process(
127
        {
128
            record_ids           => [ $item_with_serial->id ],
129
            delete_biblios       => 1,
130
            delete_serial_issues => 1,
131
        }
132
    );
133
134
    my $serial_check      = Koha::Serials->find( $serial->serialid );
135
    my $serial_item_check = Koha::Serial::Items->find( $serial_item->itemnumber );
136
137
    is( $serial_check,      undef, 'Serial deleted' );
138
    is( $serial_item_check, undef, 'Serial item deleted' );
139
102
    $schema->storage->txn_rollback;
140
    $schema->storage->txn_rollback;
103
};
141
};
(-)a/tools/batchMod.pl (-14 / +15 lines)
Lines 41-58 use Koha::BackgroundJob::BatchUpdateItem; Link Here
41
use Koha::UI::Form::Builder::Item;
41
use Koha::UI::Form::Builder::Item;
42
use Koha::UI::Table::Builder::Items;
42
use Koha::UI::Table::Builder::Items;
43
43
44
my $input = CGI->new;
44
my $input                             = CGI->new;
45
my $dbh = C4::Context->dbh;
45
my $dbh                               = C4::Context->dbh;
46
my $error        = $input->param('error');
46
my $error                             = $input->param('error');
47
my @itemnumbers  = $input->multi_param('itemnumber');
47
my @itemnumbers                       = $input->multi_param('itemnumber');
48
my $biblionumber = $input->param('biblionumber');
48
my $biblionumber                      = $input->param('biblionumber');
49
my $op           = $input->param('op');
49
my $op                                = $input->param('op');
50
my $del          = $input->param('del');
50
my $del                               = $input->param('del');
51
my $del_records  = $input->param('del_records');
51
my $del_records                       = $input->param('del_records');
52
my $src          = $input->param('src');
52
my $del_serial_issues                 = $input->param('del_serial_issues');
53
my $use_default_values = $input->param('use_default_values');
53
my $src                               = $input->param('src');
54
my $use_default_values                = $input->param('use_default_values');
54
my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority');
55
my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority');
55
my $mark_items_returned = $input->param('mark_items_returned');
56
my $mark_items_returned               = $input->param('mark_items_returned');
56
57
57
my $template_name;
58
my $template_name;
58
my $template_flag;
59
my $template_flag;
Lines 91-98 if ( $op eq "cud-action" ) { Link Here
91
    if ($del) {
92
    if ($del) {
92
        try {
93
        try {
93
            my $params = {
94
            my $params = {
94
                record_ids     => \@itemnumbers,
95
                record_ids           => \@itemnumbers,
95
                delete_biblios => $del_records,
96
                delete_biblios       => $del_records,
97
                delete_serial_issues => $del_serial_issues,
96
            };
98
            };
97
            my $job_id =
99
            my $job_id =
98
              Koha::BackgroundJob::BatchDeleteItem->new->enqueue($params);
100
              Koha::BackgroundJob::BatchDeleteItem->new->enqueue($params);
99
- 

Return to bug 37115