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\DashboardBundle\Command; |
||
4 | |||
5 | use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; |
||
6 | use Symfony\Component\Console\Input\InputArgument; |
||
7 | use Symfony\Component\Console\Input\InputInterface; |
||
8 | use Symfony\Component\Console\Output\OutputInterface; |
||
9 | use Doctrine\ORM\EntityManagerInterface; |
||
10 | |||
11 | /** |
||
12 | * @final since 5.1 |
||
13 | * NEXT_MAJOR extend from `Command` and remove `$this->getContainer` usages |
||
14 | */ |
||
15 | class GoogleAnalyticsDataFlushCommand extends ContainerAwareCommand |
||
0 ignored issues
–
show
|
|||
16 | { |
||
17 | /** @var EntityManagerInterface */ |
||
18 | private $em; |
||
19 | |||
20 | /** |
||
21 | * @param EntityManagerInterface|null $em |
||
22 | */ |
||
23 | public function __construct(/* EntityManagerInterface */ $em = null) |
||
24 | { |
||
25 | parent::__construct(); |
||
26 | |||
27 | if (!$em instanceof EntityManagerInterface) { |
||
28 | @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); |
||
29 | |||
30 | $this->setName(null === $em ? 'kuma:dashboard:widget:googleanalytics:data:flush' : $em); |
||
31 | |||
32 | return; |
||
33 | } |
||
34 | |||
35 | $this->em = $em; |
||
36 | } |
||
37 | |||
38 | protected function configure() |
||
39 | { |
||
40 | $this |
||
41 | ->setName('kuma:dashboard:widget:googleanalytics:data:flush') |
||
42 | ->setDescription('Flush the data of a config') |
||
43 | ->addArgument( |
||
44 | 'config', |
||
45 | InputArgument::OPTIONAL, |
||
46 | 'The config id' |
||
47 | ); |
||
48 | } |
||
49 | |||
50 | /** |
||
51 | * @param InputInterface $input |
||
52 | * @param OutputInterface $output |
||
53 | * |
||
54 | * @return int|null|void |
||
55 | */ |
||
56 | protected function execute(InputInterface $input, OutputInterface $output) |
||
57 | { |
||
58 | if (null === $this->em) { |
||
59 | $this->em = $this->getContainer()->get('doctrine.orm.entity_manager'); |
||
60 | } |
||
61 | |||
62 | $configRepository = $this->em->getRepository('KunstmaanDashboardBundle:AnalyticsConfig'); |
||
63 | |||
64 | $configId = $input->getArgument('config') ? $input->getArgument('config') : false; |
||
65 | |||
66 | try { |
||
67 | $configRepository->flushConfig($configId); |
||
68 | $output->writeln('<fg=green>Data flushed</fg=green>'); |
||
69 | } catch (\Exception $e) { |
||
70 | $output->writeln('<fg=red>'.$e->getMessage().'</fg=red>'); |
||
71 | } |
||
72 | } |
||
73 | } |
||
74 |
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.