do not show search box when no search adapter configured
[phorkie.git] / src / phorkie / SetupCheck.php
1 <?php
2 namespace phorkie;
3
4 class SetupCheck
5 {
6     protected $deps = array(
7         'pear.php.net/VersionControl_Git'  => 'VersionControl_Git',
8         'pear.twig-project.org/Twig'       => 'Twig_Autoloader',
9         'pear.php.net/Date_HumanDiff'      => 'Date_HumanDiff',
10         'pear.php.net/HTTP_Request2'       => 'HTTP_Request2',
11         'pear.php.net/Pager'               => 'Pager',
12         'pear.php.net/Services_Libravatar' => 'Services_Libravatar',
13     );
14
15     protected $writableDirs;
16
17
18     public function __construct()
19     {
20         $cfg = $GLOBALS['phorkie']['cfg'];
21         $this->writableDirs = array(
22             'gitdir' => $cfg['gitdir'],
23             'workdir' => $cfg['workdir'],
24         );
25     }
26
27     public static function run()
28     {
29         $sc = new self();
30         $sc->checkDeps();
31         $sc->checkDirs();
32         $sc->checkGit();
33         $sc->checkDatabase();
34     }
35
36     public function checkDeps()
37     {
38         foreach ($this->deps as $package => $class) {
39             if (!class_exists($class, true)) {
40                 $this->fail('PEAR package not installed: ' . $package);
41             }
42         }
43     }
44
45     public function checkDirs()
46     {
47         foreach ($this->writableDirs as $name => $dir) {
48             if (!is_dir($dir)) {
49                 $this->fail($name . ' directory does not exist at ' . $dir);
50             }
51             if (!is_writable($dir)) {
52                 $this->fail($name . ' directory is not writable at ' . $dir);
53             }
54         }
55     }
56
57     public function checkGit()
58     {
59         $line = exec('git --version', $lines, $retval);
60         if ($retval !== 0) {
61             $this->fail('Running git executable failed.');
62         }
63         if (!preg_match('#^git version ([0-9.]+)$#', $line, $matches)) {
64             $this->fail('git version output format unexpected: ' . $line);
65         }
66         if (version_compare($matches[1], '1.7.5') < 0) {
67             $this->fail(
68                 'git version needs to be at least 1.7.5, got: ' . $matches[1]
69             );
70         }
71     }
72
73     public function checkDatabase()
74     {
75         $dbs = new Database_Setup_Elasticsearch();
76         $dbs->setup();
77     }
78
79     public function fail($msg)
80     {
81         throw new Exception($msg);
82     }
83 }
84
85 ?>