Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
148 lars 1
<?php
2
 
3
namespace Illuminate\Queue\Console;
4
 
5
use Illuminate\Console\Command;
6
use Illuminate\Console\ConfirmableTrait;
7
use Illuminate\Contracts\Queue\ClearableQueue;
8
use ReflectionClass;
9
use Symfony\Component\Console\Attribute\AsCommand;
10
use Symfony\Component\Console\Input\InputArgument;
11
use Symfony\Component\Console\Input\InputOption;
12
 
13
#[AsCommand(name: 'queue:clear')]
14
class ClearCommand extends Command
15
{
16
    use ConfirmableTrait;
17
 
18
    /**
19
     * The console command name.
20
     *
21
     * @var string
22
     */
23
    protected $name = 'queue:clear';
24
 
25
    /**
26
     * The name of the console command.
27
     *
28
     * This name is used to identify the command during lazy loading.
29
     *
30
     * @var string|null
31
     *
32
     * @deprecated
33
     */
34
    protected static $defaultName = 'queue:clear';
35
 
36
    /**
37
     * The console command description.
38
     *
39
     * @var string
40
     */
41
    protected $description = 'Delete all of the jobs from the specified queue';
42
 
43
    /**
44
     * Execute the console command.
45
     *
46
     * @return int|null
47
     */
48
    public function handle()
49
    {
50
        if (! $this->confirmToProceed()) {
51
            return 1;
52
        }
53
 
54
        $connection = $this->argument('connection')
55
                        ?: $this->laravel['config']['queue.default'];
56
 
57
        // We need to get the right queue for the connection which is set in the queue
58
        // configuration file for the application. We will pull it based on the set
59
        // connection being run for the queue operation currently being executed.
60
        $queueName = $this->getQueue($connection);
61
 
62
        $queue = $this->laravel['queue']->connection($connection);
63
 
64
        if ($queue instanceof ClearableQueue) {
65
            $count = $queue->clear($queueName);
66
 
67
            $this->components->info('Cleared '.$count.' jobs from the ['.$queueName.'] queue');
68
        } else {
69
            $this->components->error('Clearing queues is not supported on ['.(new ReflectionClass($queue))->getShortName().']');
70
        }
71
 
72
        return 0;
73
    }
74
 
75
    /**
76
     * Get the queue name to clear.
77
     *
78
     * @param  string  $connection
79
     * @return string
80
     */
81
    protected function getQueue($connection)
82
    {
83
        return $this->option('queue') ?: $this->laravel['config']->get(
84
            "queue.connections.{$connection}.queue", 'default'
85
        );
86
    }
87
 
88
    /**
89
     *  Get the console command arguments.
90
     *
91
     * @return array
92
     */
93
    protected function getArguments()
94
    {
95
        return [
96
            ['connection', InputArgument::OPTIONAL, 'The name of the queue connection to clear'],
97
        ];
98
    }
99
 
100
    /**
101
     * Get the console command options.
102
     *
103
     * @return array
104
     */
105
    protected function getOptions()
106
    {
107
        return [
108
            ['queue', null, InputOption::VALUE_OPTIONAL, 'The name of the queue to clear'],
109
 
110
            ['force', null, InputOption::VALUE_NONE, 'Force the operation to run when in production'],
111
        ];
112
    }
113
}