Get the Installer via DI
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
This commit is contained in:
parent
a97a290fd5
commit
0e2f00ec59
15 changed files with 116 additions and 83 deletions
|
@ -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) {
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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')) {
|
||||
|
|
|
@ -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 = [];
|
||||
|
|
|
@ -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()));
|
||||
|
|
12
lib/base.php
12
lib/base.php
|
@ -915,9 +915,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();
|
||||
|
|
|
@ -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()
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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())) {
|
||||
$this->emit('\OC\Updater', 'upgradeAppStoreApp', [$app]);
|
||||
$installer->updateAppstoreApp($app);
|
||||
$this->installer->updateAppstoreApp($app);
|
||||
}
|
||||
$this->emit('\OC\Updater', 'checkAppStoreApp', [$app]);
|
||||
} catch (\Exception $ex) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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(),
|
||||
|
@ -197,7 +197,8 @@ gLgK8d8sKL60JMmKHN3boHrsThKBVA==
|
|||
->willReturn($appArray);
|
||||
|
||||
|
||||
$this->installer->downloadApp('news');
|
||||
$installer = $this->getInstaller();
|
||||
$installer->downloadApp('news');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -239,7 +240,8 @@ YSu356M=
|
|||
->method('get')
|
||||
->willReturn($appArray);
|
||||
|
||||
$this->installer->downloadApp('news');
|
||||
$installer = $this->getInstaller();
|
||||
$installer->downloadApp('news');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -281,7 +283,8 @@ cR92p/PYCFXkAKP3OO0RPlf6dXNKTw==
|
|||
->method('get')
|
||||
->willReturn($appArray);
|
||||
|
||||
$this->installer->downloadApp('news');
|
||||
$installer = $this->getInstaller();
|
||||
$installer->downloadApp('news');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -348,7 +351,8 @@ cR92p/PYCFXkAKP3OO0RPlf6dXNKTw==
|
|||
->method('newClient')
|
||||
->willReturn($client);
|
||||
|
||||
$this->installer->downloadApp('passman');
|
||||
$installer = $this->getInstaller();
|
||||
$installer->downloadApp('passman');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -431,7 +435,8 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
|
|||
->method('newClient')
|
||||
->willReturn($client);
|
||||
|
||||
$this->installer->downloadApp('testapp');
|
||||
$installer = $this->getInstaller();
|
||||
$installer->downloadApp('testapp');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -513,7 +518,8 @@ YwDVP+QmNRzx72jtqAN/Kc3CvQ9nkgYhU65B95aX0xA=',
|
|||
->method('newClient')
|
||||
->willReturn($client);
|
||||
|
||||
$this->installer->downloadApp('testapp');
|
||||
$installer = $this->getInstaller();
|
||||
$installer->downloadApp('testapp');
|
||||
}
|
||||
|
||||
public function testDownloadAppSuccessful() {
|
||||
|
@ -591,7 +597,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 +686,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/'));
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue