summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorJoas Schilling <coding@schilljs.com>2023-10-31 12:06:09 +0100
committerJoas Schilling <coding@schilljs.com>2023-11-03 15:46:06 +0100
commitb864f3909fe382ee8ebf8dadfecd7f2386e74e94 (patch)
tree9491d37cbbbf4a8b9478898e4b27154af281e9d8 /lib
parent0e44a73b13299fb488de325914bb4472b118de01 (diff)
downloadnextcloud-server-b864f3909fe382ee8ebf8dadfecd7f2386e74e94.tar.gz
nextcloud-server-b864f3909fe382ee8ebf8dadfecd7f2386e74e94.zip
fix(install): Make installing more verbose
Signed-off-by: Joas Schilling <coding@schilljs.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Console/TimestampFormatter.php19
-rw-r--r--lib/private/DB/MigrationService.php6
-rw-r--r--lib/private/Installer.php23
-rw-r--r--lib/private/Migration/ConsoleOutput.php4
-rw-r--r--lib/private/Migration/SimpleOutput.php4
-rw-r--r--lib/private/Repair.php3
-rw-r--r--lib/private/Setup.php20
-rw-r--r--lib/private/Setup/AbstractDatabase.php5
-rw-r--r--lib/public/Migration/IOutput.php7
9 files changed, 74 insertions, 17 deletions
diff --git a/lib/private/Console/TimestampFormatter.php b/lib/private/Console/TimestampFormatter.php
index 8d74c28e94f..afb1f67c37f 100644
--- a/lib/private/Console/TimestampFormatter.php
+++ b/lib/private/Console/TimestampFormatter.php
@@ -27,17 +27,17 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;
class TimestampFormatter implements OutputFormatterInterface {
- /** @var IConfig */
+ /** @var ?IConfig */
protected $config;
/** @var OutputFormatterInterface */
protected $formatter;
/**
- * @param IConfig $config
+ * @param ?IConfig $config
* @param OutputFormatterInterface $formatter
*/
- public function __construct(IConfig $config, OutputFormatterInterface $formatter) {
+ public function __construct(?IConfig $config, OutputFormatterInterface $formatter) {
$this->config = $config;
$this->formatter = $formatter;
}
@@ -104,11 +104,16 @@ class TimestampFormatter implements OutputFormatterInterface {
return $this->formatter->format($message);
}
- $timeZone = $this->config->getSystemValue('logtimezone', 'UTC');
- $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;
+ if ($this->config instanceof IConfig) {
+ $timeZone = $this->config->getSystemValue('logtimezone', 'UTC');
+ $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;
- $time = new \DateTime('now', $timeZone);
- $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTimeInterface::ATOM));
+ $time = new \DateTime('now', $timeZone);
+ $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTimeInterface::ATOM));
+ } else {
+ $time = new \DateTime('now');
+ $timestampInfo = $time->format(\DateTimeInterface::ATOM);
+ }
return $timestampInfo . ' ' . $this->formatter->format($message);
}
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php
index 7993730b230..f8c6a9907ce 100644
--- a/lib/private/DB/MigrationService.php
+++ b/lib/private/DB/MigrationService.php
@@ -406,6 +406,7 @@ class MigrationService {
*/
public function migrate($to = 'latest', $schemaOnly = false) {
if ($schemaOnly) {
+ $this->output->debug('Migrating schema only');
$this->migrateSchemaOnly($to);
return;
}
@@ -439,6 +440,7 @@ class MigrationService {
$toSchema = null;
foreach ($toBeExecuted as $version) {
+ $this->output->debug('- Reading ' . $version);
$instance = $this->createInstance($version);
$toSchema = $instance->changeSchema($this->output, function () use ($toSchema): ISchemaWrapper {
@@ -447,15 +449,19 @@ class MigrationService {
}
if ($toSchema instanceof SchemaWrapper) {
+ $this->output->debug('- Checking target database schema');
$targetSchema = $toSchema->getWrappedSchema();
if ($this->checkOracle) {
$beforeSchema = $this->connection->createSchema();
$this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix()));
}
+
+ $this->output->debug('- Migrate database schema');
$this->connection->migrateToSchema($targetSchema);
$toSchema->performDropTableCalls();
}
+ $this->output->debug('- Mark migrations as executed');
foreach ($toBeExecuted as $version) {
$this->markAsExecuted($version);
}
diff --git a/lib/private/Installer.php b/lib/private/Installer.php
index 0458c14da8a..f7a2f632a42 100644
--- a/lib/private/Installer.php
+++ b/lib/private/Installer.php
@@ -52,6 +52,7 @@ use OCP\HintException;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
use OCP\ITempManager;
+use OCP\Migration\IOutput;
use phpseclib\File\X509;
use Psr\Log\LoggerInterface;
@@ -535,7 +536,10 @@ class Installer {
* working ownCloud at the end instead of an aborted update.
* @return array Array of error messages (appid => Exception)
*/
- public static function installShippedApps($softErrors = false) {
+ public static function installShippedApps($softErrors = false, ?IOutput $output = null) {
+ if ($output instanceof IOutput) {
+ $output->debug('Installing shipped apps');
+ }
$appManager = \OC::$server->getAppManager();
$config = \OC::$server->getConfig();
$errors = [];
@@ -550,7 +554,7 @@ class Installer {
&& $config->getAppValue($filename, 'enabled') !== 'no') {
if ($softErrors) {
try {
- Installer::installShippedApp($filename);
+ Installer::installShippedApp($filename, $output);
} catch (HintException $e) {
if ($e->getPrevious() instanceof TableExistsException) {
$errors[$filename] = $e;
@@ -559,7 +563,7 @@ class Installer {
throw $e;
}
} else {
- Installer::installShippedApp($filename);
+ Installer::installShippedApp($filename, $output);
}
$config->setAppValue($filename, 'enabled', 'yes');
}
@@ -577,9 +581,12 @@ class Installer {
/**
* install an app already placed in the app folder
* @param string $app id of the app to install
- * @return integer
+ * @return string
*/
- public static function installShippedApp($app) {
+ public static function installShippedApp($app, ?IOutput $output = null) {
+ if ($output instanceof IOutput) {
+ $output->debug('Installing ' . $app);
+ }
//install the database
$appPath = OC_App::getAppPath($app);
\OC_App::registerAutoloading($app, $appPath);
@@ -587,6 +594,9 @@ class Installer {
$config = \OC::$server->getConfig();
$ms = new MigrationService($app, \OC::$server->get(Connection::class));
+ if ($output instanceof IOutput) {
+ $ms->setOutput($output);
+ }
$previousVersion = $config->getAppValue($app, 'installed_version', false);
$ms->migrate('latest', !$previousVersion);
@@ -597,6 +607,9 @@ class Installer {
if (is_null($info)) {
return false;
}
+ if ($output instanceof IOutput) {
+ $output->debug('Registering tasks of ' . $app);
+ }
\OC_App::setupBackgroundJobs($info['background-jobs']);
OC_App::executeRepairSteps($app, $info['repair-steps']['install']);
diff --git a/lib/private/Migration/ConsoleOutput.php b/lib/private/Migration/ConsoleOutput.php
index 9e3396f2a75..00b79f34866 100644
--- a/lib/private/Migration/ConsoleOutput.php
+++ b/lib/private/Migration/ConsoleOutput.php
@@ -44,6 +44,10 @@ class ConsoleOutput implements IOutput {
$this->output = $output;
}
+ public function debug(string $message): void {
+ $this->output->writeln($message, OutputInterface::VERBOSITY_VERBOSE);
+ }
+
/**
* @param string $message
*/
diff --git a/lib/private/Migration/SimpleOutput.php b/lib/private/Migration/SimpleOutput.php
index f97bcb767f8..6b0908500be 100644
--- a/lib/private/Migration/SimpleOutput.php
+++ b/lib/private/Migration/SimpleOutput.php
@@ -41,6 +41,10 @@ class SimpleOutput implements IOutput {
$this->appName = $appName;
}
+ public function debug(string $message): void {
+ $this->logger->debug($message, ['app' => $this->appName]);
+ }
+
/**
* @param string $message
* @since 9.1.0
diff --git a/lib/private/Repair.php b/lib/private/Repair.php
index 00cc40a00b3..541073de1ee 100644
--- a/lib/private/Repair.php
+++ b/lib/private/Repair.php
@@ -250,6 +250,9 @@ class Repair implements IOutput {
return $steps;
}
+ public function debug(string $message): void {
+ }
+
/**
* @param string $message
*/
diff --git a/lib/private/Setup.php b/lib/private/Setup.php
index 9447625fc70..749d4c7bdb0 100644
--- a/lib/private/Setup.php
+++ b/lib/private/Setup.php
@@ -60,6 +60,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults;
use OCP\IGroup;
use OCP\IL10N;
+use OCP\Migration\IOutput;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
@@ -275,7 +276,7 @@ class Setup {
* @param $options
* @return array
*/
- public function install($options) {
+ public function install($options, ?IOutput $output = null) {
$l = $this->l10n;
$error = [];
@@ -349,6 +350,7 @@ class Setup {
$this->config->setValues($newConfigValues);
+ $this->outputDebug($output, 'Configuring database');
$dbSetup->initialize($options);
try {
$dbSetup->setupDatabase($username);
@@ -367,9 +369,11 @@ class Setup {
];
return $error;
}
+
+ $this->outputDebug($output, 'Run server migrations');
try {
// apply necessary migrations
- $dbSetup->runMigrations();
+ $dbSetup->runMigrations($output);
} catch (Exception $e) {
$error[] = [
'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
@@ -379,6 +383,7 @@ class Setup {
return $error;
}
+ $this->outputDebug($output, 'Create admin user');
//create the user and group
$user = null;
try {
@@ -407,16 +412,19 @@ class Setup {
}
// Install shipped apps and specified app bundles
- Installer::installShippedApps();
+ $this->outputDebug($output, 'Install default apps');
+ Installer::installShippedApps(false, $output);
// create empty file in data dir, so we can later find
// out that this is indeed an ownCloud data directory
+ $this->outputDebug($output, 'Setup data directory');
file_put_contents($config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
// Update .htaccess files
self::updateHtaccess();
self::protectDataDirectory();
+ $this->outputDebug($output, 'Install background jobs');
self::installBackgroundJobs();
//and we are done
@@ -616,4 +624,10 @@ class Setup {
public function canInstallFileExists() {
return is_file(\OC::$configDir.'/CAN_INSTALL');
}
+
+ protected function outputDebug(?IOutput $output, string $message): void {
+ if ($output instanceof IOutput) {
+ $output->debug($message);
+ }
+ }
}
diff --git a/lib/private/Setup/AbstractDatabase.php b/lib/private/Setup/AbstractDatabase.php
index 9ec4137cdef..b79578fd737 100644
--- a/lib/private/Setup/AbstractDatabase.php
+++ b/lib/private/Setup/AbstractDatabase.php
@@ -33,6 +33,7 @@ use OC\DB\ConnectionFactory;
use OC\DB\MigrationService;
use OC\SystemConfig;
use OCP\IL10N;
+use OCP\Migration\IOutput;
use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface;
@@ -150,11 +151,11 @@ abstract class AbstractDatabase {
*/
abstract public function setupDatabase($username);
- public function runMigrations() {
+ public function runMigrations(?IOutput $output = null) {
if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) {
return;
}
- $ms = new MigrationService('core', \OC::$server->get(Connection::class));
+ $ms = new MigrationService('core', \OC::$server->get(Connection::class), $output);
$ms->migrate('latest', true);
}
}
diff --git a/lib/public/Migration/IOutput.php b/lib/public/Migration/IOutput.php
index 70fb56b6bdd..97b0e15b9b5 100644
--- a/lib/public/Migration/IOutput.php
+++ b/lib/public/Migration/IOutput.php
@@ -32,6 +32,13 @@ interface IOutput {
/**
* @param string $message
* @return void
+ * @since 28.0.0
+ */
+ public function debug(string $message): void;
+
+ /**
+ * @param string $message
+ * @return void
* @since 9.1.0
*/
public function info($message);