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

(-)a/catch_missing_op.pl (-1 / +69 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
my @errors;
36
for my $file ( @files ) {
37
    my @e = catch_missing_op($file);
38
    push @errors, { file => $file, errors => \@e } if @e;
39
}
40
41
say sprintf("%s:%s",  $_->{file}, join(',', @{$_->{errors}})) for @errors;
42
43
sub catch_missing_op{
44
    my ( $file ) = @_;
45
46
    my @lines = read_file($file);
47
    my @errors;
48
    return unless grep { $_ =~ m|<form| } @lines;
49
    my ($in_form, $closed_form, $line_open_form, $has_op);
50
    my $line_number = 0;
51
    for my $line (@lines) {
52
        $line_number++;
53
        if ( $line =~ m{^(\s*)<form.*method=('|")post('|")}i ) {
54
            $in_form = 1;
55
            $line_open_form = $line_number;
56
        }
57
        if ( $in_form && $line =~ m{name="op"}) {
58
            $has_op = 1;
59
        }
60
        if ( $in_form && $line =~ m{</form} ) {
61
            $closed_form = 0;
62
            unless ( $has_op ) {
63
                push @errors, $line_open_form;
64
            }
65
            $in_form = 0;
66
        }
67
    }
68
    return @errors;
69
}

Return to bug 34478