Completed
Push — master ( 82de2a...ab45a8 )
by Grégoire
11s
created

src/Command/CleanupCommand.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
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Sonata Project package.
7
 *
8
 * (c) Thomas Rabaix <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace Sonata\NotificationBundle\Command;
15
16
use Sonata\NotificationBundle\Backend\QueueDispatcherInterface;
17
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
18
use Symfony\Component\Console\Input\InputInterface;
19
use Symfony\Component\Console\Output\OutputInterface;
20
21
class CleanupCommand 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...
22
{
23
    /**
24
     * {@inheritdoc}
25
     */
26
    public function configure(): void
27
    {
28
        $this->setName('sonata:notification:cleanup');
29
        $this->setDescription('Clean up backend message');
30
    }
31
32
    /**
33
     * {@inheritdoc}
34
     */
35
    public function execute(InputInterface $input, OutputInterface $output): void
36
    {
37
        $output->write('<info>Starting ... </info>');
38
39
        $this->getBackend()->cleanup();
40
41
        $output->writeln('done!');
42
    }
43
44
    /**
45
     * @return BackendInterface
46
     */
47
    private function getBackend()
48
    {
49
        $backend = $this->getContainer()->get('sonata.notification.backend');
50
51
        if ($backend instanceof QueueDispatcherInterface) {
52
            return $backend->getBackend(null);
53
        }
54
55
        return $backend;
56
    }
57
}
58