From 2f162c496685e5b6f26fe65f65a3d70427c8b84d Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Thu, 10 Apr 2025 18:22:24 +0000 Subject: [PATCH] Bug 24843: WIP To do: 1 - Add back JS checks to prevent submit if no actions selected 2 - Unit tests --- Koha/BackgroundJob/BatchUpdateBiblio.pm | 12 ++-- .../BackgroundJob/BatchUpdateBiblio.pm | 57 +++++++++++++++++++ .../tools/batch_record_modification.tt | 49 ++++++++++------ tools/batch_record_modification.pl | 29 ++++++++-- 4 files changed, 122 insertions(+), 25 deletions(-) create mode 100644 Koha/Exceptions/BackgroundJob/BatchUpdateBiblio.pm diff --git a/Koha/BackgroundJob/BatchUpdateBiblio.pm b/Koha/BackgroundJob/BatchUpdateBiblio.pm index df6d53e7ade..f0a70927c80 100644 --- a/Koha/BackgroundJob/BatchUpdateBiblio.pm +++ b/Koha/BackgroundJob/BatchUpdateBiblio.pm @@ -18,6 +18,7 @@ package Koha::BackgroundJob::BatchUpdateBiblio; use Modern::Perl; use Koha::Biblios; +use Koha::Exceptions::BackgroundJob::BatchUpdateBiblio; use Koha::Virtualshelves; use Koha::SearchEngine; use Koha::SearchEngine::Indexer; @@ -67,8 +68,9 @@ sub process { $self->start; - my $mmtid = $args->{mmtid}; - my @record_ids = @{ $args->{record_ids} }; + my $mmtid = $args->{mmtid}; + my $update_frameworkcode = $args->{frameworkcode}; + my @record_ids = @{ $args->{record_ids} }; my $report = { total_records => scalar @record_ids, @@ -86,7 +88,7 @@ RECORD_IDS: for my $biblionumber ( sort { $a <=> $b } @record_ids ) { my $biblio = Koha::Biblios->find($biblionumber); my $record = $biblio->metadata->record; C4::MarcModificationTemplates::ModifyRecordWithTemplate( $mmtid, $record ); - my $frameworkcode = C4::Biblio::GetFrameworkCode($biblionumber); + my $frameworkcode = $update_frameworkcode // C4::Biblio::GetFrameworkCode($biblionumber); if ( marc_record_contains_item_data($record) ) { my ( $can_add_item, $add_item_error_message ) = can_add_item_from_marc_record($record); @@ -145,7 +147,9 @@ sub enqueue { my ( $self, $args ) = @_; # TODO Raise exception instead - return unless exists $args->{mmtid}; + Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoAction->throw() + unless ( exists $args->{mmtid} && $args->{mmtid} > 0 + || exists $args->{frameworkcode} && $args->{frameworkcode} != '_USE_ORIG' ); return unless exists $args->{record_ids}; $self->SUPER::enqueue( diff --git a/Koha/Exceptions/BackgroundJob/BatchUpdateBiblio.pm b/Koha/Exceptions/BackgroundJob/BatchUpdateBiblio.pm new file mode 100644 index 00000000000..31f7217c89d --- /dev/null +++ b/Koha/Exceptions/BackgroundJob/BatchUpdateBiblio.pm @@ -0,0 +1,57 @@ +package Koha::Exceptions::BackgroundJob::BatchUpdateBiblio; + +# This file is part of Koha. +# +# Koha is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 3 of the License, or +# (at your option) any later version. +# +# Koha is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Koha; if not, see . + +use Modern::Perl; + +use Koha::Exception; + +use Exception::Class ( + + 'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio' => { + isa => 'Koha::Exception', + }, + 'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoAction' => { + isa => 'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio', + description => 'Batch update requested but no modifications selected', + }, + 'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoRecords' => { + isa => 'Koha::Exceptions::BackgroundJob::BatchUpdateBiblio', + description => 'Batch update requested but no records selected' + }, +); + +=head1 NAME + +Koha::Exceptions::BackgroundJob::BatchUpdateBiblio - Base class for BatchUpdateBiblio BackgroundJob exceptions + +=head1 Exceptions + +=head2 Koha::Exceptions::BackgroundJob::BatchUpdateBiblio + +Generic BatchUpdateBiblio BackgroundJob exception + +=head2 Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoAction + +Exception to be used when a BatchUpdateBiblio BackgroundJob has no actions specified. + +=head2 Koha::Exceptions::BackgroundJob::BatchUpdateBiblio::NoRecords + +Exception to be used when no records are sent to batch modification. + +=cut + +1; 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..cd61e38246d 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 @@ -153,8 +153,8 @@ MARC modification template
  1. - - [% FOREACH mmt IN MarcModificationTemplatesLoop %] @@ -163,6 +163,21 @@
+
+ Update framework +
    +
  1. + + +
  2. +
+
@@ -174,8 +189,8 @@ [% IF records %]
[% INCLUDE 'csrf-token.inc' %] - - [% FOREACH mmt IN MarcModificationTemplatesLoop %] [% IF mmt.selected %] @@ -202,6 +217,18 @@ [% IF recordtype == 'biblio' %] + +
Select all | Clear all @@ -325,9 +352,11 @@ if (selected_type == 'authority') { $("a[href='#shelves_tab_panel']").parent().hide(); $("a[href='#uploadfile_tab_panel']").tab("show"); + $("fieldset.frameworkcode").hide(); } else if (selected_type == 'biblio') { $("a[href='#shelves_tab_panel']").parent().show(); $("a[href='#uploadfile_tab_panel']").tab("show"); + $("fieldset.frameworkcode").show(); } } $(document).ready(function() { @@ -373,18 +402,6 @@ paginate: false, }); - $("#mainformsubmit").click(function() { - if ($("input[type=checkbox][name='record_id']:checked").length == 0) { - alert(_("Please select at least one record to process")); - return false; - } - if ($("#marc_modification_template_id").val() <= 0) { - alert(_("Please select a modification template.")); - return false; - } - return true; - }); - $("#record_ids_selection").on("submit", function(e) { var tab = $(this).find('#batch_mod_form li a.active:first').attr('href'); if (tab == '#uploadfile_tab_panel') { diff --git a/tools/batch_record_modification.pl b/tools/batch_record_modification.pl index 115fdc75535..2fb976d1040 100755 --- a/tools/batch_record_modification.pl +++ b/tools/batch_record_modification.pl @@ -35,6 +35,7 @@ use C4::MarcModificationTemplates qw( use Koha::Biblios; use Koha::BackgroundJob::BatchUpdateBiblio; use Koha::BackgroundJob::BatchUpdateAuthority; +use Koha::BiblioFrameworks; use Koha::MetadataRecord::Authority; use Koha::Virtualshelves; @@ -82,6 +83,11 @@ if ($mmtid) { if ( $op eq 'form' ) { + my $frameworks = Koha::BiblioFrameworks->search( + { tagfield => { 'not' => undef } }, + { join => 'marc_tag_structure', distinct => 'frameworkcode', order_by => ['frameworktext'] } + ); + # Display the form $template->param( view => 'form', @@ -90,8 +96,10 @@ if ( $op eq 'form' ) { { public => 0, owner => $loggedinuser }, { public => 1 } ] - ) + ), + frameworks => $frameworks ); + } elsif ( $op eq 'cud-list' ) { # List all records to process @@ -122,7 +130,13 @@ if ( $op eq 'form' ) { # The user enters manually the list of id push @record_ids, split( /\s\n/, scalar $input->param('recordnumber_list') ); } + my $frameworkcode = $input->param('overlay_framework'); + my $frameworks; + $frameworks = Koha::BiblioFrameworks->search( + { tagfield => { 'not' => undef } }, + { join => 'marc_tag_structure', distinct => 'frameworkcode', order_by => ['frameworktext'] } + ); for my $record_id ( uniq @record_ids ) { if ( $recordtype eq 'biblio' ) { @@ -157,18 +171,23 @@ if ( $op eq 'form' ) { } } $template->param( - records => \@records, - mmtid => $mmtid, - view => 'list', + records => \@records, + mmtid => $mmtid, + view => 'list', + frameworks => $frameworks, + frameworkcode => $frameworkcode, ); } elsif ( $op eq 'cud-modify' ) { # We want to modify selected records! - my @record_ids = $input->multi_param('record_id'); + my @record_ids = $input->multi_param('record_id'); + my $frameworkcode = $input->param('overlay_framework'); + $frameworkcode = undef if $frameworkcode eq '_USE_ORIG_'; try { my $patron = Koha::Patrons->find($loggedinuser); my $params = { + frameworkcode => $frameworkcode, mmtid => $mmtid, record_ids => \@record_ids, overlay_context => { -- 2.39.5