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

(-)a/Koha/Items.pm (-6 / +9 lines)
Lines 363-375 sub batch_update { Link Here
363
    return ( { modified_itemnumbers => \@modified_itemnumbers, modified_fields => $modified_fields }, $self );
363
    return ( { modified_itemnumbers => \@modified_itemnumbers, modified_fields => $modified_fields }, $self );
364
}
364
}
365
365
366
sub apply_regex { # FIXME Should be moved outside of Koha::Items
366
sub apply_regex {
367
    # FIXME Should be moved outside of Koha::Items
368
    # FIXME This is nearly identical to Koha::SimpleMARC::_modify_values
367
    my ($params) = @_;
369
    my ($params) = @_;
368
    my $search   = $params->{search};
370
    my $search   = $params->{search};
369
    my $replace  = $params->{replace};
371
    my $replace  = $params->{replace};
370
    my $modifiers = $params->{modifiers} || q{};
372
    my $modifiers = $params->{modifiers} || q{};
371
    my $value = $params->{value};
373
    my $value = $params->{value};
372
374
375
    $replace =~ s/"/\\"/g;                    # Protection from embedded code
376
    $replace = '"' . $replace . '"'; # Put in a string for /ee
373
    my @available_modifiers = qw( i g );
377
    my @available_modifiers = qw( i g );
374
    my $retained_modifiers  = q||;
378
    my $retained_modifiers  = q||;
375
    for my $modifier ( split //, $modifiers ) {
379
    for my $modifier ( split //, $modifiers ) {
Lines 377-392 sub apply_regex { # FIXME Should be moved outside of Koha::Items Link Here
377
          if grep { /$modifier/ } @available_modifiers;
381
          if grep { /$modifier/ } @available_modifiers;
378
    }
382
    }
379
    if ( $retained_modifiers =~ m/^(ig|gi)$/ ) {
383
    if ( $retained_modifiers =~ m/^(ig|gi)$/ ) {
380
        $value =~ s/$search/$replace/ig;
384
        $value =~ s/$search/$replace/igee;
381
    }
385
    }
382
    elsif ( $retained_modifiers eq 'i' ) {
386
    elsif ( $retained_modifiers eq 'i' ) {
383
        $value =~ s/$search/$replace/i;
387
        $value =~ s/$search/$replace/iee;
384
    }
388
    }
385
    elsif ( $retained_modifiers eq 'g' ) {
389
    elsif ( $retained_modifiers eq 'g' ) {
386
        $value =~ s/$search/$replace/g;
390
        $value =~ s/$search/$replace/gee;
387
    }
391
    }
388
    else {
392
    else {
389
        $value =~ s/$search/$replace/;
393
        $value =~ s/$search/$replace/ee;
390
    }
394
    }
391
395
392
    return $value;
396
    return $value;
393
- 

Return to bug 29781