Bugzilla – Attachment 82902 Details for
Bug 21959
Add ability to apply regular expressions to text fields in the batch item modification tool
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 21959: Batch item modification - ability to apply regular expression on text fields
Bug-21959-Batch-item-modification---ability-to-app.patch (text/plain), 6.29 KB, created by
Alex Arnaud
on 2018-12-06 09:07:02 UTC
(
hide
)
Description:
Bug 21959: Batch item modification - ability to apply regular expression on text fields
Filename:
MIME Type:
Creator:
Alex Arnaud
Created:
2018-12-06 09:07:02 UTC
Size:
6.29 KB
patch
obsolete
>From 645628398e84e93dedf0ab71adf06c50073c0392 Mon Sep 17 00:00:00 2001 >From: Alex Arnaud <alex.arnaud@biblibre.com> >Date: Thu, 6 Dec 2018 09:43:42 +0100 >Subject: [PATCH] Bug 21959: Batch item modification - ability to apply regular > expression on text fields > >Test plan: > - go to Tools > Batch item modification, > - select items to modify, > - for one or some text fields, check the second checkbox (Use regular > expression) and type your regex, > - check the regex has been applied. >--- > .../prog/en/modules/tools/batchMod-edit.tt | 30 +++++++++++++++++++++ > tools/batchMod.pl | 31 +++++++++++++++++++++- > 2 files changed, 60 insertions(+), 1 deletion(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt >index 07a916d..f30bd36 100644 >--- a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt >+++ b/koha-tmpl/intranet-tmpl/prog/en/modules/tools/batchMod-edit.tt >@@ -25,17 +25,37 @@ $(document).ready(function(){ > var row = $(this).attr("id"); > row = row.replace("row","hint"); > var editor = $(this).parent().find("[name='field_value']"); >+ var regex_input = $(this).parent().find("[name='field_regex']"); > if ($(this).is(":checked")) { > $(editor).prop('disabled', true); > $("#"+row).html(_("This subfield will be deleted")); >+ $(regex_input).prop('disabled', true); > } else { > $(editor).prop('disabled', false); > $("#"+row).html(""); >+ $(regex_input).prop('disabled', false); > } > }); > $("#mainformsubmit").on("click",function(){ > return submitBackgroundJob(this.form); > }); >+ $('input[name="field_regex"]').change(function() { >+ var id = $(this).attr('id'); >+ var editor = $(this).parent().find("[name='field_value']"); >+ var regex = $(this).parent().find("[name='regex_fields']"); >+ var disable_input = $(this).parent().find("[name='disable_input']"); >+ if ($(this).is(':checked')) { >+ $(editor).hide(); >+ $(regex).show(); >+ $(this).parent().find('.hint').html(_("Enter a regular expression for this subflied")); >+ $(disable_input).prop('disabled', true); >+ } else { >+ $(editor).show(); >+ $(regex).hide(); >+ $(this).parent().find('.hint').html(_("")); >+ $(disable_input).prop('disabled', false); >+ } >+ }); > }); > //]]> > </script> >@@ -281,12 +301,22 @@ $(document).ready(function(){ > <textarea tabindex="1" id="[%- mv.id | html -%]" name="field_value" class="input_marceditor" size="50" maxlength="255">[%- mv.value | html -%]"</textarea> > [%- END -%] > >+ <span name="regex_fields" style="display: none;"> >+ s/<input type="text" id="[% mv.id | html %]" name="regex_search" placeholder="regex pattern" />/ >+ <input type="text" id="[% mv.id | html %]" name="regex_replace" placeholder="regex replacement" />/ >+ <input type="text" id="[% mv.id | html %]" name="regex_modifiers" placeholder="ig" size="3" /> >+ </span> >+ > [% UNLESS ( ite.mandatory ) %] > <input type="checkbox" id="row[% ite.tag | html %][% ite.subfield | html %][% ite.random | html %]" title="Check to delete subfield [% ite.subfield | html %]" name="disable_input" value="[% ite.subfield | html %]" /> > [% ELSE %] > <span class="required">Required</span> > [% END %] > >+ [% IF (mv.type == 'text' || mv.type == 'textarea' ) %] >+ <input type="checkbox" name="field_regex" id="[% ite.id | html %]" title="Use regular expression"> >+ [% END %] >+ > <input type="hidden" name="tag" value="[% ite.tag | html %]" /> > <input type="hidden" name="subfield" value="[% ite.subfield | html %]" /> > <input type="hidden" name="mandatory" value="[% ite.mandatory | html %]" /> >diff --git a/tools/batchMod.pl b/tools/batchMod.pl >index 59d824b..9e41480 100755 >--- a/tools/batchMod.pl >+++ b/tools/batchMod.pl >@@ -105,6 +105,9 @@ if ($op eq "action") { > my @tags = $input->multi_param('tag'); > my @subfields = $input->multi_param('subfield'); > my @values = $input->multi_param('field_value'); >+ my @searches = $input->multi_param('regex_search'); >+ my @replaces = $input->multi_param('regex_replace'); >+ my @modifiers = $input->multi_param('regex_modifiers'); > my @disabled = $input->multi_param('disable_input'); > # build indicator hash. > my @ind_tag = $input->multi_param('ind_tag'); >@@ -112,8 +115,9 @@ if ($op eq "action") { > > # Is there something to modify ? > # TODO : We shall use this var to warn the user in case no modification was done to the items >- my $values_to_modify = scalar(grep {!/^$/} @values); >+ my $values_to_modify = scalar(grep {!/^$/} @values) || scalar(grep {!/^$/} @searches); > my $values_to_blank = scalar(@disabled); >+ > my $marcitem; > > # Once the job is done >@@ -204,6 +208,31 @@ if ($op eq "action") { > if ($values_to_modify || $values_to_blank) { > my $localmarcitem = Item2Marc($itemdata); > >+ for ( my $i = 0 ; $i < @tags ; $i++ ) { >+ my $search = $searches[$i]; >+ next unless $search; >+ >+ my $tag = $tags[$i]; >+ my $subfield = $subfields[$i]; >+ my $replace = $replaces[$i]; >+ my $mod = $modifiers[$i]; >+ >+ my $value = $localmarcitem->field( $tag )->subfield( $subfield ); >+ ## no critic (StringyEval) >+ eval "\$value =~ s/$search/$replace/$mod"; >+ >+ if ( my $field = $marcitem->field( $tag ) ) { >+ $field->add_subfields( $subfield => $value ); >+ } else { >+ $marcitem->insert_fields_ordered( >+ MARC::Field->new( >+ $tag, '', '', >+ $subfield => $value >+ ) >+ ); >+ } >+ } >+ > my $modified = UpdateMarcWith( $marcitem, $localmarcitem ); > if ( $modified ) { > eval { >-- >2.7.4
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 21959
:
82902
|
83392
|
83470
|
87323
|
87324
|
87325
|
92870
|
92871
|
92872
|
95432
|
95433
|
95434
|
96636
|
96637
|
96638