Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App dependencies are now analysed on app enable as well - not only on app install. #26295

Merged
merged 1 commit into from Oct 10, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/private/App/DependencyAnalyzer.php
Expand Up @@ -223,6 +223,9 @@ private function analyzeLibraries(array $dependencies) {
if (!is_array($libs)) {
$libs = [$libs];
}
if (isset($libs['@value'])) {
$libs = [$libs];
}
foreach ($libs as $lib) {
$libName = $this->getValue($lib);
$libVersion = $this->platform->getLibraryVersion($libName);
Expand Down
37 changes: 27 additions & 10 deletions lib/private/legacy/app.php
Expand Up @@ -329,6 +329,13 @@ public static function enable($app, $groups = null) {
self::$enabledAppsCache = []; // 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();
Expand Down Expand Up @@ -1171,16 +1178,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',
[$info['name'], $missingMsg]
)
);
}
self::checkAppDependencies($config, $l, $info);

$config->setAppValue($app, 'enabled', 'yes');
if (isset($appData['id'])) {
Expand Down Expand Up @@ -1351,4 +1349,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]
)
);
}
}
}
12 changes: 8 additions & 4 deletions tests/lib/App/DependencyAnalyzerTest.php
Expand Up @@ -9,7 +9,7 @@

namespace Test\App;

use OC;
use OC\App\DependencyAnalyzer;
use OC\App\Platform;
use OCP\IL10N;
use Test\TestCase;
Expand All @@ -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())
Expand Down Expand Up @@ -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);
}

/**
Expand Down Expand Up @@ -101,6 +101,8 @@ public function testPhpVersion($expectedMissing, $minVersion, $maxVersion, $intS

/**
* @dataProvider providesDatabases
* @param $expectedMissing
* @param $databases
*/
public function testDatabases($expectedMissing, $databases) {
$app = [
Expand Down Expand Up @@ -247,6 +249,8 @@ function providesLibs() {
[['@attributes' => ['min-version' => '2.3', 'max-version' => '2.3'], '@value' => 'curl']]],
[[],
[['@attributes' => ['min-version' => '2', 'max-version' => '2'], '@value' => 'curl']]],
[[],
['@attributes' => ['min-version' => '2', 'max-version' => '2'], '@value' => 'curl']],
];
}

Expand Down