Skip to content

Adds some more colors to the output of certain setup cli commands #29298

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions lib/internal/Magento/Framework/Setup/BackupRollback.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
*/
class BackupRollback
{
/**
* Default backup directory
*/
public const DEFAULT_BACKUP_DIRECTORY = 'backups';

/**
Expand All @@ -42,7 +39,7 @@ class BackupRollback
/**
* Logger
*
* @var LoggerInterface
* @var ConsoleLoggerInterface
*/
private $log;

Expand All @@ -69,14 +66,14 @@ class BackupRollback
* Constructor
*
* @param ObjectManagerInterface $objectManager
* @param LoggerInterface $log
* @param ConsoleLoggerInterface $log
* @param DirectoryList $directoryList
* @param File $file
* @param Helper $fsHelper
*/
public function __construct(
ObjectManagerInterface $objectManager,
LoggerInterface $log,
ConsoleLoggerInterface $log,
DirectoryList $directoryList,
File $file,
Helper $fsHelper
Expand Down
28 changes: 15 additions & 13 deletions lib/internal/Magento/Framework/Setup/ConsoleLogger.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,7 @@
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Formatter\OutputFormatterStyle;

/**
* Console Logger
*
* @package Magento\Setup\Model
*/
class ConsoleLogger implements LoggerInterface
class ConsoleLogger implements ConsoleLoggerInterface
{
/**
* Indicator of whether inline output is started
Expand All @@ -24,8 +19,6 @@ class ConsoleLogger implements LoggerInterface
private $isInline = false;

/**
* Console
*
* @var OutputInterface
*/
protected $console;
Expand All @@ -44,7 +37,7 @@ public function __construct(OutputInterface $output)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function logSuccess($message)
{
Expand All @@ -53,7 +46,7 @@ public function logSuccess($message)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function logError(\Exception $e)
{
Expand All @@ -62,7 +55,7 @@ public function logError(\Exception $e)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function log($message)
{
Expand All @@ -71,7 +64,7 @@ public function log($message)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function logInline($message)
{
Expand All @@ -80,14 +73,23 @@ public function logInline($message)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function logMeta($message)
{
$this->terminateLine();
$this->console->writeln('<metadata>' . $message . '</metadata>');
}

/**
* @inheritdoc
*/
public function logMetaInline($message)
{
$this->isInline = true;
$this->console->write('<metadata>' . $message . '</metadata>');
}

/**
* Terminates line if the inline logging is started
*
Expand Down
64 changes: 64 additions & 0 deletions lib/internal/Magento/Framework/Setup/ConsoleLoggerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Framework\Setup;

/**
* Interface to Log Message in Setup
*
* @api
*/
interface ConsoleLoggerInterface
{
/**
* Logs success message
*
* @param string $message
* @return void
*/
public function logSuccess(string $message);

/**
* Logs error message
*
* @param \Exception $e
* @return void
*/
public function logError(\Exception $e);

/**
* Logs a message
*
* @param string $message
* @return void
*/
public function log(string $message);

/**
* Logs a message in the current line
*
* @param string $message
* @return void
*/
public function logInline(string $message);

/**
* Logs meta information
*
* @param string $message
* @return void
*/
public function logMeta(string $message);

/**
* Logs meta information in the current line
*
* @param string $message
* @return void
*/
public function logMetaInline(string $message);
}
3 changes: 3 additions & 0 deletions lib/internal/Magento/Framework/Setup/LoggerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
* Interface to Log Message in Setup
*
* @api
* @deprecated Replaced with ConsoleLogger
* @see Magento\Framework\Setup\ConsoleLogger
*
* @since 100.0.2
*/
interface LoggerInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
use Magento\Framework\ObjectManager\ConfigLoaderInterface;
use Magento\Framework\ObjectManagerInterface;
use Magento\Framework\Setup\BackupRollback;
use Magento\Framework\Setup\LoggerInterface;
use Magento\Framework\Setup\ConsoleLoggerInterface;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -33,7 +33,7 @@ class BackupRollbackTest extends TestCase
private $objectManager;

/**
* @var LoggerInterface|MockObject
* @var ConsoleLoggerInterface|MockObject
*/
private $log;

Expand Down Expand Up @@ -75,7 +75,7 @@ class BackupRollbackTest extends TestCase
protected function setUp(): void
{
$this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class);
$this->log = $this->getMockForAbstractClass(LoggerInterface::class);
$this->log = $this->getMockForAbstractClass(ConsoleLoggerInterface::class);
$this->directoryList = $this->createMock(DirectoryList::class);
$this->path = realpath(__DIR__);
$this->directoryList->expects($this->any())
Expand Down
38 changes: 19 additions & 19 deletions setup/src/Magento/Setup/Model/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@
use Magento\Framework\Module\ModuleListInterface;
use Magento\Framework\Module\ModuleResource;
use Magento\Framework\Mview\TriggerCleaner;
use Magento\Framework\Setup\ConsoleLoggerInterface;
use Magento\Framework\Setup\Declaration\Schema\DryRunLogger;
use Magento\Framework\Setup\FilePermissions;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\InstallSchemaInterface;
use Magento\Framework\Setup\LoggerInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\Patch\PatchApplier;
use Magento\Framework\Setup\Patch\PatchApplierFactory;
Expand Down Expand Up @@ -136,7 +136,7 @@ class Installer
/**
* Logger
*
* @var LoggerInterface
* @var ConsoleLoggerInterface
*/
private $log;

Expand Down Expand Up @@ -269,7 +269,7 @@ class Installer
* @param ModuleListInterface $moduleList
* @param ModuleLoader $moduleLoader
* @param AdminAccountFactory $adminAccountFactory
* @param LoggerInterface $log
* @param ConsoleLoggerInterface $log
* @param ConnectionFactory $connectionFactory
* @param MaintenanceMode $maintenanceMode
* @param Filesystem $filesystem
Expand All @@ -294,7 +294,7 @@ public function __construct(
ModuleListInterface $moduleList,
ModuleLoader $moduleLoader,
AdminAccountFactory $adminAccountFactory,
LoggerInterface $log,
ConsoleLoggerInterface $log,
ConnectionFactory $connectionFactory,
MaintenanceMode $maintenanceMode,
Filesystem $filesystem,
Expand Down Expand Up @@ -394,7 +394,7 @@ public function install($request)
$total = count($script) + 4 * count(array_filter($estimatedModules));
$this->progress = new Installer\Progress($total, 0);

$this->log->log('Starting Magento installation:');
$this->log->logMeta('Starting Magento installation:');

foreach ($script as $item) {
/* Note: Because the $this->DeploymentConfig gets written to, but plugins use $this->firstDeploymentConfig,
Expand Down Expand Up @@ -912,7 +912,7 @@ public function installSchema(array $request)
$this->setupModuleRegistry($setup);
$this->setupCoreTables($setup);
$this->cleanMemoryTables($setup);
$this->log->log('Schema creation/updates:');
$this->log->logMeta('Schema creation/updates:');
$this->declarativeInstallSchema($request);
$this->handleDBSchemaData($setup, 'schema', $request);
/** @var Mysql $adapter */
Expand Down Expand Up @@ -960,7 +960,7 @@ public function installDataFixtures(array $request = [])
$this->assertDbAccessible();
$setup = $this->dataSetupFactory->create();
$this->checkFilePermissionsForDbUpgrade();
$this->log->log('Data install/update:');
$this->log->logMeta('Data install/update:');

$this->handleDBSchemaData($setup, 'data', $request);

Expand Down Expand Up @@ -1054,7 +1054,7 @@ private function handleDBSchemaData($setup, $type, array $request)
if ($status == \Magento\Framework\Setup\ModuleDataSetupInterface::VERSION_COMPARE_GREATER) {
$upgrader = $this->getSchemaDataHandler($moduleName, $upgradeType);
if ($upgrader) {
$this->log->logInline("Upgrading $type.. ");
$this->log->logMetaInline("Upgrading $type.. ");
$upgrader->upgrade($setup, $moduleContextList[$moduleName]);
if ($type === 'schema') {
$resource->setDbVersion($moduleName, $configVer);
Expand All @@ -1066,12 +1066,12 @@ private function handleDBSchemaData($setup, $type, array $request)
} elseif ($configVer) {
$installer = $this->getSchemaDataHandler($moduleName, $installType);
if ($installer) {
$this->log->logInline("Installing $type... ");
$this->log->logMetaInline("Installing $type... ");
$installer->install($setup, $moduleContextList[$moduleName]);
}
$upgrader = $this->getSchemaDataHandler($moduleName, $upgradeType);
if ($upgrader) {
$this->log->logInline("Upgrading $type... ");
$this->log->logMetaInline("Upgrading $type... ");
$upgrader->upgrade($setup, $moduleContextList[$moduleName]);
}
}
Expand All @@ -1097,9 +1097,9 @@ private function handleDBSchemaData($setup, $type, array $request)
}

if ($type === 'schema') {
$this->log->log('Schema post-updates:');
$this->log->logMeta('Schema post-updates:');
} elseif ($type === 'data') {
$this->log->log('Data post-updates:');
$this->log->logMeta('Data post-updates:');
}
$handlerType = $type === 'schema' ? 'schema-recurring' : 'data-recurring';

Expand All @@ -1112,7 +1112,7 @@ private function handleDBSchemaData($setup, $type, array $request)
$this->log->log("Module '{$moduleName}':");
$modulePostUpdater = $this->getSchemaDataHandler($moduleName, $handlerType);
if ($modulePostUpdater) {
$this->log->logInline('Running ' . str_replace('-', ' ', $handlerType) . '...');
$this->log->logMetaInline('Running ' . str_replace('-', ' ', $handlerType) . '...');
$modulePostUpdater->install($setup, $moduleContextList[$moduleName]);
}
$this->logProgress();
Expand Down Expand Up @@ -1367,7 +1367,7 @@ public function updateModulesSequence($keepGeneratedFiles = false)
if (!$keepGeneratedFiles) {
$this->cleanupGeneratedFiles();
}
$this->log->log('Updating modules:');
$this->log->logMeta('Updating modules:');
$this->createModulesConfig([]);
}

Expand All @@ -1389,7 +1389,7 @@ public function getModulesConfig()
*/
public function uninstall()
{
$this->log->log('Starting Magento uninstallation:');
$this->log->logMeta('Starting Magento uninstallation:');

try {
$this->cleanCaches();
Expand All @@ -1403,7 +1403,7 @@ public function uninstall()

$this->cleanupDb();

$this->log->log('File system cleanup:');
$this->log->logMeta('File system cleanup:');
$messages = $this->cleanupFiles->clearAllFiles();
foreach ($messages as $message) {
$this->log->log($message);
Expand Down Expand Up @@ -1454,7 +1454,7 @@ private function cleanCaches()
$cacheManager = $this->objectManagerProvider->get()->get(Manager::class);
$types = $cacheManager->getAvailableTypes();
$cacheManager->clean($types);
$this->log->log('Cache cleared successfully');
$this->log->logSuccess('Cache cleared successfully');
}

/**
Expand All @@ -1471,7 +1471,7 @@ private function flushCaches($types = [])
$cacheManager = $this->objectManagerProvider->get()->get(Manager::class);
$types = empty($types) ? $cacheManager->getAvailableTypes() : $types;
$cacheManager->flush($types);
$this->log->log('Cache types ' . implode(',', $types) . ' flushed successfully');
$this->log->logSuccess('Cache types ' . implode(',', $types) . ' flushed successfully');
}

/**
Expand Down Expand Up @@ -1703,7 +1703,7 @@ private function generateListOfModuleContext($resource, $type)
*/
private function cleanupGeneratedFiles()
{
$this->log->log('File system cleanup:');
$this->log->logMeta('File system cleanup:');
$messages = $this->cleanupFiles->clearCodeGeneratedFiles();

// unload Magento autoloader because it may be using compiled definition
Expand Down
Loading