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 $messages = array();
23 public function __construct()
25 $cfg = $GLOBALS['phorkie']['cfg'];
26 $this->writableDirs = array(
27 'gitdir' => $cfg['gitdir'],
28 'workdir' => $cfg['workdir'],
30 $this->elasticsearch = $cfg['elasticsearch'];
33 public static function run()
36 $sc->checkConfigFiles();
41 $sc->checkMimeTypeDetection();
46 public function checkConfigFiles()
48 foreach ($GLOBALS['phorkie']['cfgfiles'] as $file => $loaded) {
50 $this->ok('Loaded config file: ' . $file);
52 $this->info('Possible config file: ' . $file . ' (not loaded)');
57 public function checkDeps()
59 foreach ($this->deps as $package => $class) {
60 if (!class_exists($class, true)) {
61 $this->fail('PEAR package not installed: ' . $package);
65 if (!class_exists('geshi', true)) {
66 $geshi = stream_resolve_include_path(
67 $GLOBALS['phorkie']['cfg']['geshi']
69 if ($geshi === false) {
70 $this->fail('GeSHi not available');
74 if (!class_exists('\\Michelf\\Markdown', true)) {
75 //PEAR-installed version 1.0.2 has a different API
76 $markdown = stream_resolve_include_path('markdown.php');
77 if ($markdown === false) {
78 $this->fail('Markdown renderer not available');
83 public function checkDirs()
85 foreach ($this->writableDirs as $name => $dir) {
87 $this->fail($name . ' directory does not exist at ' . $dir);
88 } else if (!is_writable($dir)) {
89 $this->fail($name . ' directory is not writable at ' . $dir);
94 public function checkGit()
96 $line = exec('git --version', $lines, $retval);
98 $this->fail('Running git executable failed.');
100 if (!preg_match('#^git version ([0-9.]+(rc[0-9]+)?)$#', $line, $matches)) {
101 $this->fail('git version output format unexpected: ' . $line);
103 if (version_compare($matches[1], '1.7.5') < 0) {
105 'git version needs to be at least 1.7.5, got: ' . $matches[1]
110 public function checkDatabase()
112 if ($this->elasticsearch == '') {
116 $es = parse_url($this->elasticsearch);
117 if (!preg_match("#/.+/#", $es['path'], $matches)) {
119 'Improper elasticsearch url. Elasticsearch requires a'
120 . ' search domain to store your data.'
121 . ' (e.g. http://localhost:9200/phorkie/)'
124 $dbs = new Database();
125 $dbs->getSetup()->setup();
128 public function checkMimeTypeDetection()
130 $rp = new Repository_Post();
131 if ($rp->getType('<?php echo "foo"; ?>') != 'php') {
132 $this->fail('MIME type detection fails');
136 public function fail($msg)
138 $this->messages[] = array('error', $msg);
141 public function info($msg)
143 $this->messages[] = array('info', $msg);
146 public function ok($msg)
148 $this->messages[] = array('ok', $msg);