Bugzilla – Attachment 168134 Details for
Bug 37115
Add the option to delete linked serials when deleting items
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37115: Batch delete linked serials
Bug-37115-Batch-delete-linked-serials.patch (text/plain), 8.80 KB, created by
Matt Blenkinsop
on 2024-06-26 10:51:12 UTC
(
hide
)
Description:
Bug 37115: Batch delete linked serials
Filename:
MIME Type:
Creator:
Matt Blenkinsop
Created:
2024-06-26 10:51:12 UTC
Size:
8.80 KB
patch
obsolete
>From a4310afd75a7619daa81c0d3ccf6802c427adf0a Mon Sep 17 00:00:00 2001 >From: Matt Blenkinsop <matt.blenkinsop@ptfs-europe.com> >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 ) %] > <div id="cataloguing_additem_newitem" class="item_edit_form"> >- <input type="hidden" name="op" value="[% op | html %]" /> >- <p>This will delete [% IF ( too_many_items_display ) %]all the[% ELSE %]the selected[% END %] items.</p> >- <input type="hidden" name="del" value="1" /> >- <input type="checkbox" name="del_records" id="del_records" /> <label for="del_records">Delete records if no items remain.</label> >+ <input type="hidden" name="op" value="[% op | html %]" /> >+ <p>This will delete [% IF ( too_many_items_display ) %]all the[% ELSE %]the selected[% END %] items.</p> >+ <input type="hidden" name="del" value="1" /> >+ <div style="display: flex; flex-direction: column; gap: 5px;"> >+ <div> >+ <input type="checkbox" name="del_records" id="del_records" /> >+ <label for="del_records">Delete records if no items remain.</label> >+ </div> >+ <div> >+ <input type="checkbox" name="del_serial_issues" id="del_serial_issues" /> >+ <label for="del_serial_issues">Delete serial issues linked to items.</label> >+ </div> >+ </div> > >- <fieldset class="action"> >+ <fieldset class="action"> > [% IF too_many_items_display %] > <input type="submit" name="mainformsubmit" class="btn btn-primary" value="Delete ALL submitted items" /> > [% 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)
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37115
:
167847
|
167848
|
168133
|
168134
|
168373
|
168374
|
168495
|
168496
|
168497
|
171208
|
171209
|
171210
|
171938
|
171939
|
171940
|
173256
|
173257
|
173258