From 9533f6355db6679a3541fdb1aa05f07a2b68f9d7 Mon Sep 17 00:00:00 2001 From: Arthur Suzuki Date: Tue, 28 May 2024 00:38:36 +0200 Subject: [PATCH] Bug 36975 : set record source in modifications templates --- C4/MarcModificationTemplates.pm | 8 ++++++ .../data/mysql/atomicupdate/bug_36975.pl | 13 +++++++++ .../tools/marc_modification_templates.tt | 27 ++++++++++++++++--- .../prog/js/marc_modification_templates.js | 10 ++++++- tools/marc_modification_templates.pl | 14 ++++++---- 5 files changed, 62 insertions(+), 10 deletions(-) create mode 100644 installer/data/mysql/atomicupdate/bug_36975.pl diff --git a/C4/MarcModificationTemplates.pm b/C4/MarcModificationTemplates.pm index 13b81ca0b41..9088773d062 100644 --- a/C4/MarcModificationTemplates.pm +++ b/C4/MarcModificationTemplates.pm @@ -32,6 +32,7 @@ use Koha::SimpleMARC qw( move_field update_field ); +use Koha::Biblios; use Koha::MoreUtils; use Koha::DateUtils qw( dt_from_string ); @@ -698,6 +699,13 @@ sub ModifyRecordWithTemplate { field_numbers => $field_numbers, }); } + elsif ( $action eq 'set_record_source' ) { + my $biblionumber = $record->subfield('999', 'c'); + return unless $biblionumber; + my $biblio = Koha::Biblios->find($biblionumber); + return unless $biblio; + $biblio->metadata->set({record_source_id => $field_value})->store; + } } } diff --git a/installer/data/mysql/atomicupdate/bug_36975.pl b/installer/data/mysql/atomicupdate/bug_36975.pl new file mode 100644 index 00000000000..705b561aa1c --- /dev/null +++ b/installer/data/mysql/atomicupdate/bug_36975.pl @@ -0,0 +1,13 @@ +use Modern::Perl; + +return { + bug_number => "36975", + description => "Add set_record_source action to marc_modification_templates_action table", + up => sub { + my ($args) = @_; + my ( $dbh, $out ) = @$args{qw(dbh out)}; + + $dbh->do(q{ALTER TABLE `marc_modification_template_actions` MODIFY COLUMN `action` enum('delete_field', 'add_field', 'update_field', 'move_field', 'copy_field', 'copy_and_replace_field', 'set_record_source') NOT NULL AFTER `ordering`;}); + say $out "Added new action type 'set_record_source'"; + }, +}; diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt index f2eecda2938..082a6ffde6a 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt @@ -162,6 +162,15 @@ [% ActionsLoo.ordering | html %] + [% IF ( ActionsLoo.action_set_record_source ) %] + Set record source + with value + [% FOREACH source IN RecordSources %] + [% IF ( source.record_source_id == ActionsLoo.field_value ) %] + [% source.name | html %] + [% END %] + [% END %] + [% ELSE %] [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %] [% IF ( ActionsLoo.action_add_field ) %] Add new [% END %] [% IF ( ActionsLoo.action_update_field ) %] Update existing or add new [% END %] @@ -174,9 +183,9 @@ 1st [% END %] [% END %] - + field - + [% ActionsLoo.from_field | html %][% IF ( ActionsLoo.from_subfield.length ) %]$[% ActionsLoo.from_subfield | html %][% END %] [% IF ( ActionsLoo.field_value ) %] @@ -190,7 +199,7 @@ using RegEx s/[% ActionsLoo.to_regex_search | html %]/[% ActionsLoo.to_regex_replace | html %]/[% ActionsLoo.to_regex_modifiers | html %] [% END %] [% END %] - + [% END %] [% IF ( ActionsLoo.conditional ) %] [% IF ( ActionsLoo.conditional_if ) %] if [% END %] [% IF ( ActionsLoo.conditional_unless ) %] unless [% END %] @@ -244,6 +253,7 @@ + @@ -252,12 +262,21 @@ - + field(s) + +