From 517ddcd747d8ebd4e1fdf1aeeadac158b0ca4476 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 --- .../en/modules/tools/batch_delete_records.tt | 11 +- .../tools/batch_record_modification.tt | 7 + tools/batch_delete_records.pl | 158 +++++++++--------- tools/batch_record_modification.pl | 137 ++++++++------- 4 files changed, 169 insertions(+), 144 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 c325868b00d..ddc3fa58690 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,8 +149,17 @@ [% END # /WRAPPER tab_panels %] [% END # /WRAPPER tabs %] + +
+ 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 d61e04840aa..6f7f5d3703b 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 @@ -163,6 +163,13 @@ +
+ Next step +
    +
  1. +
  2. +
+
diff --git a/tools/batch_delete_records.pl b/tools/batch_delete_records.pl index b5fec31ccec..cf0ef012b2a 100755 --- a/tools/batch_delete_records.pl +++ b/tools/batch_delete_records.pl @@ -54,8 +54,35 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( my @records; my @messages; -if ( $op eq 'form' ) { +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( op => 'form', @@ -66,8 +93,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') ) { @@ -76,7 +102,6 @@ if ( $op eq 'form' ) { @record_ids = split /\//, $bib_list; $recordtype = 'biblio'; } elsif ( my $uploadfile = $input->param('uploadfile') ) { - # A file of id is given binmode $uploadfile, ':encoding(UTF-8)'; while ( my $content = <$uploadfile> ) { @@ -92,91 +117,68 @@ if ( $op eq 'form' ) { push @record_ids, $biblionumber; } } else { - # The user enters manually the list of id 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 115fdc75535..32a63bdea14 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -55,6 +55,40 @@ my ( $template, $loggedinuser, $cookie ) = get_template_and_user( } ); + +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); @@ -92,7 +126,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 ); @@ -123,78 +157,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.34.1