Bug 23151: Modifiy database structure
[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 Koha::Script;
14 use C4::Context;
15
16 @ARGV = qw(.) unless @ARGV;
17
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( FILE, "$_" ) || die "can't open $name";
26             while ( my $inp = <FILE> ) {
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;
34                         }
35                     }
36                     print
37 "$name has a reference to $variable, this does not exist in the database\n";
38                 }
39             }
40             close FILE;
41         }
42     }
43     $sth->finish();
44 }
45
46 find( \&check_sys_pref, @ARGV );