From e96a27490a0a7f6fe6c3d0b5e2e09780e9339df9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Sat, 22 Oct 2022 21:14:49 +0200 Subject: [PATCH] Use error style for notifications stderr is not a great name for something that is not meant to be processed (piped into) a program, but to be read by humans. Most commands should use stderr, and some of them should partially use stdout, typically when dumping SQL requests. --- .../ClearCache/CollectionRegionCommand.php | 2 +- .../Command/ClearCache/EntityRegionCommand.php | 2 +- .../Command/ClearCache/MetadataCommand.php | 2 +- .../Command/ClearCache/QueryCommand.php | 2 +- .../Command/ClearCache/QueryRegionCommand.php | 2 +- .../Command/ClearCache/ResultCommand.php | 2 +- .../Command/ConvertDoctrine1SchemaCommand.php | 2 +- .../Console/Command/ConvertMappingCommand.php | 2 +- .../EnsureProductionSettingsCommand.php | 2 +- .../Command/GenerateEntitiesCommand.php | 2 +- .../Console/Command/GenerateProxiesCommand.php | 2 +- .../Command/GenerateRepositoriesCommand.php | 2 +- .../ORM/Tools/Console/Command/InfoCommand.php | 2 +- .../Console/Command/MappingDescribeCommand.php | 2 +- .../Command/SchemaTool/AbstractCommand.php | 2 +- .../Command/SchemaTool/CreateCommand.php | 10 ++++++---- .../Console/Command/SchemaTool/DropCommand.php | 14 ++++++++------ .../Command/SchemaTool/UpdateCommand.php | 18 ++++++++++-------- .../Console/Command/ValidateSchemaCommand.php | 2 +- 19 files changed, 40 insertions(+), 34 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php index b31c3bec2e6..c9f378d7061 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/CollectionRegionCommand.php @@ -67,7 +67,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $em = $this->getEntityManager($input); $ownerClass = $input->getArgument('owner-class'); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php index 1a689b37c89..a2826142d70 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/EntityRegionCommand.php @@ -66,7 +66,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $em = $this->getEntityManager($input); $entityClass = $input->getArgument('entity-class'); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php index 25a76eadf1b..a3e9101d053 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/MetadataCommand.php @@ -40,7 +40,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $em = $this->getEntityManager($input); $cacheDriver = $em->getConfiguration()->getMetadataCache(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php index b88e270609b..edfa6ac0ad9 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryCommand.php @@ -63,7 +63,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $em = $this->getEntityManager($input); $cache = $em->getConfiguration()->getQueryCache(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php index 8b665760316..b7e163c65bc 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/QueryRegionCommand.php @@ -65,7 +65,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $em = $this->getEntityManager($input); $name = $input->getArgument('region-name'); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php index e9336965958..85a9e5280b4 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ClearCache/ResultCommand.php @@ -65,7 +65,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $em = $this->getEntityManager($input); $cache = $em->getConfiguration()->getResultCache(); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php index 72577f0a8c6..39701a7f22c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertDoctrine1SchemaCommand.php @@ -97,7 +97,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $ui = new SymfonyStyle($input, $output); - $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); + $ui->getErrorStyle()->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); // Process source directories $fromPaths = array_merge([$input->getArgument('from-path')], $input->getOption('from')); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php index 031da1bdd11..3ee83166d76 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ConvertMappingCommand.php @@ -88,7 +88,7 @@ protected function configure() protected function execute(InputInterface $input, OutputInterface $output) { $ui = new SymfonyStyle($input, $output); - $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); + $ui->getErrorStyle()->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); $em = $this->getEntityManager($input); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php index ced57647ec9..38545d92e0d 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/EnsureProductionSettingsCommand.php @@ -38,7 +38,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $ui->warning('This console command has been deprecated and will be removed in a future version of Doctrine ORM.'); $em = $this->getEntityManager($input); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php index ecd969c25cd..4bebdddb800 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateEntitiesCommand.php @@ -76,7 +76,7 @@ class is supposed to extend which. You have to adjust the entity */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); $em = $this->getEntityManager($input); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php index 9e17bc00a2a..e14b98c0fe3 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateProxiesCommand.php @@ -47,7 +47,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $em = $this->getEntityManager($input); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php index 84cc3fe719b..0bb71f4cd6c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/GenerateRepositoriesCommand.php @@ -48,7 +48,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $ui->warning('Command ' . $this->getName() . ' is deprecated and will be removed in Doctrine ORM 3.0.'); $em = $this->getEntityManager($input); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php index e040b81d2e3..3152d51c53c 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/InfoCommand.php @@ -43,7 +43,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $entityManager = $this->getEntityManager($input); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php index 4c7190e9b06..9030c236f53 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/MappingDescribeCommand.php @@ -62,7 +62,7 @@ protected function configure(): void protected function execute(InputInterface $input, OutputInterface $output): int { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $entityManager = $this->getEntityManager($input); diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php index ae4d0fb0f90..c58029cdae8 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/AbstractCommand.php @@ -38,7 +38,7 @@ protected function execute(InputInterface $input, OutputInterface $output) $metadatas = $em->getMetadataFactory()->getAllMetadata(); if (empty($metadatas)) { - $ui->success('No Metadata Classes to process.'); + $ui->getErrorStyle()->success('No Metadata Classes to process.'); return 0; } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php index cbc1244eec7..16302b271ce 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/CreateCommand.php @@ -57,14 +57,16 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ return 0; } - $ui->caution('This operation should not be executed in a production environment!'); + $notificationUi = $ui->getErrorStyle(); - $ui->text('Creating database schema...'); - $ui->newLine(); + $notificationUi->caution('This operation should not be executed in a production environment!'); + + $notificationUi->text('Creating database schema...'); + $notificationUi->newLine(); $schemaTool->createSchema($metadatas); - $ui->success('Database schema created successfully!'); + $notificationUi->success('Database schema created successfully!'); return 0; } diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php index d67cad363f1..4cf027ff949 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/DropCommand.php @@ -67,9 +67,11 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ return 0; } + $notificationUi = $ui->getErrorStyle(); + if ($force) { - $ui->text('Dropping database schema...'); - $ui->newLine(); + $notificationUi->text('Dropping database schema...'); + $notificationUi->newLine(); if ($isFullDatabaseDrop) { $schemaTool->dropDatabase(); @@ -77,12 +79,12 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ $schemaTool->dropSchema($metadatas); } - $ui->success('Database schema dropped successfully!'); + $notificationUi->success('Database schema dropped successfully!'); return 0; } - $ui->caution('This operation should not be executed in a production environment!'); + $notificationUi->caution('This operation should not be executed in a production environment!'); if ($isFullDatabaseDrop) { $sqls = $schemaTool->getDropDatabaseSQL(); @@ -91,12 +93,12 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ } if (empty($sqls)) { - $ui->success('Nothing to drop. The database is empty!'); + $notificationUi->success('Nothing to drop. The database is empty!'); return 0; } - $ui->text( + $notificationUi->text( [ sprintf('The Schema-Tool would execute "%s" queries to update the database.', count($sqls)), '', diff --git a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php index 5031387e56e..42f5709c20b 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/SchemaTool/UpdateCommand.php @@ -78,8 +78,10 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ $sqls = $schemaTool->getUpdateSchemaSql($metadatas, $saveMode); + $notificationUi = $ui->getErrorStyle(); + if (empty($sqls)) { - $ui->success('Nothing to update - your database is already in sync with the current entity metadata.'); + $notificationUi->success('Nothing to update - your database is already in sync with the current entity metadata.'); return 0; } @@ -95,25 +97,25 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ if ($force) { if ($dumpSql) { - $ui->newLine(); + $notificationUi->newLine(); } - $ui->text('Updating database schema...'); - $ui->newLine(); + $notificationUi->text('Updating database schema...'); + $notificationUi->newLine(); $schemaTool->updateSchema($metadatas, $saveMode); $pluralization = count($sqls) === 1 ? 'query was' : 'queries were'; - $ui->text(sprintf(' %s %s executed', count($sqls), $pluralization)); - $ui->success('Database schema updated successfully!'); + $notificationUi->text(sprintf(' %s %s executed', count($sqls), $pluralization)); + $notificationUi->success('Database schema updated successfully!'); } if ($dumpSql || $force) { return 0; } - $ui->caution( + $notificationUi->caution( [ 'This operation should not be executed in a production environment!', '', @@ -122,7 +124,7 @@ protected function executeSchemaCommand(InputInterface $input, OutputInterface $ ] ); - $ui->text( + $notificationUi->text( [ sprintf('The Schema-Tool would execute "%s" queries to update the database.', count($sqls)), '', diff --git a/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php b/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php index 3d9680fd55c..19b50dbf8ab 100644 --- a/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php +++ b/lib/Doctrine/ORM/Tools/Console/Command/ValidateSchemaCommand.php @@ -40,7 +40,7 @@ protected function configure() */ protected function execute(InputInterface $input, OutputInterface $output) { - $ui = new SymfonyStyle($input, $output); + $ui = (new SymfonyStyle($input, $output))->getErrorStyle(); $em = $this->getEntityManager($input); $validator = new SchemaValidator($em);