From fe1806c5a7f09a9c6cf6669cdce7986b1df9231d Mon Sep 17 00:00:00 2001 From: Vincent Petry Date: Mon, 10 Oct 2016 09:25:58 +0200 Subject: [PATCH 1/2] [stable9.1] Merge pull request #26295 from owncloud/analyse-dependencies-on-app-enable-as-well App dependencies are now analysed on app enable as well - not only on app install. --- lib/private/App/DependencyAnalyzer.php | 3 ++ lib/private/legacy/app.php | 37 +++++++++++++++++------- tests/lib/App/DependencyAnalyzerTest.php | 12 +++++--- 3 files changed, 38 insertions(+), 14 deletions(-) diff --git a/lib/private/App/DependencyAnalyzer.php b/lib/private/App/DependencyAnalyzer.php index db9130badcd3..790c208731c8 100644 --- a/lib/private/App/DependencyAnalyzer.php +++ b/lib/private/App/DependencyAnalyzer.php @@ -223,6 +223,9 @@ private function analyzeLibraries(array $dependencies) { if (!is_array($libs)) { $libs = array($libs); } + if (isset($libs['@value'])) { + $libs = [$libs]; + } foreach ($libs as $lib) { $libName = $this->getValue($lib); $libVersion = $this->platform->getLibraryVersion($libName); diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 553ded280a43..f3db4067d26d 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -328,6 +328,13 @@ public static function enable($app, $groups = null) { self::$enabledAppsCache = array(); // flush if (!Installer::isInstalled($app)) { $app = self::installApp($app); + } else { + // check for required dependencies + $config = \OC::$server->getConfig(); + $l = \OC::$server->getL10N('core'); + $info = self::getAppInfo($app); + + self::checkAppDependencies($config, $l, $info); } $appManager = \OC::$server->getAppManager(); @@ -1159,16 +1166,7 @@ public static function installApp($app) { } // check for required dependencies - $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); - $missing = $dependencyAnalyzer->analyze($info); - if (!empty($missing)) { - $missingMsg = join(PHP_EOL, $missing); - throw new \Exception( - $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', - array($info['name'], $missingMsg) - ) - ); - } + self::checkAppDependencies($config, $l, $info); $config->setAppValue($app, 'enabled', 'yes'); if (isset($appData['id'])) { @@ -1335,4 +1333,23 @@ public static function parseAppInfo(array $data) { return $data; } + + /** + * @param $config + * @param $l + * @param $info + * @throws Exception + */ + protected static function checkAppDependencies($config, $l, $info) { + $dependencyAnalyzer = new DependencyAnalyzer(new Platform($config), $l); + $missing = $dependencyAnalyzer->analyze($info); + if (!empty($missing)) { + $missingMsg = join(PHP_EOL, $missing); + throw new \Exception( + $l->t('App "%s" cannot be installed because the following dependencies are not fulfilled: %s', + [$info['name'], $missingMsg] + ) + ); + } + } } diff --git a/tests/lib/App/DependencyAnalyzerTest.php b/tests/lib/App/DependencyAnalyzerTest.php index 7882f6dd0315..2da6529bae28 100644 --- a/tests/lib/App/DependencyAnalyzerTest.php +++ b/tests/lib/App/DependencyAnalyzerTest.php @@ -9,7 +9,7 @@ namespace Test\App; -use OC; +use OC\App\DependencyAnalyzer; use OC\App\Platform; use OCP\IL10N; use Test\TestCase; @@ -22,11 +22,11 @@ class DependencyAnalyzerTest extends TestCase { /** @var IL10N */ private $l10nMock; - /** @var \OC\App\DependencyAnalyzer */ + /** @var DependencyAnalyzer */ private $analyser; public function setUp() { - $this->platformMock = $this->getMockBuilder('\OC\App\Platform') + $this->platformMock = $this->getMockBuilder(Platform::class) ->disableOriginalConstructor() ->getMock(); $this->platformMock->expects($this->any()) @@ -67,7 +67,7 @@ public function setUp() { return vsprintf($text, $parameters); })); - $this->analyser = new \OC\App\DependencyAnalyzer($this->platformMock, $this->l10nMock); + $this->analyser = new DependencyAnalyzer($this->platformMock, $this->l10nMock); } /** @@ -101,6 +101,8 @@ public function testPhpVersion($expectedMissing, $minVersion, $maxVersion, $intS /** * @dataProvider providesDatabases + * @param $expectedMissing + * @param $databases */ public function testDatabases($expectedMissing, $databases) { $app = array( @@ -247,6 +249,8 @@ function providesLibs() { array(array('@attributes' => array('min-version' => '2.3', 'max-version' => '2.3'), '@value' => 'curl'))), array(array(), array(array('@attributes' => array('min-version' => '2', 'max-version' => '2'), '@value' => 'curl'))), + array(array(), + array('@attributes' => array('min-version' => '2', 'max-version' => '2'), '@value' => 'curl')), ); } From db197999cd40476d2428471d9b9a2d19178605a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Mon, 10 Oct 2016 12:45:24 +0200 Subject: [PATCH 2/2] PHP 5.4 compliant --- tests/lib/App/DependencyAnalyzerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/lib/App/DependencyAnalyzerTest.php b/tests/lib/App/DependencyAnalyzerTest.php index 2da6529bae28..aa7aecf8434a 100644 --- a/tests/lib/App/DependencyAnalyzerTest.php +++ b/tests/lib/App/DependencyAnalyzerTest.php @@ -26,7 +26,7 @@ class DependencyAnalyzerTest extends TestCase { private $analyser; public function setUp() { - $this->platformMock = $this->getMockBuilder(Platform::class) + $this->platformMock = $this->getMockBuilder('\OC\App\Platform') ->disableOriginalConstructor() ->getMock(); $this->platformMock->expects($this->any())