summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLukas Reschke <lukas@statuscode.ch>2017-11-27 11:48:59 +0100
committerGitHub <noreply@github.com>2017-11-27 11:48:59 +0100
commit8ccb4868762b13adc02f49654a7867b556009a41 (patch)
treebfdbb3deea57edf49122c12c05ef28b7c61a25cf
parentf0d809fddecd63ca16028222a355b1c7f5aca4d9 (diff)
parentdf61d43529418aace241b99be106ff9a35188dac (diff)
downloadnextcloud-server-8ccb4868762b13adc02f49654a7867b556009a41.tar.gz
nextcloud-server-8ccb4868762b13adc02f49654a7867b556009a41.zip
Merge pull request #7264 from nextcloud/cache-fetched-apps
Cache fetched apps in update check
-rw-r--r--apps/updatenotification/lib/Notification/BackgroundJob.php9
-rw-r--r--apps/updatenotification/tests/Notification/BackgroundJobTest.php8
-rw-r--r--core/Command/App/Install.php8
-rw-r--r--core/Command/Maintenance/Install.php13
-rw-r--r--core/Command/Upgrade.php8
-rw-r--r--core/ajax/update.php3
-rw-r--r--core/register_command.php2
-rw-r--r--lib/base.php12
-rw-r--r--lib/private/Installer.php25
-rw-r--r--lib/private/Server.php10
-rw-r--r--lib/private/Setup.php28
-rw-r--r--lib/private/Updater.php19
-rw-r--r--lib/private/legacy/app.php16
-rw-r--r--lib/private/legacy/util.php11
-rw-r--r--settings/Controller/AppSettingsController.php19
-rw-r--r--settings/ajax/updateapp.php8
-rw-r--r--tests/Settings/Controller/AppSettingsControllerTest.php10
-rw-r--r--tests/lib/InstallerTest.php47
-rw-r--r--tests/lib/SetupTest.php6
-rw-r--r--tests/lib/UpdaterTest.php13
20 files changed, 168 insertions, 107 deletions
diff --git a/apps/updatenotification/lib/Notification/BackgroundJob.php b/apps/updatenotification/lib/Notification/BackgroundJob.php
index 08baa35664f..3c0cac60cde 100644
--- a/apps/updatenotification/lib/Notification/BackgroundJob.php
+++ b/apps/updatenotification/lib/Notification/BackgroundJob.php
@@ -53,6 +53,9 @@ class BackgroundJob extends TimedJob {
/** @var IClientService */
protected $client;
+ /** @var Installer */
+ protected $installer;
+
/** @var string[] */
protected $users;
@@ -64,8 +67,9 @@ class BackgroundJob extends TimedJob {
* @param IGroupManager $groupManager
* @param IAppManager $appManager
* @param IClientService $client
+ * @param Installer $installer
*/
- public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client) {
+ public function __construct(IConfig $config, IManager $notificationManager, IGroupManager $groupManager, IAppManager $appManager, IClientService $client, Installer $installer) {
// Run once a day
$this->setInterval(60 * 60 * 24);
@@ -74,6 +78,7 @@ class BackgroundJob extends TimedJob {
$this->groupManager = $groupManager;
$this->appManager = $appManager;
$this->client = $client;
+ $this->installer = $installer;
}
protected function run($argument) {
@@ -257,6 +262,6 @@ class BackgroundJob extends TimedJob {
* @return string|false
*/
protected function isUpdateAvailable($app) {
- return Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher());
+ return $this->installer->isUpdateAvailable($app);
}
}
diff --git a/apps/updatenotification/tests/Notification/BackgroundJobTest.php b/apps/updatenotification/tests/Notification/BackgroundJobTest.php
index 92a8a687f5a..0355b10a09c 100644
--- a/apps/updatenotification/tests/Notification/BackgroundJobTest.php
+++ b/apps/updatenotification/tests/Notification/BackgroundJobTest.php
@@ -23,6 +23,7 @@
namespace OCA\UpdateNotification\Tests\Notification;
+use OC\Installer;
use OCA\UpdateNotification\Notification\BackgroundJob;
use OCP\App\IAppManager;
use OCP\Http\Client\IClientService;
@@ -47,6 +48,8 @@ class BackgroundJobTest extends TestCase {
protected $appManager;
/** @var IClientService|\PHPUnit_Framework_MockObject_MockObject */
protected $client;
+ /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
+ protected $installer;
public function setUp() {
parent::setUp();
@@ -56,6 +59,7 @@ class BackgroundJobTest extends TestCase {
$this->groupManager = $this->createMock(IGroupManager::class);
$this->appManager = $this->createMock(IAppManager::class);
$this->client = $this->createMock(IClientService::class);
+ $this->installer = $this->createMock(Installer::class);
}
/**
@@ -69,7 +73,8 @@ class BackgroundJobTest extends TestCase {
$this->notificationManager,
$this->groupManager,
$this->appManager,
- $this->client
+ $this->client,
+ $this->installer
);
} {
return $this->getMockBuilder(BackgroundJob::class)
@@ -79,6 +84,7 @@ class BackgroundJobTest extends TestCase {
$this->groupManager,
$this->appManager,
$this->client,
+ $this->installer,
])
->setMethods($methods)
->getMock();
diff --git a/core/Command/App/Install.php b/core/Command/App/Install.php
index c8c4652d7ba..8f530975be9 100644
--- a/core/Command/App/Install.php
+++ b/core/Command/App/Install.php
@@ -51,13 +51,7 @@ class Install extends Command {
}
try {
- $installer = new Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->getLogger(),
- \OC::$server->getConfig()
- );
+ $installer = \OC::$server->query(Installer::class);
$installer->downloadApp($appId);
$result = $installer->installApp($appId);
} catch(\Exception $e) {
diff --git a/core/Command/Maintenance/Install.php b/core/Command/Maintenance/Install.php
index 755d3d386c1..be6a2da22c8 100644
--- a/core/Command/Maintenance/Install.php
+++ b/core/Command/Maintenance/Install.php
@@ -30,6 +30,7 @@
namespace OC\Core\Command\Maintenance;
use InvalidArgumentException;
+use OC\Installer;
use OC\Setup;
use OC\SystemConfig;
use OCP\Defaults;
@@ -73,9 +74,15 @@ class Install extends Command {
// validate the environment
$server = \OC::$server;
- $setupHelper = new Setup($this->config, $server->getIniWrapper(),
- $server->getL10N('lib'), $server->query(Defaults::class), $server->getLogger(),
- $server->getSecureRandom());
+ $setupHelper = new Setup(
+ $this->config,
+ $server->getIniWrapper(),
+ $server->getL10N('lib'),
+ $server->query(Defaults::class),
+ $server->getLogger(),
+ $server->getSecureRandom(),
+ \OC::$server->query(Installer::class)
+ );
$sysInfo = $setupHelper->getSystemInfo(true);
$errors = $sysInfo['errors'];
if (count($errors) > 0) {
diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php
index 0877c19bc01..2a502dbe921 100644
--- a/core/Command/Upgrade.php
+++ b/core/Command/Upgrade.php
@@ -35,6 +35,7 @@
namespace OC\Core\Command;
use OC\Console\TimestampFormatter;
+use OC\Installer;
use OC\Updater;
use OCP\IConfig;
use OCP\ILogger;
@@ -63,11 +64,13 @@ class Upgrade extends Command {
/**
* @param IConfig $config
* @param ILogger $logger
+ * @param Installer $installer
*/
- public function __construct(IConfig $config, ILogger $logger) {
+ public function __construct(IConfig $config, ILogger $logger, Installer $installer) {
parent::__construct();
$this->config = $config;
$this->logger = $logger;
+ $this->installer = $installer;
}
protected function configure() {
@@ -101,7 +104,8 @@ class Upgrade extends Command {
$updater = new Updater(
$this->config,
\OC::$server->getIntegrityCodeChecker(),
- $this->logger
+ $this->logger,
+ $this->installer
);
if ($input->getOption('no-app-disable')) {
diff --git a/core/ajax/update.php b/core/ajax/update.php
index 71d60f5c432..2a29d1e536c 100644
--- a/core/ajax/update.php
+++ b/core/ajax/update.php
@@ -116,7 +116,8 @@ if (OC::checkUpgrade(false)) {
$updater = new \OC\Updater(
$config,
\OC::$server->getIntegrityCodeChecker(),
- $logger
+ $logger,
+ \OC::$server->query(\OC\Installer::class)
);
$incompatibleApps = [];
$disabledThirdPartyApps = [];
diff --git a/core/register_command.php b/core/register_command.php
index 3f7fbf508e5..60e151a5f2c 100644
--- a/core/register_command.php
+++ b/core/register_command.php
@@ -137,7 +137,7 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) {
$application->add(new OC\Core\Command\Maintenance\UpdateHtaccess());
$application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory()));
- $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger()));
+ $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class)));
$application->add(new OC\Core\Command\Maintenance\Repair(
new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(),
\OC::$server->getEventDispatcher(), \OC::$server->getAppManager()));
diff --git a/lib/base.php b/lib/base.php
index 6193b591ab5..f6b4f5555eb 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -923,9 +923,15 @@ class OC {
// Check if Nextcloud is installed or in maintenance (update) mode
if (!$systemConfig->getValue('installed', false)) {
\OC::$server->getSession()->clear();
- $setupHelper = new OC\Setup(\OC::$server->getSystemConfig(), \OC::$server->getIniWrapper(),
- \OC::$server->getL10N('lib'), \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(),
- \OC::$server->getSecureRandom());
+ $setupHelper = new OC\Setup(
+ \OC::$server->getSystemConfig(),
+ \OC::$server->getIniWrapper(),
+ \OC::$server->getL10N('lib'),
+ \OC::$server->query(\OCP\Defaults::class),
+ \OC::$server->getLogger(),
+ \OC::$server->getSecureRandom(),
+ \OC::$server->query(\OC\Installer::class)
+ );
$controller = new OC\Core\Controller\SetupController($setupHelper);
$controller->run($_POST);
exit();
diff --git a/lib/private/Installer.php b/lib/private/Installer.php
index 45bec26831e..48bd57f4c10 100644
--- a/lib/private/Installer.php
+++ b/lib/private/Installer.php
@@ -67,6 +67,10 @@ class Installer {
private $logger;
/** @var IConfig */
private $config;
+ /** @var array - for caching the result of app fetcher */
+ private $apps = null;
+ /** @var bool|null - for caching the result of the ready status */
+ private $isInstanceReadyForUpdates = null;
/**
* @param AppFetcher $appFetcher
@@ -187,7 +191,7 @@ class Installer {
* @return bool
*/
public function updateAppstoreApp($appId) {
- if(self::isUpdateAvailable($appId, $this->appFetcher)) {
+ if($this->isUpdateAvailable($appId)) {
try {
$this->downloadApp($appId);
} catch (\Exception $e) {
@@ -375,27 +379,26 @@ class Installer {
* Check if an update for the app is available
*
* @param string $appId
- * @param AppFetcher $appFetcher
* @return string|false false or the version number of the update
*/
- public static function isUpdateAvailable($appId,
- AppFetcher $appFetcher) {
- static $isInstanceReadyForUpdates = null;
-
- if ($isInstanceReadyForUpdates === null) {
+ public function isUpdateAvailable($appId) {
+ if ($this->isInstanceReadyForUpdates === null) {
$installPath = OC_App::getInstallPath();
if ($installPath === false || $installPath === null) {
- $isInstanceReadyForUpdates = false;
+ $this->isInstanceReadyForUpdates = false;
} else {
- $isInstanceReadyForUpdates = true;
+ $this->isInstanceReadyForUpdates = true;
}
}
- if ($isInstanceReadyForUpdates === false) {
+ if ($this->isInstanceReadyForUpdates === false) {
return false;
}
- $apps = $appFetcher->get();
+ if ($this->apps === null) {
+ $apps = $this->appFetcher->get();
+ }
+
foreach($apps as $app) {
if($app['id'] === $appId) {
$currentVersion = OC_App::getAppVersion($appId);
diff --git a/lib/private/Server.php b/lib/private/Server.php
index faa0ce2f2ac..0c6338f6a4c 100644
--- a/lib/private/Server.php
+++ b/lib/private/Server.php
@@ -1099,6 +1099,16 @@ class Server extends ServerContainer implements IServerContainer {
$c->query(\OCP\Share\IManager::class)
);
});
+
+ $this->registerService(Installer::class, function(Server $c) {
+ return new Installer(
+ $c->getAppFetcher(),
+ $c->getHTTPClientService(),
+ $c->getTempManager(),
+ $c->getLogger(),
+ $c->getConfig()
+ );
+ });
}
/**
diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index 8214db2d4ef..92246e8322e 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -65,6 +65,8 @@ class Setup {
protected $logger;
/** @var ISecureRandom */
protected $random;
+ /** @var Installer */
+ protected $installer;
/**
* @param SystemConfig $config
@@ -73,13 +75,15 @@ class Setup {
* @param Defaults $defaults
* @param ILogger $logger
* @param ISecureRandom $random
+ * @param Installer $installer
*/
public function __construct(SystemConfig $config,
IniGetWrapper $iniWrapper,
IL10N $l10n,
Defaults $defaults,
ILogger $logger,
- ISecureRandom $random
+ ISecureRandom $random,
+ Installer $installer
) {
$this->config = $config;
$this->iniWrapper = $iniWrapper;
@@ -87,6 +91,7 @@ class Setup {
$this->defaults = $defaults;
$this->logger = $logger;
$this->random = $random;
+ $this->installer = $installer;
}
static protected $dbSetupClasses = [
@@ -371,18 +376,11 @@ class Setup {
// Install shipped apps and specified app bundles
Installer::installShippedApps();
- $installer = new Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->getLogger(),
- \OC::$server->getConfig()
- );
$bundleFetcher = new BundleFetcher(\OC::$server->getL10N('lib'));
$defaultInstallationBundles = $bundleFetcher->getDefaultInstallationBundle();
foreach($defaultInstallationBundles as $bundle) {
try {
- $installer->installAppBundle($bundle);
+ $this->installer->installAppBundle($bundle);
} catch (Exception $e) {}
}
@@ -444,9 +442,15 @@ class Setup {
$webRoot = !empty(\OC::$WEBROOT) ? \OC::$WEBROOT : '/';
}
- $setupHelper = new \OC\Setup($config, \OC::$server->getIniWrapper(),
- \OC::$server->getL10N('lib'), \OC::$server->query(Defaults::class), \OC::$server->getLogger(),
- \OC::$server->getSecureRandom());
+ $setupHelper = new \OC\Setup(
+ $config,
+ \OC::$server->getIniWrapper(),
+ \OC::$server->getL10N('lib'),
+ \OC::$server->query(Defaults::class),
+ \OC::$server->getLogger(),
+ \OC::$server->getSecureRandom(),
+ \OC::$server->query(Installer::class)
+ );
$htaccessContent = file_get_contents($setupHelper->pathToHtaccess());
$content = "#### DO NOT CHANGE ANYTHING ABOVE THIS LINE ####\n";
diff --git a/lib/private/Updater.php b/lib/private/Updater.php
index 4f5bb45ae15..996163daacc 100644
--- a/lib/private/Updater.php
+++ b/lib/private/Updater.php
@@ -63,6 +63,9 @@ class Updater extends BasicEmitter {
/** @var Checker */
private $checker;
+ /** @var Installer */
+ private $installer;
+
/** @var bool */
private $skip3rdPartyAppsDisable;
@@ -78,13 +81,16 @@ class Updater extends BasicEmitter {
* @param IConfig $config
* @param Checker $checker
* @param ILogger $log
+ * @param Installer $installer
*/
public function __construct(IConfig $config,
Checker $checker,
- ILogger $log = null) {
+ ILogger $log = null,
+ Installer $installer) {
$this->log = $log;
$this->config = $config;
$this->checker = $checker;
+ $this->installer = $installer;
// If at least PHP 7.0.0 is used we don't need to disable apps as we catch
// fatal errors and exceptions and disable the app just instead.
@@ -461,17 +467,10 @@ class Updater extends BasicEmitter {
private function upgradeAppStoreApps(array $disabledApps) {
foreach($disabledApps as $app) {
try {
- $installer = new Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- $this->log,
- \OC::$server->getConfig()
- );
$this->emit('\OC\Updater', 'checkAppStoreAppBefore', [$app]);
- if (Installer::isUpdateAvailable($app, \OC::$server->getAppFetcher())) {
+ if ($this->installer->isUpdateAvailable($app)) {
$this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
- $installer->updateAppstoreApp($app);
+ $this->installer->updateAppstoreApp($app);
}
$this->emit('\OC\Updater', 'checkAppStoreApp', [$app]);
} catch (\Exception $ex) {
diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php
index d2b0f96d593..1b9fc28873e 100644
--- a/lib/private/legacy/app.php
+++ b/lib/private/legacy/app.php
@@ -375,13 +375,7 @@ class OC_App {
self::$enabledAppsCache = []; // flush
// Check if app is already downloaded
- $installer = new Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->getLogger(),
- \OC::$server->getConfig()
- );
+ $installer = \OC::$server->query(Installer::class);
$isDownloaded = $installer->isDownloaded($appId);
if(!$isDownloaded) {
@@ -415,13 +409,7 @@ class OC_App {
return false;
}
- $installer = new Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->getLogger(),
- \OC::$server->getConfig()
- );
+ $installer = \OC::$server->query(Installer::class);
return $installer->removeApp($app);
}
diff --git a/lib/private/legacy/util.php b/lib/private/legacy/util.php
index 1e9090960c1..3ce11746672 100644
--- a/lib/private/legacy/util.php
+++ b/lib/private/legacy/util.php
@@ -708,8 +708,15 @@ class OC_Util {
}
$webServerRestart = false;
- $setup = new \OC\Setup($config, \OC::$server->getIniWrapper(), \OC::$server->getL10N('lib'),
- \OC::$server->query(\OCP\Defaults::class), \OC::$server->getLogger(), \OC::$server->getSecureRandom());
+ $setup = new \OC\Setup(
+ $config,
+ \OC::$server->getIniWrapper(),
+ \OC::$server->getL10N('lib'),
+ \OC::$server->query(\OCP\Defaults::class),
+ \OC::$server->getLogger(),
+ \OC::$server->getSecureRandom(),
+ \OC::$server->query(\OC\Installer::class)
+ );
$urlGenerator = \OC::$server->getURLGenerator();
diff --git a/settings/Controller/AppSettingsController.php b/settings/Controller/AppSettingsController.php
index 26858eabcf3..f2a92b52f6d 100644
--- a/settings/Controller/AppSettingsController.php
+++ b/settings/Controller/AppSettingsController.php
@@ -37,6 +37,7 @@ use OC\App\AppStore\Fetcher\CategoryFetcher;
use OC\App\AppStore\Version\VersionParser;
use OC\App\DependencyAnalyzer;
use OC\App\Platform;
+use OC\Installer;
use OCP\App\IAppManager;
use \OCP\AppFramework\Controller;
use OCP\AppFramework\Http\ContentSecurityPolicy;
@@ -74,6 +75,8 @@ class AppSettingsController extends Controller {
private $l10nFactory;
/** @var BundleFetcher */
private $bundleFetcher;
+ /** @var Installer */
+ private $installer;
/**
* @param string $appName
@@ -86,6 +89,7 @@ class AppSettingsController extends Controller {
* @param AppFetcher $appFetcher
* @param IFactory $l10nFactory
* @param BundleFetcher $bundleFetcher
+ * @param Installer $installer
*/
public function __construct($appName,
IRequest $request,
@@ -96,7 +100,8 @@ class AppSettingsController extends Controller {
CategoryFetcher $categoryFetcher,
AppFetcher $appFetcher,
IFactory $l10nFactory,
- BundleFetcher $bundleFetcher) {
+ BundleFetcher $bundleFetcher,
+ Installer $installer) {
parent::__construct($appName, $request);
$this->l10n = $l10n;
$this->config = $config;
@@ -106,6 +111,7 @@ class AppSettingsController extends Controller {
$this->appFetcher = $appFetcher;
$this->l10nFactory = $l10nFactory;
$this->bundleFetcher = $bundleFetcher;
+ $this->installer = $installer;
}
/**
@@ -270,8 +276,7 @@ class AppSettingsController extends Controller {
];
- $appFetcher = \OC::$server->getAppFetcher();
- $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $appFetcher);
+ $newVersion = $this->installer->isUpdateAvailable($app['id']);
if($newVersion && $this->appManager->isInstalled($app['id'])) {
$formattedApps[count($formattedApps)-1]['update'] = $newVersion;
}
@@ -284,7 +289,7 @@ class AppSettingsController extends Controller {
$appClass = new \OC_App();
$apps = $appClass->listAllApps();
foreach($apps as $key => $app) {
- $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
+ $newVersion = $this->installer->isUpdateAvailable($app['id']);
if($newVersion !== false) {
$apps[$key]['update'] = $newVersion;
} else {
@@ -317,7 +322,7 @@ class AppSettingsController extends Controller {
$apps = $appClass->listAllApps();
foreach($apps as $key => $app) {
- $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
+ $newVersion = $this->installer->isUpdateAvailable($app['id']);
$apps[$key]['update'] = $newVersion;
}
@@ -342,7 +347,7 @@ class AppSettingsController extends Controller {
});
foreach($apps as $key => $app) {
- $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
+ $newVersion = $this->installer->isUpdateAvailable($app['id']);
$apps[$key]['update'] = $newVersion;
}
@@ -363,7 +368,7 @@ class AppSettingsController extends Controller {
});
$apps = array_map(function ($app) {
- $newVersion = \OC\Installer::isUpdateAvailable($app['id'], $this->appFetcher);
+ $newVersion = $this->installer->isUpdateAvailable($app['id']);
if ($newVersion !== false) {
$app['update'] = $newVersion;
}
diff --git a/settings/ajax/updateapp.php b/settings/ajax/updateapp.php
index 7b615cb56bb..3431c68dbd7 100644
--- a/settings/ajax/updateapp.php
+++ b/settings/ajax/updateapp.php
@@ -41,13 +41,7 @@ $appId = OC_App::cleanAppId($appId);
$config = \OC::$server->getConfig();
$config->setSystemValue('maintenance', true);
try {
- $installer = new \OC\Installer(
- \OC::$server->getAppFetcher(),
- \OC::$server->getHTTPClientService(),
- \OC::$server->getTempManager(),
- \OC::$server->getLogger(),
- \OC::$server->getConfig()
- );
+ $installer = \OC::$server->query(\OC\Installer::class);
$result = $installer->updateAppstoreApp($appId);
$config->setSystemValue('maintenance', false);
} catch(Exception $ex) {
diff --git a/tests/Settings/Controller/AppSettingsControllerTest.php b/tests/Settings/Controller/AppSettingsControllerTest.php
index e264d0dfbfe..6631873d8ad 100644
--- a/tests/Settings/Controller/AppSettingsControllerTest.php
+++ b/tests/Settings/Controller/AppSettingsControllerTest.php
@@ -25,6 +25,7 @@ namespace Tests\Settings\Controller;
use OC\App\AppStore\Bundles\BundleFetcher;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\App\AppStore\Fetcher\CategoryFetcher;
+use OC\Installer;
use OC\Settings\Controller\AppSettingsController;
use OCP\AppFramework\Http\ContentSecurityPolicy;
use OCP\AppFramework\Http\JSONResponse;
@@ -63,6 +64,8 @@ class AppSettingsControllerTest extends TestCase {
private $l10nFactory;
/** @var BundleFetcher|\PHPUnit_Framework_MockObject_MockObject */
private $bundleFetcher;
+ /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
+ private $installer;
public function setUp() {
parent::setUp();
@@ -79,6 +82,7 @@ class AppSettingsControllerTest extends TestCase {
$this->appFetcher = $this->createMock(AppFetcher::class);
$this->l10nFactory = $this->createMock(IFactory::class);
$this->bundleFetcher = $this->createMock(BundleFetcher::class);
+ $this->installer = $this->createMock(Installer::class);
$this->appSettingsController = new AppSettingsController(
'settings',
@@ -90,11 +94,15 @@ class AppSettingsControllerTest extends TestCase {
$this->categoryFetcher,
$this->appFetcher,
$this->l10nFactory,
- $this->bundleFetcher
+ $this->bundleFetcher,
+ $this->installer
);
}
public function testListCategories() {
+ $this->installer->expects($this->any())
+ ->method('isUpdateAvailable')
+ ->willReturn(false);
$expected = new JSONResponse([
[
'id' => 2,
diff --git a/tests/lib/InstallerTest.php b/tests/lib/InstallerTest.php
index 107b9dcb41f..897bc472103 100644
--- a/tests/lib/InstallerTest.php
+++ b/tests/lib/InstallerTest.php
@@ -40,9 +40,6 @@ class InstallerTest extends TestCase {
/** @var IConfig|\PHPUnit_Framework_MockObject_MockObject */
private $config;
- /** @var Installer */
- private $installer;
-
protected function setUp() {
parent::setUp();
@@ -51,13 +48,6 @@ class InstallerTest extends TestCase {
$this->tempManager = $this->createMock(ITempManager::class);
$this->logger = $this->createMock(ILogger::class);
$this->config = $this->createMock(IConfig::class);
- $this->installer = new Installer(
- $this->appFetcher,
- $this->clientService,
- $this->tempManager,
- $this->logger,
- $this->config
- );
$config = \OC::$server->getConfig();
$this->appstore = $config->setSystemValue('appstoreenabled', true);
@@ -72,6 +62,16 @@ class InstallerTest extends TestCase {
$installer->removeApp(self::$appid);
}
+ protected function getInstaller() {
+ return new Installer(
+ $this->appFetcher,
+ $this->clientService,
+ $this->tempManager,
+ $this->logger,
+ $this->config
+ );
+ }
+
protected function tearDown() {
$installer = new Installer(
\OC::$server->getAppFetcher(),
@@ -154,7 +154,8 @@ class InstallerTest extends TestCase {
->method('get')
->willReturn($appArray);
- $this->assertSame($updateAvailable, Installer::isUpdateAvailable('files', $this->appFetcher));
+ $installer = $this->getInstaller();
+ $this->assertSame($updateAvailable, $installer->isUpdateAvailable('files'));
}
/**
@@ -197,7 +198,8 @@ gLgK8d8sKL60JMmKHN3boHrsThKBVA==
->willReturn($appArray);
- $this->installer->downloadApp('news');
+ $installer = $this->getInstaller();
+ $installer->downloadApp('news');
}
/**
@@ -239,7 +241,8 @@ YSu356M=
->method('get')
->willReturn($appArray);
- $this->installer->downloadApp('news');
+ $installer = $this->getInstaller();
+ $installer->downloadApp('news');
}
/**
@@ -281,7 +284,8 @@ cR92p/PYCFXkAKP3OO0RPlf6dXNKTw==
->method('get')
->willReturn($appArray);
- $this->installer->downloadApp('news');
+ $installer = $this->getInstaller();
+ $installer->downloadApp('news');
}
/**
@@ -348,7 +352,8 @@ cR92p/PYCFXkAKP3OO0RPlf6dXNKTw==
->method('newClient')
->willReturn($client);
- $this->installer->downloadApp('passman');
+ $installer = $this->getInstaller();
+ $installer->downloadApp('passman');
}
/**
@@ -431,7 +436,8 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
->method('newClient')
->willReturn($client);
- $this->installer->downloadApp('testapp');
+ $installer = $this->getInstaller();
+ $installer->downloadApp('testapp');
}
/**
@@ -513,7 +519,8 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
->method('newClient')
->willReturn($client);
- $this->installer->downloadApp('testapp');
+ $installer = $this->getInstaller();
+ $installer->downloadApp('testapp');
}
public function testDownloadAppSuccessful() {
@@ -591,7 +598,8 @@ MPLX6f5V9tCJtlH6ztmEcDROfvuVc0U3rEhqx2hphoyo+MZrPFpdcJL8KkIdMKbY
->method('newClient')
->willReturn($client);
- $this->installer->downloadApp('testapp');
+ $installer = $this->getInstaller();
+ $installer->downloadApp('testapp');
$this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
$this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
@@ -679,7 +687,8 @@ JXhrdaWDZ8fzpUjugrtC3qslsqL0dzgU37anS3HwrT8=',
$this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
$this->assertEquals('0.9', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
- $this->installer->downloadApp('testapp');
+ $installer = $this->getInstaller();
+ $installer->downloadApp('testapp');
$this->assertTrue(file_exists(__DIR__ . '/../../apps/testapp/appinfo/info.xml'));
$this->assertEquals('0.8', \OC_App::getAppVersionByPath(__DIR__ . '/../../apps/testapp/'));
}
diff --git a/tests/lib/SetupTest.php b/tests/lib/SetupTest.php
index 78c35a5b0bb..e6e9fb5c56c 100644
--- a/tests/lib/SetupTest.php
+++ b/tests/lib/SetupTest.php
@@ -9,6 +9,7 @@
namespace Test;
use bantu\IniGetWrapper\IniGetWrapper;
+use OC\Installer;
use OC\SystemConfig;
use OCP\Defaults;
use OCP\IL10N;
@@ -31,6 +32,8 @@ class SetupTest extends \Test\TestCase {
protected $logger;
/** @var \OCP\Security\ISecureRandom|\PHPUnit_Framework_MockObject_MockObject */
protected $random;
+ /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
+ protected $installer;
protected function setUp() {
parent::setUp();
@@ -41,9 +44,10 @@ class SetupTest extends \Test\TestCase {
$this->defaults = $this->createMock(Defaults::class);
$this->logger = $this->createMock(ILogger::class);
$this->random = $this->createMock(ISecureRandom::class);
+ $this->installer = $this->createMock(Installer::class);
$this->setupClass = $this->getMockBuilder('\OC\Setup')
->setMethods(['class_exists', 'is_callable', 'getAvailableDbDriversForPdo'])
- ->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random])
+ ->setConstructorArgs([$this->config, $this->iniWrapper, $this->l10n, $this->defaults, $this->logger, $this->random, $this->installer])
->getMock();
}
diff --git a/tests/lib/UpdaterTest.php b/tests/lib/UpdaterTest.php
index afa0635768d..a6a8224ac34 100644
--- a/tests/lib/UpdaterTest.php
+++ b/tests/lib/UpdaterTest.php
@@ -22,6 +22,7 @@
namespace Test;
+use OC\Installer;
use OC\Updater;
use OCP\IConfig;
use OCP\ILogger;
@@ -36,6 +37,8 @@ class UpdaterTest extends TestCase {
private $updater;
/** @var Checker | \PHPUnit_Framework_MockObject_MockObject */
private $checker;
+ /** @var Installer|\PHPUnit_Framework_MockObject_MockObject */
+ private $installer;
public function setUp() {
parent::setUp();
@@ -46,13 +49,17 @@ class UpdaterTest extends TestCase {
->disableOriginalConstructor()
->getMock();
$this->checker = $this->getMockBuilder(Checker::class)
- ->disableOriginalConstructor()
- ->getMock();
+ ->disableOriginalConstructor()
+ ->getMock();
+ $this->installer = $this->getMockBuilder(Installer::class)
+ ->disableOriginalConstructor()
+ ->getMock();
$this->updater = new Updater(
$this->config,
$this->checker,
- $this->logger
+ $this->logger,
+ $this->installer
);
}