fix(install): Make installing more verbose

Signed-off-by: Joas Schilling <coding@schilljs.com>
pull/41214/head
Joas Schilling 2023-10-31 12:06:09 +07:00
parent 50de7553b5
commit 6f39d82031
No known key found for this signature in database
GPG Key ID: 74434EFE0D2E2205
10 changed files with 86 additions and 18 deletions

@ -32,7 +32,9 @@ namespace OC\Core\Command\Maintenance;
use bantu\IniGetWrapper\IniGetWrapper; use bantu\IniGetWrapper\IniGetWrapper;
use InvalidArgumentException; use InvalidArgumentException;
use OC\Console\TimestampFormatter;
use OC\Installer; use OC\Installer;
use OC\Migration\ConsoleOutput;
use OC\Setup; use OC\Setup;
use OC\SystemConfig; use OC\SystemConfig;
use OCP\Defaults; use OCP\Defaults;
@ -98,8 +100,17 @@ class Install extends Command {
// validate user input // validate user input
$options = $this->validateInput($input, $output, array_keys($sysInfo['databases'])); $options = $this->validateInput($input, $output, array_keys($sysInfo['databases']));
if ($output->isVerbose()) {
// Prepend each line with a little timestamp
$timestampFormatter = new TimestampFormatter(null, $output->getFormatter());
$output->setFormatter($timestampFormatter);
$migrationOutput = new ConsoleOutput($output);
} else {
$migrationOutput = null;
}
// perform installation // perform installation
$errors = $setupHelper->install($options); $errors = $setupHelper->install($options, $migrationOutput);
if (count($errors) > 0) { if (count($errors) > 0) {
$this->printErrors($output, $errors); $this->printErrors($output, $errors);
return 1; return 1;

@ -27,17 +27,17 @@ use Symfony\Component\Console\Formatter\OutputFormatterInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface; use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;
class TimestampFormatter implements OutputFormatterInterface { class TimestampFormatter implements OutputFormatterInterface {
/** @var IConfig */ /** @var ?IConfig */
protected $config; protected $config;
/** @var OutputFormatterInterface */ /** @var OutputFormatterInterface */
protected $formatter; protected $formatter;
/** /**
* @param IConfig $config * @param ?IConfig $config
* @param OutputFormatterInterface $formatter * @param OutputFormatterInterface $formatter
*/ */
public function __construct(IConfig $config, OutputFormatterInterface $formatter) { public function __construct(?IConfig $config, OutputFormatterInterface $formatter) {
$this->config = $config; $this->config = $config;
$this->formatter = $formatter; $this->formatter = $formatter;
} }
@ -104,11 +104,16 @@ class TimestampFormatter implements OutputFormatterInterface {
return $this->formatter->format($message); return $this->formatter->format($message);
} }
$timeZone = $this->config->getSystemValue('logtimezone', 'UTC'); if ($this->config instanceof IConfig) {
$timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null; $timeZone = $this->config->getSystemValue('logtimezone', 'UTC');
$timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;
$time = new \DateTime('now', $timeZone); $time = new \DateTime('now', $timeZone);
$timestampInfo = $time->format($this->config->getSystemValue('logdateformat', \DateTimeInterface::ATOM)); $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); return $timestampInfo . ' ' . $this->formatter->format($message);
} }

@ -390,6 +390,7 @@ class MigrationService {
*/ */
public function migrate(string $to = 'latest', bool $schemaOnly = false): void { public function migrate(string $to = 'latest', bool $schemaOnly = false): void {
if ($schemaOnly) { if ($schemaOnly) {
$this->output->debug('Migrating schema only');
$this->migrateSchemaOnly($to); $this->migrateSchemaOnly($to);
return; return;
} }
@ -421,6 +422,7 @@ class MigrationService {
$toSchema = null; $toSchema = null;
foreach ($toBeExecuted as $version) { foreach ($toBeExecuted as $version) {
$this->output->debug('- Reading ' . $version);
$instance = $this->createInstance($version); $instance = $this->createInstance($version);
$toSchema = $instance->changeSchema($this->output, function () use ($toSchema): ISchemaWrapper { $toSchema = $instance->changeSchema($this->output, function () use ($toSchema): ISchemaWrapper {
@ -429,16 +431,20 @@ class MigrationService {
} }
if ($toSchema instanceof SchemaWrapper) { if ($toSchema instanceof SchemaWrapper) {
$this->output->debug('- Checking target database schema');
$targetSchema = $toSchema->getWrappedSchema(); $targetSchema = $toSchema->getWrappedSchema();
$this->ensureUniqueNamesConstraints($targetSchema); $this->ensureUniqueNamesConstraints($targetSchema);
if ($this->checkOracle) { if ($this->checkOracle) {
$beforeSchema = $this->connection->createSchema(); $beforeSchema = $this->connection->createSchema();
$this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix())); $this->ensureOracleConstraints($beforeSchema, $targetSchema, strlen($this->connection->getPrefix()));
} }
$this->output->debug('- Migrate database schema');
$this->connection->migrateToSchema($targetSchema); $this->connection->migrateToSchema($targetSchema);
$toSchema->performDropTableCalls(); $toSchema->performDropTableCalls();
} }
$this->output->debug('- Mark migrations as executed');
foreach ($toBeExecuted as $version) { foreach ($toBeExecuted as $version) {
$this->markAsExecuted($version); $this->markAsExecuted($version);
} }

@ -53,6 +53,7 @@ use OCP\HintException;
use OCP\Http\Client\IClientService; use OCP\Http\Client\IClientService;
use OCP\IConfig; use OCP\IConfig;
use OCP\ITempManager; use OCP\ITempManager;
use OCP\Migration\IOutput;
use phpseclib\File\X509; use phpseclib\File\X509;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -536,7 +537,10 @@ class Installer {
* working ownCloud at the end instead of an aborted update. * working ownCloud at the end instead of an aborted update.
* @return array Array of error messages (appid => Exception) * @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(); $appManager = \OC::$server->getAppManager();
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$errors = []; $errors = [];
@ -551,7 +555,7 @@ class Installer {
&& $config->getAppValue($filename, 'enabled') !== 'no') { && $config->getAppValue($filename, 'enabled') !== 'no') {
if ($softErrors) { if ($softErrors) {
try { try {
Installer::installShippedApp($filename); Installer::installShippedApp($filename, $output);
} catch (HintException $e) { } catch (HintException $e) {
if ($e->getPrevious() instanceof TableExistsException) { if ($e->getPrevious() instanceof TableExistsException) {
$errors[$filename] = $e; $errors[$filename] = $e;
@ -560,7 +564,7 @@ class Installer {
throw $e; throw $e;
} }
} else { } else {
Installer::installShippedApp($filename); Installer::installShippedApp($filename, $output);
} }
$config->setAppValue($filename, 'enabled', 'yes'); $config->setAppValue($filename, 'enabled', 'yes');
} }
@ -578,9 +582,12 @@ class Installer {
/** /**
* install an app already placed in the app folder * install an app already placed in the app folder
* @param string $app id of the app to install * @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 //install the database
$appPath = OC_App::getAppPath($app); $appPath = OC_App::getAppPath($app);
\OC_App::registerAutoloading($app, $appPath); \OC_App::registerAutoloading($app, $appPath);
@ -588,6 +595,9 @@ class Installer {
$config = \OC::$server->getConfig(); $config = \OC::$server->getConfig();
$ms = new MigrationService($app, \OC::$server->get(Connection::class)); $ms = new MigrationService($app, \OC::$server->get(Connection::class));
if ($output instanceof IOutput) {
$ms->setOutput($output);
}
$previousVersion = $config->getAppValue($app, 'installed_version', false); $previousVersion = $config->getAppValue($app, 'installed_version', false);
$ms->migrate('latest', !$previousVersion); $ms->migrate('latest', !$previousVersion);
@ -598,6 +608,9 @@ class Installer {
if (is_null($info)) { if (is_null($info)) {
return false; return false;
} }
if ($output instanceof IOutput) {
$output->debug('Registering tasks of ' . $app);
}
\OC_App::setupBackgroundJobs($info['background-jobs']); \OC_App::setupBackgroundJobs($info['background-jobs']);
OC_App::executeRepairSteps($app, $info['repair-steps']['install']); OC_App::executeRepairSteps($app, $info['repair-steps']['install']);

@ -44,6 +44,10 @@ class ConsoleOutput implements IOutput {
$this->output = $output; $this->output = $output;
} }
public function debug(string $message): void {
$this->output->writeln($message, OutputInterface::VERBOSITY_VERBOSE);
}
/** /**
* @param string $message * @param string $message
*/ */

@ -41,6 +41,10 @@ class SimpleOutput implements IOutput {
$this->appName = $appName; $this->appName = $appName;
} }
public function debug(string $message): void {
$this->logger->debug($message, ['app' => $this->appName]);
}
/** /**
* @param string $message * @param string $message
* @since 9.1.0 * @since 9.1.0

@ -246,6 +246,9 @@ class Repair implements IOutput {
return $steps; return $steps;
} }
public function debug(string $message): void {
}
/** /**
* @param string $message * @param string $message
*/ */

@ -60,6 +60,7 @@ use OCP\AppFramework\Utility\ITimeFactory;
use OCP\Defaults; use OCP\Defaults;
use OCP\IGroup; use OCP\IGroup;
use OCP\IL10N; use OCP\IL10N;
use OCP\Migration\IOutput;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -275,7 +276,7 @@ class Setup {
* @param $options * @param $options
* @return array * @return array
*/ */
public function install($options) { public function install($options, ?IOutput $output = null) {
$l = $this->l10n; $l = $this->l10n;
$error = []; $error = [];
@ -349,6 +350,7 @@ class Setup {
$this->config->setValues($newConfigValues); $this->config->setValues($newConfigValues);
$this->outputDebug($output, 'Configuring database');
$dbSetup->initialize($options); $dbSetup->initialize($options);
try { try {
$dbSetup->setupDatabase($username); $dbSetup->setupDatabase($username);
@ -367,9 +369,11 @@ class Setup {
]; ];
return $error; return $error;
} }
$this->outputDebug($output, 'Run server migrations');
try { try {
// apply necessary migrations // apply necessary migrations
$dbSetup->runMigrations(); $dbSetup->runMigrations($output);
} catch (Exception $e) { } catch (Exception $e) {
$error[] = [ $error[] = [
'error' => 'Error while trying to initialise the database: ' . $e->getMessage(), 'error' => 'Error while trying to initialise the database: ' . $e->getMessage(),
@ -379,6 +383,7 @@ class Setup {
return $error; return $error;
} }
$this->outputDebug($output, 'Create admin user');
//create the user and group //create the user and group
$user = null; $user = null;
try { try {
@ -407,16 +412,19 @@ class Setup {
} }
// Install shipped apps and specified app bundles // 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 // create empty file in data dir, so we can later find
// out that this is indeed an ownCloud data directory // 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', ''); file_put_contents($config->getSystemValueString('datadirectory', \OC::$SERVERROOT . '/data') . '/.ocdata', '');
// Update .htaccess files // Update .htaccess files
self::updateHtaccess(); self::updateHtaccess();
self::protectDataDirectory(); self::protectDataDirectory();
$this->outputDebug($output, 'Install background jobs');
self::installBackgroundJobs(); self::installBackgroundJobs();
//and we are done //and we are done
@ -616,4 +624,10 @@ class Setup {
public function canInstallFileExists() { public function canInstallFileExists() {
return is_file(\OC::$configDir.'/CAN_INSTALL'); return is_file(\OC::$configDir.'/CAN_INSTALL');
} }
protected function outputDebug(?IOutput $output, string $message): void {
if ($output instanceof IOutput) {
$output->debug($message);
}
}
} }

@ -33,6 +33,7 @@ use OC\DB\ConnectionFactory;
use OC\DB\MigrationService; use OC\DB\MigrationService;
use OC\SystemConfig; use OC\SystemConfig;
use OCP\IL10N; use OCP\IL10N;
use OCP\Migration\IOutput;
use OCP\Security\ISecureRandom; use OCP\Security\ISecureRandom;
use Psr\Log\LoggerInterface; use Psr\Log\LoggerInterface;
@ -150,11 +151,11 @@ abstract class AbstractDatabase {
*/ */
abstract public function setupDatabase($username); abstract public function setupDatabase($username);
public function runMigrations() { public function runMigrations(?IOutput $output = null) {
if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) { if (!is_dir(\OC::$SERVERROOT."/core/Migrations")) {
return; return;
} }
$ms = new MigrationService('core', \OC::$server->get(Connection::class)); $ms = new MigrationService('core', \OC::$server->get(Connection::class), $output);
$ms->migrate('latest', true); $ms->migrate('latest', true);
} }
} }

@ -29,6 +29,13 @@ namespace OCP\Migration;
* @since 9.1.0 * @since 9.1.0
*/ */
interface IOutput { interface IOutput {
/**
* @param string $message
* @return void
* @since 28.0.0
*/
public function debug(string $message): void;
/** /**
* @param string $message * @param string $message
* @return void * @return void