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

(-)a/C4/MarcModificationTemplates.pm (-14 / +30 lines)
Lines 127-133 sub AddModificationTemplate { Link Here
127
        $action->{'field_value'},
127
        $action->{'field_value'},
128
        $action->{'to_field'},
128
        $action->{'to_field'},
129
        $action->{'to_subfield'},
129
        $action->{'to_subfield'},
130
        $action->{'to_regex'},
130
        $action->{'to_regex_search'},
131
        $action->{'to_regex_replace'},
132
        $action->{'to_regex_modifiers'},
131
        $action->{'conditional'},
133
        $action->{'conditional'},
132
        $action->{'conditional_field'},
134
        $action->{'conditional_field'},
133
        $action->{'conditional_subfield'},
135
        $action->{'conditional_subfield'},
Lines 210-216 sub GetModificationTemplateActions { Link Here
210
  AddModificationTemplateAction(
212
  AddModificationTemplateAction(
211
    $template_id, $action, $field_number,
213
    $template_id, $action, $field_number,
212
    $from_field, $from_subfield, $field_value,
214
    $from_field, $from_subfield, $field_value,
213
    $to_field, $to_subfield, $to_regex,
215
    $to_field, $to_subfield, $to_regex_search, $to_regex_replace, $to_regex_modifiers
214
    $conditional, $conditional_field, $conditional_subfield,
216
    $conditional, $conditional_field, $conditional_subfield,
215
    $conditional_comparison, $conditional_value,
217
    $conditional_comparison, $conditional_value,
216
    $conditional_regex, $description
218
    $conditional_regex, $description
Lines 230-236 sub AddModificationTemplateAction { Link Here
230
    $field_value,
232
    $field_value,
231
    $to_field,
233
    $to_field,
232
    $to_subfield,
234
    $to_subfield,
233
    $to_regex,
235
    $to_regex_search,
236
    $to_regex_replace,
237
    $to_regex_modifiers,
234
    $conditional,
238
    $conditional,
235
    $conditional_field,
239
    $conditional_field,
236
    $conditional_subfield,
240
    $conditional_subfield,
Lines 242-252 sub AddModificationTemplateAction { Link Here
242
246
243
  C4::Koha::Log( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
247
  C4::Koha::Log( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
244
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
248
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
245
                    $to_regex, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
249
                    $to_regex_search, $to_regex_replace, $to_regex_modifiers, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
246
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
250
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
247
  warn( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
251
  warn( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
248
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
252
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
249
                    $to_regex, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
253
                    $to_regex_search, $to_regex_replace, $to_regex_modifiers, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
250
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
254
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
251
255
252
  $conditional_regex ||= '0';
256
  $conditional_regex ||= '0';
Lines 269-275 sub AddModificationTemplateAction { Link Here
269
  field_value,
273
  field_value,
270
  to_field,
274
  to_field,
271
  to_subfield,
275
  to_subfield,
272
  to_regex,
276
  to_regex_search,
277
  to_regex_replace,
278
  to_regex_modifiers,
273
  conditional,
279
  conditional,
274
  conditional_field,
280
  conditional_field,
275
  conditional_subfield,
281
  conditional_subfield,
Lines 278-284 sub AddModificationTemplateAction { Link Here
278
  conditional_regex,
284
  conditional_regex,
279
  description
285
  description
280
  )
286
  )
281
  VALUES ( NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
287
  VALUES ( NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
282
288
283
  $sth = $dbh->prepare( $query );
289
  $sth = $dbh->prepare( $query );
284
290
Lines 292-298 sub AddModificationTemplateAction { Link Here
292
    $field_value,
298
    $field_value,
293
    $to_field,
299
    $to_field,
294
    $to_subfield,
300
    $to_subfield,
295
    $to_regex,
301
    $to_regex_search,
302
    $to_regex_replace,
303
    $to_regex_modifiers,
296
    $conditional,
304
    $conditional,
297
    $conditional_field,
305
    $conditional_field,
298
    $conditional_subfield,
306
    $conditional_subfield,
Lines 309-315 sub AddModificationTemplateAction { Link Here
309
  ModModificationTemplateAction(
317
  ModModificationTemplateAction(
310
    $mmta_id, $action, $field_number, $from_field,
318
    $mmta_id, $action, $field_number, $from_field,
311
    $from_subfield, $field_value, $to_field,
319
    $from_subfield, $field_value, $to_field,
312
    $to_subfield, $to_regex, $conditional,
320
    $to_subfield, $to_regex_search, $to_regex_replace, $to_regex_modifiers, $conditional,
313
    $conditional_field, $conditional_subfield,
321
    $conditional_field, $conditional_subfield,
314
    $conditional_comparison, $conditional_value,
322
    $conditional_comparison, $conditional_value,
315
    $conditional_regex, $description
323
    $conditional_regex, $description
Lines 329-335 sub ModModificationTemplateAction { Link Here
329
    $field_value,
337
    $field_value,
330
    $to_field,
338
    $to_field,
331
    $to_subfield,
339
    $to_subfield,
332
    $to_regex,
340
    $to_regex_search,
341
    $to_regex_replace,
342
    $to_regex_modifiers,
333
    $conditional,
343
    $conditional,
334
    $conditional_field,
344
    $conditional_field,
335
    $conditional_subfield,
345
    $conditional_subfield,
Lines 350-356 sub ModModificationTemplateAction { Link Here
350
  field_value = ?,
360
  field_value = ?,
351
  to_field = ?,
361
  to_field = ?,
352
  to_subfield = ?,
362
  to_subfield = ?,
353
  to_regex = ?,
363
  to_regex_search = ?,
364
  to_regex_replace = ?,
365
  to_regex_modifiers = ?,
354
  conditional = ?,
366
  conditional = ?,
355
  conditional_field = ?,
367
  conditional_field = ?,
356
  conditional_subfield = ?,
368
  conditional_subfield = ?,
Lines 370-376 sub ModModificationTemplateAction { Link Here
370
    $field_value,
382
    $field_value,
371
    $to_field,
383
    $to_field,
372
    $to_subfield,
384
    $to_subfield,
373
    $to_regex,
385
    $to_regex_search,
386
    $to_regex_replace,
387
    $to_regex_modifiers,
374
    $conditional,
388
    $conditional,
375
    $conditional_field,
389
    $conditional_field,
376
    $conditional_subfield,
390
    $conditional_subfield,
Lines 511-517 sub ModifyRecordWithTemplate { Link Here
511
        my $field_value = $a->{'field_value'};
525
        my $field_value = $a->{'field_value'};
512
        my $to_field = $a->{'to_field'};
526
        my $to_field = $a->{'to_field'};
513
        my $to_subfield = $a->{'to_subfield'};
527
        my $to_subfield = $a->{'to_subfield'};
514
        my $to_regex = $a->{'to_regex'};
528
        my $to_regex_search = $a->{'to_regex_search'};
529
        my $to_regex_replace = $a->{'to_regex_replace'};
530
        my $to_regex_modifiers = $a->{'to_regex_modifiers'};
515
        my $conditional = $a->{'conditional'};
531
        my $conditional = $a->{'conditional'};
516
        my $conditional_field = $a->{'conditional_field'};
532
        my $conditional_field = $a->{'conditional_field'};
517
        my $conditional_subfield = $a->{'conditional_subfield'};
533
        my $conditional_subfield = $a->{'conditional_subfield'};
Lines 540-546 sub ModifyRecordWithTemplate { Link Here
540
        }
556
        }
541
        push @params, (
557
        push @params, (
542
                ( ( not $field_value and $to_field )
558
                ( ( not $field_value and $to_field )
543
                    ? ( $to_field, $to_subfield, $to_regex )
559
                    ? ( $to_field, $to_subfield, { search => $to_regex_search, replace => $to_regex_replace, modifiers => $to_regex_modifiers} )
544
                    : () ),
560
                    : () ),
545
                ( $field_number
561
                ( $field_number
546
                    ? $field_number
562
                    ? $field_number
(-)a/Koha/SimpleMARC.pm (-10 / +27 lines)
Lines 2-9 package Koha::SimpleMARC; Link Here
2
2
3
# Copyright 2009 Kyle M. Hall <kyle.m.hall@gmail.com>
3
# Copyright 2009 Kyle M. Hall <kyle.m.hall@gmail.com>
4
4
5
use strict;
5
use Modern::Perl;
6
use warnings;
7
6
8
#use MARC::Record;
7
#use MARC::Record;
9
8
Lines 66-72 at your option, any later version of Perl 5 you may have available. Link Here
66
65
67
  Copies a value from one field to another. If a regular expression ( $regex ) is supplied,
66
  Copies a value from one field to another. If a regular expression ( $regex ) is supplied,
68
  the value will be transformed by the given regex before being copied into the new field.
67
  the value will be transformed by the given regex before being copied into the new field.
69
  Example: $regex = 's/Old Text/Replacement Text/'
68
  Example: $regex = { search => 'Old Text', replace => 'Replacement Text', modifiers => 'g' };
70
69
71
  If $n is passed, copy_field will only copy the Nth field of the list of fields.
70
  If $n is passed, copy_field will only copy the Nth field of the list of fields.
72
  E.g. $n = 1 will only use the first field's value, $n = 2 will use only the 2nd field's value.
71
  E.g. $n = 1 will only use the first field's value, $n = 2 will use only the 2nd field's value.
Lines 83-97 sub copy_field { Link Here
83
  @values = ( $values[$n-1] ) if ( $n );
82
  @values = ( $values[$n-1] ) if ( $n );
84
  C4::Koha::Log( "@values = read_field( $record, $fromFieldName, $fromSubfieldName )" ) if $debug >= 3;
83
  C4::Koha::Log( "@values = read_field( $record, $fromFieldName, $fromSubfieldName )" ) if $debug >= 3;
85
84
86
  if ( $regex ) {
85
  if ( $regex and $regex->{search} ) {
86
    $regex->{modifiers} //= q||;
87
    my @available_modifiers = qw( i g );
88
    my $modifiers = q||;
89
    for my $modifier ( split //, $regex->{modifiers} ) {
90
        $modifiers .= $modifier
91
            if grep {/$modifier/} @available_modifiers;
92
    }
87
    foreach my $value ( @values ) {
93
    foreach my $value ( @values ) {
88
      C4::Koha::Log( "\$value =~ s$regex" ) if ( $debug >= 3 );
94
      C4::Koha::Log( "\$value =~ s/$regex->{search}/$regex->{replace}/$modifiers" ) if ( $debug >= 3 );
89
      eval "\$value =~ s$regex";
95
        for ( $modifiers ) {
96
          when ( /^(ig|gi)$/ ) {
97
            $value =~ s/$regex->{search}/$regex->{replace}/ig;
98
          }
99
          when ( /^i$/ ) {
100
            $value =~ s/$regex->{search}/$regex->{replace}/i;
101
          }
102
          when ( /^g$/ ) {
103
            $value =~ s/$regex->{search}/$regex->{replace}/g;
104
          }
105
          default {
106
            $value =~ s/$regex->{search}/$regex->{replace}/;
107
          }
108
      }
90
    }
109
    }
91
  }
110
  }
92
93
  update_field( $record, $toFieldName, $toSubfieldName, $dont_erase, @values );
111
  update_field( $record, $toFieldName, $toSubfieldName, $dont_erase, @values );
94
95
}
112
}
96
113
97
=head2 update_field
114
=head2 update_field
Lines 220-226 sub field_exists { Link Here
220
  Returns true if the field equals the given value, false otherwise.
237
  Returns true if the field equals the given value, false otherwise.
221
238
222
  If a regular expression ( $regex ) is supplied, the value will be compared using
239
  If a regular expression ( $regex ) is supplied, the value will be compared using
223
  the given regex. Example: $regex = 'm/sought_text/'
240
  the given regex. Example: $regex = 'sought_text'
224
241
225
  If $n is passed, the Nth field of a repeatable series will be used for comparison.
242
  If $n is passed, the Nth field of a repeatable series will be used for comparison.
226
  Set $n to 1 or leave empty for a non-repeatable field.
243
  Set $n to 1 or leave empty for a non-repeatable field.
Lines 238-244 sub field_equals { Link Here
238
  my $field_value = $field_values[$n-1];
255
  my $field_value = $field_values[$n-1];
239
256
240
  if ( $regex ) {
257
  if ( $regex ) {
241
    C4::Koha::Log( "Testing '$field_value' =~ m$value" ) if $debug >= 3;
258
    C4::Koha::Log( "Testing '$field_value' =~ m/$value/" ) if $debug >= 3;
242
    return $field_value =~ m/$value/;
259
    return $field_value =~ m/$value/;
243
  } else {
260
  } else {
244
    return $field_value eq $value;
261
    return $field_value eq $value;
(-)a/installer/data/mysql/kohastructure.sql (-2 / +5 lines)
Lines 3256-3262 CREATE TABLE IF NOT EXISTS marc_modification_template_actions ( Link Here
3256
  field_value varchar(100) DEFAULT NULL,
3256
  field_value varchar(100) DEFAULT NULL,
3257
  to_field varchar(3) DEFAULT NULL,
3257
  to_field varchar(3) DEFAULT NULL,
3258
  to_subfield varchar(1) DEFAULT NULL,
3258
  to_subfield varchar(1) DEFAULT NULL,
3259
  to_regex text,
3259
  to_regex_search text,
3260
  to_regex_replace text,
3261
  to_regex_modifiers varchar(8) DEFAULT '',
3260
  conditional enum('if','unless') DEFAULT NULL,
3262
  conditional enum('if','unless') DEFAULT NULL,
3261
  conditional_field varchar(3) DEFAULT NULL,
3263
  conditional_field varchar(3) DEFAULT NULL,
3262
  conditional_subfield varchar(1) DEFAULT NULL,
3264
  conditional_subfield varchar(1) DEFAULT NULL,
Lines 3264-3270 CREATE TABLE IF NOT EXISTS marc_modification_template_actions ( Link Here
3264
  conditional_value text,
3266
  conditional_value text,
3265
  conditional_regex tinyint(1) NOT NULL DEFAULT '0',
3267
  conditional_regex tinyint(1) NOT NULL DEFAULT '0',
3266
  description text,
3268
  description text,
3267
  PRIMARY KEY (mmta_id)
3269
  PRIMARY KEY (mmta_id),
3270
  CONSTRAINT `mmta_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `marc_modification_templates` (`template_id`) ON DELETE CASCADE ON UPDATE CASCADE
3268
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3271
) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
3269
3272
3270
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
3273
/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */;
(-)a/installer/data/mysql/updatedatabase.pl (-2 / +5 lines)
Lines 7176-7182 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
7176
      field_value varchar(100) default NULL,
7176
      field_value varchar(100) default NULL,
7177
      to_field varchar(3) default NULL,
7177
      to_field varchar(3) default NULL,
7178
      to_subfield varchar(1) default NULL,
7178
      to_subfield varchar(1) default NULL,
7179
      to_regex text,
7179
      to_regex_search text,
7180
      to_regex_replace text,
7181
      to_regex_modifiers varchar(8) default '',
7180
      conditional enum('if','unless') default NULL,
7182
      conditional enum('if','unless') default NULL,
7181
      conditional_field varchar(3) default NULL,
7183
      conditional_field varchar(3) default NULL,
7182
      conditional_subfield varchar(1) default NULL,
7184
      conditional_subfield varchar(1) default NULL,
Lines 7184-7190 if (C4::Context->preference("Version") < TransformToNum($DBversion)) { Link Here
7184
      conditional_value text,
7186
      conditional_value text,
7185
      conditional_regex tinyint(1) NOT NULL default '0',
7187
      conditional_regex tinyint(1) NOT NULL default '0',
7186
      description text,
7188
      description text,
7187
      PRIMARY KEY  (mmta_id)
7189
      PRIMARY KEY  (mmta_id),
7190
      CONSTRAINT `mmta_ibfk_1` FOREIGN KEY (`template_id`) REFERENCES `marc_modification_templates` (`template_id`) ON DELETE CASCADE ON UPDATE CASCADE
7188
      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7191
      ) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
7189
    ");
7192
    ");
7190
7193
(-)a/koha-tmpl/intranet-tmpl/prog/en/modules/tools/marc_modification_templates.tt (-9 / +15 lines)
Lines 149-155 var modaction_legend_innerhtml; Link Here
149
var action_submit_value;
149
var action_submit_value;
150
150
151
function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
151
function editAction( mmta_id, ordering, action, field_number, from_field, from_subfield, field_value, to_field,
152
    to_subfield, to_regex, conditional, conditional_field, conditional_subfield,
152
    to_subfield, to_regex_search, to_regex_replace, to_regex_modifiers, conditional, conditional_field, conditional_subfield,
153
    conditional_comparison, conditional_value, conditional_regex, description
153
    conditional_comparison, conditional_value, conditional_regex, description
154
) {
154
) {
155
    document.getElementById('mmta_id').value = mmta_id;
155
    document.getElementById('mmta_id').value = mmta_id;
Lines 164-172 function editAction( mmta_id, ordering, action, field_number, from_field, from_s Link Here
164
    document.getElementById('field_value').value = field_value;
164
    document.getElementById('field_value').value = field_value;
165
    document.getElementById('to_field').value = to_field;
165
    document.getElementById('to_field').value = to_field;
166
    document.getElementById('to_subfield').value = to_subfield;
166
    document.getElementById('to_subfield').value = to_subfield;
167
    document.getElementById('to_regex').value = to_regex;
167
    $("#to_regex_search").val(to_regex_search);
168
    $("#to_regex_replace").val(to_regex_replace);
169
    $("#to_regex_modifiers").val(to_regex_modifiers);
168
170
169
    document.getElementById('to_field_regex').checked = to_regex.length;
171
    document.getElementById('to_field_regex').checked = conditional_regex.length;
170
    document.getElementById('to_field_regex').onchange();
172
    document.getElementById('to_field_regex').onchange();
171
173
172
    setSelectByValue( 'conditional', conditional );
174
    setSelectByValue( 'conditional', conditional );
Lines 204-210 function cancelEditAction() { Link Here
204
    document.getElementById('field_value').value = '';
206
    document.getElementById('field_value').value = '';
205
    document.getElementById('to_field').value = '';
207
    document.getElementById('to_field').value = '';
206
    document.getElementById('to_subfield').value = '';
208
    document.getElementById('to_subfield').value = '';
207
    document.getElementById('to_regex').value = '';
209
    $("#to_regex_search").val("");
210
    $("#to_regex_replace").val("");
211
    $("#to_regex_modifiers").val("");
208
212
209
    document.getElementById('to_field_regex').checked = false;
213
    document.getElementById('to_field_regex').checked = false;
210
    document.getElementById('to_field_regex').onchange();
214
    document.getElementById('to_field_regex').onchange();
Lines 306-312 function setSelectByValue( selectId, value ) { Link Here
306
                                        </a>
310
                                        </a>
307
311
308
                                        <a title="Move Action Down" href="marc_modification_templates.pl?op=move_action&amp;where=down&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
312
                                        <a title="Move Action Down" href="marc_modification_templates.pl?op=move_action&amp;where=down&amp;template_id=[% ActionsLoo.template_id %]&amp;mmta_id=[% ActionsLoo.mmta_id %]">
309
                                    <img src="/[% interface %]/[% theme %]/img/go-down.png" border="0" alt="Go down" />
313
                                    <img src="[% interface %]/[% theme %]/img/go-down.png" border="0" alt="Go down" />
310
                                        </a>
314
                                        </a>
311
                                </td>
315
                                </td>
312
316
Lines 334-341 function setSelectByValue( selectId, value ) { Link Here
334
                                    [% IF ( ActionsLoo.to_field ) %]
338
                                    [% IF ( ActionsLoo.to_field ) %]
335
                                        to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %]
339
                                        to [% ActionsLoo.to_field %][% IF ( ActionsLoo.to_subfield ) %]$[% ActionsLoo.to_subfield %][% END %]
336
340
337
                                        [% IF ( ActionsLoo.to_regex ) %]
341
                                        [% IF ( ActionsLoo.to_regex_search ) %]
338
                                             using RegEx s<strong>[% ActionsLoo.to_regex %]</strong>
342
                                             using RegEx s<strong>/[% ActionsLoo.to_regex_search %]/[% ActionsLoo.to_regex_replace %]/[% ActionsLoo.to_regex_modifiers %]</strong>
339
                                        [% END %]
343
                                        [% END %]
340
                                    [% END %]
344
                                    [% END %]
341
345
Lines 364-370 function setSelectByValue( selectId, value ) { Link Here
364
                                                    "[% ActionsLoo.field_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
368
                                                    "[% ActionsLoo.field_value |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
365
                                                    "[% ActionsLoo.to_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
369
                                                    "[% ActionsLoo.to_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
366
                                                    "[% ActionsLoo.to_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
370
                                                    "[% ActionsLoo.to_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
367
                                                    "[% ActionsLoo.to_regex |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
371
                                                    "[% ActionsLoo.to_regex_search |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
372
                                                    "[% ActionsLoo.to_regex_replace |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
373
                                                    "[% ActionsLoo.to_regex_modifiers |replace('\\\\', '\\\\') |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
368
                                                    "[% ActionsLoo.conditional |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
374
                                                    "[% ActionsLoo.conditional |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
369
                                                    "[% ActionsLoo.conditional_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
375
                                                    "[% ActionsLoo.conditional_field |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
370
                                                    "[% ActionsLoo.conditional_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
376
                                                    "[% ActionsLoo.conditional_subfield |replace('\\\\', '\\\\') |replace("'", "\'") |replace('"', '\"') |replace('\n', '\\n') |replace('\r', '\\r') %]",
Lines 415-421 function setSelectByValue( selectId, value ) { Link Here
415
                                    <input type="checkbox" name="to_field_regex" id="to_field_regex" onchange="onToFieldRegexChange(this);" />
421
                                    <input type="checkbox" name="to_field_regex" id="to_field_regex" onchange="onToFieldRegexChange(this);" />
416
422
417
                                    <span name="to_field_regex_value_block" id="to_field_regex_value_block" style="display:none;">
423
                                    <span name="to_field_regex_value_block" id="to_field_regex_value_block" style="display:none;">
418
                                        s<input type="text" name="to_regex" id="to_regex" />
424
                                        s/<input type="text" name="to_regex_search" id="to_regex_search" placeholder="regex pattern" />/<input type="text" name="to_regex_replace" id="to_regex_replace" placeholder="regex replacement" />/<input type="text" name="to_regex_modifiers" id="to_regex_modifiers" placeholder="ig" size="3" />
419
                                    </span>
425
                                    </span>
420
                                </sup>
426
                                </sup>
421
                            </span>
427
                            </span>
(-)a/t/SimpleMARC.t (-7 / +23 lines)
Lines 1-6 Link Here
1
use Modern::Perl;
1
use Modern::Perl;
2
2
3
use Test::More tests => 33;
3
use Test::More tests => 37;
4
4
5
use_ok("MARC::Field");
5
use_ok("MARC::Field");
6
use_ok("MARC::Record");
6
use_ok("MARC::Record");
Lines 83-99 copy_field( $record, '650', 'a', '651', 'a', undef, 2 ); Link Here
83
is_deeply( read_field( $record, '651', 'a' ), 'Computer algorithms.', 'Copy second field 650$a' );
83
is_deeply( read_field( $record, '651', 'a' ), 'Computer algorithms.', 'Copy second field 650$a' );
84
delete_field( $record, '651' );
84
delete_field( $record, '651' );
85
85
86
copy_field( $record, '650', 'a', '651', 'a', '/Computer/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 = read_field( $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', '/Computer/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 = read_field( $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
delete_field( $record, '651' );
94
94
95
copy_field( $record, '650', 'a', '651', 'a', '/Computer/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', '/Computer/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 = read_field( $record, '651', 'a' );
98
is_deeply( \@fields_651a, [
98
is_deeply( \@fields_651a, [
99
    'The art of programming.',
99
    'The art of programming.',
Lines 103-110 is_deeply( \@fields_651a, [ Link Here
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
delete_field( $record, '651' );
105
105
106
copy_field( $record, '650', 'a', '651', 'a', '/Computer/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', '/Computer/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 = read_field( $record, '651', 'a' );
109
is_deeply( \@fields_651a, [
109
is_deeply( \@fields_651a, [
110
    'The art of programming.',
110
    'The art of programming.',
Lines 116-121 is_deeply( \@fields_651a, [ Link Here
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
delete_field( $record, '651' );
118
118
119
# Copy with regex modifiers
120
copy_field( $record, '650', 'a', '652', 'a', { search => 'o', replace => 'foo' } );
121
my @fields_652a = read_field( $record, '652', 'a' );
122
is_deeply( \@fields_652a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' );
123
124
copy_field( $record, '650', 'a', '653', 'a', { search => 'o', replace => 'foo', modifiers => 'g' } );
125
my @fields_653a = read_field( $record, '653', 'a' );
126
is_deeply( \@fields_653a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' );
127
128
copy_field( $record, '650', 'a', '654', 'a', { search => 'O', replace => 'foo', modifiers => 'i' } );
129
my @fields_654a = read_field( $record, '654', 'a' );
130
is_deeply( \@fields_654a, ['Cfoomputer programming.', 'Cfoomputer algorithms.'], 'Copy field using regex' );
131
132
copy_field( $record, '650', 'a', '655', 'a', { search => 'O', replace => 'foo', modifiers => 'gi' } );
133
my @fields_655a = read_field( $record, '655', 'a' );
134
is_deeply( \@fields_655a, ['Cfoomputer prfoogramming.', 'Cfoomputer algfoorithms.'], 'Copy field using regex' );
119
135
120
# update_field
136
# update_field
121
update_field( $record, '952', 'p', undef, '3010023918' );
137
update_field( $record, '952', 'p', undef, '3010023918' );
(-)a/tools/marc_modification_templates.pl (-4 / +9 lines)
Lines 59-65 if ( $op eq "create_template" ) { Link Here
59
  my $field_value = $cgi->param('field_value');
59
  my $field_value = $cgi->param('field_value');
60
  my $to_field = $cgi->param('to_field');
60
  my $to_field = $cgi->param('to_field');
61
  my $to_subfield = $cgi->param('to_subfield');
61
  my $to_subfield = $cgi->param('to_subfield');
62
  my $to_regex = $cgi->param('to_regex');
62
  my $to_regex_search = $cgi->param('to_regex_search');
63
  my $to_regex_replace = $cgi->param('to_regex_replace');
64
  my $to_regex_modifiers = $cgi->param('to_regex_modifiers');
63
  my $conditional = $cgi->param('conditional');
65
  my $conditional = $cgi->param('conditional');
64
  my $conditional_field = $cgi->param('conditional_field');
66
  my $conditional_field = $cgi->param('conditional_field');
65
  my $conditional_subfield = $cgi->param('conditional_subfield');
67
  my $conditional_subfield = $cgi->param('conditional_subfield');
Lines 78-84 if ( $op eq "create_template" ) { Link Here
78
      $field_value,
80
      $field_value,
79
      $to_field,
81
      $to_field,
80
      $to_subfield,
82
      $to_subfield,
81
      $to_regex,
83
      $to_regex_search,
84
      $to_regex_replace,
85
      $to_regex_modifiers,
82
      $conditional,
86
      $conditional,
83
      $conditional_field,
87
      $conditional_field,
84
      $conditional_subfield,
88
      $conditional_subfield,
Lines 97-103 if ( $op eq "create_template" ) { Link Here
97
      $field_value,
101
      $field_value,
98
      $to_field,
102
      $to_field,
99
      $to_subfield,
103
      $to_subfield,
100
      $to_regex,
104
      $to_regex_search,
105
      $to_regex_replace,
106
      $to_regex_modifiers,
101
      $conditional,
107
      $conditional,
102
      $conditional_field,
108
      $conditional_field,
103
      $conditional_subfield,
109
      $conditional_subfield,
104
- 

Return to bug 8015