From 1c20df8b252f2625b5066864032b78e6483c1ed7 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 | 8 +- .../tools/batch_record_modification.tt | 8 +- tools/batch_delete_records.pl | 135 ++++++++++-------- tools/batch_record_modification.pl | 133 +++++++++-------- 4 files changed, 158 insertions(+), 126 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 8a522832ca..2312361733 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 @@ -129,8 +129,14 @@ +
+ Next step +
    +
  1. +
  2. +
+
- Cancel
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 1f31be64ef..9b81ddac45 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 @@ -155,8 +155,14 @@ +
+ Next step +
    +
  1. +
  2. +
+
- Cancel
diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index a1781802b8..96a87a82f3 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -50,6 +50,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( @@ -61,7 +89,7 @@ if ( $op eq 'form' ) { ] ) ); -} elsif ( $op eq 'list' ) { +} elsif ( $op eq 'list' || $op eq 'delete_all' ) { # List all records to process my @record_ids; if ( my $bib_list = $input->param('bib_list') ) { @@ -88,75 +116,58 @@ 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; - 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; + 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 '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 1cbda22785..a42d74a3f5 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 'list' ) { +} elsif ( $op eq '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 '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.30.2