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

(-)a/rename_op_with_op-cud.pl (-1 / +59 lines)
Line 0 Link Here
0
- 
1
#!/usr/bin/perl
2
3
use Modern::Perl;
4
use File::Find;
5
use File::Slurp;
6
use Data::Dumper;
7
8
my @themes;
9
10
# OPAC themes
11
my $opac_dir  = 'koha-tmpl/opac-tmpl';
12
opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!";
13
for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) {
14
    push @themes, "$opac_dir/$theme/en";
15
}
16
close $dh;
17
18
# STAFF themes
19
my $staff_dir = 'koha-tmpl/intranet-tmpl';
20
opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!";
21
for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) {
22
    push @themes, "$staff_dir/$theme/en";
23
}
24
close $dh;
25
26
my @files;
27
sub wanted {
28
    my $name = $File::Find::name;
29
    push @files, $name
30
        if $name =~ m[\.(tt|inc)$] and -f $name;
31
}
32
33
find({ wanted => \&wanted, no_chdir => 1 }, @themes );
34
35
rename_op($_) for @files;
36
37
sub rename_op {
38
    my ( $file ) = @_;
39
40
    my @lines = read_file($file);
41
    my @errors;
42
    return unless grep { $_ =~ m|<form| } @lines;
43
    my ($in_form, $closed_form, $line_open_form, $has_op);
44
    my $line_number = 0;
45
    for my $line (@lines) {
46
        $line_number++;
47
        if ( $line =~ m{^(\s*)<form.*method=('|")post('|")}i ) {
48
            $in_form = 1;
49
            $line_open_form = $line_number;
50
        }
51
        if ( $in_form && $line =~ m{name="op"}) {
52
            $line =~ s{name="op"}{name="op-cud"}g;
53
        }
54
        if ( $in_form && $line =~ m{</form} ) {
55
            $in_form = 0;
56
        }
57
    }
58
    write_file($file, @lines);
59
}

Return to bug 34478