Issues (3627)

QueueBundle/Command/ConsumeQueueCommand.php (1 issue)

1
<?php
2
3
/*
4
 * @copyright   2014 Mautic Contributors. All rights reserved
5
 * @author      Mautic
6
 *
7
 * @link        http://mautic.org
8
 *
9
 * @license     GNU/GPLv3 http://www.gnu.org/licenses/gpl-3.0.html
10
 */
11
12
namespace Mautic\QueueBundle\Command;
13
14
use Mautic\QueueBundle\Queue\QueueService;
15
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
16
use Symfony\Component\Console\Input\InputInterface;
17
use Symfony\Component\Console\Input\InputOption;
18
use Symfony\Component\Console\Output\OutputInterface;
19
20
/**
21
 * CLI Command to process orders that have been queued.
22
 * Class ProcessQueuesCommand.
23
 */
24
class ConsumeQueueCommand extends ContainerAwareCommand
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function configure()
30
    {
31
        $this->setName('mautic:queue:process')
32
            ->setDescription('Process queues')
33
            ->addOption(
34
                '--queue-name',
35
                '-i',
36
                InputOption::VALUE_REQUIRED,
37
                'Process queues orders for a specific queue.',
38
                null
39
            )
40
            ->addOption(
41
                '--messages',
42
                '-m',
43
                InputOption::VALUE_OPTIONAL,
44
                'Number of messages from the queue to process. Default is infinite',
45
                null
46
            );
47
        parent::configure();
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    protected function execute(InputInterface $input, OutputInterface $output)
54
    {
55
        $container    = $this->getContainer();
56
        /** @var QueueService $queueService */
57
        $queueService = $container->get('mautic.queue.service');
58
59
        if (!$queueService->isQueueEnabled()) {
60
            $output->writeLn('You have not configured mautic to use queue mode, nothing will be processed');
61
62
            return 0;
63
        }
64
65
        $queueName = $input->getOption('queue-name');
66
        if (empty($queueName)) {
67
            $output->writeLn('You did not provide a valid queue name');
68
69
            return 0;
70
        }
71
72
        $messages = $input->getOption('messages');
73
        if (0 > $messages) {
74
            $output->writeLn('You did not provide a valid number of messages. It should be null or greater than 0');
75
76
            return 0;
77
        }
78
79
        $queueService->consumeFromQueue($queueName, $messages);
0 ignored issues
show
It seems like $queueName can also be of type string[]; however, parameter $queueName of Mautic\QueueBundle\Queue...ice::consumeFromQueue() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

79
        $queueService->consumeFromQueue(/** @scrutinizer ignore-type */ $queueName, $messages);
Loading history...
80
81
        return 0;
82
    }
83
}
84