View | Details | Raw Unified | Return to bug 13560
Collapse All | Expand All

(-)a/C4/MarcModificationTemplates.pm (+9 lines)
Lines 626-631 sub ModifyRecordWithTemplate { Link Here
626
                    field_numbers => $field_numbers,
626
                    field_numbers => $field_numbers,
627
                });
627
                });
628
            }
628
            }
629
            elsif ( $action eq 'add_field' ) {
630
                add_field({
631
                    record => $record,
632
                    field => $from_field,
633
                    subfield => $from_subfield,
634
                    values => [ $field_value ],
635
                    field_numbers => $field_numbers,
636
                });
637
            }
629
            elsif ( $action eq 'update_field' ) {
638
            elsif ( $action eq 'update_field' ) {
630
                update_field({
639
                update_field({
631
                    record => $record,
640
                    record => $record,
(-)a/Koha/SimpleMARC.pm (+23 lines)
Lines 17-22 our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); Link Here
17
17
18
our @EXPORT = qw(
18
our @EXPORT = qw(
19
  read_field
19
  read_field
20
  add_field
20
  update_field
21
  update_field
21
  copy_field
22
  copy_field
22
  copy_and_replace_field
23
  copy_and_replace_field
Lines 172-177 sub update_field { Link Here
172
    }
173
    }
173
}
174
}
174
175
176
sub add_field {
177
    my ( $params ) = @_;
178
    my $record = $params->{record};
179
    my $fieldName = $params->{field};
180
    my $subfieldName = $params->{subfield};
181
    my @values = @{ $params->{values} };
182
    my $field_numbers = $params->{field_numbers} // [];
183
184
    if ( ! ( $record && $fieldName ) ) { return; }
185
    if ( $fieldName > 10 ) {
186
        foreach my $value ( @values ) {
187
            my $field = MARC::Field->new( $fieldName, '', '', "$subfieldName" => $value );
188
            $record->append_fields( $field );
189
        }
190
    } else {
191
        foreach my $value ( @values ) {
192
            my $field = MARC::Field->new( $fieldName, $value );
193
            $record->append_fields( $field );
194
        }
195
    }
196
}
197
175
sub _update_field {
198
sub _update_field {
176
    my ( $params ) = @_;
199
    my ( $params ) = @_;
177
    my $record = $params->{record};
200
    my $record = $params->{record};
(-)a/installer/data/mysql/atomicupdate/bug13560.perl (+6 lines)
Line 0 Link Here
1
$DBversion = 'XXX';  # will be replaced by the RM
2
if( CheckVersion( $DBversion ) ) {
3
    $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')" );
4
    SetVersion( $DBversion );
5
    print "Upgrade to $DBversion done (Bug 13560 - need an add option in marc modification templates)\n";
6
}
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt (-2 / +4 lines)
Lines 132-138 Link Here
132
                                        <td>[% ActionsLoo.ordering %]</td>
132
                                        <td>[% ActionsLoo.ordering %]</td>
133
                                        <td>
133
                                        <td>
134
                                            [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
134
                                            [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
135
                                            [% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
135
                                            [% IF ( ActionsLoo.action_add_field ) %] Add new [% END %]
136
                                            [% IF ( ActionsLoo.action_update_field ) %] Update existing or add new [% END %]
136
                                            [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
137
                                            [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
137
                                            [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
138
                                            [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
138
                                            [% IF ( ActionsLoo.action_copy_and_replace_field ) %] Copy and replace [% END %]
139
                                            [% IF ( ActionsLoo.action_copy_and_replace_field ) %] Copy and replace [% END %]
Lines 218-224 Link Here
218
219
219
                            <select name="action" id="action" onchange="onActionChange(this);">
220
                            <select name="action" id="action" onchange="onActionChange(this);">
220
                                <option value="delete_field">Delete</option>
221
                                <option value="delete_field">Delete</option>
221
                                <option value="update_field">Add/Update</option>
222
                                <option value="add_field">Add new</option>
223
                                <option value="update_field">Update existing or add new</option>
222
                                <option value="move_field">Move</option>
224
                                <option value="move_field">Move</option>
223
                                <option value="copy_field">Copy</option>
225
                                <option value="copy_field">Copy</option>
224
                                <option value="copy_and_replace_field">Copy and replace</option>
226
                                <option value="copy_and_replace_field">Copy and replace</option>
(-)a/koha-tmpl/intranet-tmpl/prog/js/marc_modification_templates.js (+6 lines)
Lines 105-110 function onActionChange(selectObj) { Link Here
105
            hide('to_field_block');
105
            hide('to_field_block');
106
            break;
106
            break;
107
107
108
        case 'add_field':
109
            hide('field_number_block');
110
            show('with_value_block');
111
            hide('to_field_block');
112
            break;
113
108
        case 'update_field':
114
        case 'update_field':
109
            hide('field_number_block');
115
            hide('field_number_block');
110
            show('with_value_block');
116
            show('with_value_block');
(-)a/t/db_dependent/MarcModificationTemplates.t (-11 / +64 lines)
Lines 1-6 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 95;
3
use Test::More tests => 114;
4
4
5
use Koha::SimpleMARC;
5
use Koha::SimpleMARC;
6
6
Lines 42-50 is( AddModificationTemplateAction( Link Here
42
    'Copy field 606$a to 607$a unless 606$a matches RegEx m^AJAX'
42
    'Copy field 606$a to 607$a unless 606$a matches RegEx m^AJAX'
43
), 1, "Add third action");
43
), 1, "Add third action");
44
44
45
is( AddModificationTemplateAction(
46
    $template_id, 'add_field', 0,
47
    '650', 'a', 'Additional', '', '',
48
    '', '', '',
49
    'unless', '650', 'a', 'exists', '', '',
50
    'Add field 650$aAdditional unless 650$a exists'
51
), 1, "Add fourth action");
45
# Getter
52
# Getter
53
46
my @actions = GetModificationTemplateActions( $template_id );
54
my @actions = GetModificationTemplateActions( $template_id );
47
is( @actions, 3, "3 actions are insered");
55
is( @actions, 4, "4 actions are insered");
48
56
49
for my $action ( @actions ) {
57
for my $action ( @actions ) {
50
    isnt( GetModificationTemplateAction( $action->{mmta_id} ), undef, "action with id $action->{mmta_id} exists" );
58
    isnt( GetModificationTemplateAction( $action->{mmta_id} ), undef, "action with id $action->{mmta_id} exists" );
Lines 73-79 is( $second_action->{conditional_comparison}, 'equals', "test conditional_compar Link Here
73
81
74
my $third_action = $actions[2];
82
my $third_action = $actions[2];
75
is( $third_action->{ordering}, 3, "test ordering for third action" );
83
is( $third_action->{ordering}, 3, "test ordering for third action" );
76
is( $third_action->{action}, 'copy_field', "test  factionor third action" );
84
is( $third_action->{action}, 'copy_field', "test action for third action" );
77
is( $third_action->{from_field}, '606', "test from_field for third action" );
85
is( $third_action->{from_field}, '606', "test from_field for third action" );
78
is( $third_action->{from_subfield}, 'a', "test from_subfield for third action" );
86
is( $third_action->{from_subfield}, 'a', "test from_subfield for third action" );
79
is( $third_action->{to_field}, '607', "test to_field for third action" );
87
is( $third_action->{to_field}, '607', "test to_field for third action" );
Lines 84-89 is( $third_action->{conditional_subfield}, 'a', "test conditional_subfield for t Link Here
84
is( $third_action->{conditional_comparison}, 'not_equals', "test conditional_comparison for third action" );
92
is( $third_action->{conditional_comparison}, 'not_equals', "test conditional_comparison for third action" );
85
is( $third_action->{conditional_value}, '^AJAX', "test conditional_value for third action" );
93
is( $third_action->{conditional_value}, '^AJAX', "test conditional_value for third action" );
86
94
95
my $fourth_action = $actions[3];
96
is( $fourth_action->{ordering}, 4, "test ordering for fourth action" );
97
is( $fourth_action->{action}, 'add_field', "test action for fourth action" );
98
is( $fourth_action->{from_field}, '650', "test from_field for fourth action" );
99
is( $fourth_action->{from_subfield}, 'a', "test from_subfield for fourth action" );
100
is( $fourth_action->{to_field}, '', "test to_field for fourth action" );
101
is( $fourth_action->{to_subfield}, '', "test to_subfield for fourth action" );
102
is( $fourth_action->{conditional}, 'unless', "test conditional for fourth action" );
103
is( $fourth_action->{conditional_field}, '650', "test conditional_field for fourth action" );
104
is( $fourth_action->{conditional_subfield}, 'a', "test conditional_subfield for fourth action" );
105
is( $fourth_action->{conditional_comparison}, 'exists', "test conditional_comparison for fourth action" );
106
is( $fourth_action->{conditional_value}, '', "test conditional_value for fourth action" );
87
107
88
# Modifications
108
# Modifications
89
is( ModModificationTemplateAction(
109
is( ModModificationTemplateAction(
Lines 111-136 is( $second_action->{conditional_comparison}, 'equals', "test conditional_compar Link Here
111
is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'top' ), '1', 'Move the third action on top' );
131
is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'top' ), '1', 'Move the third action on top' );
112
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'bottom' ), '1', 'Move the first action on bottom' );
132
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'bottom' ), '1', 'Move the first action on bottom' );
113
133
114
is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '3', 'First becomes third' );
134
is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '4', 'First becomes fourth' );
115
is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays second' );
135
is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays second' );
116
is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '1', 'Third becomes first' );
136
is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '1', 'Third becomes first' );
137
is( GetModificationTemplateAction( $actions[3]->{mmta_id} )->{ordering}, '3', 'Fourth becomes third' );
117
138
139
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was fourth)' );
118
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was third)' );
140
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was third)' );
119
is( MoveModificationTemplateAction( $actions[0]->{mmta_id}, 'up' ), '1', 'Move up the first action (was second)' );
141
is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'down' ), '1', 'Move down the third action (was first)' );
120
is( MoveModificationTemplateAction( $actions[2]->{mmta_id}, 'down' ), '1', 'Move down the third action (was second)' );
121
142
122
is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '1', 'First becomes again first' );
143
is( GetModificationTemplateAction( $actions[0]->{mmta_id} )->{ordering}, '1', 'First becomes again first' );
123
is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '2', 'Second stays again second' );
144
is( GetModificationTemplateAction( $actions[1]->{mmta_id} )->{ordering}, '3', 'Second becomes third' );
124
is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '3', 'Third becomes again third' );
145
is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '2', 'Third becomes second' );
146
is( GetModificationTemplateAction( $actions[3]->{mmta_id} )->{ordering}, '4', 'Fourth becomes again fourth' );
125
147
126
# Cleaning
148
# Cleaning
127
is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 2, "Delete the first action, 2 others are reordered" );
149
is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 3, "Delete the first action, 2 others are reordered" );
128
is( GetModificationTemplateAction( $actions[0]->{mmta_id} ), undef, "first action does not exist anymore" );
150
is( GetModificationTemplateAction( $actions[0]->{mmta_id} ), undef, "first action does not exist anymore" );
129
151
130
is( DelModificationTemplate( $template_id ), 1, "The template has been deleted" );
152
is( DelModificationTemplate( $template_id ), 1, "The template has been deleted" );
131
153
132
is( GetModificationTemplateAction( $actions[1]->{mmta_id} ), undef, "second action does not exist anymore" );
154
is( GetModificationTemplateAction( $actions[1]->{mmta_id} ), undef, "second action does not exist anymore" );
133
is( GetModificationTemplateAction( $actions[2]->{mmta_id} ), undef, "third action does not exist anymore" );
155
is( GetModificationTemplateAction( $actions[2]->{mmta_id} ), undef, "third action does not exist anymore" );
156
is( GetModificationTemplateAction( $actions[3]->{mmta_id} ), undef, "fourth action does not exist anymore" );
134
157
135
is( GetModificationTemplateActions( $template_id ), 0, "There is no action for deleted template" );
158
is( GetModificationTemplateActions( $template_id ), 0, "There is no action for deleted template" );
136
159
Lines 215-222 is( AddModificationTemplateAction( Link Here
215
    'Update non existent field 999$a with "non existent"'
238
    'Update non existent field 999$a with "non existent"'
216
), 1, 'Add eighth action: update field non existent 999$a with "non existent."');
239
), 1, 'Add eighth action: update field non existent 999$a with "non existent."');
217
240
218
my $record = new_record();
241
is( AddModificationTemplateAction(
242
    $template_id, 'update_field', 0,
243
    '999', 'a', 'existent - updated.', '', '',
244
    '', '', '',
245
    '', '', '', '', '', '',
246
    'Update existent field 999$a with "existent - updated."'
247
), 1, 'Add ninth action: update field non existent 999$a with "existent - updated."');
248
249
is( AddModificationTemplateAction(
250
    $template_id, 'add_field', 0,
251
    '999', 'a', 'additional existent.', '', '',
252
    '', '', '',
253
    '', '', '', '', '', '',
254
    'Add new existent field 999$a with "additional existent"'
255
), 1, 'Add tenth action: add additional field existent 999$a with "additional existent."');
219
256
257
is( AddModificationTemplateAction(
258
    $template_id, 'add_field', 0,
259
    '007', '', 'vxcdq', '', '',
260
    '', '', '',
261
    '', '', '', '', '', '',
262
    'Add new existent field 999$a with "additional existent"'
263
), 1, 'Add eleventh action: add additional field existent 007');
264
265
my $record = new_record();
220
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
266
is( ModifyRecordWithTemplate( $template_id, $record ), undef, "The ModifyRecordWithTemplate returns undef" );
221
267
222
my $expected_record = expected_record_1();
268
my $expected_record = expected_record_1();
Lines 423-429 sub expected_record_1 { Link Here
423
        ),
