Skip to content

Commit 4052354

Browse files
lsvNyholm
authored andcommitted
Feature/command obsolete (#173)
* Setting the php_translation.storage.default to public * Updated obsolete command, with some more debug if needed, and dont ask if no messages are obsolete * Style fix * minor fixes * cs
1 parent 7c58aaa commit 4052354

File tree

2 files changed

+29
-5
lines changed

2 files changed

+29
-5
lines changed

Command/DeleteObsoleteCommand.php

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,41 @@ protected function execute(InputInterface $input, OutputInterface $output)
5454
$storage = $container->get('php_translation.storage.'.$configName);
5555
$messages = $catalogueManager->findMessages(['locale' => $inputLocale, 'isObsolete' => true]);
5656

57+
$messageCount = count($messages);
58+
if (0 === $messageCount) {
59+
$output->writeln('No messages are obsolete');
60+
61+
return;
62+
}
63+
5764
$helper = $this->getHelper('question');
58-
$question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue?', count($messages)), false);
65+
$question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue? (y/N) ', $messageCount), false);
5966
if (!$helper->ask($input, $output, $question)) {
6067
return;
6168
}
6269

63-
$progress = new ProgressBar($output, count($messages));
70+
$progress = null;
71+
if (OutputInterface::VERBOSITY_NORMAL === $output->getVerbosity() && OutputInterface::VERBOSITY_QUIET !== $output->getVerbosity()) {
72+
$progress = new ProgressBar($output, $messageCount);
73+
}
6474
foreach ($messages as $message) {
6575
$storage->delete($message->getLocale(), $message->getDomain(), $message->getKey());
66-
$progress->advance();
76+
if ($output->getVerbosity() > OutputInterface::VERBOSITY_NORMAL) {
77+
$output->writeln(sprintf(
78+
'Deleted obsolete message "<info>%s</info>" from domain "<info>%s</info>" and locale "<info>%s</info>"',
79+
$message->getKey(),
80+
$message->getDomain(),
81+
$message->getLocale()
82+
));
83+
}
84+
85+
if ($progress) {
86+
$progress->advance();
87+
}
88+
}
89+
90+
if ($progress) {
91+
$progress->finish();
6792
}
68-
$progress->finish();
6993
}
7094
}

DependencyInjection/TranslationExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ private function handleConfigNode(ContainerBuilder $container, array $config)
142142
// Create some aliases for the default storage
143143
$container->setAlias('php_translation.storage', new Alias('php_translation.storage.'.$first, true));
144144
if ('default' !== $first) {
145-
$container->setAlias('php_translation.storage.default', 'php_translation.storage.'.$first);
145+
$container->setAlias('php_translation.storage.default', new Alias('php_translation.storage.'.$first, true));
146146
}
147147
}
148148
}

0 commit comments

Comments
 (0)