mirror of https://github.com/nextcloud/server.git
Merge pull request #12533 from owncloud/app-dependencies-php-version
App dependencies php versionremotes/origin/fix-10825
commit
884eb14181
@ -0,0 +1,87 @@
|
||||
<?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 {
|
||||
|
||||
/** @var Platform */
|
||||
private $system;
|
||||
|
||||
/** @var \OCP\IL10N */
|
||||
private $l;
|
||||
|
||||
/** @var array */
|
||||
private $missing;
|
||||
|
||||
/** @var array */
|
||||
private $dependencies;
|
||||
|
||||
/**
|
||||
* @param array $app
|
||||
* @param Platform $platform
|
||||
* @param \OCP\IL10N $l
|
||||
*/
|
||||
function __construct(array $app, $platform, $l) {
|
||||
$this->system = $platform;
|
||||
$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();
|
||||
$this->analyseSupportedDatabases();
|
||||
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 (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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private function analyseSupportedDatabases() {
|
||||
if (!isset($this->dependencies['database'])) {
|
||||
return;
|
||||
}
|
||||
|
||||
$supportedDatabases = $this->dependencies['database'];
|
||||
if (empty($supportedDatabases)) {
|
||||
return;
|
||||
}
|
||||
$supportedDatabases = array_map(function($db) {
|
||||
if (isset($db['@value'])) {
|
||||
return $db['@value'];
|
||||
}
|
||||
return $db;
|
||||
}, $supportedDatabases);
|
||||
$currentDatabase = $this->system->getDatabase();
|
||||
if (!in_array($currentDatabase, $supportedDatabases)) {
|
||||
$this->missing[] = (string)$this->l->t('Following databases are supported: %s', join(', ', $supportedDatabases));
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?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;
|
||||
|
||||
use OCP\IConfig;
|
||||
|
||||
class Platform {
|
||||
|
||||
function __construct(IConfig $config) {
|
||||
$this->config = $config;
|
||||
}
|
||||
|
||||
public function getPhpVersion() {
|
||||
return phpversion();
|
||||
}
|
||||
|
||||
public function getDatabase() {
|
||||
$dbType = $this->config->getSystemValue('dbtype', 'sqlite');
|
||||
if ($dbType === 'sqlite3') {
|
||||
$dbType = 'sqlite';
|
||||
}
|
||||
|
||||
return $dbType;
|
||||
}
|
||||
}
|
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* @author Thomas Müller
|
||||
* @copyright 2014 Thomas Müller deepdiver@owncloud.com
|
||||
* later.
|
||||
* See the COPYING-README file.
|
||||
*/
|
||||
|
||||
namespace Test\App;
|
||||
|
||||
use OC;
|
||||
use OC\App\Platform;
|
||||
use OCP\IL10N;
|
||||
|
||||
class DependencyAnalyzer extends \PHPUnit_Framework_TestCase {
|
||||
|
||||
/**
|
||||
* @var Platform
|
||||
*/
|
||||
private $platformMock;
|
||||
|
||||
/**
|
||||
* @var IL10N
|
||||
*/
|
||||
private $l10nMock;
|
||||
|
||||
public function setUp() {
|
||||
$this->platformMock = $this->getMockBuilder('\OC\App\Platform')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->platformMock->expects($this->any())
|
||||
->method('getPhpVersion')
|
||||
->will( $this->returnValue('5.4.3'));
|
||||
$this->platformMock->expects($this->any())
|
||||
->method('getDatabase')
|
||||
->will( $this->returnValue('mysql'));
|
||||
$this->l10nMock = $this->getMockBuilder('\OCP\IL10N')
|
||||
->disableOriginalConstructor()
|
||||
->getMock();
|
||||
$this->l10nMock->expects($this->any())
|
||||
->method('t')
|
||||
->will($this->returnCallback(function($text, $parameters = array()) {
|
||||
return vsprintf($text, $parameters);
|
||||
}));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providesPhpVersion
|
||||
*/
|
||||
public function testPhpVersion($expectedMissing, $minVersion, $maxVersion) {
|
||||
$app = array(
|
||||
'dependencies' => array(
|
||||
'php' => array()
|
||||
)
|
||||
);
|
||||
if (!is_null($minVersion)) {
|
||||
$app['dependencies']['php']['@attributes']['min-version'] = $minVersion;
|
||||
}
|
||||
if (!is_null($maxVersion)) {
|
||||
$app['dependencies']['php']['@attributes']['max-version'] = $maxVersion;
|
||||
}
|
||||
$analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
|
||||
$missing = $analyser->analyze();
|
||||
|
||||
$this->assertTrue(is_array($missing));
|
||||
$this->assertEquals(count($expectedMissing), count($missing));
|
||||
$this->assertEquals($expectedMissing, $missing);
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider providesDatabases
|
||||
*/
|
||||
public function testDatabases($expectedMissing, $databases) {
|
||||
$app = array(
|
||||
'dependencies' => array(
|
||||
)
|
||||
);
|
||||
if (!is_null($databases)) {
|
||||
$app['dependencies']['database'] = $databases;
|
||||
}
|
||||
$analyser = new \OC\App\DependencyAnalyzer($app, $this->platformMock, $this->l10nMock);
|
||||
$missing = $analyser->analyze();
|
||||
|
||||
$this->assertTrue(is_array($missing));
|
||||
$this->assertEquals(count($expectedMissing), count($missing));
|
||||
$this->assertEquals($expectedMissing, $missing);
|
||||
}
|
||||
|
||||
function providesDatabases() {
|
||||
return array(
|
||||
// non BC - in case on databases are defined -> all are supported
|
||||
array(array(), null),
|
||||
array(array(), array()),
|
||||
array(array('Following databases are supported: sqlite, postgres'), array('sqlite', array('@value' => 'postgres'))),
|
||||
);
|
||||
}
|
||||
|
||||
function providesPhpVersion() {
|
||||
return array(
|
||||
array(array(), null, null),
|
||||
array(array(), '5.4', null),
|
||||
array(array(), null, '5.5'),
|
||||
array(array(), '5.4', '5.5'),
|
||||
array(array('PHP 5.4.4 or higher is required.'), '5.4.4', null),
|
||||
array(array('PHP with a version less then 5.4.2 is required.'), null, '5.4.2'),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue