bootstrap 2.0 support
[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         'zustellzentrum.cweiske.de/MIME_Type_PlainDetect' => 'MIME_Type_PlainDetect',
14         'pear.michelf.ca/Markdown'         => 'Markdown',
15     );
16
17     protected $writableDirs;
18
19
20     public function __construct()
21     {
22         $cfg = $GLOBALS['phorkie']['cfg'];
23         $this->writableDirs = array(
24             'gitdir' => $cfg['gitdir'],
25             'workdir' => $cfg['workdir'],
26         );
27     }
28
29     public static function run()
30     {
31         $sc = new self();
32         $sc->checkDeps();
33         $sc->checkDirs();
34         $sc->checkGit();
35         $sc->checkDatabase();
36     }
37
38     public function checkDeps()
39     {
40         foreach ($this->deps as $package => $class) {
41             if (!class_exists($class, true)) {
42                 $this->fail('PEAR package not installed: ' . $package);
43             }
44         }
45     }
46
47     public function checkDirs()
48     {
49         foreach ($this->writableDirs as $name => $dir) {
50             if (!is_dir($dir)) {
51                 $this->fail($name . ' directory does not exist at ' . $dir);
52             }
53             if (!is_writable($dir)) {
54                 $this->fail($name . ' directory is not writable at ' . $dir);
55             }
56         }
57     }
58
59     public function checkGit()
60     {
61         $line = exec('git --version', $lines, $retval);
62         if ($retval !== 0) {
63             $this->fail('Running git executable failed.');
64         }
65         if (!preg_match('#^git version ([0-9.]+)$#', $line, $matches)) {
66             $this->fail('git version output format unexpected: ' . $line);
67         }
68         if (version_compare($matches[1], '1.7.5') < 0) {
69             $this->fail(
70                 'git version needs to be at least 1.7.5, got: ' . $matches[1]
71             );
72         }
73     }
74
75     public function checkDatabase()
76     {
77         $dbs = new Database();
78         $dbs->getSetup()->setup();
79     }
80
81     public function fail($msg)
82     {
83         throw new Exception($msg);
84     }
85 }
86
87 ?>