diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 12 | ||||
-rw-r--r-- | lib/private/Installer.php | 25 | ||||
-rw-r--r-- | lib/private/Server.php | 10 | ||||
-rw-r--r-- | lib/private/Setup.php | 28 | ||||
-rw-r--r-- | lib/private/Updater.php | 19 | ||||
-rw-r--r-- | lib/private/legacy/app.php | 16 | ||||
-rw-r--r-- | lib/private/legacy/util.php | 11 |
7 files changed, 69 insertions, 52 deletions
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(); |