Move unlock processor and unlock assignor to the job order service. #270

This commit is contained in:
Korina Cordero 2019-10-01 06:27:55 +00:00
parent 304ef3274c
commit 7de72e2ca3
4 changed files with 72 additions and 23 deletions

View file

@ -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');

View file

@ -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()
{

View file

@ -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()
{

View file

@ -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();