diff --git a/src/Command/GetJobOrderArchiveDataCommand.php b/src/Command/GetJobOrderArchiveDataCommand.php index 563f77d0..4fe27fb7 100644 --- a/src/Command/GetJobOrderArchiveDataCommand.php +++ b/src/Command/GetJobOrderArchiveDataCommand.php @@ -169,13 +169,9 @@ class GetJobOrderArchiveDataCommand extends Command // need to get the list of invoice ids for deletion for invoice items $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 // 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 $this->deleteData($jo_id_list, $invoice_id_list, $related_tables); @@ -830,6 +826,7 @@ class GetJobOrderArchiveDataCommand extends Command $invoice_id_list = []; $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'; @@ -851,42 +848,18 @@ class GetJobOrderArchiveDataCommand extends Command return $invoice_id_list; } - protected function findRiderIDs($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) + protected function updateRiderJobOrders($jo_id_list) { $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); - foreach ($rider_id_list as $rider_id) + foreach ($jo_id_list as $jo_id) { $update_stmt->execute([ - 'id' => $rider_id, + 'id' => $jo_id, ]); } }