Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 7 additions & 16 deletions core/Command/Maintenance/Install.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
*
Expand Down Expand Up @@ -33,12 +36,9 @@
use bantu\IniGetWrapper\IniGetWrapper;
use InvalidArgumentException;
use OC\Console\TimestampFormatter;
use OC\Installer;
use OC\Migration\ConsoleOutput;
use OC\Setup;
use OC\SystemConfig;
use OCP\Defaults;
use Psr\Log\LoggerInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
Expand All @@ -56,7 +56,7 @@ public function __construct(
parent::__construct();
}

protected function configure() {
protected function configure(): void {
$this
->setName('maintenance:install')
->setDescription('install Nextcloud')
Expand All @@ -75,16 +75,7 @@ protected function configure() {

protected function execute(InputInterface $input, OutputInterface $output): int {
// validate the environment
$server = \OC::$server;
$setupHelper = new Setup(
$this->config,
$this->iniGetWrapper,
$server->getL10N('lib'),
$server->query(Defaults::class),
$server->get(LoggerInterface::class),
$server->getSecureRandom(),
\OC::$server->query(Installer::class)
);
$setupHelper = \OCP\Server::get(\OC\Setup::class);
$sysInfo = $setupHelper->getSystemInfo(true);
$errors = $sysInfo['errors'];
if (count($errors) > 0) {
Expand Down Expand Up @@ -206,9 +197,9 @@ protected function validateInput(InputInterface $input, OutputInterface $output,

/**
* @param OutputInterface $output
* @param $errors
* @param array<string|array> $errors
*/
protected function printErrors(OutputInterface $output, $errors) {
protected function printErrors(OutputInterface $output, array $errors): void {
foreach ($errors as $error) {
if (is_array($error)) {
$output->writeln('<error>' . $error['error'] . '</error>');
Expand Down
12 changes: 1 addition & 11 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -988,17 +988,7 @@ public static function handleRequest(): void {
// Check if Nextcloud is installed or in maintenance (update) mode
if (!$systemConfig->getValue('installed', false)) {
\OC::$server->getSession()->clear();
$logger = Server::get(\Psr\Log\LoggerInterface::class);
$setupHelper = new OC\Setup(
$systemConfig,
Server::get(\bantu\IniGetWrapper\IniGetWrapper::class),
Server::get(\OCP\L10N\IFactory::class)->get('lib'),
Server::get(\OCP\Defaults::class),
$logger,
Server::get(\OCP\Security\ISecureRandom::class),
Server::get(\OC\Installer::class)
);
$controller = new OC\Core\Controller\SetupController($setupHelper, $logger);
$controller = Server::get(\OC\Core\Controller\SetupController::class);
$controller->run($_POST);
exit();
}
Expand Down
101 changes: 35 additions & 66 deletions lib/private/Installer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

declare(strict_types=1);

/**
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @copyright Copyright (c) 2016, Lukas Reschke <[email protected]>
Expand Down Expand Up @@ -61,37 +64,17 @@
* This class provides the functionality needed to install, update and remove apps
*/
class Installer {
/** @var AppFetcher */
private $appFetcher;
/** @var IClientService */
private $clientService;
/** @var ITempManager */
private $tempManager;
/** @var LoggerInterface */
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;
/** @var bool */
private $isCLI;
private ?bool $isInstanceReadyForUpdates = null;
private ?array $apps = null;

public function __construct(
AppFetcher $appFetcher,
IClientService $clientService,
ITempManager $tempManager,
LoggerInterface $logger,
IConfig $config,
bool $isCLI
private AppFetcher $appFetcher,
private IClientService $clientService,
private ITempManager $tempManager,
private LoggerInterface $logger,
private IConfig $config,
private bool $isCLI,
) {
$this->appFetcher = $appFetcher;
$this->clientService = $clientService;
$this->tempManager = $tempManager;
$this->logger = $logger;
$this->config = $config;
$this->isCLI = $isCLI;
}

/**
Expand All @@ -114,7 +97,7 @@ public function installApp(string $appId, bool $forceEnable = false): string {
throw new \Exception('The appinfo/database.xml file is not longer supported. Used in ' . $appId);
}

$l = \OC::$server->getL10N('core');
$l = \OCP\Util::getL10N('core');
$info = \OCP\Server::get(IAppManager::class)->getAppInfo($basedir . '/appinfo/info.xml', true, $l->getLanguageCode());

if (!is_array($info)) {
Expand Down Expand Up @@ -151,7 +134,7 @@ public function installApp(string $appId, bool $forceEnable = false): string {
}

//install the database
$ms = new MigrationService($info['id'], \OC::$server->get(Connection::class));
$ms = new MigrationService($info['id'], \OCP\Server::get(Connection::class));
$ms->migrate('latest', !$previousVersion);

if ($previousVersion) {
Expand All @@ -165,16 +148,17 @@ public function installApp(string $appId, bool $forceEnable = false): string {

OC_App::executeRepairSteps($appId, $info['repair-steps']['install']);

$config = \OCP\Server::get(IConfig::class);
//set the installed version
\OC::$server->getConfig()->setAppValue($info['id'], 'installed_version', \OCP\Server::get(IAppManager::class)->getAppVersion($info['id'], false));
\OC::$server->getConfig()->setAppValue($info['id'], 'enabled', 'no');
$config->setAppValue($info['id'], 'installed_version', \OCP\Server::get(IAppManager::class)->getAppVersion($info['id'], false));
$config->setAppValue($info['id'], 'enabled', 'no');

//set remote/public handlers
foreach ($info['remote'] as $name => $path) {
\OC::$server->getConfig()->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path);
$config->setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path);
}
foreach ($info['public'] as $name => $path) {
\OC::$server->getConfig()->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path);
$config->setAppValue('core', 'public_'.$name, $info['id'].'/'.$path);
}

OC_App::setAppTypes($info['id']);
Expand All @@ -185,11 +169,9 @@ public function installApp(string $appId, bool $forceEnable = false): string {
/**
* Updates the specified app from the appstore
*
* @param string $appId
* @param bool [$allowUnstable] Allow unstable releases
* @return bool
* @param bool $allowUnstable Allow unstable releases
*/
public function updateAppstoreApp($appId, $allowUnstable = false) {
public function updateAppstoreApp(string $appId, bool $allowUnstable = false): bool {
if ($this->isUpdateAvailable($appId, $allowUnstable)) {
try {
$this->downloadApp($appId, $allowUnstable);
Expand Down Expand Up @@ -225,7 +207,7 @@ private function splitCerts(string $cert): array {
*
* @throws \Exception If the installation was not successful
*/
public function downloadApp($appId, $allowUnstable = false) {
public function downloadApp(string $appId, bool $allowUnstable = false): void {
$appId = strtolower($appId);

$apps = $this->appFetcher->get($allowUnstable);
Expand Down Expand Up @@ -401,10 +383,10 @@ public function downloadApp($appId, $allowUnstable = false) {
* @param bool $allowUnstable
* @return string|false false or the version number of the update
*/
public function isUpdateAvailable($appId, $allowUnstable = false) {
public function isUpdateAvailable($appId, $allowUnstable = false): string|false {
if ($this->isInstanceReadyForUpdates === null) {
$installPath = OC_App::getInstallPath();
if ($installPath === false || $installPath === null) {
if ($installPath === null) {
$this->isInstanceReadyForUpdates = false;
} else {
$this->isInstanceReadyForUpdates = true;
Comment on lines +389 to 392
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit:

Suggested change
if ($installPath === null) {
$this->isInstanceReadyForUpdates = false;
} else {
$this->isInstanceReadyForUpdates = true;
$this->isInstanceReadyForUpdates = $installPath !== null;

Expand Down Expand Up @@ -444,12 +426,10 @@ public function isUpdateAvailable($appId, $allowUnstable = false) {

/**
* Check if app has been installed from git
* @param string $name name of the application to remove
* @return boolean
*
* The function will check if the path contains a .git folder
*/
private function isInstalledFromGit($appId) {
private function isInstalledFromGit(string $appId): bool {
$app = \OC_App::findAppInDirectories($appId);
if ($app === false) {
return false;
Expand All @@ -460,12 +440,10 @@ private function isInstalledFromGit($appId) {

/**
* Check if app is already downloaded
* @param string $name name of the application to remove
* @return boolean
*
* The function will check if the app is already downloaded in the apps repository
*/
public function isDownloaded($name) {
public function isDownloaded(string $name): bool {
foreach (\OC::$APPSROOTS as $dir) {
$dirToTest = $dir['path'];
$dirToTest .= '/';
Expand All @@ -482,9 +460,6 @@ public function isDownloaded($name) {

/**
* Removes an app
* @param string $appId ID of the application to remove
* @return boolean
*
*
* This function works as follows
* -# call uninstall repair steps
Expand All @@ -493,9 +468,9 @@ public function isDownloaded($name) {
* The function will not delete preferences, tables and the configuration,
* this has to be done by the function oc_app_uninstall().
*/
public function removeApp($appId) {
public function removeApp(string $appId): bool {
if ($this->isDownloaded($appId)) {
if (\OC::$server->getAppManager()->isShipped($appId)) {
if (\OCP\Server::get(IAppManager::class)->isShipped($appId)) {
return false;
}
$appDir = OC_App::getInstallPath() . '/' . $appId;
Expand All @@ -511,10 +486,9 @@ public function removeApp($appId) {
/**
* Installs the app within the bundle and marks the bundle as installed
*
* @param Bundle $bundle
* @throws \Exception If app could not get installed
*/
public function installAppBundle(Bundle $bundle) {
public function installAppBundle(Bundle $bundle): void {
$appIds = $bundle->getAppIdentifiers();
foreach ($appIds as $appId) {
if (!$this->isDownloaded($appId)) {
Expand All @@ -537,12 +511,12 @@ public function installAppBundle(Bundle $bundle) {
* working ownCloud at the end instead of an aborted update.
* @return array Array of error messages (appid => Exception)
*/
public static function installShippedApps($softErrors = false, ?IOutput $output = null) {
public static function installShippedApps(bool $softErrors = false, ?IOutput $output = null): array {
if ($output instanceof IOutput) {
$output->debug('Installing shipped apps');
}
$appManager = \OC::$server->getAppManager();
$config = \OC::$server->getConfig();
$appManager = \OCP\Server::get(IAppManager::class);
$config = \OCP\Server::get(IConfig::class);
$errors = [];
foreach (\OC::$APPSROOTS as $app_dir) {
if ($dir = opendir($app_dir['path'])) {
Expand Down Expand Up @@ -581,20 +555,18 @@ public static function installShippedApps($softErrors = false, ?IOutput $output

/**
* install an app already placed in the app folder
* @param string $app id of the app to install
* @return string
*/
public static function installShippedApp($app, ?IOutput $output = null) {
public static function installShippedApp(string $app, ?IOutput $output = null): string|false {
if ($output instanceof IOutput) {
$output->debug('Installing ' . $app);
}
//install the database
$appPath = OC_App::getAppPath($app);
\OC_App::registerAutoloading($app, $appPath);

$config = \OC::$server->getConfig();
$config = \OCP\Server::get(IConfig::class);

$ms = new MigrationService($app, \OC::$server->get(Connection::class));
$ms = new MigrationService($app, \OCP\Server::get(Connection::class));
if ($output instanceof IOutput) {
$ms->setOutput($output);
}
Expand Down Expand Up @@ -633,10 +605,7 @@ public static function installShippedApp($app, ?IOutput $output = null) {
return $info['id'];
}

/**
* @param string $script
*/
private static function includeAppScript($script) {
private static function includeAppScript(string $script): void {
if (file_exists($script)) {
include $script;
}
Expand Down
Loading