469
        ),
424
        MARC::Field->new(
470
        MARC::Field->new(
425
            999, ' ', ' ',
471
            999, ' ', ' ',
426
            a => 'non existent.',
472
            a => 'existent - updated.',
473
        ),
474
        MARC::Field->new(
475
            999, ' ', ' ',
476
            a => 'additional existent.',
477
        ),
478
        MARC::Field->new(
479
           '007', 'vxcdq',
427
        ),
480
        ),
428
    );
481
    );
429
    $record->append_fields(@fields);
482
    $record->append_fields(@fields);
(-)a/tools/marc_modification_templates.pl (-1 / +1 lines)
Lines 116-121 my @templates = GetModificationTemplates( $template_id ); Link Here
116
my @actions = GetModificationTemplateActions( $template_id );
116
my @actions = GetModificationTemplateActions( $template_id );
117
foreach my $action ( @actions ) {
117
foreach my $action ( @actions ) {
118
  $action->{'action_delete_field'} = ( $action->{'action'} eq 'delete_field' );
118
  $action->{'action_delete_field'} = ( $action->{'action'} eq 'delete_field' );
119
  $action->{'action_add_field'} = ( $action->{'action'} eq 'add_field' );
119
  $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' );
120
  $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' );
120
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
121
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
121
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
122
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
122
- 

Return to bug 13560