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/OpenID' => 'OpenID',
12 'pear.php.net/Pager' => 'Pager',
13 'pear.php.net/Services_Libravatar' => 'Services_Libravatar',
14 'pear2.php.net/PEAR2_Services_Linkback' => '\\PEAR2\\Services\\Linkback\\Client',
15 'zustellzentrum.cweiske.de/MIME_Type_PlainDetect' => 'MIME_Type_PlainDetect',
18 protected $writableDirs;
19 protected $elasticsearch;
21 public function __construct()
23 $cfg = $GLOBALS['phorkie']['cfg'];
24 $this->writableDirs = array(
25 'gitdir' => $cfg['gitdir'],
26 'workdir' => $cfg['workdir'],
28 $this->elasticsearch = $cfg['elasticsearch'];
31 public static function run()
38 $sc->checkMimeTypeDetection();
41 public function checkDeps()
43 foreach ($this->deps as $package => $class) {
44 if (!class_exists($class, true)) {
45 $this->fail('PEAR package not installed: ' . $package);
49 if (!class_exists('GeSHi', true)) {
50 @include_once 'geshi.php';
51 if (!class_exists('GeSHi', false)) {
52 $this->fail('PEAR package not installed: pear.geshi.org/geshi');
56 if (!class_exists('\\Michelf\\Markdown', true)) {
57 //PEAR-installed version 1.0.2 has a different API
58 $markdown = stream_resolve_include_path('markdown.php');
59 if ($markdown === false) {
60 $this->fail('Markdown renderer not available');
65 public function checkDirs()
67 foreach ($this->writableDirs as $name => $dir) {
69 $this->fail($name . ' directory does not exist at ' . $dir);
71 if (!is_writable($dir)) {
72 $this->fail($name . ' directory is not writable at ' . $dir);
77 public function checkGit()
79 $line = exec('git --version', $lines, $retval);
81 $this->fail('Running git executable failed.');
83 if (!preg_match('#^git version ([0-9.]+(rc[0-9]+)?)$#', $line, $matches)) {
84 $this->fail('git version output format unexpected: ' . $line);
86 if (version_compare($matches[1], '1.7.5') < 0) {
88 'git version needs to be at least 1.7.5, got: ' . $matches[1]
93 public function checkDatabase()
95 if ($this->elasticsearch == '') {
99 $es = parse_url($this->elasticsearch);
100 if (!preg_match("#/.+/#", $es['path'], $matches)) {
102 'Improper elasticsearch url. Elasticsearch requires a'
103 . ' search domain to store your data.'
104 . ' (e.g. http://localhost:9200/phorkie/)'
107 $dbs = new Database();
108 $dbs->getSetup()->setup();
111 public function checkMimeTypeDetection()
113 $rp = new Repository_Post();
114 if ($rp->getType('<?php echo "foo"; ?>') != 'php') {
115 $this->fail('MIME type detection fails');
119 public function fail($msg)
121 throw new Exception($msg);