2014-12-01 23:47:22 +03:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* @author Thomas Müller
|
|
|
|
* @copyright 2014 Thomas Müller deepdiver@owncloud.com
|
|
|
|
*
|
|
|
|
* This file is licensed under the Affero General Public License version 3 or
|
|
|
|
* later.
|
|
|
|
* See the COPYING-README file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace OC\App;
|
|
|
|
|
2014-12-04 19:04:35 +03:00
|
|
|
use OCP\IL10N;
|
|
|
|
|
2014-12-01 23:47:22 +03:00
|
|
|
class DependencyAnalyzer {
|
|
|
|
|
2014-12-02 13:49:31 +03:00
|
|
|
/** @var Platform */
|
2014-12-04 19:04:35 +03:00
|
|
|
private $platform;
|
2014-12-02 13:49:31 +03:00
|
|
|
|
|
|
|
/** @var \OCP\IL10N */
|
|
|
|
private $l;
|
|
|
|
|
|
|
|
/** @var array */
|
2014-12-04 19:04:35 +03:00
|
|
|
private $missing = array();
|
2014-12-02 13:49:31 +03:00
|
|
|
|
|
|
|
/** @var array */
|
2014-12-04 19:04:35 +03:00
|
|
|
private $dependencies = array();
|
2014-12-02 13:49:31 +03:00
|
|
|
|
2014-12-01 23:47:22 +03:00
|
|
|
/**
|
|
|
|
* @param array $app
|
2014-12-02 13:49:31 +03:00
|
|
|
* @param Platform $platform
|
2014-12-01 23:47:22 +03:00
|
|
|
* @param \OCP\IL10N $l
|
|
|
|
*/
|
2014-12-04 19:04:35 +03:00
|
|
|
function __construct(array $app, Platform $platform, IL10N $l) {
|
|
|
|
$this->platform = $platform;
|
2014-12-01 23:47:22 +03:00
|
|
|
$this->l = $l;
|
2014-12-04 19:04:35 +03:00
|
|
|
if (isset($app['dependencies'])) {
|
2014-12-01 23:47:22 +03:00
|
|
|
$this->dependencies = $app['dependencies'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param array $app
|
|
|
|
* @returns array of missing dependencies
|
|
|
|
*/
|
|
|
|
public function analyze() {
|
|
|
|
$this->analysePhpVersion();
|
2014-12-02 01:43:27 +03:00
|
|
|
$this->analyseSupportedDatabases();
|
2014-12-04 19:04:35 +03:00
|
|
|
$this->analyseCommands();
|
2014-12-01 23:47:22 +03:00
|
|
|
return $this->missing;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function analysePhpVersion() {
|
2014-12-02 13:49:31 +03:00
|
|
|
if (isset($this->dependencies['php']['@attributes']['min-version'])) {
|
|
|
|
$minVersion = $this->dependencies['php']['@attributes']['min-version'];
|
2014-12-04 19:04:35 +03:00
|
|
|
if (version_compare($this->platform->getPhpVersion(), $minVersion, '<')) {
|
|
|
|
$this->addMissing((string)$this->l->t('PHP %s or higher is required.', $minVersion));
|
2014-12-01 23:47:22 +03:00
|
|
|
}
|
|
|
|
}
|
2014-12-02 13:49:31 +03:00
|
|
|
if (isset($this->dependencies['php']['@attributes']['max-version'])) {
|
|
|
|
$maxVersion = $this->dependencies['php']['@attributes']['max-version'];
|
2014-12-04 19:04:35 +03:00
|
|
|
if (version_compare($this->platform->getPhpVersion(), $maxVersion, '>')) {
|
|
|
|
$this->addMissing((string)$this->l->t('PHP with a version less then %s is required.', $maxVersion));
|
2014-12-01 23:47:22 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-12-02 01:43:27 +03:00
|
|
|
private function analyseSupportedDatabases() {
|
2014-12-02 17:14:48 +03:00
|
|
|
if (!isset($this->dependencies['database'])) {
|
2014-12-02 01:43:27 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-12-02 17:14:48 +03:00
|
|
|
$supportedDatabases = $this->dependencies['database'];
|
2014-12-02 01:43:27 +03:00
|
|
|
if (empty($supportedDatabases)) {
|
|
|
|
return;
|
|
|
|
}
|
2014-12-02 13:49:31 +03:00
|
|
|
$supportedDatabases = array_map(function($db) {
|
2014-12-04 19:04:35 +03:00
|
|
|
return $this->getValue($db);
|
2014-12-02 13:49:31 +03:00
|
|
|
}, $supportedDatabases);
|
2014-12-04 19:04:35 +03:00
|
|
|
$currentDatabase = $this->platform->getDatabase();
|
2014-12-02 01:43:27 +03:00
|
|
|
if (!in_array($currentDatabase, $supportedDatabases)) {
|
2014-12-04 19:04:35 +03:00
|
|
|
$this->addMissing((string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function analyseCommands() {
|
|
|
|
if (!isset($this->dependencies['command'])) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$commands = $this->dependencies['command'];
|
|
|
|
$os = $this->platform->getOS();
|
|
|
|
foreach($commands as $command) {
|
|
|
|
if (isset($command['@attributes']['os']) && $command['@attributes']['os'] !== $os) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
$commandName = $this->getValue($command);
|
|
|
|
if (!$this->platform->isCommandKnown($commandName)) {
|
|
|
|
$this->addMissing((string)$this->l->t('The command line tool %s could not be found', $commandName));
|
|
|
|
}
|
2014-12-02 01:43:27 +03:00
|
|
|
}
|
|
|
|
}
|
2014-12-04 19:04:35 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $element
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
private function getValue($element) {
|
|
|
|
if (isset($element['@value']))
|
|
|
|
return $element['@value'];
|
|
|
|
return strval($element);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $minVersion
|
|
|
|
*/
|
|
|
|
private function addMissing($message) {
|
|
|
|
$this->missing[] = $message;
|
|
|
|
}
|
2014-12-01 23:47:22 +03:00
|
|
|
}
|