1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the PHP Translation package. |
5
|
|
|
* |
6
|
|
|
* (c) PHP Translation team <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace Translation\Bundle\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
15
|
|
|
use Symfony\Component\Console\Helper\ProgressBar; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
18
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
19
|
|
|
use Symfony\Component\Console\Question\ConfirmationQuestion; |
20
|
|
|
use Symfony\Component\DependencyInjection\ContainerInterface; |
21
|
|
|
use Translation\Bundle\Service\StorageService; |
22
|
|
|
|
23
|
|
|
class DeleteObsoleteCommand extends ContainerAwareCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* @var ContainerInterface |
27
|
|
|
*/ |
28
|
|
|
private $container; |
|
|
|
|
29
|
|
|
|
30
|
|
View Code Duplication |
protected function configure() |
|
|
|
|
31
|
|
|
{ |
32
|
|
|
$this |
33
|
|
|
->setName('translation:delete-obsolete') |
34
|
|
|
->setDescription('Delete all translations marked as obsolete.') |
35
|
|
|
->addArgument('configuration', InputArgument::OPTIONAL, 'The configuration to use', 'default') |
36
|
|
|
->addArgument('locale', InputArgument::OPTIONAL, 'The locale ot use. If omitted, we use all configured locales.', null); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
40
|
|
|
{ |
41
|
|
|
$configName = $input->getArgument('configuration'); |
42
|
|
|
$config = $this->getContainer()->get('php_translation.configuration_manager')->getConfiguration($configName); |
43
|
|
View Code Duplication |
if (null !== $inputLocale = $input->getArgument('locale', null)) { |
|
|
|
|
44
|
|
|
$locales = [$inputLocale]; |
45
|
|
|
} else { |
46
|
|
|
$locales = $this->getContainer()->getParameter('php_translation.locales'); |
47
|
|
|
} |
48
|
|
|
|
49
|
|
|
$transPaths = array_merge($config['external_translations_dirs'], [$config['output_dir']]); |
50
|
|
|
$catalogueManager = $this->getContainer()->get('php_translation.catalogue_manager'); |
51
|
|
|
$catalogueManager->load($this->getContainer()->get('php_translation.catalogue_fetcher')->getCatalogues($locales, $transPaths)); |
52
|
|
|
|
53
|
|
|
/** @var StorageService $storage */ |
54
|
|
|
$storage = $this->getContainer()->get('php_translation.storage.'.$configName); |
55
|
|
|
$messages = $catalogueManager->findMessages(['locale' => $inputLocale, 'isObsolete' => true]); |
56
|
|
|
|
57
|
|
|
$helper = $this->getHelper('question'); |
58
|
|
|
$question = new ConfirmationQuestion(sprintf('You are about to remove %d translations. Do you wish to continue?', count($messages)), false); |
59
|
|
|
if (!$helper->ask($input, $output, $question)) { |
60
|
|
|
return; |
61
|
|
|
} |
62
|
|
|
|
63
|
|
|
$progress = new ProgressBar($output, count($messages)); |
64
|
|
|
foreach ($messages as $message) { |
65
|
|
|
$storage->delete($message->getLocale(), $message->getDomain(), $message->getKey()); |
66
|
|
|
$progress->advance(); |
67
|
|
|
} |
68
|
|
|
$progress->finish(); |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|