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

(-)a/C4/MarcModificationTemplates.pm (-2 / +2 lines)
Lines 587-594 sub ModifyRecordWithTemplate { Link Here
587
                when ( /^move_field$/ ) {
587
                when ( /^move_field$/ ) {
588
                    move_field( @params );
588
                    move_field( @params );
589
                }
589
                }
590
                when ( /^delete_field$/ ) {
590
                when ( /^delete$/ ) {
591
                    delete_field( @params );
591
                    Koha::SimpleMarc::delete( @params );
592
                }
592
                }
593
            }
593
            }
594
        }
594
        }
(-)a/Koha/SimpleMARC.pm (-29 / +73 lines)
Lines 16-26 our %EXPORT_TAGS = ( 'all' => [ qw( Link Here
16
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
16
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
17
17
18
our @EXPORT = qw(
18
our @EXPORT = qw(
19
  read_field
19
  read
20
  update_field
20
  update_field
21
  copy_field
21
  copy_field
22
  move_field
22
  move_field
23
  delete_field
23
  delete
24
  field_exists
24
  field_exists
25
  field_equals
25
  field_equals
26
);
26
);
Lines 77-83 sub copy_field { Link Here
77
77
78
  if ( ! ( $record && $fromFieldName && $toFieldName ) ) { return; }
78
  if ( ! ( $record && $fromFieldName && $toFieldName ) ) { return; }
79
79
80
  my @values = read_field( $record, $fromFieldName, $fromSubfieldName );
80
  my @values = Koha::SimpleMARC::read( $record, $fromFieldName, $fromSubfieldName );
81
  @values = ( $values[$n-1] ) if ( $n );
81
  @values = ( $values[$n-1] ) if ( $n );
82
82
83
  if ( $regex and $regex->{search} ) {
83
  if ( $regex and $regex->{search} ) {
Lines 180-203 sub update_field { Link Here
180
180
181
=cut
181
=cut
182
182
183
sub read_field {
183
sub read {
184
  my ( $record, $fieldName, $subfieldName, $n ) = @_;
184
    my ( $record, $fieldName, $subfieldName, $n ) = @_;
185
185
186
  my @fields = $record->field( $fieldName );
186
    if ( not $subfieldName or $subfieldName eq '' ) {
187
        _read_field( $record, $fieldName, $n );
188
    } else {
189
        _read_subfield( $record, $fieldName, $subfieldName, $n );
190
    }
187
191
188
  return map { $_->data() } @fields unless $subfieldName;
192
}
189
193
190
  my @subfields;
194
sub _read_field {
191
  foreach my $field ( @fields ) {
195
    my ( $record, $fieldName, $n ) = @_;
192
    my @sf = $field->subfield( $subfieldName );
196
193
    push( @subfields, @sf );
197
    my @fields = $record->field( $fieldName );
194
  }
198
199
    return unless @fields;
200
201
    return map { $_->data() } @fields
202
        if $fieldName < 10;
203
204
    my @values;
205
    foreach my $field ( @fields ) {
206
        my @sf = $field->subfields;
207
        push( @values, @sf );
208
    }
209
210
    return $n
211
        ? $values[$n-1] # I don't think it is what we want here
212
        : @values;
195
213
196
  if ( $n ) {
214
}
197
    return $subfields[$n-1];
215
198
  } else {
216
sub _read_subfield {
199
    return @subfields;
217
    my ( $record, $fieldName, $subfieldName, $n ) = @_;
200
  }
218
219
    my @fields = $record->field( $fieldName );
220
221
    return unless @fields;
222
223
    my @values;
224
    foreach my $field ( @fields ) {
225
        my @sf = $field->subfield( $subfieldName );
226
        push( @values, @sf );
227
    }
228
229
    return $n
230
        ? $values[$n-1]
231
        : @values;
201
}
232
}
202
233
203
=head2 field_exists
234
=head2 field_exists
Lines 243-249 sub field_equals { Link Here
243
274
244
  if ( ! $record ) { return; }
275
  if ( ! $record ) { return; }
245
276
246
  my @field_values = read_field( $record, $fieldName, $subfieldName, $n );
277
  my @field_values = Koha::SimpleMARC::read( $record, $fieldName, $subfieldName, $n );
247
  my $field_value = $field_values[$n-1];
278
  my $field_value = $field_values[$n-1];
248
279
249
  if ( $regex ) {
280
  if ( $regex ) {
Lines 269-277 sub field_equals { Link Here
269
sub move_field {
300
sub move_field {
270
  my ( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n ) = @_;
301
  my ( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n ) = @_;
271
  copy_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n , 'dont_erase' );
302
  copy_field( $record, $fromFieldName, $fromSubfieldName, $toFieldName, $toSubfieldName, $regex, $n , 'dont_erase' );
272
  delete_field( $record, $fromFieldName, $fromSubfieldName, $n );
303
  Koha::SimpleMARC::delete( $record, $fromFieldName, $fromSubfieldName, $n );
273
}
304
}
274
305
306
sub delete {
307
    my ( $record, $fieldName, $subfieldName, $n ) = @_;
308
    if ( not $subfieldName or $subfieldName eq '' ) {
309
        _delete_field( $record, $fieldName, $n );
310
    } else {
311
        _delete_subfield( $record, $fieldName, $subfieldName, $n );
312
    }
313
}
275
=head2 delete_field
314
=head2 delete_field
276
315
277
  delete_field( $record, $fieldName[, $subfieldName [, $n ] ] );
316
  delete_field( $record, $fieldName[, $subfieldName [, $n ] ] );
Lines 283-304 sub move_field { Link Here
283
322
284
=cut
323
=cut
285
324
286
sub delete_field {
325
sub _delete_field {
287
  my ( $record, $fieldName, $subfieldName, $n ) = @_;
326
    my ( $record, $fieldName, $n ) = @_;
288
327
289
  my @fields = $record->field( $fieldName );
328
    my @fields = $record->field( $fieldName );
290
329
291
  @fields = ( $fields[$n-1] ) if ( $n );
330
    @fields = ( $fields[$n-1] ) if ( $n );
292
293
  if ( @fields && !$subfieldName ) {
294
    foreach my $field ( @fields ) {
331
    foreach my $field ( @fields ) {
295
      $record->delete_field( $field );
332
        $record->delete_field( $field );
296
    }
333
    }
297
  } elsif ( @fields && $subfieldName ) {
334
}
335
336
sub _delete_subfield {
337
    my ( $record, $fieldName, $subfieldName, $n ) = @_;
338
339
    my @fields = $record->field( $fieldName );
340
341
    @fields = ( $fields[$n-1] ) if ( $n );
342
298
    foreach my $field ( @fields ) {
343
    foreach my $field ( @fields ) {
299
      $field->delete_subfield( code => $subfieldName );
344
        $field->delete_subfield( code => $subfieldName );
300
    }
345
    }
301
  }
302
}
346
}
303
347
304
1;
348
1;
(-)a/installer/data/mysql/updatedatabase.pl (+12 lines)
Lines 7778-7783 if(CheckVersion($DBversion)) { Link Here
7778
    SetVersion($DBversion);
7778
    SetVersion($DBversion);
7779
}
7779
}
7780
7780
7781
7782
7783
$DBversion = "3.15.00.XXX";
7784
if(CheckVersion($DBversion)) {
7785
    $dbh->do(q|
7786
        ALTER TABLE marc_modification_template_actions
7787
        CHANGE action action VARCHAR(16) NOT NULL;
7788
    |);
7789
    print "Upgrade to $DBversion done (Bug 11275: alter deleteditems.materials from varchar(10) to text)\n";
7790
    SetVersion($DBversion);
7791
}
7792
7781
=head1 FUNCTIONS
7793
=head1 FUNCTIONS
7782
7794
7783
=head2 TableExists($table)
7795
=head2 TableExists($table)
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt (-4 / +4 lines)
Lines 24-30 function onActionChange(selectObj) { Link Here
24
    var action = selectObj.options[idx].value;
24
    var action = selectObj.options[idx].value;
25
25
26
    switch( action ) {
26
    switch( action ) {
27
        case 'delete_field':
27
        case 'delete':
28
            show('field_number_block');
28
            show('field_number_block');
29
            hide('with_value_block');
29
            hide('with_value_block');
30
            hide('to_field_block');
30
            hide('to_field_block');
Lines 198-204 function editAction( mmta_id, ordering, action, field_number, from_field, from_s Link Here
198
function cancelEditAction() {
198
function cancelEditAction() {
199
    document.getElementById('mmta_id').value = '';
199
    document.getElementById('mmta_id').value = '';
200
200
201
    setSelectByValue( 'action', 'delete_field' );
201
    setSelectByValue( 'action', 'delete' );
202
    document.getElementById('action').onchange();
202
    document.getElementById('action').onchange();
203
203
204
    document.getElementById('from_field').value = '';
204
    document.getElementById('from_field').value = '';
Lines 323-329 function setSelectByValue( selectId, value ) { Link Here
323
323
324
                                <td>[% ActionsLoo.ordering %]</td>
324
                                <td>[% ActionsLoo.ordering %]</td>
325
                                <td>
325
                                <td>
326
                                    [% IF ( ActionsLoo.action_delete_field ) %] Delete [% END %]
326
                                    [% IF ( ActionsLoo.action_delete ) %] Delete [% END %]
327
                                    [% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
327
                                    [% IF ( ActionsLoo.action_update_field ) %] Update [% END %]
328
                                    [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
328
                                    [% IF ( ActionsLoo.action_move_field ) %] Move [% END %]
329
                                    [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
329
                                    [% IF ( ActionsLoo.action_copy_field ) %] Copy [% END %]
Lines 402-408 function setSelectByValue( selectId, value ) { Link Here
402
                        <legend id="modaction_legend">Add a new action</legend>
402
                        <legend id="modaction_legend">Add a new action</legend>
403
403
404
                        <select name="action" id="action" onchange="onActionChange(this);">
404
                        <select name="action" id="action" onchange="onActionChange(this);">
405
                            <option value="delete_field">Delete</option>
405
                            <option value="delete">Delete</option>
406
                            <option value="update_field">Add/Update</option>
406
                            <option value="update_field">Add/Update</option>
407
                            <option value="move_field">Move</option>
407
                            <option value="move_field">Move</option>
408
                            <option value="copy_field">Copy</option>
408
                            <option value="copy_field">Copy</option>
(-)a/t/SimpleMARC.t (-41 / +82 lines)
Lines 1-6 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 37;
3
use Test::More tests => 41;
4
4
5
use_ok("MARC::Field");
5
use_ok("MARC::Field");
6
use_ok("MARC::Record");
6
use_ok("MARC::Record");
Lines 53-111 $record->append_fields( Link Here
53
53
54
is( field_exists( $record, '650', 'a'), 'Computer programming.', '650$a exists, field_exists returns the first one' );
54
is( field_exists( $record, '650', 'a'), 'Computer programming.', '650$a exists, field_exists returns the first one' );
55
55
56
# read_field
56
# Koha::SimpleMARC::read
57
my @fields_650a = read_field( $record, '650', 'a');
57
my @fields_650a = Koha::SimpleMARC::read( $record, '650', 'a');
58
is( $fields_650a[0], 'Computer programming.', 'first 650$a' );
58
is( $fields_650a[0], 'Computer programming.', 'first 650$a' );
59
is( $fields_650a[1], 'Computer algorithms.', 'second 650$a' );
59
is( $fields_650a[1], 'Computer algorithms.', 'second 650$a' );
60
is( read_field( $record, '650', 'a', 1 ), 'Computer programming.', 'first 650$a bis' );
60
is( Koha::SimpleMARC::read( $record, '650', 'a', 1 ), 'Computer programming.', 'first 650$a bis' );
61
is( read_field( $record, '650', 'a', 2 ), 'Computer algorithms.', 'second 650$a bis' );
61
is( Koha::SimpleMARC::read( $record, '650', 'a', 2 ), 'Computer algorithms.', 'second 650$a bis' );
62
is( read_field( $record, '650', 'a', 3 ), undef, 'There is no 3 650$a' );
62
is( Koha::SimpleMARC::read( $record, '650', 'a', 3 ), undef, 'There is no 3 650$a' );
63
63
64
# copy_field
64
# copy_field
65
copy_field( $record, '245', 'a', '246', 'a' );
65
copy_field( $record, '245', 'a', '246', 'a' );
66
is_deeply( read_field( $record, '245', 'a' ), 'The art of computer programming', 'After copy 245$a still exists' );
66
is_deeply( Koha::SimpleMARC::read( $record, '245', 'a' ), 'The art of computer programming', 'After copy 245$a still exists' );
67
is_deeply( read_field( $record, '246', 'a' ), 'The art of computer programming', '246$a is a new field' );
67
is_deeply( Koha::SimpleMARC::read( $record, '246', 'a' ), 'The art of computer programming', '246$a is a new field' );
68
delete_field( $record, '246' );
68
Koha::SimpleMARC::delete( $record, '246' );
69
is( field_exists( $record, '246', 'a', '246$a does not exist anymore' ), undef );
69
is( field_exists( $record, '246', 'a', '246$a does not exist anymore' ), undef );
70
70
71
copy_field( $record, '650', 'a', '651', 'a' );
71
copy_field( $record, '650', 'a', '651', 'a' );
72
my @fields_651a = read_field( $record, '651', 'a' );
72
my @fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' );
73
is_deeply( \@fields_651a, ['Computer programming.', 'Computer algorithms.'], 'Copy multivalued field' );
73
is_deeply( \@fields_651a, ['Computer programming.', 'Computer algorithms.'], 'Copy multivalued field' );
74
delete_field( $record, '651' );
74
Koha::SimpleMARC::delete( $record, '651' );
75
75
76
copy_field( $record, '650', 'a', '651', 'a', undef, 1 );
76
copy_field( $record, '650', 'a', '651', 'a', undef, 1 );
77
@fields_651a = read_field( $record, '651', 'a' );
77
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' );
78
is_deeply( read_field( $record, '651', 'a' ), 'Computer programming.', 'Copy first field 650$a' );
78
is_deeply( Koha::SimpleMARC::read( $record, '651', 'a' ), 'Computer programming.', 'Copy first field 650$a' );
79
delete_field( $record, '651' );
79
Koha::SimpleMARC::delete( $record, '651' );
80
80
81
copy_field( $record, '650', 'a', '651', 'a', undef, 2 );
81
copy_field( $record, '650', 'a', '651', 'a', undef, 2 );
82
@fields_651a = read_field( $record, '651', 'a' );
82
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' );
83
is_deeply( read_field( $record, '651', 'a' ), 'Computer algorithms.', 'Copy second field 650$a' );
83
is_deeply( Koha::SimpleMARC::read( $record, '651', 'a' ), 'Computer algorithms.', 'Copy second field 650$a' );
84
delete_field( $record, '651' );
84
Koha::SimpleMARC::delete( $record, '651' );
85
85
86
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } );
86
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } );
87
@fields_651a = read_field( $record, '651', 'a' );
87
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' );
88
is_deeply( \@fields_651a, ['The art of programming.', 'The art of algorithms.'], 'Copy field using regex' );
88
is_deeply( \@fields_651a, ['The art of programming.', 'The art of algorithms.'], 'Copy field using regex' );
89
89
90
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' } );
90
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' } );
91
@fields_651a = read_field( $record, '651', 'a' );
91
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' );
92
is_deeply( \@fields_651a, ['The mistake of programming.', 'The mistake of algorithms.'], 'Copy fields using regex on existing fields' );
92
is_deeply( \@fields_651a, ['The mistake of programming.', 'The mistake of algorithms.'], 'Copy fields using regex on existing fields' );
93
delete_field( $record, '651' );
93
Koha::SimpleMARC::delete( $record, '651' );
94
94
95
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } );
95
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } );
96
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' }, 1, "dont_erase" );
96
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' }, 1, "dont_erase" );
97
@fields_651a = read_field( $record, '651', 'a' );
97
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' );
98
is_deeply( \@fields_651a, [
98
is_deeply( \@fields_651a, [
99
    'The art of programming.',
99
    'The art of programming.',
100
    'The mistake of programming.',
100
    'The mistake of programming.',
101
    'The art of algorithms.',
101
    'The art of algorithms.',
102
    'The mistake of programming.'
102
    'The mistake of programming.'
103
], 'Copy first field using regex on existing fields without erase existing values' );
103
], 'Copy first field using regex on existing fields without erase existing values' );
104
delete_field( $record, '651' );
104
Koha::SimpleMARC::delete( $record, '651' );
105
105
106
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } );
106
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The art of' } );
107
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' }, undef , "dont_erase" );
107
copy_field( $record, '650', 'a', '651', 'a', { search => 'Computer', replace => 'The mistake of' }, undef , "dont_erase" );
108
@fields_651a = read_field( $record, '651', 'a' );
108
@fields_651a = Koha::SimpleMARC::read( $record, '651', 'a' );
109
is_deeply( \@fields_651a, [
109
is_deeply( \@fields_651a, [
110
    'The art of programming.',
110
    'The art of programming.',
111
    'The mistake of programming.',
111
    'The mistake of programming.',
Lines 114-146 is_deeply( \@fields_651a, [ Link Here
114
    'The mistake of programming.',
114
    'The mistake of programming.',
115
    'The mistake of algorithms.'
115
    'The mistake of algorithms.'
116
], 'Copy fields using regex on existing fields without erase existing values' );
116
], 'Copy fields using regex on existing fields without erase existing values' );
117
delete_field( $record, '651' );
117
Koha::SimpleMARC::delete( $record, '651' );
118
118
119
# Copy with regex modifiers
119
# Copy with regex modifiers
120
copy_field( $record, '650', 'a', '652', 'a', { search => 'o', replace => 'foo' } );
120
copy_field( $record, '650', 'a', '652', 'a', { search => 'o', replace => 'foo' } );
121
my @fields_652a = read_field( $record, '652', 'a' );
121
my @fields_652a = Koha::SimpleMARC::read( $record, '652', 'a' );
122
is_deeply( \@fields_652a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' );
122
is_deeply( \@fields_652a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' );
123
123
124
copy_field( $record, '650', 'a', '653', 'a', { search => 'o', replace => 'foo', modifiers => 'g' } );
124
copy_field( $record, '650', 'a', '653', 'a', { search => 'o', replace => 'foo', modifiers => 'g' } );
125
my @fields_653a = read_field( $record, '653', 'a' );
125
my @fields_653a = Koha::SimpleMARC::read( $record, '653', 'a' );
126
is_deeply( \@fields_653a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' );
126
is_deeply( \@fields_653a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' );
127
127
128
copy_field( $record, '650', 'a', '654', 'a', { search => 'O', replace => 'foo', modifiers => 'i' } );
128
copy_field( $record, '650', 'a', '654', 'a', { search => 'O', replace => 'foo', modifiers => 'i' } );
129
my @fields_654a = read_field( $record, '654', 'a' );
129
my @fields_654a = Koha::SimpleMARC::read( $record, '654', 'a' );
130
is_deeply( \@fields_654a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' );
130
is_deeply( \@fields_654a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' );
131
131
132
copy_field( $record, '650', 'a', '655', 'a', { search => 'O', replace => 'foo', modifiers => 'gi' } );
132
copy_field( $record, '650', 'a', '655', 'a', { search => 'O', replace => 'foo', modifiers => 'gi' } );
133
my @fields_655a = read_field( $record, '655', 'a' );
133
my @fields_655a = Koha::SimpleMARC::read( $record, '655', 'a' );
134
is_deeply( \@fields_655a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' );
134
is_deeply( \@fields_655a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' );
135
135
136
# update_field
136
# update_field
137
update_field( $record, '952', 'p', undef, '3010023918' );
137
update_field( $record, '952', 'p', undef, '3010023918' );
138
is_deeply( read_field( $record, '952', 'p' ), '3010023918', 'update existing subfield 952$p' );
138
is_deeply( Koha::SimpleMARC::read( $record, '952', 'p' ), '3010023918', 'update existing subfield 952$p' );
139
delete_field( $record, '952' );
139
Koha::SimpleMARC::delete( $record, '952' );
140
update_field( $record, '952', 'p', undef, '3010023918' );
140
update_field( $record, '952', 'p', undef, '3010023918' );
141
update_field( $record, '952', 'y', undef, 'BK' );
141
update_field( $record, '952', 'y', undef, 'BK' );
142
is_deeply( read_field( $record, '952', 'p' ), '3010023918', 'create subfield 952$p' );
142
is_deeply( Koha::SimpleMARC::read( $record, '952', 'p' ), '3010023918', 'create subfield 952$p' );
143
is_deeply( read_field( $record, '952', 'y' ), 'BK', 'create subfield 952$k on existing 952 field' );
143
is_deeply( Koha::SimpleMARC::read( $record, '952', 'y' ), 'BK', 'create subfield 952$k on existing 952 field' );
144
$record->append_fields(
144
$record->append_fields(
145
    MARC::Field->new(
145
    MARC::Field->new(
146
        952, ' ', ' ',
146
        952, ' ', ' ',
Lines 149-159 $record->append_fields( Link Here
149
    ),
149
    ),
150
);
150
);
151
update_field( $record, '952', 'p', undef, '3010023919' );
151
update_field( $record, '952', 'p', undef, '3010023919' );
152
my @fields_952p = read_field( $record, '952', 'p' );
152
my @fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' );
153
is_deeply( \@fields_952p, ['3010023919', '3010023919'], 'update all subfields 952$p with the same value' );
153
is_deeply( \@fields_952p, ['3010023919', '3010023919'], 'update all subfields 952$p with the same value' );
154
154
155
update_field( $record, '952', 'p', undef, ('3010023917', '3010023918') );
155
update_field( $record, '952', 'p', undef, ('3010023917', '3010023918') );
156
@fields_952p = read_field( $record, '952', 'p' );
156
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' );
157
is_deeply( \@fields_952p, ['3010023917', '3010023918'], 'update all subfields 952$p with the different values' );
157
is_deeply( \@fields_952p, ['3010023917', '3010023918'], 'update all subfields 952$p with the different values' );
158
158
159
# move_field
159
# move_field
Lines 167-184 $record->append_fields( Link Here
167
    ),
167
    ),
168
);
168
);
169
copy_field( $record, '952', 'd', '952', 'd' );
169
copy_field( $record, '952', 'd', '952', 'd' );
170
@fields_952d = read_field( $record, '952', 'd' );
170
@fields_952d = Koha::SimpleMARC::read( $record, '952', 'd' );
171
is_deeply( \@fields_952d, ['2001-06-25', '2001-06-25'], 'copy 952$d into others 952 field' );
171
is_deeply( \@fields_952d, ['2001-06-25', '2001-06-25'], 'copy 952$d into others 952 field' );
172
172
173
move_field( $record, '952', 'c', '954', 'c' );
173
move_field( $record, '952', 'c', '954', 'c' );
174
@fields_952c = read_field( $record, '952', 'c' );
174
@fields_952c = Koha::SimpleMARC::read( $record, '952', 'c' );
175
@fields_954c = read_field( $record, '954', 'c' );
175
@fields_954c = Koha::SimpleMARC::read( $record, '954', 'c' );
176
is_deeply( \@fields_952c, [], 'The 952$c has moved' );
176
is_deeply( \@fields_952c, [], 'The 952$c has moved' );
177
is_deeply( \@fields_954c, ['GEN'], 'Now 954$c exists' );
177
is_deeply( \@fields_954c, ['GEN'], 'Now 954$c exists' );
178
178
179
move_field( $record, '952', 'p', '954', 'p', undef, 1 ); # Move the first field
179
move_field( $record, '952', 'p', '954', 'p', undef, 1 ); # Move the first field
180
@fields_952p = read_field( $record, '952', 'p' );
180
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' );
181
@fields_954p = read_field( $record, '954', 'p' );
181
@fields_954p = Koha::SimpleMARC::read( $record, '954', 'p' );
182
is_deeply( \@fields_952p, ['3010023917'], 'One of 952$p has moved' );
182
is_deeply( \@fields_952p, ['3010023917'], 'One of 952$p has moved' );
183
is_deeply( \@fields_954p, ['3010023917'], 'Now 954$p exists' );
183
is_deeply( \@fields_954p, ['3010023917'], 'Now 954$p exists' );
184
184
Lines 192-199 $record->append_fields( Link Here
192
);
192
);
193
193
194
move_field( $record, '952', 'p', '954', 'p' ); # Move all field
194
move_field( $record, '952', 'p', '954', 'p' ); # Move all field
195
@fields_952p = read_field( $record, '952', 'p' );
195
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' );
196
@fields_954p = read_field( $record, '954', 'p' );
196
@fields_954p = Koha::SimpleMARC::read( $record, '954', 'p' );
197
is_deeply( \@fields_952p, [], 'All 952$p have moved' );
197
is_deeply( \@fields_952p, [], 'All 952$p have moved' );
198
is_deeply( \@fields_954p, ['3010023917', '3010023917'], 'Now 2 954$p exist' );
198
is_deeply( \@fields_954p, ['3010023917', '3010023917'], 'Now 2 954$p exist' );
199
199
200
# delete
201
$record = new_record;
202
Koha::SimpleMARC::delete( $record, '952' );
203
my @fields_952 = Koha::SimpleMARC::read( $record, '952' );
204
is_deeply( \@fields_952, [], 'Delete all 952, 1 deleted' );
205
206
$record = new_record;
207
$record->append_fields(
208
    MARC::Field->new(
209
        952, ' ', ' ',
210
        p => '3010023917',
211
        y => 'BK',
212
    ),
213
);
214
Koha::SimpleMARC::delete( $record, '952' );
215
@fields_952 = Koha::SimpleMARC::read( $record, '952' );
216
is_deeply( \@fields_952, [], 'Delete all 952, 2 deleted' );
217
218
$record = new_record;
219
$record->append_fields(
220
    MARC::Field->new(
221
        952, ' ', ' ',
222
        p => '3010023917',
223
        y => 'BK',
224
    ),
225
);
226
Koha::SimpleMARC::delete( $record, '952', 'p', 1 );
227
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' );
228
is_deeply( \@fields_952p, ['3010023917'], 'Delete first 952$p' );
229
230
$record = new_record;
231
$record->append_fields(
232
    MARC::Field->new(
233
        952, ' ', ' ',
234
        p => '3010023917',
235
        y => 'BK',
236
    ),
237
);
238
Koha::SimpleMARC::delete( $record, '952', 'p' );
239
@fields_952p = Koha::SimpleMARC::read( $record, '952', 'p' );
240
is_deeply( \@fields_952p, [], 'Delete all 952$p' );
(-)a/tools/marc_modification_templates.pl (-2 / +1 lines)
Lines 120-126 unless ( $template_id ) { Link Here
120
120
121
my @actions = GetModificationTemplateActions( $template_id );
121
my @actions = GetModificationTemplateActions( $template_id );
122
foreach my $action ( @actions ) {
122
foreach my $action ( @actions ) {
123
  $action->{'action_delete_field'} = ( $action->{'action'} eq 'delete_field' );
123
  $action->{'action_delete'} = ( $action->{'action'} eq 'delete' );
124
  $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' );
124
  $action->{'action_update_field'} = ( $action->{'action'} eq 'update_field' );
125
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
125
  $action->{'action_move_field'} = ( $action->{'action'} eq 'move_field' );
126
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
126
  $action->{'action_copy_field'} = ( $action->{'action'} eq 'copy_field' );
127
- 

Return to bug 11319