From d194fb5d5ffdb73fe6553cf1df568e68eae5afec Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Fri, 4 Aug 2023 10:45:18 +0200 Subject: [PATCH] Bug 34478: Add a script to catch missing 'op' in POST forms - catch_missing_op --- catch_missing_op.pl | 69 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 catch_missing_op.pl diff --git a/catch_missing_op.pl b/catch_missing_op.pl new file mode 100644 index 00000000000..84913354995 --- /dev/null +++ b/catch_missing_op.pl @@ -0,0 +1,69 @@ +#!/usr/bin/perl + +use Modern::Perl; +use File::Find; +use File::Slurp; +use Data::Dumper; + +my @themes; + +# OPAC themes +my $opac_dir = 'koha-tmpl/opac-tmpl'; +opendir ( my $dh, $opac_dir ) or die "can't opendir $opac_dir: $!"; +for my $theme ( grep { not /^\.|lib|js|xslt/ } readdir($dh) ) { + push @themes, "$opac_dir/$theme/en"; +} +close $dh; + +# STAFF themes +my $staff_dir = 'koha-tmpl/intranet-tmpl'; +opendir ( $dh, $staff_dir ) or die "can't opendir $staff_dir: $!"; +for my $theme ( grep { not /^\.|lib|js/ } readdir($dh) ) { + push @themes, "$staff_dir/$theme/en"; +} +close $dh; + +my @files; +sub wanted { + my $name = $File::Find::name; + push @files, $name + if $name =~ m[\.(tt|inc)$] and -f $name; +} + +find({ wanted => \&wanted, no_chdir => 1 }, @themes ); + +my @errors; +for my $file ( @files ) { + my @e = catch_missing_op($file); + push @errors, { file => $file, errors => \@e } if @e; +} + +say sprintf("%s:%s", $_->{file}, join(',', @{$_->{errors}})) for @errors; + +sub catch_missing_op{ + my ( $file ) = @_; + + my @lines = read_file($file); + my @errors; + return unless grep { $_ =~ m|