Commit b028a6af authored by Thomas Müller's avatar Thomas Müller
Browse files

adjust dependency analyzer to use attributes properly

parent c80ec91f
...@@ -12,13 +12,25 @@ namespace OC\App; ...@@ -12,13 +12,25 @@ namespace OC\App;
class DependencyAnalyzer { class DependencyAnalyzer {
/** @var Platform */
private $system;
/** @var \OCP\IL10N */
private $l;
/** @var array */
private $missing;
/** @var array */
private $dependencies;
/** /**
* @param array $app * @param array $app
* @param Platform $system * @param Platform $platform
* @param \OCP\IL10N $l * @param \OCP\IL10N $l
*/ */
function __construct(array $app, $system, $l) { function __construct(array $app, $platform, $l) {
$this->system = $system; $this->system = $platform;
$this->l = $l; $this->l = $l;
$this->missing = array(); $this->missing = array();
$this->dependencies = array(); $this->dependencies = array();
...@@ -38,18 +50,14 @@ class DependencyAnalyzer { ...@@ -38,18 +50,14 @@ class DependencyAnalyzer {
} }
private function analysePhpVersion() { private function analysePhpVersion() {
if (!array_key_exists('php', $this->dependencies)) { if (isset($this->dependencies['php']['@attributes']['min-version'])) {
return; $minVersion = $this->dependencies['php']['@attributes']['min-version'];
}
if (array_key_exists('min-version', $this->dependencies['php'])) {
$minVersion = $this->dependencies['php']['min-version'];
if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) { if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) {
$this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion); $this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion);
} }
} }
if (array_key_exists('max-version', $this->dependencies['php'])) { if (isset($this->dependencies['php']['@attributes']['max-version'])) {
$maxVersion = $this->dependencies['php']['max-version']; $maxVersion = $this->dependencies['php']['@attributes']['max-version'];
if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) { if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) {
$this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion); $this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion);
} }
...@@ -57,18 +65,23 @@ class DependencyAnalyzer { ...@@ -57,18 +65,23 @@ class DependencyAnalyzer {
} }
private function analyseSupportedDatabases() { private function analyseSupportedDatabases() {
if (!array_key_exists('database', $this->dependencies)) { if (!isset($this->dependencies['databases'])) {
return; return;
} }
$supportedDatabases = $this->dependencies['database']; $supportedDatabases = $this->dependencies['databases'];
if (empty($supportedDatabases)) { if (empty($supportedDatabases)) {
return; return;
} }
$supportedDatabases = array_map(function($db) {
if (isset($db['@value'])) {
return $db['@value'];
}
return $db;
}, $supportedDatabases);
$currentDatabase = $this->system->getDatabase(); $currentDatabase = $this->system->getDatabase();
if (!in_array($currentDatabase, $supportedDatabases)) { if (!in_array($currentDatabase, $supportedDatabases)) {
$this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases)); $this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases));
} }
} }
} }
...@@ -55,10 +55,10 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { ...@@ -55,10 +55,10 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
) )
); );
if (!is_null($minVersion)) { if (!is_null($minVersion)) {
$app['dependencies']['php']['min-version'] = $minVersion; $app['dependencies']['php']['@attributes']['min-version'] = $minVersion;
} }
if (!is_null($maxVersion)) { if (!is_null($maxVersion)) {
$app['dependencies']['php']['max-version'] = $maxVersion; $app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
} }
$analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
$missing = $analyser->analyze(); $missing = $analyser->analyze();
...@@ -77,7 +77,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { ...@@ -77,7 +77,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
) )
); );
if (!is_null($databases)) { if (!is_null($databases)) {
$app['dependencies']['database'] = $databases; $app['dependencies']['databases'] = $databases;
} }
$analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock); $analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
$missing = $analyser->analyze(); $missing = $analyser->analyze();
...@@ -92,7 +92,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase { ...@@ -92,7 +92,7 @@ class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
// non BC - in case on databases are defined -> all are supported // non BC - in case on databases are defined -> all are supported
array(array(), null), array(array(), null),
array(array(), array()), array(array(), array()),
array(array('Following databases are supported: sqlite, postgres'), array('sqlite', 'postgres')), array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))),
); );
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment