Skip to content

Commit a82ef8f

Browse files
committed
fix(install): Make installing more verbose
Signed-off-by: Joas Schilling <[email protected]>
1 parent e85f616 commit a82ef8f

File tree

10 files changed

+94
-19
lines changed

10 files changed

+94
-19
lines changed

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;
@@ -100,8 +102,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
100102
// validate user input
101103
$options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
102104

105+
if ($output->isVerbose()) {
106+
// Prepend each line with a little timestamp
107+
$timestampFormatter = new TimestampFormatter(null, $output->getFormatter());
108+
$output->setFormatter($timestampFormatter);
109+
$migrationOutput = new ConsoleOutput($output);
110+
} else {
111+
$migrationOutput = null;
112+
}
113+
103114
// perform installation
104-
$errors = $setupHelper->install($options);
115+
$errors = $setupHelper->install($options, $migrationOutput);
105116
if (count($errors) > 0) {
106117
$this->printErrors($output, $errors);
107118
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
@@ -406,6 +406,7 @@ public function setOutput(IOutput $output) {
406406
*/
407407
public function migrate($to = 'latest', $schemaOnly = false) {
408408
if ($schemaOnly) {
409+
$this->output->debug('Migrating schema only');
409410
$this->migrateSchemaOnly($to);
410411
return;
411412
}
@@ -439,6 +440,7 @@ public function migrateSchemaOnly($to = 'latest') {
439440

440441
$toSchema = null;
441442
foreach ($toBeExecuted as $version) {
443+
$this->output->debug('- Reading ' . $version);
442444
$instance = $this->createInstance($version);
443445

444446
$toSchema = $instance->changeSchema($this->output, function () use ($toSchema): ISchemaWrapper {
@@ -447,15 +449,19 @@ public function migrateSchemaOnly($to = 'latest') {
447449
}
448450

449451
if ($toSchema instanceof SchemaWrapper) {
452+
$this->output->debug('- Checking target database schema');
450453
$targetSchema = $toSchema->getWrappedSchema();
451454
if ($this->checkOracle) {
452455
$beforeSchema = $this->connection->createSchema();
453456
$this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix()));
454457
}
458+
459+
$this->output->debug('- Migrate database schema');
455460
$this->connection->migrateToSchema($targetSchema);
456461
$toSchema->performDropTableCalls();
457462
}
458463

464+
$this->output->debug('- Mark migrations as executed');
459465
foreach ($toBeExecuted as $version) {
460466
$this->markAsExecuted($version);
461467
}

lib/private/Installer.php

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

@@ -535,7 +536,10 @@ public function installAppBundle(Bundle $bundle) {
535536
* working ownCloud at the end instead of an aborted update.
536537
* @return array Array of error messages (appid => Exception)
537538
*/
538-
public static function installShippedApps($softErrors = false) {
539+
public static function installShippedApps($softErrors = false, ?IOutput $output = null) {
540+
if ($output instanceof IOutput) {
541+
$output->debug('Installing shipped apps');
542+
}
539543
$appManager = \OC::$server->getAppManager();
540544
$config = \OC::$server->getConfig();
541545
$errors = [];
@@ -550,7 +554,7 @@ public static function installShippedApps($softErrors = false) {
550554
&& $config->getAppValue($filename, 'enabled') !== 'no') {
551555
if ($softErrors) {
552556
try {
553-
Installer::installShippedApp($filename);
557+
Installer::installShippedApp($filename, $output);
554558
} catch (HintException $e) {
555559
if ($e->getPrevious() instanceof TableExistsException) {
556560
$errors[$filename] = $e;
@@ -559,7 +563,7 @@ public static function installShippedApps($softErrors = false) {
559563
throw $e;
560564
}
561565
} else {
562-
Installer::installShippedApp($filename);
566+
Installer::installShippedApp($filename, $output);
563567
}
564568
$config->setAppValue($filename, 'enabled', 'yes');
565569
}
@@ -577,16 +581,22 @@ public static function installShippedApps($softErrors = false) {
577581
/**
578582
* install an app already placed in the app folder
579583
* @param string $app id of the app to install
580-
* @return integer
584+
* @return string
581585
*/
582-
public static function installShippedApp($app) {
586+
public static function installShippedApp($app, ?IOutput $output = null) {
587+
if ($output instanceof IOutput) {
588+
$output->debug('Installing ' . $app);
589+
}
583590
//install the database
584591
$appPath = OC_App::getAppPath($app);
585592
\OC_App::registerAutoloading($app, $appPath);
586593

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

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

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

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

lib/private/Migration/ConsoleOutput.php

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

47+
/**
48+
* @param string $message
49+
*/
50+
public function debug($message) {
51+
$this->output->writeln($message);
52+
}
53+
4754
/**
4855
* @param string $message
4956
*/

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($message) {
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: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,12 @@ public static function getBeforeUpgradeRepairSteps() {
250250
return $steps;
251251
}
252252

253+
/**
254+
* @param string $message
255+
*/
256+
public function debug($message) {
257+
}
258+
253259
/**
254260
* @param string $message
255261
*/

lib/private/Setup.php

Lines changed: 19 additions & 4 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

@@ -272,10 +273,11 @@ public function getSystemInfo($allowAllDatabases = false) {
272273
}
273274

274275
/**
275-
* @param $options
276+
* @param array{dbtype: string, dbuser: string, dbpass: ?string, dbname: string, dbhost: string, adminlogin: string, adminpass: string, adminemail: ?string, directory: string, dbtablespace?: string} $options
277+
* @param ?IOutput $output
276278
* @return array
277279
*/
278-
public function install($options) {
280+
public function install($options, ?IOutput $output = null) {
279281
$l = $this->l10n;
280282

281283
$error = [];
@@ -349,6 +351,7 @@ public function install($options) {
349351

350352
$this->config->setValues($newConfigValues);
351353

354+
$this->outputDebug($output, 'Configuring database');
352355
$dbSetup->initialize($options);
353356
try {
354357
$dbSetup->setupDatabase($username);
@@ -367,9 +370,11 @@ public function install($options) {
367370
];
368371
return $error;
369372
}
373+
374+
$this->outputDebug($output, 'Run server migrations');
370375
try {
371376
// apply necessary migrations
372-
$dbSetup->runMigrations();
377+
$dbSetup->runMigrations($output);
373378
} catch (Exception $e) {
374379
$error[] = [
375380
'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
@@ -379,6 +384,7 @@ public function install($options) {
379384
return $error;
380385
}
381386

387+
$this->outputDebug($output, 'Create admin user');
382388
//create the user and group
383389
$user = null;
384390
try {
@@ -407,16 +413,19 @@ public function install($options) {
407413
}
408414

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

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

416424
// Update .htaccess files
417425
self::updateHtaccess();
418426
self::protectDataDirectory();
419427

428+
$this->outputDebug($output, 'Install background jobs');
420429
self::installBackgroundJobs();
421430

422431
//and we are done
@@ -616,4 +625,10 @@ public function shouldRemoveCanInstallFile() {
616625
public function canInstallFileExists() {
617626
return is_file(\OC::$configDir.'/CAN_INSTALL');
618627
}
628+
629+
protected function outputDebug(?IOutput $output, string $message): void {
630+
if ($output instanceof IOutput) {
631+
$output->debug($message);
632+
}
633+
}
619634
}

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($message);
38+
3239
/**
3340
* @param string $message
3441
* @return void

0 commit comments

Comments
 (0)