From 624460f6aece470699ff5859b118cb77e0e1df6d Mon Sep 17 00:00:00 2001 From: Roeland Jago Douma Date: Fri, 22 Dec 2017 13:28:38 +0100 Subject: [PATCH] DI ITimestampFormatter into upgrade command Signed-off-by: Roeland Jago Douma --- core/Command/Upgrade.php | 13 +++++++++---- core/register_command.php | 7 ++++++- lib/private/Console/TimestampFormatter.php | 3 ++- lib/private/Server.php | 3 +++ 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/core/Command/Upgrade.php b/core/Command/Upgrade.php index bb6cdcfb920bb..c5816cc5e989c 100644 --- a/core/Command/Upgrade.php +++ b/core/Command/Upgrade.php @@ -37,6 +37,7 @@ use OC\Console\TimestampFormatter; use OC\Installer; use OC\Updater; +use OCP\Console\ITimestampFormatter; use OCP\IConfig; use OCP\ILogger; use Symfony\Component\Console\Command\Command; @@ -61,16 +62,21 @@ class Upgrade extends Command { /** @var ILogger */ private $logger; + /** @var ITimestampFormatter */ + private $timestampFormatter; + /** * @param IConfig $config * @param ILogger $logger * @param Installer $installer + * @param ITimestampFormatter $timestampFormatter */ - public function __construct(IConfig $config, ILogger $logger, Installer $installer) { + public function __construct(IConfig $config, ILogger $logger, Installer $installer, ITimestampFormatter $timestampFormatter) { parent::__construct(); $this->config = $config; $this->logger = $logger; $this->installer = $installer; + $this->timestampFormatter = $timestampFormatter; } protected function configure() { @@ -96,9 +102,8 @@ protected function execute(InputInterface $input, OutputInterface $output) { if(\OC::checkUpgrade(false)) { if (OutputInterface::VERBOSITY_NORMAL < $output->getVerbosity()) { // Prepend each line with a little timestamp - $timestampFormatter = new TimestampFormatter($this->config); - $timestampFormatter->setFormatter($output->getFormatter()); - $output->setFormatter($timestampFormatter); + $this->timestampFormatter->setFormatter($output->getFormatter()); + $output->setFormatter($this->stimestampFormatter); } $self = $this; diff --git a/core/register_command.php b/core/register_command.php index 372d775dc14ae..bb2d4b20741c1 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -138,7 +138,12 @@ $application->add(new OC\Core\Command\Maintenance\UpdateHtaccess()); $application->add(new OC\Core\Command\Maintenance\UpdateTheme(\OC::$server->getMimeTypeDetector(), \OC::$server->getMemCacheFactory())); - $application->add(new OC\Core\Command\Upgrade(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->query(\OC\Installer::class))); + $application->add(new OC\Core\Command\Upgrade( + \OC::$server->getConfig(), + \OC::$server->getLogger(), + \OC::$server->query(\OC\Installer::class), + \OC::$server->query(\OCP\Console\ITimestampFormatter::class) + )); $application->add(new OC\Core\Command\Maintenance\Repair( new \OC\Repair(\OC\Repair::getRepairSteps(), \OC::$server->getEventDispatcher()), \OC::$server->getConfig(), \OC::$server->getEventDispatcher(), \OC::$server->getAppManager())); diff --git a/lib/private/Console/TimestampFormatter.php b/lib/private/Console/TimestampFormatter.php index 3784e10b036fa..d9a61f7c4e17b 100644 --- a/lib/private/Console/TimestampFormatter.php +++ b/lib/private/Console/TimestampFormatter.php @@ -23,12 +23,13 @@ namespace OC\Console; +use OCP\Console\ITimestampFormatter; use OCP\IConfig; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Formatter\OutputFormatterInterface; use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface; -class TimestampFormatter implements OutputFormatterInterface { +class TimestampFormatter implements ITimestampFormatter { /** @var IConfig */ protected $config; diff --git a/lib/private/Server.php b/lib/private/Server.php index 68c9f27b96af4..533d3ff4ff35c 100644 --- a/lib/private/Server.php +++ b/lib/private/Server.php @@ -62,6 +62,7 @@ use OC\Collaboration\Collaborators\RemotePlugin; use OC\Collaboration\Collaborators\UserPlugin; use OC\Command\CronBus; +use OC\Console\TimestampFormatter; use OC\Contacts\ContactsMenu\ActionFactory; use OC\Contacts\ContactsMenu\ContactsStore; use OC\Diagnostics\EventLogger; @@ -1147,6 +1148,8 @@ public function __construct($webRoot, \OC\Config $config) { }); $this->registerAlias(IContactsStore::class, ContactsStore::class); + $this->registerAlias(ITimestampFormatter::class, TimestampFormatter::class); + $this->connectDispatcher(); }