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

(-)a/C4/MarcModificationTemplates.pm (-17 / +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 155-163 sub DelModificationTemplate { Link Here
155
  my $dbh = C4::Context->dbh;
157
  my $dbh = C4::Context->dbh;
156
  my $sth = $dbh->prepare("DELETE FROM marc_modification_templates WHERE template_id = ?");
158
  my $sth = $dbh->prepare("DELETE FROM marc_modification_templates WHERE template_id = ?");
157
  $sth->execute( $template_id );
159
  $sth->execute( $template_id );
158
159
  $sth = $dbh->prepare("DELETE FROM marc_modification_template_actions WHERE template_id = ?");
160
  $sth->execute( $template_id );
161
}
160
}
162
161
163
=head2
162
=head2
Lines 210-216 sub GetModificationTemplateActions { Link Here
210
  AddModificationTemplateAction(
209
  AddModificationTemplateAction(
211
    $template_id, $action, $field_number,
210
    $template_id, $action, $field_number,
212
    $from_field, $from_subfield, $field_value,
211
    $from_field, $from_subfield, $field_value,
213
    $to_field, $to_subfield, $to_regex,
212
    $to_field, $to_subfield, $to_regex_search, $to_regex_replace, $to_regex_modifiers
214
    $conditional, $conditional_field, $conditional_subfield,
213
    $conditional, $conditional_field, $conditional_subfield,
215
    $conditional_comparison, $conditional_value,
214
    $conditional_comparison, $conditional_value,
216
    $conditional_regex, $description
215
    $conditional_regex, $description
Lines 230-236 sub AddModificationTemplateAction { Link Here
230
    $field_value,
229
    $field_value,
231
    $to_field,
230
    $to_field,
232
    $to_subfield,
231
    $to_subfield,
233
    $to_regex,
232
    $to_regex_search,
233
    $to_regex_replace,
234
    $to_regex_modifiers,
234
    $conditional,
235
    $conditional,
235
    $conditional_field,
236
    $conditional_field,
236
    $conditional_subfield,
237
    $conditional_subfield,
Lines 242-252 sub AddModificationTemplateAction { Link Here
242
243
243
  C4::Koha::Log( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
244
  C4::Koha::Log( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
244
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
245
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
245
                    $to_regex, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
246
                    $to_regex_search, $to_regex_replace, $to_regex_modifiers, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
246
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
247
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
247
  warn( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
248
  warn( "C4::MarcModificationTemplates::AddModificationTemplateAction( $template_id, $action,
248
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
249
                    $field_number, $from_field, $from_subfield, $field_value, $to_field, $to_subfield,
249
                    $to_regex, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
250
                    $to_regex_search, $to_regex_replace, $to_regex_modifiers, $conditional, $conditional_field, $conditional_subfield, $conditional_comparison,
250
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
251
                    $conditional_value, $conditional_regex, $description )" ) if DEBUG;
251
252
252
  $conditional_regex ||= '0';
253
  $conditional_regex ||= '0';
Lines 269-275 sub AddModificationTemplateAction { Link Here
269
  field_value,
270
  field_value,
270
  to_field,
271
  to_field,
271
  to_subfield,
272
  to_subfield,
272
  to_regex,
273
  to_regex_search,
274
  to_regex_replace,
275
  to_regex_modifiers,
273
  conditional,
276
  conditional,
274
  conditional_field,
277
  conditional_field,
275
  conditional_subfield,
278
  conditional_subfield,
Lines 278-284 sub AddModificationTemplateAction { Link Here
278
  conditional_regex,
281
  conditional_regex,
279
  description
282
  description
280
  )
283
  )
281
  VALUES ( NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
284
  VALUES ( NULL, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
282
285
283
  $sth = $dbh->prepare( $query );
286
  $sth = $dbh->prepare( $query );
284
287
Lines 292-298 sub AddModificationTemplateAction { Link Here
292
    $field_value,
295
    $field_value,
293
    $to_field,
296
    $to_field,
294
    $to_subfield,
297
    $to_subfield,
295
    $to_regex,
298
    $to_regex_search,
299
    $to_regex_replace,
300
    $to_regex_modifiers,
296
    $conditional,
301
    $conditional,
297
    $conditional_field,
302
    $conditional_field,
298
    $conditional_subfield,
303
    $conditional_subfield,
Lines 309-315 sub AddModificationTemplateAction { Link Here
309
  ModModificationTemplateAction(
314
  ModModificationTemplateAction(
310
    $mmta_id, $action, $field_number, $from_field,
315
    $mmta_id, $action, $field_number, $from_field,
311
    $from_subfield, $field_value, $to_field,
316
    $from_subfield, $field_value, $to_field,
312
    $to_subfield, $to_regex, $conditional,
317
    $to_subfield, $to_regex_search, $to_regex_replace, $to_regex_modifiers, $conditional,
313
    $conditional_field, $conditional_subfield,
318
    $conditional_field, $conditional_subfield,
314
    $conditional_comparison, $conditional_value,
319
    $conditional_comparison, $conditional_value,
315
    $conditional_regex, $description
320
    $conditional_regex, $description
Lines 329-335 sub ModModificationTemplateAction { Link Here
329
    $field_value,
334
    $field_value,
330
    $to_field,
335
    $to_field,
331
    $to_subfield,
336
    $to_subfield,
332
    $to_regex,
337
    $to_regex_search,
338
    $to_regex_replace,
339
    $to_regex_modifiers,
333
    $conditional,
340
    $conditional,
334
    $conditional_field,
341
    $conditional_field,
335
    $conditional_subfield,
342
    $conditional_subfield,
Lines 350-356 sub ModModificationTemplateAction { Link Here
350
  field_value = ?,
357
  field_value = ?,
351
  to_field = ?,
358
  to_field = ?,
352
  to_subfield = ?,
359
  to_subfield = ?,
353
  to_regex = ?,
360
  to_regex_search = ?,
361
  to_regex_replace = ?,
362
  to_regex_modifiers = ?,
354
  conditional = ?,
363
  conditional = ?,
355
  conditional_field = ?,
364
  conditional_field = ?,
356
  conditional_subfield = ?,
365
  conditional_subfield = ?,
Lines 370-376 sub ModModificationTemplateAction { Link Here
370
    $field_value,
379
    $field_value,
371
    $to_field,
380
    $to_field,
372
    $to_subfield,
381
    $to_subfield,
373
    $to_regex,
382
    $to_regex_search,
383
    $to_regex_replace,
384
    $to_regex_modifiers,
374
    $conditional,
385
    $conditional,
375
    $conditional_field,
386
    $conditional_field,
376
    $conditional_subfield,
387
    $conditional_subfield,
Lines 511-517 sub ModifyRecordWithTemplate { Link Here
511
        my $field_value = $a->{'field_value'};
522
        my $field_value = $a->{'field_value'};
512
        my $to_field = $a->{'to_field'};
523
        my $to_field = $a->{'to_field'};
513
        my $to_subfield = $a->{'to_subfield'};
524
        my $to_subfield = $a->{'to_subfield'};
514
        my $to_regex = $a->{'to_regex'};
525
        my $to_regex_search = $a->{'to_regex_search'};
526
        my $to_regex_replace = $a->{'to_regex_replace'};
527
        my $to_regex_modifiers = $a->{'to_regex_modifiers'};
515
        my $conditional = $a->{'conditional'};
528
        my $conditional = $a->{'conditional'};
516
        my $conditional_field = $a->{'conditional_field'};
529
        my $conditional_field = $a->{'conditional_field'};
517
        my $conditional_subfield = $a->{'conditional_subfield'};
530
        my $conditional_subfield = $a->{'conditional_subfield'};
Lines 540-546 sub ModifyRecordWithTemplate { Link Here
540
        }
553
        }
541
        push @params, (
554
        push @params, (
542
                ( ( not $field_value and $to_field )
555
                ( ( not $field_value and $to_field )
543
                    ? ( $to_field, $to_subfield, $to_regex )
556
                    ? ( $to_field, $to_subfield, { search => $to_regex_search, replace => $to_regex_replace, modifiers => $to_regex_modifiers} )
544
                    : () ),
557
                    : () ),
545
                ( $field_number
558
                ( $field_number
546
                    ? $field_number
559
                    ? $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/t/db_dependent/MarcModificationTemplates.t (-16 / +15 lines)
Lines 10-16 my $dbh = C4::Context->dbh; Link Here
10
$dbh->{AutoCommit} = 0;
10
$dbh->{AutoCommit} = 0;
11
$dbh->{RaiseError} = 1;
11
$dbh->{RaiseError} = 1;
12
12
13
$dbh->do(q|DELETE FROM marc_modification_template_actions|);
14
$dbh->do(q|DELETE FROM marc_modification_templates|);
13
$dbh->do(q|DELETE FROM marc_modification_templates|);
15
14
16
# Creation
15
# Creation
Lines 19-33 like( $template_id, qr|^\d+$|, "new template returns an id" ); Link Here
19
18
20
is( AddModificationTemplateAction(
19
is( AddModificationTemplateAction(
21
    $template_id, 'move_field', 1,
20
    $template_id, 'move_field', 1,
22
    '464', 'u', '',
21
    '464', 'u', '', '464', '3',
23
    '464', '3', '',
22
    '', '', '',
24
    '', '', '', '', '', '', '',
23
    '', '', '', '', '', '',
25
    'move first 464$u to 464$3'
24
    'move first 464$u to 464$3'
26
), 1, "Add first action");
25
), 1, "Add first action");
27
26
28
is( AddModificationTemplateAction(
27
is( AddModificationTemplateAction(
29
    $template_id, 'update_field', 0,
28
    $template_id, 'update_field', 0,
30
    '099', 't', 'LIV',
29
    '099', 't', 'LIV', '', '',
31
    '', '', '',
30
    '', '', '',
32
    'if', '200', 'b', 'equals', 'Text', '',
31
    'if', '200', 'b', 'equals', 'Text', '',
33
    'Update field 099$t with value LIV if 200$b matches "Text"'
32
    'Update field 099$t with value LIV if 200$b matches "Text"'
Lines 35-42 is( AddModificationTemplateAction( Link Here
35
34
36
is( AddModificationTemplateAction(
35
is( AddModificationTemplateAction(
37
    $template_id, 'copy_field', 0,
36
    $template_id, 'copy_field', 0,
38
    '606', 'a', '',
37
    '606', 'a', '', '607', 'a',
39
    '607', 'a', '',
38
    '', '', '',
40
    'unless', '606', 'a', 'not_equals', '^AJAX', '1',
39
    'unless', '606', 'a', 'not_equals', '^AJAX', '1',
41
    'Copy field 606$a to 607$a unless 606$a matches RegEx m^AJAX'
40
    'Copy field 606$a to 607$a unless 606$a matches RegEx m^AJAX'
42
), 1, "Add third action");
41
), 1, "Add third action");
Lines 87-93 is( $third_action->{conditional_value}, '^AJAX', "test conditional_value for thi Link Here
87
# Modifications
86
# Modifications
88
is( ModModificationTemplateAction(
87
is( ModModificationTemplateAction(
89
    $actions[1]->{mmta_id}, 'update_field', 0,
88
    $actions[1]->{mmta_id}, 'update_field', 0,
90
    '100', 'u', 'LIV',
89
    '100', 'u', 'LIV', '', '',
91
    '', '', '',
90
    '', '', '',
92
    'if', '200', 'c', 'equals', 'Text', '',
91
    'if', '200', 'c', 'equals', 'Text', '',
93
    'Update field 099$t with value LIV if 200$b matches "Text"'
92
    'Update field 099$t with value LIV if 200$b matches "Text"'
Lines 126-132 is( GetModificationTemplateAction( $actions[2]->{mmta_id} )->{ordering}, '3', 'T Link Here
126
is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 2, "Delete the first action, 2 others are reordered" );
125
is( DelModificationTemplateAction( $actions[0]->{mmta_id} ), 2, "Delete the first action, 2 others are reordered" );
127
is( GetModificationTemplateAction( $actions[0]->{mmta_id} ), undef, "first action does not exist anymore" );
126
is( GetModificationTemplateAction( $actions[0]->{mmta_id} ), undef, "first action does not exist anymore" );
128
127
129
is( DelModificationTemplate( $template_id ), 2, "2 actions are deleted" );
128
is( DelModificationTemplate( $template_id ), 1, "The template has been deleted" );
130
129
131
is( GetModificationTemplateAction( $actions[1]->{mmta_id} ), undef, "second action does not exist anymore" );
130
is( GetModificationTemplateAction( $actions[1]->{mmta_id} ), undef, "second action does not exist anymore" );
132
is( GetModificationTemplateAction( $actions[2]->{mmta_id} ), undef, "third action does not exist anymore" );
131
is( GetModificationTemplateAction( $actions[2]->{mmta_id} ), undef, "third action does not exist anymore" );
Lines 152-166 like( $template_id, qr|^\d+$|, "new template returns an id" ); Link Here
152
151
153
is( AddModificationTemplateAction(
152
is( AddModificationTemplateAction(
154
    $template_id, 'copy_field', 0,
153
    $template_id, 'copy_field', 0,
155
    '245', 'a', '',
154
    '245', 'a', '', '246', 'a',
156
    '246', 'a', '',
155
    '', '', '',
157
    '', '', '', '', '', '', '',
156
    '', '', '', '', '', '',
158
    'copy field 245$a to 246$a'
157
    'copy field 245$a to 246$a'
159
), 1, 'Add first action: copy 245$a to 246$a');
158
), 1, 'Add first action: copy 245$a to 246$a');
160
159
161
is( AddModificationTemplateAction(
160
is( AddModificationTemplateAction(
162
    $template_id, 'delete_field', 0,
161
    $template_id, 'delete_field', 0,
163
    '650', 'a', '',
162
    '650', 'a', '', '', '',
164
    '', '', '',
163
    '', '', '',
165
    'if', '650', '9', 'equals', '462', '',
164
    'if', '650', '9', 'equals', '462', '',
166
    'Delete field 650$a if 650$9=462'
165
    'Delete field 650$a if 650$9=462'
Lines 168-174 is( AddModificationTemplateAction( Link Here
168
167
169
is( AddModificationTemplateAction(
168
is( AddModificationTemplateAction(
170
    $template_id, 'update_field', 0,
169
    $template_id, 'update_field', 0,
171
    '952', 'p', '3010023917_updated',
170
    '952', 'p', '3010023917_updated', '', '',
172
    '', '', '',
171
    '', '', '',
173
    'unless', '650', '9', 'equals', '42', '',
172
    'unless', '650', '9', 'equals', '42', '',
174
    'Update field 952$p with "3010023917_updated" if 650$9 != 42'
173
    'Update field 952$p with "3010023917_updated" if 650$9 != 42'
Lines 176-183 is( AddModificationTemplateAction( Link Here
176
175
177
is( AddModificationTemplateAction(
176
is( AddModificationTemplateAction(
178
    $template_id, 'move_field', 0,
177
    $template_id, 'move_field', 0,
179
    '952', 'd', '',
178
    '952', 'd', '', '952', 'e', '',
180
    '952', 'e', '',
179
    '', '', '',
181
    'if', '952', 'c', 'equals', '^GEN', '1',
180
    'if', '952', 'c', 'equals', '^GEN', '1',
182
    'Move field 952$d to 952$e if 952$c =~ /^GE/'
181
    'Move field 952$d to 952$e if 952$c =~ /^GE/'
183
), 1, 'Add fourth action: move field 952$d to 952$e if 952$c =~ /^GE/');
182
), 1, 'Add fourth action: move field 952$d to 952$e if 952$c =~ /^GE/');
(-)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