Koha/misc/check_sysprefs.pl
Julian Maurice b168f4a2e9 Bug 21395: Make perlcritic happy
This patch adds a .perlcriticrc (copied from qa-test-tools) and fixes
almost all perlcrictic violations according to this .perlcriticrc
The remaining violations are silenced out by appending a '## no critic'
to the offending lines. They can still be seen by using the --force
option of perlcritic
This patch also modify t/00-testcritic.t to check all Perl files using
the new .perlcriticrc.
I'm not sure if this test script is still useful as it is now equivalent
to `perlcritic --quiet .` and it looks like it is much slower
(approximatively 5 times slower on my machine)

Test plan:
1. Run `perlcritic --quiet .` from the root directory. It should output
   nothing
2. Run `perlcritic --quiet --force .`. It should output 7 errors (6
   StringyEval, 1 BarewordFileHandles)
3. Run `TEST_QA=1 prove t/00-testcritic.t`
4. Read the patch. Check that all changes make sense and do not
   introduce undesired behaviour

Signed-off-by: Bernardo Gonzalez Kriegel <bgkriegel@gmail.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
2020-06-29 12:37:02 +02:00

46 lines
1.3 KiB
Perl
Executable file

#!/usr/bin/perl
# script to test for missing systempreferences
# export KOHA_CONF
# export PERL5LIB
# then ./check_sysprefs.pl path (if path is blank it will use .)
use strict;
use warnings;
use File::Find;
use Koha::Script;
use C4::Context;
@ARGV = qw(.) unless @ARGV;
sub check_sys_pref {
my $dbh = C4::Context->dbh();
my $query = "SELECT * FROM systempreferences WHERE variable = ?";
my $sth = $dbh->prepare($query);
if ( !-d _ ) {
my $name = $File::Find::name;
if ( $name =~ /(\.pl|\.pm)$/ ) {
open( my $fh, '<', $_ ) || die "can't open $name";
while ( my $inp = <$fh> ) {
if ( $inp =~ /C4::Context->preference\((.*?)\)/ ) {
my $variable = $1;
$variable =~ s /\'|\"//g;
$sth->execute($variable);
if ( my $data = $sth->fetchrow_hashref() ) {
if ( $data->{variable} eq $variable ) {
next;
}
}
print
"$name has a reference to $variable, this does not exist in the database\n";
}
}
close $fh;
}
}
$sth->finish();
}
find( \&check_sys_pref, @ARGV );