From 93caba511a23596d88302eb859194ee1f819436e Mon Sep 17 00:00:00 2001 From: David Gustafsson Date: Wed, 9 Mar 2022 15:12:59 +0100 Subject: [PATCH] Bug 30255: Make selection step optional for batch record del/mod Allow the user to optionally skip the record selection step in batch record deletion/modification tools and directly enqueue job for all records. 1) Create a record modification template. 2) Enter some biblionumber(s) in the batch record modification tool form, select the record modification template, the "Select records to modify" option and proceed to the next step. 3) Verify that records can be selected, proceed to the next step and verify that a job has been enqueued for the selected records. 4) Return to the batch record modification form and enter the biblionumbers(s) again. Now select "Modify all" and proceed to the next step. 5) Verify that a job has been enqueued for all records. 6) Enter some biblionumber(s) in the batch record deletion tool form, select the "Select records to delete" option and proceed to the next step. 7) Verify that records can be selected, proceed to the next step and verify that a job has been enqueued for the selected records. 8) Return to the batch record deletion form and enter the biblionumbers(s) again. Now select "Delete all" and proceed to the next step. 9) Verify that a job has been enqueued for all records. Sponsored by: Gothenburg University Library Signed-off-by: Laura --- .../en/modules/tools/batch_delete_records.tt | 7 + .../tools/batch_record_modification.tt | 7 + tools/batch_delete_records.pl | 149 ++++++++++-------- tools/batch_record_modification.pl | 133 ++++++++-------- 4 files changed, 165 insertions(+), 131 deletions(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt index cdfb20d0fb4..fd4f49fadf6 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_delete_records.tt @@ -149,6 +149,13 @@ [% END # /WRAPPER tab_panels %] [% END # /WRAPPER tabs %] +
+ Next step +
    +
  1. +
  2. +
+
diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt index e23050d091e..d86613afd55 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batch_record_modification.tt @@ -161,6 +161,13 @@
+
+ Next step +
    +
  1. +
  2. +
+
diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index ea4a5a9ba45..6db14a2b2f9 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -52,6 +52,34 @@ my ($template, $loggedinuser, $cookie) = get_template_and_user({ my @records; my @messages; + +my $enqueue_job = sub { + my ($record_ids, $recordtype) = @_; + + try { + my $params = { + record_ids => $record_ids, + }; + + my $job_id = + $recordtype eq 'biblio' + ? Koha::BackgroundJob::BatchDeleteBiblio->new->enqueue($params) + : Koha::BackgroundJob::BatchDeleteAuthority->new->enqueue($params); + + $template->param( + op => 'enqueued', + job_id => $job_id, + ); + } catch { + push @messages, { + type => 'error', + code => 'cannot_enqueue_job', + error => $_, + }; + $template->param( view => 'errors' ); + }; +}; + if ( $op eq 'form' ) { # Display the form $template->param( @@ -63,7 +91,7 @@ if ( $op eq 'form' ) { ] ) ); -} elsif ( $op eq 'cud-list' ) { +} elsif ( $op eq 'cud-list' || $op eq 'delete_all' ) { # List all records to process my @record_ids; if ( my $bib_list = $input->param('bib_list') ) { @@ -90,82 +118,65 @@ if ( $op eq 'form' ) { push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') ); } - for my $record_id ( uniq @record_ids ) { - if ( $recordtype eq 'biblio' ) { - # Retrieve biblio information - my $biblio_object = Koha::Biblios->find( $record_id ); - unless ( $biblio_object ) { - push @messages, { - type => 'warning', - code => 'biblio_not_exists', - biblionumber => $record_id, - }; - next; - } - my $biblio = $biblio_object->unblessed; - my $record = $biblio_object->metadata->record; - $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')]; - $biblio->{holds_count} = $biblio_object->holds->count; - $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id ); - $biblio->{subscriptions_count} = $biblio_object->subscriptions->count; - - # Respect skip_open_orders - next - if $skip_open_orders - && Koha::Acquisition::Orders->search( - { biblionumber => $record_id, orderstatus => [ 'new', 'ordered', 'partial' ] } )->count; - - push @records, $biblio; - } else { - # Retrieve authority information - my $authority = C4::AuthoritiesMarc::GetAuthority( $record_id ); - unless ( $authority ) { - push @messages, { - type => 'warning', - code => 'authority_not_exists', + if ( $op eq 'delete_all' ) { + $enqueue_job->(\@record_ids, $recordtype); + } + else { + for my $record_id ( uniq @record_ids ) { + if ( $recordtype eq 'biblio' ) { + # Retrieve biblio information + my $biblio_object = Koha::Biblios->find( $record_id ); + unless ( $biblio_object ) { + push @messages, { + type => 'warning', + code => 'biblio_not_exists', + biblionumber => $record_id, + }; + next; + } + my $biblio = $biblio_object->unblessed; + my $record = $biblio_object->metadata->record; + $biblio->{itemnumbers} = [Koha::Items->search({ biblionumber => $record_id })->get_column('itemnumber')]; + $biblio->{holds_count} = $biblio_object->holds->count; + $biblio->{issues_count} = C4::Biblio::CountItemsIssued( $record_id ); + $biblio->{subscriptions_count} = $biblio_object->subscriptions->count; + + # Respect skip_open_orders + next + if $skip_open_orders + && Koha::Acquisition::Orders->search( + { biblionumber => $record_id, orderstatus => [ 'new', 'ordered', 'partial' ] } )->count; + + push @records, $biblio; + } else { + # Retrieve authority information + my $authority = C4::AuthoritiesMarc::GetAuthority( $record_id ); + unless ( $authority ) { + push @messages, { + type => 'warning', + code => 'authority_not_exists', + authid => $record_id, + }; + next; + } + + $authority = { authid => $record_id, + summary => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ), + count_usage => Koha::Authorities->get_usage_count({ authid => $record_id }), }; - next; + push @records, $authority; } - - $authority = { - authid => $record_id, - summary => C4::AuthoritiesMarc::BuildSummary( $authority, $record_id ), - count_usage => Koha::Authorities->get_usage_count({ authid => $record_id }), - }; - push @records, $authority; } + $template->param( + records => \@records, + op => 'list', + ); } - $template->param( - records => \@records, - op => 'list', - ); } elsif ( $op eq 'cud-delete' ) { # We want to delete selected records! my @record_ids = $input->multi_param('record_id'); - - try { - my $params = { - record_ids => \@record_ids, - }; - - my $job_id = - $recordtype eq 'biblio' - ? Koha::BackgroundJob::BatchDeleteBiblio->new->enqueue($params) - : Koha::BackgroundJob::BatchDeleteAuthority->new->enqueue($params); - - $template->param( - op => 'enqueued', - job_id => $job_id, - ); - } catch { - push @messages, { - type => 'error', - code => 'cannot_enqueue_job', - error => $_, - }; - $template->param( view => 'errors' ); - }; + $enqueue_job->(\@record_ids, $recordtype); } $template->param( diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index b89f67294eb..7fcd407fb6d 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -53,6 +53,39 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user({ flagsrequired => { tools => 'records_batchmod' }, }); +my $enqueue_job = sub { + my ($record_ids, $recordtype) = @_; + try { + my $patron = Koha::Patrons->find( $loggedinuser ); + my $params = { + mmtid => $mmtid, + record_ids => $record_ids, + overlay_context => { + source => 'batchmod', + categorycode => $patron->categorycode, + userid => $patron->userid + } + }; + + my $job_id = + $recordtype eq 'biblio' + ? Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue($params) + : Koha::BackgroundJob::BatchUpdateAuthority->new->enqueue($params); + + $template->param( + view => 'enqueued', + job_id => $job_id, + ); + } catch { + push @messages, { + type => 'error', + code => 'cannot_enqueue_job', + error => $_, + }; + $template->param( view => 'errors' ); + }; +}; + my $sessionID = $input->cookie("CGISESSID"); my @templates = GetModificationTemplates( $mmtid ); @@ -89,7 +122,7 @@ if ( $op eq 'form' ) { ] ) ); -} elsif ( $op eq 'cud-list' ) { +} elsif ( $op eq 'cud-list' || $op eq 'modify_all') { # List all records to process my ( @records, @record_ids ); if ( my $bib_list = $input->param('bib_list') ) { @@ -116,75 +149,51 @@ if ( $op eq 'form' ) { push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') ); } - for my $record_id ( uniq @record_ids ) { - if ( $recordtype eq 'biblio' ) { - # Retrieve biblio information - my $biblio = Koha::Biblios->find( $record_id ); - unless ( $biblio ) { - push @messages, { - type => 'warning', - code => 'biblio_not_exists', - biblionumber => $record_id, - }; - next; - } - push @records, $biblio; - } else { - # Retrieve authority information - my $authority = Koha::MetadataRecord::Authority->get_from_authid( $record_id ); - unless ( $authority ) { - push @messages, { - type => 'warning', - code => 'authority_not_exists', + if ( $op eq 'modify_all' ) { + $enqueue_job->(\@record_ids, $recordtype); + } + else { + for my $record_id ( uniq @record_ids ) { + if ( $recordtype eq 'biblio' ) { + # Retrieve biblio information + my $biblio = Koha::Biblios->find( $record_id ); + unless ( $biblio ) { + push @messages, { + type => 'warning', + code => 'biblio_not_exists', + biblionumber => $record_id, + }; + next; + } + push @records, $biblio; + } else { + # Retrieve authority information + my $authority = Koha::MetadataRecord::Authority->get_from_authid( $record_id ); + unless ( $authority ) { + push @messages, { + type => 'warning', + code => 'authority_not_exists', + authid => $record_id, + }; + next; + } + + push @records, { authid => $record_id, + summary => C4::AuthoritiesMarc::BuildSummary( $authority->record, $record_id ), }; - next; } - - push @records, { - authid => $record_id, - summary => C4::AuthoritiesMarc::BuildSummary( $authority->record, $record_id ), - }; } + $template->param( + records => \@records, + mmtid => $mmtid, + view => 'list', + ); } - $template->param( - records => \@records, - mmtid => $mmtid, - view => 'list', - ); } elsif ( $op eq 'cud-modify' ) { # We want to modify selected records! my @record_ids = $input->multi_param('record_id'); - - try { - my $patron = Koha::Patrons->find( $loggedinuser ); - my $params = { - mmtid => $mmtid, - record_ids => \@record_ids, - overlay_context => { - source => 'batchmod', - categorycode => $patron->categorycode, - userid => $patron->userid - } - }; - - my $job_id = - $recordtype eq 'biblio' - ? Koha::BackgroundJob::BatchUpdateBiblio->new->enqueue($params) - : Koha::BackgroundJob::BatchUpdateAuthority->new->enqueue($params); - - $template->param( - view => 'enqueued', - job_id => $job_id, - ); - } catch { - push @messages, { - type => 'error', - code => 'cannot_enqueue_job', - error => $_, - }; - $template->param( view => 'errors' ); - }; + $enqueue_job->(\@record_ids, $recordtype); } $template->param( -- 2.48.1