Add updating of rider's current and active jo ids to null. #762
This commit is contained in:
parent
12d9c14a03
commit
9bf5d5851a
1 changed files with 7 additions and 34 deletions
|
|
@ -169,13 +169,9 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
// need to get the list of invoice ids for deletion for invoice items
|
// need to get the list of invoice ids for deletion for invoice items
|
||||||
$invoice_id_list = $this->getInvoiceIds($jo_id_list);
|
$invoice_id_list = $this->getInvoiceIds($jo_id_list);
|
||||||
|
|
||||||
// need to get the list of riders whose active_jo_id or current_jo_id is
|
|
||||||
// set to very old JOs
|
|
||||||
$rider_id_list = $this->findRiderIDs($jo_id_list);
|
|
||||||
|
|
||||||
// update rider's active_jo_id and current_jo_id to null
|
// update rider's active_jo_id and current_jo_id to null
|
||||||
// so we can delete the old job orders (foreign key constraint)
|
// so we can delete the old job orders (foreign key constraint)
|
||||||
$this->updateRiderJobOrders($rider_id_list);
|
$this->updateRiderJobOrders($jo_id_list);
|
||||||
|
|
||||||
// at this point, all the job order and related data have been archived into the database
|
// at this point, all the job order and related data have been archived into the database
|
||||||
$this->deleteData($jo_id_list, $invoice_id_list, $related_tables);
|
$this->deleteData($jo_id_list, $invoice_id_list, $related_tables);
|
||||||
|
|
@ -830,6 +826,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
$invoice_id_list = [];
|
$invoice_id_list = [];
|
||||||
|
|
||||||
$db = $this->em->getConnection();
|
$db = $this->em->getConnection();
|
||||||
|
$db->getWrappedConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
|
||||||
|
|
||||||
$query_sql = 'SELECT id FROM invoice WHERE job_order_id = :id';
|
$query_sql = 'SELECT id FROM invoice WHERE job_order_id = :id';
|
||||||
|
|
||||||
|
|
@ -851,42 +848,18 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
return $invoice_id_list;
|
return $invoice_id_list;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function findRiderIDs($jo_id_list)
|
protected function updateRiderJobOrders($jo_id_list)
|
||||||
{
|
|
||||||
$rider_id_list = [];
|
|
||||||
|
|
||||||
$db = $this->em->getConnection();
|
|
||||||
|
|
||||||
$rider_sql = 'SELECT id FROM rider WHERE ((current_jo_id = :jo_id) OR (active_jo_id = :jo_id))';
|
|
||||||
$rider_stmt = $db->prepare($rider_sql);
|
|
||||||
|
|
||||||
// find the riders with current_jo_id or active_jo_id are still set to the old JOs
|
|
||||||
foreach ($jo_id_list as $jo_id)
|
|
||||||
{
|
|
||||||
$rider_stmt->bindValue('jo_id', $jo_id);
|
|
||||||
|
|
||||||
$results = $rider_stmt->executeQuery();
|
|
||||||
|
|
||||||
while ($row = $results->fetchAssociative())
|
|
||||||
{
|
|
||||||
$rider_id_list[] = $row['id'];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return $rider_id_list;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function updateRiderJobOrders($rider_id_list)
|
|
||||||
{
|
{
|
||||||
$db = $this->em->getConnection();
|
$db = $this->em->getConnection();
|
||||||
|
$db->getWrappedConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
|
||||||
|
|
||||||
$update_sql = 'UPDATE rider SET current_jo_id = NULL, SET active_jo_id = NULL WHERE id = :id';
|
$update_sql = 'UPDATE rider SET current_jo_id = NULL, active_jo_id = NULL WHERE (current_jo_id = :id OR active_jo_id = :id)';
|
||||||
$update_stmt = $db->prepare($update_sql);
|
$update_stmt = $db->prepare($update_sql);
|
||||||
|
|
||||||
foreach ($rider_id_list as $rider_id)
|
foreach ($jo_id_list as $jo_id)
|
||||||
{
|
{
|
||||||
$update_stmt->execute([
|
$update_stmt->execute([
|
||||||
'id' => $rider_id,
|
'id' => $jo_id,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue