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']),
29 'cachedir' => Tools::foldPath($cfg['cachedir']),
31 $this->elasticsearch = $cfg['elasticsearch'];
34 public static function run()
37 $sc->checkConfigFiles();
42 $sc->checkMimeTypeDetection();
43 $sc->checkRemoteForking();
48 public function checkConfigFiles()
50 if (!isset($GLOBALS['phorkie']['cfgfiles'])
51 || count($GLOBALS['phorkie']['cfgfiles']) == 0
53 $this->info('No config files registered');
57 foreach ($GLOBALS['phorkie']['cfgfiles'] as $file => $loaded) {
59 $this->ok('Loaded config file: ' . Tools::foldPath($file));
62 'Possible config file: ' . Tools::foldPath($file)
69 public function checkDeps()
71 foreach ($this->deps as $package => $class) {
72 if (!class_exists($class, true)) {
73 $this->fail('PEAR package not installed: ' . $package);
77 if (!class_exists('GeSHi', true)) {
78 $geshi = stream_resolve_include_path(
79 $GLOBALS['phorkie']['cfg']['geshi']
81 if ($geshi === false) {
82 $this->fail('GeSHi not available');
86 if (!class_exists('\\Michelf\\Markdown', true)) {
87 //PEAR-installed version 1.0.2 has a different API
88 $markdown = stream_resolve_include_path('markdown.php');
89 if ($markdown === false) {
90 $this->fail('Markdown renderer not available');
95 public function checkDirs()
97 foreach ($this->writableDirs as $name => $dir) {
99 $this->fail($name . ' directory does not exist at ' . $dir);
100 } else if (!is_writable($dir)) {
101 $this->fail($name . ' directory is not writable at ' . $dir);
106 public function checkGit()
108 $line = exec('git --version', $lines, $retval);
110 $this->fail('Running git executable failed.');
112 if (!preg_match('#^git version ([0-9.]+(rc[0-9]+)?)(?: \(Apple Git-\d+\))?$#', $line, $matches)) {
113 $this->fail('git version output format unexpected: ' . $line);
116 if (version_compare($matches[1], '1.7.5') < 0) {
118 'git version needs to be at least 1.7.5, got: ' . $matches[1]
123 public function checkDatabase()
125 if ($this->elasticsearch == '') {
129 $es = parse_url($this->elasticsearch);
130 if (!preg_match("#/.+/#", $es['path'], $matches)) {
132 'Improper elasticsearch url. Elasticsearch requires a'
133 . ' search domain to store your data.'
134 . ' (e.g. http://localhost:9200/phorkie/)'
137 $dbs = new Database();
138 $dbs->getSetup()->setup();
141 public function checkMimeTypeDetection()
143 $rp = new Repository_Post();
144 $type = $rp->getType('<?php echo "foo"; ?>', true);
145 if ($type != 'php') {
146 $msg = 'MIME type detection fails';
147 if ($type instanceof \PEAR_Error) {
148 $msg .= '. Error: ' . $type->getMessage();
154 public function checkRemoteForking()
156 if (!isset($GLOBALS['phorkie']['cfg']['git']['public'])
157 || $GLOBALS['phorkie']['cfg']['git']['public'] == ''
160 'No public git URL prefix configured.'
161 . ' Remote forking will not work'
166 public function fail($msg)
168 $this->messages[] = array('error', $msg);
171 public function info($msg)
173 $this->messages[] = array('info', $msg);
176 public function ok($msg)
178 $this->messages[] = array('ok', $msg);