summaryrefslogtreecommitdiffstats
path: root/lib/private
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2014-12-04 17:04:35 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2014-12-11 12:02:11 +0100
commit08f1db445134e98188f3e1e5b6b84a6eac1f6346 (patch)
tree1df2c7365690ecd7277e46b14116bd8b8ca806f9 /lib/private
parentb33d8a3d60555de3e6e99a92eed3a303e55a3380 (diff)
downloadnextcloud-server-08f1db445134e98188f3e1e5b6b84a6eac1f6346.tar.gz
nextcloud-server-08f1db445134e98188f3e1e5b6b84a6eac1f6346.zip
adding dependencies for command line tools
Diffstat (limited to 'lib/private')
-rw-r--r--lib/private/app/dependencyanalyzer.php69
-rw-r--r--lib/private/app/platform.php32
2 files changed, 83 insertions, 18 deletions
diff --git a/lib/private/app/dependencyanalyzer.php b/lib/private/app/dependencyanalyzer.php
index fb4b3761656..172b8e88c06 100644
--- a/lib/private/app/dependencyanalyzer.php
+++ b/lib/private/app/dependencyanalyzer.php
@@ -10,31 +10,31 @@
namespace OC\App;
+use OCP\IL10N;
+
class DependencyAnalyzer {
/** @var Platform */
- private $system;
+ private $platform;
/** @var \OCP\IL10N */
private $l;
/** @var array */
- private $missing;
+ private $missing = array();
/** @var array */
- private $dependencies;
+ private $dependencies = array();
/**
* @param array $app
* @param Platform $platform
* @param \OCP\IL10N $l
*/
- function __construct(array $app, $platform, $l) {
- $this->system = $platform;
+ function __construct(array $app, Platform $platform, IL10N $l) {
+ $this->platform = $platform;
$this->l = $l;
- $this->missing = array();
- $this->dependencies = array();
- if (array_key_exists('dependencies', $app)) {
+ if (isset($app['dependencies'])) {
$this->dependencies = $app['dependencies'];
}
}
@@ -46,20 +46,21 @@ class DependencyAnalyzer {
public function analyze() {
$this->analysePhpVersion();
$this->analyseSupportedDatabases();
+ $this->analyseCommands();
return $this->missing;
}
private function analysePhpVersion() {
if (isset($this->dependencies['php']['@attributes']['min-version'])) {
$minVersion = $this->dependencies['php']['@attributes']['min-version'];
- if (version_compare($this->system->getPhpVersion(), $minVersion, '<')) {
- $this->missing[] = (string)$this->l->t('PHP %s or higher is required.', $minVersion);
+ if (version_compare($this->platform->getPhpVersion(), $minVersion, '<')) {
+ $this->addMissing((string)$this->l->t('PHP %s or higher is required.', $minVersion));
}
}
if (isset($this->dependencies['php']['@attributes']['max-version'])) {
$maxVersion = $this->dependencies['php']['@attributes']['max-version'];
- if (version_compare($this->system->getPhpVersion(), $maxVersion, '>')) {
- $this->missing[] = (string)$this->l->t('PHP with a version less then %s is required.', $maxVersion);
+ if (version_compare($this->platform->getPhpVersion(), $maxVersion, '>')) {
+ $this->addMissing((string)$this->l->t('PHP with a version less then %s is required.', $maxVersion));
}
}
}
@@ -74,14 +75,46 @@ class DependencyAnalyzer {
return;
}
$supportedDatabases = array_map(function($db) {
- if (isset($db['@value'])) {
- return $db['@value'];
- }
- return $db;
+ return $this->getValue($db);
}, $supportedDatabases);
- $currentDatabase = $this->system->getDatabase();
+ $currentDatabase = $this->platform->getDatabase();
if (!in_array($currentDatabase, $supportedDatabases)) {
- $this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases));
+ $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));
+ }
}
}
+
+ /**
+ * @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;
+ }
}
diff --git a/lib/private/app/platform.php b/lib/private/app/platform.php
index 39f8a2979f9..da515a235a2 100644
--- a/lib/private/app/platform.php
+++ b/lib/private/app/platform.php
@@ -12,16 +12,32 @@ namespace OC\App;
use OCP\IConfig;
+/**
+ * Class Platform
+ *
+ * This class basically abstracts any kind of information which can be retrieved from the underlying system.
+ *
+ * @package OC\App
+ */
class Platform {
+ /**
+ * @param IConfig $config
+ */
function __construct(IConfig $config) {
$this->config = $config;
}
+ /**
+ * @return string
+ */
public function getPhpVersion() {
return phpversion();
}
+ /**
+ * @return string
+ */
public function getDatabase() {
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
if ($dbType === 'sqlite3') {
@@ -30,4 +46,20 @@ class Platform {
return $dbType;
}
+
+ /**
+ * @return string
+ */
+ public function getOS() {
+ return php_uname('s');
+ }
+
+ /**
+ * @param $command
+ * @return bool
+ */
+ public function isCommandKnown($command) {
+ $path = \OC_Helper::findBinaryPath($command);
+ return ($path !== null);
+ }
}