Skip to content

Commit 7660644

Browse files
Indrani SonawaneIndrani Sonawane
authored andcommitted
Merge remote-tracking branch '29298/colorize-cli-output-setup-commands' into community_prs_march
2 parents ede902f + cd6c7bf commit 7660644

File tree

9 files changed

+307
-86
lines changed

9 files changed

+307
-86
lines changed

lib/internal/Magento/Framework/Setup/BackupRollback.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
*/
2323
class BackupRollback
2424
{
25-
/**
26-
* Default backup directory
27-
*/
2825
public const DEFAULT_BACKUP_DIRECTORY = 'backups';
2926

3027
/**
@@ -42,7 +39,7 @@ class BackupRollback
4239
/**
4340
* Logger
4441
*
45-
* @var LoggerInterface
42+
* @var ConsoleLoggerInterface
4643
*/
4744
private $log;
4845

@@ -69,14 +66,14 @@ class BackupRollback
6966
* Constructor
7067
*
7168
* @param ObjectManagerInterface $objectManager
72-
* @param LoggerInterface $log
69+
* @param ConsoleLoggerInterface $log
7370
* @param DirectoryList $directoryList
7471
* @param File $file
7572
* @param Helper $fsHelper
7673
*/
7774
public function __construct(
7875
ObjectManagerInterface $objectManager,
79-
LoggerInterface $log,
76+
ConsoleLoggerInterface $log,
8077
DirectoryList $directoryList,
8178
File $file,
8279
Helper $fsHelper

lib/internal/Magento/Framework/Setup/ConsoleLogger.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,7 @@
99
use Symfony\Component\Console\Output\OutputInterface;
1010
use Symfony\Component\Console\Formatter\OutputFormatterStyle;
1111

12-
/**
13-
* Console Logger
14-
*
15-
* @package Magento\Setup\Model
16-
*/
17-
class ConsoleLogger implements LoggerInterface
12+
class ConsoleLogger implements ConsoleLoggerInterface
1813
{
1914
/**
2015
* Indicator of whether inline output is started
@@ -24,8 +19,6 @@ class ConsoleLogger implements LoggerInterface
2419
private $isInline = false;
2520

2621
/**
27-
* Console
28-
*
2922
* @var OutputInterface
3023
*/
3124
protected $console;
@@ -44,7 +37,7 @@ public function __construct(OutputInterface $output)
4437
}
4538

4639
/**
47-
* {@inheritdoc}
40+
* @inheritdoc
4841
*/
4942
public function logSuccess($message)
5043
{
@@ -53,7 +46,7 @@ public function logSuccess($message)
5346
}
5447

5548
/**
56-
* {@inheritdoc}
49+
* @inheritdoc
5750
*/
5851
public function logError(\Exception $e)
5952
{
@@ -62,7 +55,7 @@ public function logError(\Exception $e)
6255
}
6356

6457
/**
65-
* {@inheritdoc}
58+
* @inheritdoc
6659
*/
6760
public function log($message)
6861
{
@@ -71,7 +64,7 @@ public function log($message)
7164
}
7265

7366
/**
74-
* {@inheritdoc}
67+
* @inheritdoc
7568
*/
7669
public function logInline($message)
7770
{
@@ -80,14 +73,23 @@ public function logInline($message)
8073
}
8174

8275
/**
83-
* {@inheritdoc}
76+
* @inheritdoc
8477
*/
8578
public function logMeta($message)
8679
{
8780
$this->terminateLine();
8881
$this->console->writeln('<metadata>' . $message . '</metadata>');
8982
}
9083

84+
/**
85+
* @inheritdoc
86+
*/
87+
public function logMetaInline($message)
88+
{
89+
$this->isInline = true;
90+
$this->console->write('<metadata>' . $message . '</metadata>');
91+
}
92+
9193
/**
9294
* Terminates line if the inline logging is started
9395
*
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
declare(strict_types=1);
7+
8+
namespace Magento\Framework\Setup;
9+
10+
/**
11+
* Interface to Log Message in Setup
12+
*
13+
* @api
14+
*/
15+
interface ConsoleLoggerInterface
16+
{
17+
/**
18+
* Logs success message
19+
*
20+
* @param string $message
21+
* @return void
22+
*/
23+
public function logSuccess(string $message);
24+
25+
/**
26+
* Logs error message
27+
*
28+
* @param \Exception $e
29+
* @return void
30+
*/
31+
public function logError(\Exception $e);
32+
33+
/**
34+
* Logs a message
35+
*
36+
* @param string $message
37+
* @return void
38+
*/
39+
public function log(string $message);
40+
41+
/**
42+
* Logs a message in the current line
43+
*
44+
* @param string $message
45+
* @return void
46+
*/
47+
public function logInline(string $message);
48+
49+
/**
50+
* Logs meta information
51+
*
52+
* @param string $message
53+
* @return void
54+
*/
55+
public function logMeta(string $message);
56+
57+
/**
58+
* Logs meta information in the current line
59+
*
60+
* @param string $message
61+
* @return void
62+
*/
63+
public function logMetaInline(string $message);
64+
}

lib/internal/Magento/Framework/Setup/LoggerInterface.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
* Interface to Log Message in Setup
1111
*
1212
* @api
13+
* @deprecated Replaced with ConsoleLogger
14+
* @see Magento\Framework\Setup\ConsoleLogger
15+
*
1316
* @since 100.0.2
1417
*/
1518
interface LoggerInterface

lib/internal/Magento/Framework/Setup/Test/Unit/BackupRollbackTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
use Magento\Framework\ObjectManager\ConfigLoaderInterface;
1919
use Magento\Framework\ObjectManagerInterface;
2020
use Magento\Framework\Setup\BackupRollback;
21-
use Magento\Framework\Setup\LoggerInterface;
21+
use Magento\Framework\Setup\ConsoleLoggerInterface;
2222
use PHPUnit\Framework\MockObject\MockObject;
2323
use PHPUnit\Framework\TestCase;
2424

@@ -33,7 +33,7 @@ class BackupRollbackTest extends TestCase
3333
private $objectManager;
3434

3535
/**
36-
* @var LoggerInterface|MockObject
36+
* @var ConsoleLoggerInterface|MockObject
3737
*/
3838
private $log;
3939

@@ -75,7 +75,7 @@ class BackupRollbackTest extends TestCase
7575
protected function setUp(): void
7676
{
7777
$this->objectManager = $this->getMockForAbstractClass(ObjectManagerInterface::class);
78-
$this->log = $this->getMockForAbstractClass(LoggerInterface::class);
78+
$this->log = $this->getMockForAbstractClass(ConsoleLoggerInterface::class);
7979
$this->directoryList = $this->createMock(DirectoryList::class);
8080
$this->path = realpath(__DIR__);
8181
$this->directoryList->expects($this->any())

setup/src/Magento/Setup/Model/Installer.php

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
use Magento\Framework\Module\ModuleListInterface;
3434
use Magento\Framework\Module\ModuleResource;
3535
use Magento\Framework\Mview\TriggerCleaner;
36+
use Magento\Framework\Setup\ConsoleLoggerInterface;
3637
use Magento\Framework\Setup\Declaration\Schema\DryRunLogger;
3738
use Magento\Framework\Setup\FilePermissions;
3839
use Magento\Framework\Setup\InstallDataInterface;
3940
use Magento\Framework\Setup\InstallSchemaInterface;
40-
use Magento\Framework\Setup\LoggerInterface;
4141
use Magento\Framework\Setup\ModuleDataSetupInterface;
4242
use Magento\Framework\Setup\Patch\PatchApplier;
4343
use Magento\Framework\Setup\Patch\PatchApplierFactory;
@@ -136,7 +136,7 @@ class Installer
136136
/**
137137
* Logger
138138
*
139-
* @var LoggerInterface
139+
* @var ConsoleLoggerInterface
140140
*/
141141
private $log;
142142

@@ -269,7 +269,7 @@ class Installer
269269
* @param ModuleListInterface $moduleList
270270
* @param ModuleLoader $moduleLoader
271271
* @param AdminAccountFactory $adminAccountFactory
272-
* @param LoggerInterface $log
272+
* @param ConsoleLoggerInterface $log
273273
* @param ConnectionFactory $connectionFactory
274274
* @param MaintenanceMode $maintenanceMode
275275
* @param Filesystem $filesystem
@@ -294,7 +294,7 @@ public function __construct(
294294
ModuleListInterface $moduleList,
295295
ModuleLoader $moduleLoader,
296296
AdminAccountFactory $adminAccountFactory,
297-
LoggerInterface $log,
297+
ConsoleLoggerInterface $log,
298298
ConnectionFactory $connectionFactory,
299299
MaintenanceMode $maintenanceMode,
300300
Filesystem $filesystem,
@@ -394,7 +394,7 @@ public function install($request)
394394
$total = count($script) + 4 * count(array_filter($estimatedModules));
395395
$this->progress = new Installer\Progress($total, 0);
396396

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

399399
foreach ($script as $item) {
400400
/* Note: Because the $this->DeploymentConfig gets written to, but plugins use $this->firstDeploymentConfig,
@@ -912,7 +912,7 @@ public function installSchema(array $request)
912912
$this->setupModuleRegistry($setup);
913913
$this->setupCoreTables($setup);
914914
$this->cleanMemoryTables($setup);
915-
$this->log->log('Schema creation/updates:');
915+
$this->log->logMeta('Schema creation/updates:');
916916
$this->declarativeInstallSchema($request);
917917
$this->handleDBSchemaData($setup, 'schema', $request);
918918
/** @var Mysql $adapter */
@@ -960,7 +960,7 @@ public function installDataFixtures(array $request = [])
960960
$this->assertDbAccessible();
961961
$setup = $this->dataSetupFactory->create();
962962
$this->checkFilePermissionsForDbUpgrade();
963-
$this->log->log('Data install/update:');
963+
$this->log->logMeta('Data install/update:');
964964

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

@@ -1054,7 +1054,7 @@ private function handleDBSchemaData($setup, $type, array $request)
10541054
if ($status == \Magento\Framework\Setup\ModuleDataSetupInterface::VERSION_COMPARE_GREATER) {
10551055
$upgrader = $this->getSchemaDataHandler($moduleName, $upgradeType);
10561056
if ($upgrader) {
1057-
$this->log->logInline("Upgrading $type.. ");
1057+
$this->log->logMetaInline("Upgrading $type.. ");
10581058
$upgrader->upgrade($setup, $moduleContextList[$moduleName]);
10591059
if ($type === 'schema') {
10601060
$resource->setDbVersion($moduleName, $configVer);
@@ -1066,12 +1066,12 @@ private function handleDBSchemaData($setup, $type, array $request)
10661066
} elseif ($configVer) {
10671067
$installer = $this->getSchemaDataHandler($moduleName, $installType);
10681068
if ($installer) {
1069-
$this->log->logInline("Installing $type... ");
1069+
$this->log->logMetaInline("Installing $type... ");
10701070
$installer->install($setup, $moduleContextList[$moduleName]);
10711071
}
10721072
$upgrader = $this->getSchemaDataHandler($moduleName, $upgradeType);
10731073
if ($upgrader) {
1074-
$this->log->logInline("Upgrading $type... ");
1074+
$this->log->logMetaInline("Upgrading $type... ");
10751075
$upgrader->upgrade($setup, $moduleContextList[$moduleName]);
10761076
}
10771077
}
@@ -1097,9 +1097,9 @@ private function handleDBSchemaData($setup, $type, array $request)
10971097
}
10981098

10991099
if ($type === 'schema') {
1100-
$this->log->log('Schema post-updates:');
1100+
$this->log->logMeta('Schema post-updates:');
11011101
} elseif ($type === 'data') {
1102-
$this->log->log('Data post-updates:');
1102+
$this->log->logMeta('Data post-updates:');
11031103
}
11041104
$handlerType = $type === 'schema' ? 'schema-recurring' : 'data-recurring';
11051105

@@ -1112,7 +1112,7 @@ private function handleDBSchemaData($setup, $type, array $request)
11121112
$this->log->log("Module '{$moduleName}':");
11131113
$modulePostUpdater = $this->getSchemaDataHandler($moduleName, $handlerType);
11141114
if ($modulePostUpdater) {
1115-
$this->log->logInline('Running ' . str_replace('-', ' ', $handlerType) . '...');
1115+
$this->log->logMetaInline('Running ' . str_replace('-', ' ', $handlerType) . '...');
11161116
$modulePostUpdater->install($setup, $moduleContextList[$moduleName]);
11171117
}
11181118
$this->logProgress();
@@ -1367,7 +1367,7 @@ public function updateModulesSequence($keepGeneratedFiles = false)
13671367
if (!$keepGeneratedFiles) {
13681368
$this->cleanupGeneratedFiles();
13691369
}
1370-
$this->log->log('Updating modules:');
1370+
$this->log->logMeta('Updating modules:');
13711371
$this->createModulesConfig([]);
13721372
}
13731373

@@ -1389,7 +1389,7 @@ public function getModulesConfig()
13891389
*/
13901390
public function uninstall()
13911391
{
1392-
$this->log->log('Starting Magento uninstallation:');
1392+
$this->log->logMeta('Starting Magento uninstallation:');
13931393

13941394
try {
13951395
$this->cleanCaches();
@@ -1403,7 +1403,7 @@ public function uninstall()
14031403

14041404
$this->cleanupDb();
14051405

1406-
$this->log->log('File system cleanup:');
1406+
$this->log->logMeta('File system cleanup:');
14071407
$messages = $this->cleanupFiles->clearAllFiles();
14081408
foreach ($messages as $message) {
14091409
$this->log->log($message);
@@ -1454,7 +1454,7 @@ private function cleanCaches()
14541454
$cacheManager = $this->objectManagerProvider->get()->get(Manager::class);
14551455
$types = $cacheManager->getAvailableTypes();
14561456
$cacheManager->clean($types);
1457-
$this->log->log('Cache cleared successfully');
1457+
$this->log->logSuccess('Cache cleared successfully');
14581458
}
14591459

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

14771477
/**
@@ -1703,7 +1703,7 @@ private function generateListOfModuleContext($resource, $type)
17031703
*/
17041704
private function cleanupGeneratedFiles()
17051705
{
1706-
$this->log->log('File system cleanup:');
1706+
$this->log->logMeta('File system cleanup:');
17071707
$messages = $this->cleanupFiles->clearCodeGeneratedFiles();
17081708

17091709
// unload Magento autoloader because it may be using compiled definition

0 commit comments

Comments
 (0)