Code
Explorer
You are a developer and looking for Shopware projects?
Apply Now!
getAllTasks example
public
function
testListAllTasks
(
)
: void
{
$taskEntity
=
new
ScheduledTaskEntity
(
)
;
$taskEntity
->
setId
(
'cleanupTask'
)
;
$taskEntity
->
setName
(
'foo'
)
;
/** @var StaticEntityRepository<ScheduledTaskCollection> $repository */
$repository
=
new
StaticEntityRepository
(
[
new
ScheduledTaskCollection
(
[
$taskEntity
]
)
]
)
;
$tasks
=
(
new
TaskRegistry
(
[
]
,
$repository
,
new
ParameterBag
(
[
]
)
)
)
->
getAllTasks
(
Context::
createDefaultContext
(
)
)
;
static
::
assertCount
(
1,
$tasks
)
;
static
::
assertEquals
(
$taskEntity
,
$tasks
->
first
(
)
)
;
}
}
/** * @internal */
public
function
__construct
(
private
readonly TaskRegistry
$taskRegistry
)
{
parent::
__construct
(
)
;
}
protected
function
execute
(
InputInterface
$input
, OutputInterface
$output
)
: int
{
$entities
=
$this
->taskRegistry->
getAllTasks
(
Context::
createDefaultContext
(
)
)
;
$table
=
new
Table
(
$output
)
;
$table
->
setHeaders
(
[
'Name', 'Next execution', 'Last execution', 'Run interval', 'Status'
]
)
;
/** @var ScheduledTaskEntity $entity */
foreach
(
$entities
as
$entity
)
{
$table
->
addRow
(
[
$entity
->
getName
(
)
,
$entity
->
getNextExecutionTime
(
)
->
format
(
\DATE_ATOM
)
,
$entity
->
getLastExecutionTime
(
)
?
$entity
->
getLastExecutionTime
(
)
->
format
(
\DATE_ATOM
)
: '-',
$entity
->
getRunInterval
(
)
,