Fix sending of rider event when JO is requeued. #630

This commit is contained in:
Korina Cordero 2021-10-20 06:45:12 +00:00
parent c955516acf
commit e9fa25dada

View file

@ -53,7 +53,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command
// that will be updated // that will be updated
// need rider id to set rider to available since rider becomes unavailable // need rider id to set rider to available since rider becomes unavailable
// the minute JO is assigned to rider // the minute JO is assigned to rider
$query_sql = 'SELECT id, rider_id FROM job_order WHERE status = :current_status and TIMESTAMPDIFF(MINUTE, date_assign, NOW()) >= :timeout'; $query_sql = 'SELECT id FROM job_order WHERE status = :current_status and TIMESTAMPDIFF(MINUTE, date_assign, NOW()) >= :timeout';
$query_stmt = $db->prepare($query_sql); $query_stmt = $db->prepare($query_sql);
$query_stmt->execute([ $query_stmt->execute([
@ -66,12 +66,14 @@ class UpdateUnacceptedJobOrdersCommand extends Command
while ($row = $query_stmt->fetch(PDO::FETCH_NUM)) while ($row = $query_stmt->fetch(PDO::FETCH_NUM))
{ {
// $row[0] is the jo id // $row[0] is the jo id
// $row[1] is the rider id // store the jos for now for the event sending after update of JOs
// store the ids for now for the event sending after update of JOs
// and the updating of rider's availability // and the updating of rider's availability
$jo_id = $row[0];
$requeued_jo = $em->getRepository(JobOrder::class)->find($jo_id);
$requeued_jos[] = [ $requeued_jos[] = [
'jo_id' => $row[0], 'jo' => $requeued_jo,
'rider_id' => $row[1],
]; ];
} }
@ -88,10 +90,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command
foreach ($requeued_jos as $jo_info) foreach ($requeued_jos as $jo_info)
{ {
$jo_id = $jo_info['jo_id']; $jo = $jo_info['jo'];
$rider_id = $jo_info['rider_id'];
$jo = $em->getRepository(JobOrder::class)->find($jo_id);
if ($jo != null) if ($jo != null)
{ {
$output->writeln('Requeuing for rider assignment ' . $jo->getID()); $output->writeln('Requeuing for rider assignment ' . $jo->getID());
@ -113,7 +112,7 @@ class UpdateUnacceptedJobOrdersCommand extends Command
$mclient->sendEvent($jo, $payload); $mclient->sendEvent($jo, $payload);
} }
$rider = $em->getRepository(Rider::class)->find($rider_id); $rider = $jo->getRider();
if ($rider != null) if ($rider != null)
{ {
// set rider's availability to true // set rider's availability to true