1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Basebuilder\Scheduling\Command; |
4
|
|
|
|
5
|
|
|
use Basebuilder\Scheduling\Schedule; |
6
|
|
|
use Carbon\Carbon; |
7
|
|
|
use Symfony\Component\Console\Command\Command; |
8
|
|
|
use Symfony\Component\Console\Helper\Table; |
9
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
10
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* This command lets you inspect all the scheduled events |
14
|
|
|
*/ |
15
|
|
|
class View extends Command |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var Schedule |
19
|
|
|
*/ |
20
|
|
|
protected $schedule; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param Schedule $schedule |
24
|
|
|
* @param null|string $name |
25
|
|
|
*/ |
26
|
|
|
public function __construct(Schedule $schedule, $name = null) |
27
|
|
|
{ |
28
|
|
|
$this->schedule = $schedule; |
29
|
|
|
parent::__construct($name); |
30
|
|
|
} |
31
|
|
|
|
32
|
|
|
/** |
33
|
|
|
* @inheritdoc |
34
|
|
|
*/ |
35
|
|
|
protected function configure() |
36
|
|
|
{ |
37
|
|
|
$this->setName('scheduler:view'); |
38
|
|
|
} |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @inheritdoc |
42
|
|
|
*/ |
43
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) |
44
|
|
|
{ |
45
|
|
|
$date = Carbon::now(); |
|
|
|
|
46
|
|
|
$schedule = $this->schedule; |
47
|
|
|
|
48
|
|
|
$output->writeln('======================================================'); |
49
|
|
|
$output->writeln('# Schedule for <info>' . $schedule->getName() . '</info>'); |
50
|
|
|
$output->writeln('======================================================'); |
51
|
|
|
$output->writeln(''); |
52
|
|
|
|
53
|
|
|
$events = $schedule->allEvents(); |
54
|
|
|
|
55
|
|
|
if (empty($events)) { |
56
|
|
|
$output->writeln('<comment>No events found...</comment>'); |
57
|
|
|
$output->writeln(''); |
58
|
|
|
return; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$table = new Table($output); |
62
|
|
|
$table->setHeaders(['Event', 'Cron expression', 'Next run date']); |
63
|
|
|
|
64
|
|
|
foreach ($schedule->allEvents() as $event) { |
65
|
|
|
$exp = $event->getCronExpression(); |
66
|
|
|
|
67
|
|
|
$table->addRow([ |
68
|
|
|
(string) $event, |
69
|
|
|
(string) $exp, |
70
|
|
|
$exp->getNextRunDate($date)->format('d-m-Y H:i:s') |
71
|
|
|
]); |
72
|
|
|
} |
73
|
|
|
|
74
|
|
|
$table->render(); |
75
|
|
|
$output->writeln(''); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
|
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.
To visualize
will produce issues in the first and second line, while this second example
will produce no issues.