From 5f1cb8a6fb36bce54b7af7e4552db318abd2aeff Mon Sep 17 00:00:00 2001 From: Johannes Wachter Date: Thu, 24 Nov 2016 11:24:20 +0100 Subject: [PATCH] added selective flush to repositories --- src/Command/RunCommand.php | 20 ++------------------ src/Command/RunHandlerCommand.php | 3 ++- src/Command/ScheduleTaskCommand.php | 14 +------------- src/Entity/TaskExecutionRepository.php | 2 ++ src/Entity/TaskRepository.php | 2 ++ 5 files changed, 9 insertions(+), 32 deletions(-) diff --git a/src/Command/RunCommand.php b/src/Command/RunCommand.php index 43b94d2..f496513 100644 --- a/src/Command/RunCommand.php +++ b/src/Command/RunCommand.php @@ -11,7 +11,6 @@ namespace Task\TaskBundle\Command; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -33,28 +32,17 @@ class RunCommand extends Command */ private $scheduler; - /** - * @var EntityManagerInterface - */ - private $entityManager; - /** * @param string $name * @param TaskRunnerInterface $runner * @param TaskSchedulerInterface $scheduler - * @param EntityManagerInterface $entityManager */ - public function __construct( - $name, - TaskRunnerInterface $runner, - TaskSchedulerInterface $scheduler, - EntityManagerInterface $entityManager = null - ) { + public function __construct($name, TaskRunnerInterface $runner, TaskSchedulerInterface $scheduler) + { parent::__construct($name); $this->runner = $runner; $this->scheduler = $scheduler; - $this->entityManager = $entityManager; } /** @@ -72,9 +60,5 @@ protected function execute(InputInterface $input, OutputInterface $output) { $this->runner->runTasks(); $this->scheduler->scheduleTasks(); - - if ($this->entityManager) { - $this->entityManager->flush(); - } } } diff --git a/src/Command/RunHandlerCommand.php b/src/Command/RunHandlerCommand.php index 20768d5..d265178 100644 --- a/src/Command/RunHandlerCommand.php +++ b/src/Command/RunHandlerCommand.php @@ -43,7 +43,8 @@ public function __construct($name, TaskHandlerFactoryInterface $handlerFactory) */ protected function configure() { - $this->setDescription('Run pending tasks') + $this + ->setDescription('Run pending tasks') ->addArgument('handlerClass', InputArgument::REQUIRED) ->addArgument('workload', InputArgument::OPTIONAL); } diff --git a/src/Command/ScheduleTaskCommand.php b/src/Command/ScheduleTaskCommand.php index 87eaaa7..837919c 100644 --- a/src/Command/ScheduleTaskCommand.php +++ b/src/Command/ScheduleTaskCommand.php @@ -11,7 +11,6 @@ namespace Task\TaskBundle\Command; -use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -29,22 +28,15 @@ class ScheduleTaskCommand extends Command */ private $scheduler; - /** - * @var EntityManagerInterface - */ - private $entityManager; - /** * @param string $name * @param TaskSchedulerInterface $runner - * @param EntityManagerInterface $entityManager */ - public function __construct($name, TaskSchedulerInterface $runner, EntityManagerInterface $entityManager = null) + public function __construct($name, TaskSchedulerInterface $runner) { parent::__construct($name); $this->scheduler = $runner; - $this->entityManager = $entityManager; } /** @@ -92,9 +84,5 @@ protected function execute(InputInterface $input, OutputInterface $output) } $taskBuilder->schedule(); - - if ($this->entityManager) { - $this->entityManager->flush(); - } } } diff --git a/src/Entity/TaskExecutionRepository.php b/src/Entity/TaskExecutionRepository.php index ff6663e..6671fb3 100644 --- a/src/Entity/TaskExecutionRepository.php +++ b/src/Entity/TaskExecutionRepository.php @@ -37,6 +37,7 @@ public function create(TaskInterface $task, \DateTime $scheduleTime) public function save(TaskExecutionInterface $execution) { $this->_em->persist($execution); + $this->_em->flush($execution); return $this; } @@ -47,6 +48,7 @@ public function save(TaskExecutionInterface $execution) public function remove(TaskExecutionInterface $execution) { $this->_em->remove($execution); + $this->_em->flush($execution); return $this; } diff --git a/src/Entity/TaskRepository.php b/src/Entity/TaskRepository.php index 8adfe57..9970a0d 100644 --- a/src/Entity/TaskRepository.php +++ b/src/Entity/TaskRepository.php @@ -42,6 +42,7 @@ public function findByUuid($uuid) public function save(TaskInterface $task) { $this->_em->persist($task); + $this->_em->flush($task); return $this; } @@ -52,6 +53,7 @@ public function save(TaskInterface $task) public function remove(TaskInterface $task) { $this->_em->remove($task); + $this->_em->flush($task); return $this; }