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;
|
|
|
|
|
|
|
|
class DependencyAnalyzer {
|
|
|
|
|
2014-12-02 13:49:31 +03:00
|
|
|
/** @var Platform */
|
|
|
|
private $system;
|
|
|
|
|
|
|
|
/** @var \OCP\IL10N */
|
|
|
|
private $l;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $missing;
|
|
|
|
|
|
|
|
/** @var array */
|
|
|
|
private $dependencies;
|
|
|
|
|
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-02 13:49:31 +03:00
|
|
|
function __construct(array $app, $platform, $l) {
|
|
|
|
$this->system = $platform;
|
2014-12-01 23:47:22 +03:00
|
|
|
$this->l = $l;
|
|
|
|
$this->missing = array();
|
|
|
|
$this->dependencies = array();
|
|
|
|
if (array_key_exists('dependencies', $app)) {
|
|
|
|
$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-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-01 23:47:22 +03:00
|
|
|
if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) {
|
|
|
|
$this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion);
|
|
|
|
}
|
|
|
|
}
|
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-01 23:47:22 +03:00
|
|
|
if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) {
|
|
|
|
$this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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) {
|
|
|
|
if (isset($db['@value'])) {
|
|
|
|
return $db['@value'];
|
|
|
|
}
|
|
|
|
return $db;
|
|
|
|
}, $supportedDatabases);
|
2014-12-02 01:43:27 +03:00
|
|
|
$currentDatabase = $this->system->getDatabase();
|
|
|
|
if (!in_array($currentDatabase, $supportedDatabases)) {
|
|
|
|
$this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases));
|
|
|
|
}
|
|
|
|
}
|
2014-12-01 23:47:22 +03:00
|
|
|
}
|