Bug 9811: Patron search improvement
[koha.git] / misc / check_sysprefs.pl
1 #!/usr/bin/perl
2
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 .)
7
8 use strict;
9 use warnings;
10
11 use File::Find;
12
13 use C4::Context;
14
15 @ARGV = qw(.) unless @ARGV;
16
17 sub check_sys_pref {
18     my $dbh   = C4::Context->dbh();
19     my $query = "SELECT * FROM systempreferences WHERE variable = ?";
20     my $sth   = $dbh->prepare($query);
21     if ( !-d _ ) {
22         my $name = $File::Find::name;
23         if ( $name =~ /(\.pl|\.pm)$/ ) {
24             open( FILE, "$_" ) || die "cant open $name";
25             while ( my $inp = <FILE> ) {
26                 if ( $inp =~ /C4::Context->preference\((.*?)\)/ ) {
27                     my $variable = $1;
28                     $variable =~ s /\'|\"//g;
29                     $sth->execute($variable);
30                     if ( my $data = $sth->fetchrow_hashref() ) {
31                         if ( $data->{variable} eq $variable ) {
32                             next;
33                         }
34                     }
35                     print
36 "$name has a reference to $variable, this does not exist in the database\n";
37                 }
38             }
39             close FILE;
40         }
41     }
42     $sth->finish();
43 }
44
45 find( \&check_sys_pref, @ARGV );