Merge branch 'master' of ssh://lx-office/~/lx-office-erp
[kivitendo-erp.git] / SL / InstallationCheck.pm
1 package SL::InstallationCheck;
2
3 use English '-no_match_vars';
4 use IO::File;
5
6 use vars qw(@required_modules @optional_modules);
7
8 use strict;
9
10 @required_modules = (
11   { "name" => "Class::Accessor", "url" => "http://search.cpan.org/~kasei/" },
12   { "name" => "CGI", "url" => "http://search.cpan.org/~lds/" },
13   { "name" => "CGI::Ajax", "url" => "http://search.cpan.org/~bct/" },
14   { "name" => "DBI", "url" => "http://search.cpan.org/~timb/" },
15   { "name" => "DBD::Pg", "url" => "http://search.cpan.org/~dbdpg/" },
16   { "name" => "Archive::Zip", "url" => "http://search.cpan.org/~adamk/" },
17   { "name" => "Text::Iconv", "url" => "http://search.cpan.org/~mpiotr/" },
18   { "name" => "Time::HiRes", "url" => "http://search.cpan.org/~jhi/" },
19   { "name" => "YAML", "url" => "http://search.cpan.org/~ingy/" },
20   { "name" => "IO::Wrap", "url" => "http://search.cpan.org/~dskoll/" },
21   { "name" => "Text::CSV_XS", "url" => "http://search.cpan.org/~hmbrand/" },
22   { "name" => "List::Util", "url" => "http://search.cpan.org/~gbarr/" },
23   { "name" => "Template", "url" => "http://search.cpan.org/~abw/" },
24   { "name" => "Digest::MD5", "url" => "http://search.cpan.org/~gaas/" },
25   { "name" => "PDF::API2", "url" => "http://search.cpan.org/~areibens/" },
26   { "name" => "URI", "url" => "http://search.cpan.org/~gaas/" },
27   { "name" => "XML::Writer", "url" => "http://search.cpan.org/~josephw/" },
28   );
29
30 @optional_modules = (
31   );
32
33 sub module_available {
34   my ($module) = @_;
35
36   if (!defined(eval("require $module;"))) {
37     return 0;
38   } else {
39     return 1;
40   }
41 }
42
43 my %conditional_dependencies;
44
45 sub check_for_conditional_dependencies {
46   if (!$conditional_dependencies{net_ldap}) {
47     $conditional_dependencies{net_ldap} = 1;
48
49     my $in = IO::File->new('config/authentication.pl', 'r');
50     if ($in) {
51       my $self = {};
52       my $code;
53
54       while (my $line = <$in>) {
55         $code .= $line;
56       }
57       $in->close();
58
59       eval $code;
60
61       if (! $EVAL_ERROR) {
62
63         if ($self->{module} && ($self->{module} eq 'LDAP')) {
64           push @required_modules, { 'name' => 'Net::LDAP', 'url' => 'http://search.cpan.org/~gbarr/' };
65         }
66       }
67     }
68   }
69 }
70
71 sub test_all_modules {
72   return grep { !module_available($_->{name}) } @required_modules;
73 }
74
75 1;