Completed
Push — master ( aba493...5356ed )
by Ruud
315:38 queued 305:00
created

Command/TranslationFlagCommand.php (1 issue)

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
namespace Kunstmaan\TranslatorBundle\Command;
4
5
use Kunstmaan\TranslatorBundle\Repository\TranslationRepository;
6
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
7
use Symfony\Component\Console\Input\InputInterface;
8
use Symfony\Component\Console\Input\InputOption;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Command to reset/request translation flags from the stash
13
 *
14
 * @final since 5.1
15
 * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages
16
 */
17
class TranslationFlagCommand extends ContainerAwareCommand
0 ignored issues
show
Deprecated Code introduced by
The class Symfony\Bundle\Framework...d\ContainerAwareCommand has been deprecated with message: since Symfony 4.2, use {@see Command} instead.

This class, trait or interface has been deprecated. The supplier of the file has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the type will be removed from the class and what other constant to use instead.

Loading history...
18
{
19
    /**
20
     * @var TranslationRepository
21
     */
22
    private $translationRepository;
23
24
    /**
25
     * @param TranslationRepository|null $translationRepository
26
     */
27
    public function __construct(/* TranslationRepository */ $translationRepository = null)
28
    {
29
        parent::__construct();
30
31
        if (!$translationRepository instanceof TranslationRepository) {
32
            @trigger_error(sprintf('Passing a command name as the first argument of "%s" is deprecated since version symfony 3.4 and will be removed in symfony 4.0. If the command was registered by convention, make it a service instead. ', __METHOD__), E_USER_DEPRECATED);
33
34
            $this->setName(null === $translationRepository ? 'kuma:translator:flag' : $translationRepository);
35
36
            return;
37
        }
38
39
        $this->translationRepository = $translationRepository;
40
    }
41
42
    protected function configure()
43
    {
44
        parent::configure();
45
46
        $this
47
            ->setName('kuma:translator:flag')
48
            ->setDescription('Reset translation flags')
49
            ->addOption('reset', 'r', InputOption::VALUE_NONE, 'Reset all flags to null in stash')
50
        ;
51
    }
52
53
    public function execute(InputInterface $input, OutputInterface $output)
54
    {
55
        if ($input->getOption('reset')) {
56
            $this->resetAllTranslationFlags();
57
            $output->writeln('<info>All translation and translation domain flags are reset.</info>');
58
        }
59
    }
60
61
    /**
62
     * Rest all flags of all translations and all domains
63
     */
64
    public function resetAllTranslationFlags()
65
    {
66
        if (null === $this->translationRepository) {
67
            $this->translationRepository = $this->getContainer()->get('kunstmaan_translator.repository.translation');
68
        }
69
70
        $this->translationRepository->resetAllFlags();
71
    }
72
}
73