Bug 25534: (QA follow-up) Add AV category
[koha.git] / misc / check_sysprefs.pl
blob942d8f27c460f2041277d7f0bc99608d5d09f7e2
1 #!/usr/bin/perl
3 # script to test for missing systempreferences
4 # export KOHA_CONF
5 # export PERL5LIB
6 # then ./check_sysprefs.pl path (if path is blank it will use .)
8 use strict;
9 use warnings;
11 use File::Find;
13 use Koha::Script;
14 use C4::Context;
16 @ARGV = qw(.) unless @ARGV;
18 sub check_sys_pref {
19 my $dbh = C4::Context->dbh();
20 my $query = "SELECT * FROM systempreferences WHERE variable = ?";
21 my $sth = $dbh->prepare($query);
22 if ( !-d _ ) {
23 my $name = $File::Find::name;
24 if ( $name =~ /(\.pl|\.pm)$/ ) {
25 open( my $fh, '<', $_ ) || die "can't open $name";
26 while ( my $inp = <$fh> ) {
27 if ( $inp =~ /C4::Context->preference\((.*?)\)/ ) {
28 my $variable = $1;
29 $variable =~ s /\'|\"//g;
30 $sth->execute($variable);
31 if ( my $data = $sth->fetchrow_hashref() ) {
32 if ( $data->{variable} eq $variable ) {
33 next;
36 print
37 "$name has a reference to $variable, this does not exist in the database\n";
40 close $fh;
43 $sth->finish();
46 find( \&check_sys_pref, @ARGV );