Bugzilla – Attachment 180799 Details for
Bug 24843
Allow change of framework via batch record modification
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 24843: WIP
Bug-24843-WIP.patch (text/plain), 13.00 KB, created by
Nick Clemens (kidclamp)
on 2025-04-10 18:23:45 UTC
(
hide
)
Description:
Bug 24843: WIP
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2025-04-10 18:23:45 UTC
Size:
13.00 KB
patch
obsolete
>From 2f162c496685e5b6f26fe65f65a3d70427c8b84d Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >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 <http://www.gnu.org/licenses>. >+ >+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 @@ > <legend>MARC modification template</legend> > <ol> > <li> >- <label for="marc_modification_template_id" class="required">Template: </label> >- <select name="marc_modification_template_id" id="marc_modification_template_id" required="required"> >+ <label for="marc_modification_template_id">Template: </label> >+ <select name="marc_modification_template_id" id="marc_modification_template_id"> > <option value="">Select a template</option> > [% FOREACH mmt IN MarcModificationTemplatesLoop %] > <option value="[% mmt.template_id | html %]">[% mmt.name | html %]</option> >@@ -163,6 +163,21 @@ > </li> > </ol> > </fieldset> >+ <fieldset class="rows frameworkcode"> >+ <legend>Update framework</legend> >+ <ol> >+ <li> >+ <label for="overlay_framework">Update framework: </label> >+ <select name="overlay_framework" id="overlay_framework"> >+ <option value="_USE_ORIG_">Keep original framework</option> >+ <option value="">Default</option> >+ [% FOREACH framework IN frameworks %] >+ <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> >+ [% END %] >+ </select> >+ </li> >+ </ol> >+ </fieldset> > <fieldset class="action"> > <input type="hidden" name="op" value="cud-list" /> > <input type="submit" class="btn btn-primary" value="Continue" /> >@@ -174,8 +189,8 @@ > [% IF records %] > <form action="/cgi-bin/koha/tools/batch_record_modification.pl" method="post"> > [% INCLUDE 'csrf-token.inc' %] >- <label for="marc_modification_template_id" class="required">Modify record using the following template: </label> >- <select name="marc_modification_template_id" id="marc_modification_template_id" required="required"> >+ <label for="marc_modification_template_id">Modify record using the following template: </label> >+ <select name="marc_modification_template_id" id="marc_modification_template_id"> > <option value="">Select a template</option> > [% FOREACH mmt IN MarcModificationTemplatesLoop %] > [% IF mmt.selected %] >@@ -202,6 +217,18 @@ > </div> > </div> > [% IF recordtype == 'biblio' %] >+ <label for="update_framework">Update framework: </label> >+ <select name="overlay_framework" id="overlay_framework"> >+ <option value="_USE_ORIG_" [% IF frameworkcode == "_USE_ORIG" %]selected="selected"[% END %]>Keep original framework</option> >+ <option value="" [% IF frameworkcode == "" %]selected="selected"[% END %]>Default</option> >+ [%- FOREACH framework IN frameworks -%] >+ [%- IF framework.frameworkcode == frameworkcode -%] >+ <option value="[% framework.frameworkcode | html %]" selected="selected">[% framework.frameworktext | html %]</option> >+ [%- ELSE -%] >+ <option value="[% framework.frameworkcode | html %]">[% framework.frameworktext | html %]</option> >+ [%- END -%] >+ [%- END -%] >+ </select> > <div class="btn-toolbar selections-toolbar"> > <a id="selectall" href="#"><i class="fa fa-check"></i> Select all</a> > | <a id="clearall" href="#"><i class="fa fa-times"></i> Clear all</a> >@@ -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
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 24843
: 180799