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' => Tools::foldPath($cfg['gitdir']),
28 'workdir' => Tools::foldPath($cfg['workdir']),
30 $this->elasticsearch = $cfg['elasticsearch'];
33 public static function run()
36 $sc->checkConfigFiles();
41 $sc->checkMimeTypeDetection();
42 $sc->checkRemoteForking();
47 public function checkConfigFiles()
49 foreach ($GLOBALS['phorkie']['cfgfiles'] as $file => $loaded) {
51 $this->ok('Loaded config file: ' . Tools::foldPath($file));
54 'Possible config file: ' . Tools::foldPath($file)
61 public function checkDeps()
63 foreach ($this->deps as $package => $class) {
64 if (!class_exists($class, true)) {
65 $this->fail('PEAR package not installed: ' . $package);
69 if (!class_exists('geshi', true)) {
70 $geshi = stream_resolve_include_path(
71 $GLOBALS['phorkie']['cfg']['geshi']
73 if ($geshi === false) {
74 $this->fail('GeSHi not available');
78 if (!class_exists('\\Michelf\\Markdown', true)) {
79 //PEAR-installed version 1.0.2 has a different API
80 $markdown = stream_resolve_include_path('markdown.php');
81 if ($markdown === false) {
82 $this->fail('Markdown renderer not available');
87 public function checkDirs()
89 foreach ($this->writableDirs as $name => $dir) {
91 $this->fail($name . ' directory does not exist at ' . $dir);
92 } else if (!is_writable($dir)) {
93 $this->fail($name . ' directory is not writable at ' . $dir);
98 public function checkGit()
100 $line = exec('git --version', $lines, $retval);
102 $this->fail('Running git executable failed.');
104 if (!preg_match('#^git version ([0-9.]+(rc[0-9]+)?)$#', $line, $matches)) {
105 $this->fail('git version output format unexpected: ' . $line);
107 if (version_compare($matches[1], '1.7.5') < 0) {
109 'git version needs to be at least 1.7.5, got: ' . $matches[1]
114 public function checkDatabase()
116 if ($this->elasticsearch == '') {
120 $es = parse_url($this->elasticsearch);
121 if (!preg_match("#/.+/#", $es['path'], $matches)) {
123 'Improper elasticsearch url. Elasticsearch requires a'
124 . ' search domain to store your data.'
125 . ' (e.g. http://localhost:9200/phorkie/)'
128 $dbs = new Database();
129 $dbs->getSetup()->setup();
132 public function checkMimeTypeDetection()
134 $rp = new Repository_Post();
135 if ($rp->getType('<?php echo "foo"; ?>') != 'php') {
136 $this->fail('MIME type detection fails');
140 public function checkRemoteForking()
142 if (!isset($GLOBALS['phorkie']['cfg']['git']['public'])
143 || $GLOBALS['phorkie']['cfg']['git']['public'] == ''
146 'No public git URL prefix configured.'
147 . ' Remote forking will not work'
152 public function fail($msg)
154 $this->messages[] = array('error', $msg);
157 public function info($msg)
159 $this->messages[] = array('info', $msg);
162 public function ok($msg)
164 $this->messages[] = array('ok', $msg);