1111
1212namespace Task \TaskBundle \Command ;
1313
14+ use Doctrine \ORM \EntityManagerInterface ;
1415use Symfony \Component \Console \Command \Command ;
1516use Symfony \Component \Console \Input \InputInterface ;
1617use Symfony \Component \Console \Output \OutputInterface ;
@@ -32,17 +33,28 @@ class RunCommand extends Command
3233 */
3334 private $ scheduler ;
3435
36+ /**
37+ * @var EntityManagerInterface
38+ */
39+ private $ entityManager ;
40+
3541 /**
3642 * @param string $name
3743 * @param TaskRunnerInterface $runner
3844 * @param TaskSchedulerInterface $scheduler
45+ * @param EntityManagerInterface $entityManager
3946 */
40- public function __construct ($ name , TaskRunnerInterface $ runner , TaskSchedulerInterface $ scheduler )
41- {
47+ public function __construct (
48+ $ name ,
49+ TaskRunnerInterface $ runner ,
50+ TaskSchedulerInterface $ scheduler ,
51+ EntityManagerInterface $ entityManager = null
52+ ) {
4253 parent ::__construct ($ name );
4354
4455 $ this ->runner = $ runner ;
4556 $ this ->scheduler = $ scheduler ;
57+ $ this ->entityManager = $ entityManager ;
4658 }
4759
4860 /**
@@ -60,5 +72,9 @@ protected function execute(InputInterface $input, OutputInterface $output)
6072 {
6173 $ this ->runner ->runTasks ();
6274 $ this ->scheduler ->scheduleTasks ();
75+
76+ if ($ this ->entityManager ) {
77+ $ this ->entityManager ->flush ();
78+ }
6379 }
6480}
0 commit comments