diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index 3d39e167..2abe90d2 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -36,18 +36,14 @@ use App\Service\APNSClient; use Doctrine\ORM\Query; use Doctrine\DBAL\Connection; use Doctrine\DBAL\LockMode; -use Doctrine\ORM\PessimisticLockException; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; -use Symfony\Component\Validator\Validator\ValidatorInterface; use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Contracts\Translation\TranslatorInterface; use Catalyst\MenuBundle\Annotation\Menu; -use CrEOF\Spatial\PHP\Types\Geometry\Point; - use Mosquitto\Client as MosquittoClient; use DateTime; use DateInterval; @@ -1520,36 +1516,23 @@ class JobOrderController extends Controller ]); } - public function unlockProcessor($id) + public function unlockProcessor($id, JobOrderHandlerInterface $jo_handler) { $this->denyAccessUnlessGranted('jo_proc.unlock', null, 'No access.'); - // clear lock - $em = $this->getDoctrine()->getManager(); - $jo = $em->getRepository(JobOrder::class)->find($id); - if ($jo == null) - return $this->redirectToRoute('jo_proc'); - - $jo->setProcessedBy(null); - - $em->flush(); + // call unlockProcessor in job order service + $jo_handler->unlockProcessor($id); // redirect to list return $this->redirectToRoute('jo_proc'); } - public function unlockAssignor($id) + public function unlockAssignor($id, JobOrderHandlerInterface $jo_handler) { $this->denyAccessUnlessGranted('jo_assign.unlock', null, 'No access.'); - // clear lock - $em = $this->getDoctrine()->getManager(); - $jo = $em->getRepository(JobOrder::class)->find($id); - if ($jo == null) - return $this->redirectToRoute('jo_assign'); - - $jo->setAssignedBy(null); - $em->flush(); + // call unlockAssignor in job order service + $jo_handler->unlockAssignor($id); // redirect to list return $this->redirectToRoute('jo_assign'); diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index a151f76e..f3bec029 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -864,6 +864,36 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface return $error_array; } + // unlock processor + public function unlockProcessor($id) + { + // clear lock + $em = $this->em; + $jo = $em->getRepository(JobOrder::class)->find($id); + if ($jo != null) + { + $jo->setProcessedBy(null); + + $em->flush(); + } + } + + // unlock assignor + public function unlockAssignor($id) + { + // clear lock + $em = $this->em; + $jo = $em->getRepository(JobOrder::class)->find($id); + if ($jo != null) + { + $jo->setAssignedBy(null); + + $em->flush(); + } + + } + + // initialize incoming job order form public function initializeIncomingForm() { diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 9d27af14..742f51b1 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -864,6 +864,36 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface return $error_array; } + // unlock processor + public function unlockProcessor($id) + { + // clear lock + $em = $this->em; + $jo = $em->getRepository(JobOrder::class)->find($id); + if ($jo != null) + { + $jo->setProcessedBy(null); + + $em->flush(); + } + } + + // unlock assignor + public function unlockAssignor($id) + { + // clear lock + $em = $this->em; + $jo = $em->getRepository(JobOrder::class)->find($id); + if ($jo != null) + { + $jo->setAssignedBy(null); + + $em->flush(); + } + + } + + // initialize incoming job order form public function initializeIncomingForm() { diff --git a/src/Service/JobOrderHandlerInterface.php b/src/Service/JobOrderHandlerInterface.php index f371e2e2..4d836cd5 100644 --- a/src/Service/JobOrderHandlerInterface.php +++ b/src/Service/JobOrderHandlerInterface.php @@ -34,6 +34,12 @@ interface JobOrderHandlerInterface // set rider for job order public function setRider(Request $req, int $id, MQTTClient $mclient); + // unlock processor + public function unlockProcessor(int $id); + + // unlock assignor + public function unlockAssignor(int $id); + // initialize incoming job order form public function initializeIncomingForm();