| 199 |
lars |
1 |
<?php namespace Clockwork\Support\Laravel;
|
|
|
2 |
|
|
|
3 |
use Illuminate\Console\Command;
|
|
|
4 |
use Symfony\Component\Console\Input\InputOption;
|
|
|
5 |
|
|
|
6 |
// Console command for cleaning old requests metadata
|
|
|
7 |
class ClockworkCleanCommand extends Command
|
|
|
8 |
{
|
|
|
9 |
// Command name
|
|
|
10 |
protected $name = 'clockwork:clean';
|
|
|
11 |
|
|
|
12 |
// Command description
|
|
|
13 |
protected $description = 'Cleans Clockwork request metadata';
|
|
|
14 |
|
|
|
15 |
// Command options
|
|
|
16 |
public function getOptions()
|
|
|
17 |
{
|
|
|
18 |
return [
|
|
|
19 |
[ 'all', 'a', InputOption::VALUE_NONE, 'cleans all data' ],
|
|
|
20 |
[ 'expiration', 'e', InputOption::VALUE_REQUIRED, 'cleans data older than specified value in minutes' ]
|
|
|
21 |
];
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
// Execute the console command
|
|
|
25 |
public function handle()
|
|
|
26 |
{
|
|
|
27 |
if ($this->option('all')) {
|
|
|
28 |
$this->laravel['config']->set('clockwork.storage_expiration', 0);
|
|
|
29 |
} elseif ($expiration = $this->option('expiration')) {
|
|
|
30 |
$this->laravel['config']->set('clockwork.storage_expiration', $expiration);
|
|
|
31 |
}
|
|
|
32 |
|
|
|
33 |
$this->laravel['clockwork.support']->makeStorage()->cleanup($force = true);
|
|
|
34 |
|
|
|
35 |
$this->info('Metadata cleaned successfully.');
|
|
|
36 |
}
|
|
|
37 |
|
|
|
38 |
// Compatibility for the old Laravel versions
|
|
|
39 |
public function fire()
|
|
|
40 |
{
|
|
|
41 |
return $this->handle();
|
|
|
42 |
}
|
|
|
43 |
}
|