Skip to content

Commit 6f39d82

Browse files
committed
fix(install): Make installing more verbose
Signed-off-by: Joas Schilling <coding@schilljs.com>
1 parent 50de755 commit 6f39d82

10 files changed

Lines changed: 86 additions & 18 deletions

File tree

core/Command/Maintenance/Install.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,9 @@
3232

3333
use bantu\IniGetWrapper\IniGetWrapper;
3434
use InvalidArgumentException;
35+
use OC\Console\TimestampFormatter;
3536
use OC\Installer;
37+
use OC\Migration\ConsoleOutput;
3638
use OC\Setup;
3739
use OC\SystemConfig;
3840
use OCP\Defaults;
@@ -98,8 +100,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
98100
// validate user input
99101
$options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
100102

103+
if ($output->isVerbose()) {
104+
// Prepend each line with a little timestamp
105+
$timestampFormatter = new TimestampFormatter(null, $output->getFormatter());
106+
$output->setFormatter($timestampFormatter);
107+
$migrationOutput = new ConsoleOutput($output);
108+
} else {
109+
$migrationOutput = null;
110+
}
111+
101112
// perform installation
102-
$errors = $setupHelper->install($options);
113+
$errors = $setupHelper->install($options, $migrationOutput);
103114
if (count($errors) > 0) {
104115
$this->printErrors($output, $errors);
105116
return 1;

lib/private/Console/TimestampFormatter.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,17 @@
2727
use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;
2828

2929
class TimestampFormatter implements OutputFormatterInterface {
30-
/** @var IConfig */
30+
/** @var ?IConfig */
3131
protected $config;
3232

3333
/** @var OutputFormatterInterface */
3434
protected $formatter;
3535

3636
/**
37-
* @param IConfig $config
37+
* @param ?IConfig $config
3838
* @param OutputFormatterInterface $formatter
3939
*/
40-
public function __construct(IConfig $config, OutputFormatterInterface $formatter) {
40+
public function __construct(?IConfig $config, OutputFormatterInterface $formatter) {
4141
$this->config = $config;
4242
$this->formatter = $formatter;
4343
}
@@ -104,11 +104,16 @@ public function format(?string $message): ?string {
104104
return $this->formatter->format($message);
105105
}
106106

107-
$timeZone = $this->config->getSystemValue('logtimezone', 'UTC');
108-
$timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;
107+
if ($this->config instanceof IConfig) {
108+
$timeZone = $this->config->getSystemValue('logtimezone', 'UTC');
109+
$timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;
109110

110-
$time = new \DateTime('now', $timeZone);
111-
$timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTimeInterface::ATOM));
111+
$time = new \DateTime('now', $timeZone);
112+
$timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTimeInterface::ATOM));
113+
} else {
114+
$time = new \DateTime('now');
115+
$timestampInfo = $time->format(\DateTimeInterface::ATOM);
116+
}
112117

113118
return $timestampInfo . ' ' . $this->formatter->format($message);
114119
}

