From a4310afd75a7619daa81c0d3ccf6802c427adf0a Mon Sep 17 00:00:00 2001 From: Matt Blenkinsop Date: Mon, 3 Jun 2024 12:24:46 +0000 Subject: [PATCH] Bug 37115: Batch delete linked serials --- Koha/BackgroundJob/BatchDeleteItem.pm | 24 ++++++++--- .../prog/en/modules/tools/batchMod-del.tt | 19 ++++++--- .../Koha/BackgroundJobs/BatchDeleteItem.t | 40 ++++++++++++++++++- tools/batchMod.pl | 28 +++++++------ 4 files changed, 86 insertions(+), 25 deletions(-) diff --git a/Koha/BackgroundJob/BatchDeleteItem.pm b/Koha/BackgroundJob/BatchDeleteItem.pm index 474450e57b..6431911e70 100644 --- a/Koha/BackgroundJob/BatchDeleteItem.pm +++ b/Koha/BackgroundJob/BatchDeleteItem.pm @@ -81,8 +81,9 @@ sub process { $self->start; - my @record_ids = @{ $args->{record_ids} }; - my $delete_biblios = $args->{delete_biblios}; + my @record_ids = @{ $args->{record_ids} }; + my $delete_biblios = $args->{delete_biblios}; + my $delete_serial_issues = $args->{delete_serial_issues}; my $report = { total_records => scalar @record_ids, @@ -123,6 +124,15 @@ sub process { next; } + if ( $return && $delete_serial_issues ) { + my $serial_item = $item->serial_item; + if ($serial_item) { + my $serial = Koha::Serials->find( $serial_item->serialid ); + $serial->delete; + $serial_item->delete; + } + } + push @deleted_itemnumbers, $item->itemnumber; push @biblionumbers, $item->biblionumber; @@ -221,15 +231,17 @@ sub enqueue { # TODO Raise exception instead return unless exists $args->{record_ids}; - my @record_ids = @{ $args->{record_ids} }; - my $delete_biblios = $args->{delete_biblios} || 0; + my @record_ids = @{ $args->{record_ids} }; + my $delete_biblios = $args->{delete_biblios} || 0; + my $delete_serial_issues = $args->{delete_serial_issues} || 0; $self->SUPER::enqueue( { job_size => scalar @record_ids, job_args => { - record_ids => \@record_ids, - delete_biblios => $delete_biblios, + record_ids => \@record_ids, + delete_biblios => $delete_biblios, + delete_serial_issues => $delete_serial_issues, }, job_queue => 'long_tasks', } diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt index ffa1addbb9..5064338100 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-del.tt @@ -167,12 +167,21 @@ [% IF ( itemresults ) %]
- -

This will delete [% IF ( too_many_items_display ) %]all the[% ELSE %]the selected[% END %] items.

- - + +

This will delete [% IF ( too_many_items_display ) %]all the[% ELSE %]the selected[% END %] items.

+ +
+
+ + +
+
+ + +
+
-
+
[% IF too_many_items_display %] [% ELSE %] diff --git a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t b/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t index ee40088c8c..e142877451 100755 --- a/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t +++ b/t/db_dependent/Koha/BackgroundJobs/BatchDeleteItem.t @@ -24,6 +24,8 @@ use JSON qw( encode_json ); use Koha::Database; use Koha::BackgroundJob::BatchDeleteItem; +use Koha::Serial; +use Koha::Serial::Items; use t::lib::Mocks; use t::lib::TestBuilder; @@ -33,7 +35,7 @@ my $builder = t::lib::TestBuilder->new; subtest "process() tests" => sub { - plan tests => 2; + plan tests => 4; $schema->storage->txn_begin; @@ -99,5 +101,41 @@ subtest "process() tests" => sub { is( $counter, 1, 'Counter untouched with RealTimeHoldsQueue disabled' ); + $biblio = $builder->build_sample_biblio; + my $item_with_serial = $builder->build_sample_item( { biblionumber => $biblio->id } ); + my $serial_item = + $builder->build_object( + { class => 'Koha::Serial::Items', value => { itemnumber => $item_with_serial->itemnumber } } ); + my $serial = + $builder->build_object( { class => 'Koha::Serials', value => { biblionumber => $biblio->biblionumber } } ); + + $job = Koha::BackgroundJob::BatchDeleteItem->new( + { + status => 'new', + size => 2, + borrowernumber => undef, + type => 'batch_item_record_deletion', + data => encode_json { + record_ids => [ $item_with_serial->id ], + delete_biblios => 1, + delete_serial_issues => 1, + } + } + ); + + $job->process( + { + record_ids => [ $item_with_serial->id ], + delete_biblios => 1, + delete_serial_issues => 1, + } + ); + + my $serial_check = Koha::Serials->find( $serial->serialid ); + my $serial_item_check = Koha::Serial::Items->find( $serial_item->itemnumber ); + + is( $serial_check, undef, 'Serial deleted' ); + is( $serial_item_check, undef, 'Serial item deleted' ); + $schema->storage->txn_rollback; }; diff --git a/tools/batchMod.pl b/tools/batchMod.pl index 1b43231857..e6dc6ded99 100755 --- a/tools/batchMod.pl +++ b/tools/batchMod.pl @@ -41,18 +41,19 @@ use Koha::BackgroundJob::BatchUpdateItem; use Koha::UI::Form::Builder::Item; use Koha::UI::Table::Builder::Items; -my $input = CGI->new; -my $dbh = C4::Context->dbh; -my $error = $input->param('error'); -my @itemnumbers = $input->multi_param('itemnumber'); -my $biblionumber = $input->param('biblionumber'); -my $op = $input->param('op'); -my $del = $input->param('del'); -my $del_records = $input->param('del_records'); -my $src = $input->param('src'); -my $use_default_values = $input->param('use_default_values'); +my $input = CGI->new; +my $dbh = C4::Context->dbh; +my $error = $input->param('error'); +my @itemnumbers = $input->multi_param('itemnumber'); +my $biblionumber = $input->param('biblionumber'); +my $op = $input->param('op'); +my $del = $input->param('del'); +my $del_records = $input->param('del_records'); +my $del_serial_issues = $input->param('del_serial_issues'); +my $src = $input->param('src'); +my $use_default_values = $input->param('use_default_values'); my $exclude_from_local_holds_priority = $input->param('exclude_from_local_holds_priority'); -my $mark_items_returned = $input->param('mark_items_returned'); +my $mark_items_returned = $input->param('mark_items_returned'); my $template_name; my $template_flag; @@ -91,8 +92,9 @@ if ( $op eq "cud-action" ) { if ($del) { try { my $params = { - record_ids => \@itemnumbers, - delete_biblios => $del_records, + record_ids => \@itemnumbers, + delete_biblios => $del_records, + delete_serial_issues => $del_serial_issues, }; my $job_id = Koha::BackgroundJob::BatchDeleteItem->new->enqueue($params); -- 2.39.3 (Apple Git-146)