Bugzilla – Attachment 64808 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 - need an add option in marc modification templates
Bug-13560---need-an-add-option-in-marc-modificatio.patch (text/plain), 15.05 KB, created by
Nick Clemens (kidclamp)
on 2017-07-05 16:20:33 UTC
(
hide
)
Description:
Bug 13560 - need an add option in marc modification templates
Filename:
MIME Type:
Creator:
Nick Clemens (kidclamp)
Created:
2017-07-05 16:20:33 UTC
Size:
15.05 KB
patch
obsolete
>From 1b41f98199f67421eb5418e943dd1a7370c778b4 Mon Sep 17 00:00:00 2001 >From: Nick Clemens <nick@bywatersolutions.com> >Date: Wed, 5 Jul 2017 16:12:13 +0000 >Subject: [PATCH] Bug 13560 - need an add option in 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 >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 >--- > C4/MarcModificationTemplates.pm | 9 +++ > Koha/SimpleMARC.pm | 25 ++++++++ > installer/data/mysql/atomicupdate/bug13560.perl | 6 ++ > .../modules/tools/marc_modification_templates.tt | 4 +- > .../prog/js/marc_modification_templates.js | 6 ++ > t/db_dependent/MarcModificationTemplates.t | 75 ++++++++++++++++++---- > tools/marc_modification_templates.pl | 1 + > 7 files changed, 114 insertions(+), 12 deletions(-) > create mode 100644 installer/data/mysql/atomicupdate/bug13560.perl > >diff --git a/C4/MarcModificationTemplates.pm b/C4/MarcModificationTemplates.pm >index cbd4204..e245784 100644 >--- a/C4/MarcModificationTemplates.pm >+++ b/C4/MarcModificationTemplates.pm >@@ -626,6 +626,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..81b92a7 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,30 @@ sub update_field { > } > } > >+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 ); >+ warn Data::Dumper::Dumper( $field ); >+ $record->append_fields( $field ); >+ } >+ } else { >+ foreach my $value ( @values ) { >+ my $field = MARC::Field->new( $fieldName, $value ); >+ warn Data::Dumper::Dumper( $field ); >+ $record->append_fields( $field ); >+ } >+ } >+} >+ > sub _update_field { > my ( $params ) = @_; > my $record = $params->{record}; >diff --git a/installer/data/mysql/atomicupdate/bug13560.perl b/installer/data/mysql/atomicupdate/bug13560.perl >new file mode 100644 >index 0000000..81e39bc >--- /dev/null >+++ b/installer/data/mysql/atomicupdate/bug13560.perl >@@ -0,0 +1,6 @@ >+$DBversion = 'XXX'; # will be replaced by the RM >+if( CheckVersion( $DBversion ) ) { >+ $dbh->do( "ALTER TABLE marc_modification_template_actions CHANGE action action ENUM('delete_field','add_field','update_field','move_field','copy_field','copy_and_replace_field')" ); >+ SetVersion( $DBversion ); >+ print "Upgrade to $DBversion done (Bug 13560 - need an add option in marc modification templates)\n"; >+} >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 6d32500..36936d5 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 >@@ -132,6 +132,7 @@ > <td>[% ActionsLoo.ordering %]</td> > <td> > [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %] >+ [% IF ( ActionsLoo.action_add_field ) %] Add [% END %] > [% IF ( ActionsLoo.action_update_field ) %] Update [% END %] > [% IF ( ActionsLoo.action_move_field ) %] Move [% END %] > [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %] >@@ -218,7 +219,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</option> >+ <option value="update_field">Update</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/t/db_dependent/MarcModificationTemplates.t b/t/db_dependent/MarcModificationTemplates.t >index 3ea702a..21ddc1c 100644 >--- a/t/db_dependent/MarcModificationTemplates.t >+++ b/t/db_dependent/MarcModificationTemplates.t >@@ -1,6 +1,6 @@ > use Modern::Perl; > >-use Test::More tests => 95; >+use Test::More tests => 114; > > use Koha::SimpleMARC; > >@@ -42,9 +42,17 @@ is( AddModificationTemplateAction( > 'Copy field 606$a to 607$a unless 606$a matches RegEx m^AJAX' > ), 1, "Add third action"); > >+is( AddModificationTemplateAction( >+ $template_id, 'add_field', 0, >+ '650', 'a', 'Additional', '', '', >+ '', '', '', >+ 'unless', '650', 'a', 'exists', '', '', >+ 'Add field 650$aAdditional unless 650$a exists' >+), 1, "Add fourth action"); > # Getter >+ > my @actions = GetModificationTemplateActions( $template_id ); >-is( @actions, 3, "3 actions are insered"); >+is( @actions, 4, "4 actions are insered"); > > for my $action ( @actions ) { > isnt( GetModificationTemplateAction( $action->{mmta_id} ), undef, "action with id $action->{mmta_id} exists" ); >@@ -73,7 +81,7 @@ is( $second_action->{conditional_comparison}, 'equals', "test conditional_compar > > my $third_action = $actions[2]; > is( $third_action->{ordering}, 3, "test ordering for third action" ); >-is( $third_action->{action}, 'copy_field', "test factionor third action" ); >+is( $third_action->{action}, 'copy_field', "test action for third action" ); > is( $third_action->{from_field}, '606', "test from_field for third action" ); > is( $third_action->{from_subfield}, 'a', "test from_subfield for third action" ); > is( $third_action->{to_field}, '607', "test to_field for third action" ); >@@ -84,6 +92,18 @@ is( $third_action->{conditional_subfield}, 'a', "test conditional_subfield for t > is( $third_action->{conditional_comparison}, 'not_equals', "test conditional_comparison for third action" ); > is( $third_action->{conditional_value}, '^AJAX', "test conditional_value for third action" ); > >+my $fourth_action = $actions[3]; >+is( $fourth_action->{ordering}, 4, "test ordering for fourth action" ); >+is( $fourth_action->{action}, 'add_field', "test action for fourth action" ); >+is( $fourth_action->{from_field}, '650', "test from_field for fourth action" ); >+is( $fourth_action->{from_subfield}, 'a', "test from_subfield for fourth action" ); >+is( $fourth_action->{to_field}, '', "test to_field for fourth action" ); >+is( $fourth_action->{to_subfield}, '', "test to_subfield for fourth action" ); >+is( $fourth_action->{conditional}, 'unless', "test conditional for fourth action" ); >+is( $fourth_action->{conditional_field}, '650', "test conditional_field for fourth action" ); >+is( $fourth_action->{conditional_subfield}, 'a', "test conditional_subfield for fourth action" ); >+is( $fourth_action->{conditional_comparison}, 'exists', "test conditional_comparison for fourth action" ); >+is( $fourth_action->{conditional_value}, '', "test conditional_value for fourth action" ); > > # Modifications > is( ModModificationTemplateAction( >@@ -111,26 +131,29 @@ is( $second_action->{conditional_comparison}, 'equals', "test conditional_compar > is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'top' ), '1', 'Move the third action on top' ); > is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'bottom' ), '1', 'Move the first action on bottom' ); > >-is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '3', 'First becomes third' ); >+is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '4', 'First becomes fourth' ); > is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays second' ); > is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '1', 'Third becomes first' ); >+is( GetModificationTemplateAction( $actions[3]->{mmta_id} )->{ordering}, '3', 'Fourth becomes third' ); > >+is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was fourth)' ); > is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was third)' ); >-is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was second)' ); >-is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'down' ), '1', 'Move down the third action (was second)' ); >+is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'down' ), '1', 'Move down the third action (was first)' ); > > is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '1', 'First becomes again first' ); >-is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays again second' ); >-is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '3', 'Third becomes again third' ); >+is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '3', 'Second becomes third' ); >+is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '2', 'Third becomes second' ); >+is( GetModificationTemplateAction( $actions[3]->{mmta_id} )->{ordering}, '4', 'Fourth becomes again fourth' ); > > # Cleaning >-is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 2, "Delete the first action, 2 others are reordered" ); >+is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 3, "Delete the first action, 2 others are reordered" ); > is( GetModificationTemplateAction( $actions[0]->{mmta_id} ), undef, "first action does not exist anymore" ); > > is( DelModificationTemplate( $template_id ), 1, "The template has been deleted" ); > > is( GetModificationTemplateAction( $actions[1]->{mmta_id} ), undef, "second action does not exist anymore" ); > is( GetModificationTemplateAction( $actions[2]->{mmta_id} ), undef, "third action does not exist anymore" ); >+is( GetModificationTemplateAction( $actions[3]->{mmta_id} ), undef, "fourth action does not exist anymore" ); > > is( GetModificationTemplateActions( $template_id ), 0, "There is no action for deleted template" ); > >@@ -215,8 +238,31 @@ is( AddModificationTemplateAction( > 'Update non existent field 999$a with "non existent"' > ), 1, 'Add eighth action: update field non existent 999$a with "non existent."'); > >-my $record = new_record(); >+is( AddModificationTemplateAction( >+ $template_id, 'update_field', 0, >+ '999', 'a', 'existent - updated.', '', '', >+ '', '', '', >+ '', '', '', '', '', '', >+ 'Update existent field 999$a with "existent - updated."' >+), 1, 'Add ninth action: update field non existent 999$a with "existent - updated."'); >+ >+is( AddModificationTemplateAction( >+ $template_id, 'add_field', 0, >+ '999', 'a', 'additional existent.', '', '', >+ '', '', '', >+ '', '', '', '', '', '', >+ 'Add new existent field 999$a with "additional existent"' >+), 1, 'Add tenth action: add additional field existent 999$a with "additional existent."'); > >+is( AddModificationTemplateAction( >+ $template_id, 'add_field', 0, >+ '007', '', 'vxcdq', '', '', >+ '', '', '', >+ '', '', '', '', '', '', >+ 'Add new existent field 999$a with "additional existent"' >+), 1, 'Add eleventh action: add additional field existent 007'); >+ >+my $record = new_record(); > is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" ); > > my $expected_record = expected_record_1(); >@@ -423,7 +469,14 @@ sub expected_record_1 { > ), > MARC::Field->new( > 999, ' ', ' ', >- a => 'non existent.', >+ a => 'existent - updated.', >+ ), >+ MARC::Field->new( >+ 999, ' ', ' ', >+ a => 'additional existent.', >+ ), >+ MARC::Field->new( >+ '007', 'vxcdq', > ), > ); > $record->append_fields(@fields); >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.1.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