15
15
use Symfony \Component \Console \Command \Command ;
16
16
use Symfony \Component \Console \Input \InputArgument ;
17
17
use Symfony \Component \Console \Input \InputInterface ;
18
+ use Symfony \Component \Console \Input \InputOption ;
18
19
use Symfony \Component \Console \Output \OutputInterface ;
19
20
use Symfony \Component \Console \Style \SymfonyStyle ;
20
21
use Symfony \Component \Messenger \Envelope ;
21
22
use Symfony \Component \Scheduler \RecurringMessage ;
22
23
use Symfony \Component \Scheduler \ScheduleProviderInterface ;
23
24
use Symfony \Contracts \Service \ServiceProviderInterface ;
24
25
25
- use function Symfony \Component \Clock \now ;
26
-
27
26
/**
28
27
* Command to list/debug schedules.
29
28
*
@@ -45,7 +44,8 @@ protected function configure(): void
45
44
{
46
45
$ this
47
46
->addArgument ('schedule ' , InputArgument::OPTIONAL | InputArgument::IS_ARRAY , sprintf ('The schedule name (one of "%s") ' , implode ('", " ' , $ this ->scheduleNames )), null , $ this ->scheduleNames )
48
- ->addOption ('date ' , null , InputArgument::OPTIONAL , 'The date to use for the next run date ' , 'now ' )
47
+ ->addOption ('date ' , null , InputOption::VALUE_REQUIRED , 'The date to use for the next run date ' , 'now ' )
48
+ ->addOption ('all ' , null , InputOption::VALUE_NONE , 'Display all recurring messages, including the terminated ones ' )
49
49
->setHelp (<<<'EOF'
50
50
The <info>%command.name%</info> lists schedules and their recurring messages:
51
51
@@ -59,6 +59,10 @@ protected function configure(): void
59
59
60
60
<info>php %command.full_name% --date=2025-10-18</info>
61
61
62
+ To also display the terminated recurring messages, use the <info>--all</info> option:
63
+
64
+ <info>php %command.full_name% --all</info>
65
+
62
66
EOF
63
67
)
64
68
;
@@ -92,17 +96,17 @@ protected function execute(InputInterface $input, OutputInterface $output): int
92
96
}
93
97
$ io ->table (
94
98
['Message ' , 'Trigger ' , 'Next Run ' ],
95
- array_map (self ::renderRecurringMessage (...), $ messages , array_fill (0 , count ($ messages ), $ date )),
99
+ array_filter ( array_map (self ::renderRecurringMessage (...), $ messages , array_fill (0 , count ($ messages ), $ date), array_fill ( 0 , count ( $ messages ), $ input -> getOption ( ' all ' )) )),
96
100
);
97
101
}
98
102
99
103
return 0 ;
100
104
}
101
105
102
106
/**
103
- * @return array{0:string,1:string,2:string}
107
+ * @return array{0:string,1:string,2:string}|null
104
108
*/
105
- private static function renderRecurringMessage (RecurringMessage $ recurringMessage , \DateTimeImmutable $ date ): array
109
+ private static function renderRecurringMessage (RecurringMessage $ recurringMessage , \DateTimeImmutable $ date, bool $ all ): ? array
106
110
{
107
111
$ message = $ recurringMessage ->getMessage ();
108
112
$ trigger = $ recurringMessage ->getTrigger ();
@@ -111,10 +115,12 @@ private static function renderRecurringMessage(RecurringMessage $recurringMessag
111
115
$ message = $ message ->getMessage ();
112
116
}
113
117
114
- return [
115
- $ message instanceof \Stringable ? (string ) $ message : (new \ReflectionClass ($ message ))->getShortName (),
116
- (string ) $ trigger ,
117
- $ trigger ->getNextRunDate ($ date )?->format(\DateTimeInterface::ATOM ) ?? '- ' ,
118
- ];
118
+ $ next = $ trigger ->getNextRunDate ($ date )?->format(\DateTimeInterface::ATOM ) ?? '- ' ;
119
+ if ('- ' === $ next && !$ all ) {
120
+ return null ;
121
+ }
122
+ $ name = $ message instanceof \Stringable ? (string ) $ message : (new \ReflectionClass ($ message ))->getShortName ();
123
+
124
+ return [$ name , (string ) $ trigger , $ next ];
119
125
}
120
126
}
0 commit comments