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 if (!isset($GLOBALS['phorkie']['cfgfiles'])
50 || count($GLOBALS['phorkie']['cfgfiles']) == 0
52 $this->info('No config files registered');
56 foreach ($GLOBALS['phorkie']['cfgfiles'] as $file => $loaded) {
58 $this->ok('Loaded config file: ' . Tools::foldPath($file));
61 'Possible config file: ' . Tools::foldPath($file)
68 public function checkDeps()
70 foreach ($this->deps as $package => $class) {
71 if (!class_exists($class, true)) {
72 $this->fail('PEAR package not installed: ' . $package);
76 if (!class_exists('geshi', true)) {
77 $geshi = stream_resolve_include_path(
78 $GLOBALS['phorkie']['cfg']['geshi']
80 if ($geshi === false) {
81 $this->fail('GeSHi not available');
85 if (!class_exists('\\Michelf\\Markdown', true)) {
86 //PEAR-installed version 1.0.2 has a different API
87 $markdown = stream_resolve_include_path('markdown.php');
88 if ($markdown === false) {
89 $this->fail('Markdown renderer not available');
94 public function checkDirs()
96 foreach ($this->writableDirs as $name => $dir) {
98 $this->fail($name . ' directory does not exist at ' . $dir);
99 } else if (!is_writable($dir)) {
100 $this->fail($name . ' directory is not writable at ' . $dir);
105 public function checkGit()
107 $line = exec('git --version', $lines, $retval);
109 $this->fail('Running git executable failed.');
111 if (!preg_match('#^git version ([0-9.]+(rc[0-9]+)?)(?: \(Apple Git-\d+\))?$#', $line, $matches)) {
112 $this->fail('git version output format unexpected: ' . $line);
115 if (version_compare($matches[1], '1.7.5') < 0) {
117 'git version needs to be at least 1.7.5, got: ' . $matches[1]
122 public function checkDatabase()
124 if ($this->elasticsearch == '') {
128 $es = parse_url($this->elasticsearch);
129 if (!preg_match("#/.+/#", $es['path'], $matches)) {
131 'Improper elasticsearch url. Elasticsearch requires a'
132 . ' search domain to store your data.'
133 . ' (e.g. http://localhost:9200/phorkie/)'
136 $dbs = new Database();
137 $dbs->getSetup()->setup();
140 public function checkMimeTypeDetection()
142 $rp = new Repository_Post();
143 $type = $rp->getType('<?php echo "foo"; ?>', true);
144 if ($type != 'php') {
145 $msg = 'MIME type detection fails';
146 if ($type instanceof \PEAR_Error) {
147 $msg .= '. Error: ' . $type->getMessage();
153 public function checkRemoteForking()
155 if (!isset($GLOBALS['phorkie']['cfg']['git']['public'])
156 || $GLOBALS['phorkie']['cfg']['git']['public'] == ''
159 'No public git URL prefix configured.'
160 . ' Remote forking will not work'
165 public function fail($msg)
167 $this->messages[] = array('error', $msg);
170 public function info($msg)
172 $this->messages[] = array('info', $msg);
175 public function ok($msg)
177 $this->messages[] = array('ok', $msg);