Commit 284226a4 authored by Wm. Nick Clemens's avatar Wm. Nick Clemens
Browse files

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/tuxayo's avatarVictor Grousset <victor.grousset@biblibre.com>
Signed-off-by: default avatarChris Cormack <chrisc@catalyst.net.nz>
Signed-off-by: Wm. Nick Clemens's avatarNick Clemens <nick@bywatersolutions.com>
parent c20fbda4
......@@ -644,6 +644,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,
......
......@@ -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};
......
......@@ -117,7 +117,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 %]
......@@ -203,7 +204,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>
......
......@@ -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');
......
......@@ -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' );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment