Added batch update for rider table. #762
This commit is contained in:
parent
f78e376576
commit
85483fb744
1 changed files with 36 additions and 12 deletions
|
|
@ -174,16 +174,23 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: can we maybe find a way to not load the archive files successively?
|
|
||||||
// we get the memory exception after loading the data to the last table, jo_rejection.
|
|
||||||
$this->loadArchiveFiles($archive_files, $year);
|
$this->loadArchiveFiles($archive_files, $year);
|
||||||
|
|
||||||
|
error_log('Done loading files into database...');
|
||||||
|
|
||||||
|
$jo_id_array = array_chunk($jo_id_list, 10000);
|
||||||
|
|
||||||
|
unset($jo_id_list);
|
||||||
|
|
||||||
|
foreach($jo_id_array as $key => $jo_ids)
|
||||||
|
{
|
||||||
// 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($jo_id_list);
|
$this->updateRiderActiveJobOrders($jo_ids);
|
||||||
|
$this->updateRiderCurrentJobOrders($jo_ids);
|
||||||
|
|
||||||
// at this point, all the job order and related data have been archived into the database
|
$this->deleteData($jo_ids, $related_tables);
|
||||||
$this->deleteData($jo_id_list, $related_tables);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getRelatedArchiveData($row, $query_stmt, $table_name, $year)
|
protected function getRelatedArchiveData($row, $query_stmt, $table_name, $year)
|
||||||
|
|
@ -279,6 +286,8 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
if (count($ii_id_list) > 0)
|
if (count($ii_id_list) > 0)
|
||||||
$this->deleteInvoiceItems($ii_id_list);
|
$this->deleteInvoiceItems($ii_id_list);
|
||||||
|
|
||||||
|
unset($ii_id_list);
|
||||||
|
|
||||||
return $file;
|
return $file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -848,23 +857,38 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
$jo_stmt->execute($jo_id_list);
|
$jo_stmt->execute($jo_id_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function updateRiderJobOrders($jo_id_list)
|
protected function updateRiderActiveJobOrders($jo_id_list)
|
||||||
{
|
{
|
||||||
$db = $this->em->getConnection();
|
$db = $this->em->getConnection();
|
||||||
|
$db->getWrappedConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
|
||||||
|
|
||||||
|
$jo_ids = str_repeat('?,', count($jo_id_list) - 1) . '?';
|
||||||
|
|
||||||
|
$update_active_sql = 'UPDATE rider SET active_jo_id = NULL WHERE active_jo_id IN (' . $jo_ids . ')';
|
||||||
|
$update_active_stmt = $db->prepare($update_active_sql);
|
||||||
|
|
||||||
|
error_log('Updating active rider job orders...');
|
||||||
|
|
||||||
|
$update_active_stmt->execute($jo_id_list);
|
||||||
|
|
||||||
|
unset($update_active_stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function updateRiderCurrentJobOrders($jo_id_list)
|
||||||
|
{
|
||||||
|
$db = $this->em->getConnection();
|
||||||
|
$db->getWrappedConnection()->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, false);
|
||||||
|
|
||||||
$jo_ids = str_repeat('?,', count($jo_id_list) - 1) . '?';
|
$jo_ids = str_repeat('?,', count($jo_id_list) - 1) . '?';
|
||||||
|
|
||||||
$update_curr_sql = 'UPDATE rider SET current_jo_id = NULL WHERE current_jo_id IN (' . $jo_ids . ')';
|
$update_curr_sql = 'UPDATE rider SET current_jo_id = NULL WHERE current_jo_id IN (' . $jo_ids . ')';
|
||||||
$update_curr_stmt = $db->prepare($update_curr_sql);
|
$update_curr_stmt = $db->prepare($update_curr_sql);
|
||||||
|
|
||||||
$update_active_sql = 'UPDATE rider SET active_jo_id = NULL WHERE active_jo_id IN (' . $jo_ids . ')';
|
error_log('Updating current rider job orders...');
|
||||||
$update_active_stmt = $db->prepare($update_active_sql);
|
|
||||||
|
|
||||||
$update_curr_stmt->execute($jo_id_list);
|
$update_curr_stmt->execute($jo_id_list);
|
||||||
$update_active_stmt->execute($jo_id_list);
|
|
||||||
|
|
||||||
unset($update_curr_stmt);
|
unset($update_curr_stmt);
|
||||||
unset($update_active_stmt);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function loadDataFileForArchiveData($load_stmt)
|
protected function loadDataFileForArchiveData($load_stmt)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue