1212use Shopware \Core \Framework \DataAbstractionLayer \Search \Filter \NotFilter ;
1313use Shopware \Core \Framework \DataAbstractionLayer \Search \Filter \RangeFilter ;
1414use Shopware \Core \Framework \MessageQueue \ScheduledTask \ScheduledTaskDefinition ;
15+ use Shopware \Core \Framework \MessageQueue \ScheduledTask \ScheduledTaskEntity ;
16+ use Symfony \Component \DependencyInjection \ParameterBag \ParameterBagInterface ;
1517
1618class TaskChecker implements CheckerInterface
1719{
1820 private EntityRepositoryInterface $ scheduledTaskRepository ;
1921
20- public function __construct (EntityRepositoryInterface $ scheduledTaskRepository )
22+ private ParameterBagInterface $ parameterBag ;
23+
24+ public function __construct (EntityRepositoryInterface $ scheduledTaskRepository , ParameterBagInterface $ parameterBag )
2125 {
2226 $ this ->scheduledTaskRepository = $ scheduledTaskRepository ;
27+ $ this ->parameterBag = $ parameterBag ;
2328 }
2429
2530 public function collect (HealthCollection $ collection ): void
@@ -44,9 +49,20 @@ public function collect(HealthCollection $collection): void
4449 ));
4550
4651 $ oldTasks = $ this ->scheduledTaskRepository
47- ->searchIds ($ criteria , Context::createDefaultContext ())->getIds ();
52+ ->search ($ criteria , Context::createDefaultContext ());
53+
54+ $ oldTasks = $ oldTasks ->filter (function (ScheduledTaskEntity $ task ) {
55+ $ taskClass = $ task ->getScheduledTaskClass ();
56+
57+ // Old Shopware version
58+ if (!method_exists ($ taskClass , 'shouldRun ' )) {
59+ return true ;
60+ }
61+
62+ return $ taskClass ::shouldRun ($ this ->parameterBag );
63+ });
4864
49- if (count ( $ oldTasks ) === 0 ) {
65+ if ($ oldTasks-> count ( ) === 0 ) {
5066 $ collection ->add (SettingsResult::ok ('frosh-tools.checker.scheduledTaskGood ' ));
5167
5268 return ;
0 commit comments