lib/private/DB/MigrationService.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -390,6 +390,7 @@ public function setOutput(IOutput $output): void {
390390
*/
391391
public function migrate(string $to = 'latest', bool $schemaOnly = false): void {
392392
if ($schemaOnly) {
393+
$this->output->debug('Migrating schema only');
393394
$this->migrateSchemaOnly($to);
394395
return;
395396
}
@@ -421,6 +422,7 @@ public function migrateSchemaOnly(string $to = 'latest'): void {
421422

422423
$toSchema = null;
423424
foreach ($toBeExecuted as $version) {
425+
$this->output->debug('- Reading ' . $version);
424426
$instance = $this->createInstance($version);
425427

426428
$toSchema = $instance->changeSchema($this->output, function () use ($toSchema): ISchemaWrapper {
@@ -429,16 +431,20 @@ public function migrateSchemaOnly(string $to = 'latest'): void {
429431
}
430432

431433
if ($toSchema instanceof SchemaWrapper) {
434+
$this->output->debug('- Checking target database schema');
432435
$targetSchema = $toSchema->getWrappedSchema();
433436
$this->ensureUniqueNamesConstraints($targetSchema);
434437
if ($this->checkOracle) {
435438
$beforeSchema = $this->connection->createSchema();
436439
$this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix()));
437440
}
441+
442+
$this->output->debug('- Migrate database schema');
438443
$this->connection->migrateToSchema($targetSchema);
439444
$toSchema->performDropTableCalls();
440445
}
441446

447+
$this->output->debug('- Mark migrations as executed');
442448
foreach ($toBeExecuted as $version) {
443449
$this->markAsExecuted($version);
444450
}

lib/private/Installer.php

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
use OCP\Http\Client\IClientService;
5454
use OCP\IConfig;
5555
use OCP\ITempManager;
56+
use OCP\Migration\IOutput;
5657
use phpseclib\File\X509;
5758
use Psr\Log\LoggerInterface;
5859

@@ -536,7 +537,10 @@ public function installAppBundle(Bundle $bundle) {
536537
* working ownCloud at the end instead of an aborted update.
537538
* @return array Array of error messages (appid => Exception)
538539
*/
539-
public static function installShippedApps($softErrors = false) {
540+
public static function installShippedApps($softErrors = false, ?IOutput $output = null) {
541+
if ($output instanceof IOutput) {
542+
$output->debug('Installing shipped apps');
543+
}
540544
$appManager = \OC::$server->getAppManager();
541545
$config = \OC::$server->getConfig();
542546
$errors = [];
@@ -551,7 +555,7 @@ public static function installShippedApps($softErrors = false) {
551555
&& $config->getAppValue($filename, 'enabled') !== 'no') {
552556
if ($softErrors) {
553557
try {
554-
Installer::installShippedApp($filename);
558+
Installer::installShippedApp($filename, $output);
555559
} catch (HintException $e) {
556560
if ($e->getPrevious() instanceof TableExistsException) {
557561
$errors[$filename] = $e;
@@ -560,7 +564,7 @@ public static function installShippedApps($softErrors = false) {
560564
throw $e;
561565
}
562566
} else {
563-
Installer::installShippedApp($filename);
567+
Installer::installShippedApp($filename, $output);
564568
}
565569
$config->setAppValue($filename, 'enabled', 'yes');
566570
}
@@ -578,16 +582,22 @@ public static function installShippedApps($softErrors = false) {
578582
/**
579583
* install an app already placed in the app folder
580584
* @param string $app id of the app to install
581-
* @return integer
585+
* @return string
582586
*/
583-
public static function installShippedApp($app) {
587+
public static function installShippedApp($app, ?IOutput $output = null) {
588+
if ($output instanceof IOutput) {
589+
$output->debug('Installing ' . $app);
590+
}
584591
//install the database
585592
$appPath = OC_App::getAppPath($app);
586593
\OC_App::registerAutoloading($app, $appPath);
587594

588595
$config = \OC::$server->getConfig();
589596

590597
$ms = new MigrationService($app, \OC::$server->get(Connection::class));
598+
if ($output instanceof IOutput) {
599+
$ms->setOutput($output);
600+
}
591601
$previousVersion = $config->getAppValue($app, 'installed_version', false);
592602
$ms->migrate('latest', !$previousVersion);
593603

@@ -598,6 +608,9 @@ public static function installShippedApp($app) {
598608
if (is_null($info)) {
599609
return false;
600610
}
611+
if ($output instanceof IOutput) {
612+
$output->debug('Registering tasks of ' . $app);
613+
}
601614
\OC_App::setupBackgroundJobs($info['background-jobs']);
602615

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

lib/private/Migration/ConsoleOutput.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ public function __construct(OutputInterface $output) {
4444
$this->output = $output;
4545
}
4646

47+
public function debug(string $message): void {
48+
$this->output->writeln($message, OutputInterface::VERBOSITY_VERBOSE);
49+
}
50+
4751
/**
4852
* @param string $message
4953
*/

lib/private/Migration/SimpleOutput.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ public function __construct(LoggerInterface $logger, $appName) {
4141
$this->appName = $appName;
4242
}
4343

44+
public function debug(string $message): void {
45+
$this->logger->debug($message, ['app' => $this->appName]);
46+
}
47+
4448
/**
4549
* @param string $message
4650
* @since 9.1.0

lib/private/Repair.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,9 @@ public static function getBeforeUpgradeRepairSteps() {
246246
return $steps;
247247
}
248248

249+
public function debug(string $message): void {
250+
}
251+
249252
/**
250253
* @param string $message
251254
*/

lib/private/Setup.php

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
use OCP\Defaults;
6161
use OCP\IGroup;
6262
use OCP\IL10N;
63+
use OCP\Migration\IOutput;
6364
use OCP\Security\ISecureRandom;
6465
use Psr\Log\LoggerInterface;
6566

@@ -275,7 +276,7 @@ public function getSystemInfo($allowAllDatabases = false) {
275276
* @param $options
276277
* @return array
277278
*/
278-
public function install($options) {
279+
public function install($options, ?IOutput $output = null) {
279280
$l = $this->l10n;
280281

281282
$error = [];
@@ -349,6 +350,7 @@ public function install($options) {
349350

350351
$this->config->setValues($newConfigValues);
351352

353+
$this->outputDebug($output, 'Configuring database');
352354
$dbSetup->initialize($options);
353355
try {
354356
$dbSetup->setupDatabase($username);
@@ -367,9 +369,11 @@ public function install($options) {
367369
];
368370
return $error;
369371
}
372+
373+
$this->outputDebug($output, 'Run server migrations');
370374
try {
371375
// apply necessary migrations
372-
$dbSetup->runMigrations();
376+
$dbSetup->runMigrations($output);
373377
} catch (Exception $e) {
374378
$error[] = [
375379
'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
@@ -379,6 +383,7 @@ public function install($options) {
379383
return $error;
380384
}
381385

386+
$this->outputDebug($output, 'Create admin user');
382387
//create the user and group
383388
$user = null;
384389
try {
@@ -407,16 +412,19 @@ public function install($options) {
407412
}
408413

409414
// Install shipped apps and specified app bundles
410-
Installer::installShippedApps();
415+
$this->outputDebug($output, 'Install default apps');
416+
Installer::installShippedApps(false, $output);
411417

412418
// create empty file in data dir, so we can later find
413419
// out that this is indeed an ownCloud data directory
420+
$this->outputDebug($output, 'Setup data directory');
414421
file_put_contents($config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
415422

416423
// Update .htaccess files
417424
self::updateHtaccess();
418425
self::protectDataDirectory();
419426

427+
$this->outputDebug($output, 'Install background jobs');
420428
self::installBackgroundJobs();
421429

422430
//and we are done
@@ -616,4 +624,10 @@ public function shouldRemoveCanInstallFile() {
616624
public function canInstallFileExists() {
617625
return is_file(\OC::$configDir.'/CAN_INSTALL');
618626
}
627+
628+
protected function outputDebug(?IOutput $output, string $message): void {
629+
if ($output instanceof IOutput) {
630+
$output->debug($message);
631+
}
632+
}
619633
}

lib/private/Setup/AbstractDatabase.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
use OC\DB\MigrationService;
3434
use OC\SystemConfig;
3535
use OCP\IL10N;
36+
use OCP\Migration\IOutput;
3637
use OCP\Security\ISecureRandom;
3738
use Psr\Log\LoggerInterface;
3839

@@ -150,11 +151,11 @@ protected function connect(array $configOverwrite = []): Connection {
150151
*/
151152
abstract public function setupDatabase($username);
152153

153-
public function runMigrations() {
154+
public function runMigrations(?IOutput $output = null) {
154155
if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) {
155156
return;
156157
}
157-
$ms = new MigrationService('core', \OC::$server->get(Connection::class));
158+
$ms = new MigrationService('core', \OC::$server->get(Connection::class), $output);
158159
$ms->migrate('latest', true);
159160
}
160161
}

lib/public/Migration/IOutput.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,13 @@
2929
* @since 9.1.0
3030
*/
3131
interface IOutput {
32+
/**
33+
* @param string $message
34+
* @return void
35+
* @since 28.0.0
36+
*/
37+
public function debug(string $message): void;
38+
3239
/**
3340
* @param string $message
3441
* @return void

0 commit comments

Comments
 (0)