Bugzilla – Attachment 71117 Details for
Bug 13560
MARC modification templates - Add an 'Add' option
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 13560: Add an 'Add' option for marc modification templates
Bug-13560-Add-an-Add-option-for-marc-modification-.patch (text/plain), 7.31 KB, created by
Victor Grousset/tuxayo
on 2018-02-01 16:40:18 UTC
(
hide
)
Description:
Bug 13560: Add an 'Add' option for marc modification templates
Filename:
MIME Type:
Creator:
Victor Grousset/tuxayo
Created:
2018-02-01 16:40:18 UTC
Size:
7.31 KB
patch
obsolete
>From 33b529eb75fb4f8bd8da5d96f6bd66c2781aafb6 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Tue, 16 Jan 2018 16:16:40 +0000 >Subject: [PATCH] Bug 13560: Add an 'Add' option for marc modification > templates > >Add/Update would update a field or create new if it existed, but didn't >allow for creating new if the field existed. > >This patchset splits the options to 'Add & Update' so that 'Add' will always >add a field and 'Update' will operate as it always has > >To test: >1 - Have a record with a known existing field (make a copy) >2 - Define a marc modification template that 'Add/update' on that field >3 - Define an 'Add/Update' on a field that doesn't exist >4 - Batch modify the copy of record using the above template >5 - Verify the existing field was updated >6 - Verify the non-existing field was updated >7 - Apply patch and update database >8 - Make another copy >9 - Modify the copy with the same template as above >10 - Should match initial modification >11 - Add a new rule to add a new field >12 - Modify using the updated template >13 - Ensure your new field is created >14 - Test various options in the modification tool >15 - prove t/db_dependent/MarcModificationTemplates.t > >Signed-off-by: Victor Grousset <victor.grousset@biblibre.com> >--- > C4/MarcModificationTemplates.pm | 9 +++++ > Koha/SimpleMARC.pm | 40 ++++++++++++++++++++++ > .../modules/tools/marc_modification_templates.tt | 6 ++-- > .../prog/js/marc_modification_templates.js | 6 ++++ > tools/marc_modification_templates.pl | 1 + > 5 files changed, 60 insertions(+), 2 deletions(-) > >diff --git a/C4/MarcModificationTemplates.pm b/C4/MarcModificationTemplates.pm >index bbfb1c6..852f7b3 100644 >--- a/C4/MarcModificationTemplates.pm >+++ b/C4/MarcModificationTemplates.pm >@@ -639,6 +639,15 @@ sub ModifyRecordWithTemplate { > field_numbers => $field_numbers, > }); > } >+ elsif ( $action eq 'add_field' ) { >+ add_field({ >+ record => $record, >+ field => $from_field, >+ subfield => $from_subfield, >+ values => [ $field_value ], >+ field_numbers => $field_numbers, >+ }); >+ } > elsif ( $action eq 'update_field' ) { > update_field({ > record => $record, >diff --git a/Koha/SimpleMARC.pm b/Koha/SimpleMARC.pm >index aaab6b6..de76cd3 100644 >--- a/Koha/SimpleMARC.pm >+++ b/Koha/SimpleMARC.pm >@@ -17,6 +17,7 @@ our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); > > our @EXPORT = qw( > read_field >+ add_field > update_field > copy_field > copy_and_replace_field >@@ -172,6 +173,45 @@ sub update_field { > } > } > >+=head2 add_field >+ >+ add_field({ >+ record => $record, >+ field => $fieldName, >+ subfield => $subfieldName, >+ values => \@values, >+ field_numbers => $field_numbers, >+ }); >+ >+ Adds a new field/subfield with supplied value(s). >+ This function always add a new field as opposed to 'update_field' which will >+ either update if field exists and add if it does not. >+ >+=cut >+ >+ >+sub add_field { >+ my ( $params ) = @_; >+ my $record = $params->{record}; >+ my $fieldName = $params->{field}; >+ my $subfieldName = $params->{subfield}; >+ my @values = @{ $params->{values} }; >+ my $field_numbers = $params->{field_numbers} // []; >+ >+ if ( ! ( $record && $fieldName ) ) { return; } >+ if ( $fieldName > 10 ) { >+ foreach my $value ( @values ) { >+ my $field = MARC::Field->new( $fieldName, '', '', "$subfieldName" => $value ); >+ $record->append_fields( $field ); >+ } >+ } else { >+ foreach my $value ( @values ) { >+ my $field = MARC::Field->new( $fieldName, $value ); >+ $record->append_fields( $field ); >+ } >+ } >+} >+ > sub _update_field { > my ( $params ) = @_; > my $record = $params->{record}; >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 228c8a5..1c43cea 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 >@@ -116,7 +116,8 @@ > <td>[% ActionsLoo.ordering %]</td> > <td> > [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %] >- [% IF ( ActionsLoo.action_update_field ) %] Update [% END %] >+ [% IF ( ActionsLoo.action_add_field ) %] Add new [% END %] >+ [% IF ( ActionsLoo.action_update_field ) %] Update existing or add new [% END %] > [% IF ( ActionsLoo.action_move_field ) %] Move [% END %] > [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %] > [% IF ( ActionsLoo.action_copy_and_replace_field ) %] Copy and replace [% END %] >@@ -202,7 +203,8 @@ > > <select name="action" id="action" onchange="onActionChange(this);"> > <option value="delete_field">Delete</option> >- <option value="update_field">Add/Update</option> >+ <option value="add_field">Add new</option> >+ <option value="update_field">Update existing or add new</option> > <option value="move_field">Move</option> > <option value="copy_field">Copy</option> > <option value="copy_and_replace_field">Copy and replace</option> >diff --git a/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js b/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js >index 8ca256b..93b2a43 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js >@@ -105,6 +105,12 @@ function onActionChange(selectObj) { > hide('to_field_block'); > break; > >+ case 'add_field': >+ hide('field_number_block'); >+ show('with_value_block'); >+ hide('to_field_block'); >+ break; >+ > case 'update_field': > hide('field_number_block'); > show('with_value_block'); >diff --git a/tools/marc_modification_templates.pl b/tools/marc_modification_templates.pl >index c115429..f88f7d5 100755 >--- a/tools/marc_modification_templates.pl >+++ b/tools/marc_modification_templates.pl >@@ -116,6 +116,7 @@ my @templates = GetModificationTemplates( $template_id ); > my @actions = GetModificationTemplateActions( $template_id ); > foreach my $action ( @actions ) { > $action->{'action_delete_field'} = ( $action->{'action'} eq 'delete_field' ); >+ $action->{'action_add_field'} = ( $action->{'action'} eq 'add_field' ); > $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' ); > $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' ); > $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' ); >-- >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 13560
:
35108
|
64808
|
68540
|
70562
|
70563
|
70564
|
70613
|
71115
|
71116
|
71117
|
75584
|
75585
|
75586