feat(job): perbarui jalur file dan pemisah CSV pada ProcessArrangementDataJob
- Mengganti pemisah CSV dari ';' menjadi '~'. - Menghapus pemeriksaan keberadaan data yang redundan.
This commit is contained in:
@@ -29,7 +29,7 @@
|
|||||||
public function handle()
|
public function handle()
|
||||||
: void
|
: void
|
||||||
{
|
{
|
||||||
$filePath = storage_path('app/20240901.ST.AA.ARRANGEMENT.csv'); // Adjust this path as needed
|
$filePath = storage_path('app/20250207.ST.AA.ARRANGEMENT.csv'); // Adjust this path as needed
|
||||||
try {
|
try {
|
||||||
if (!file_exists($filePath)) {
|
if (!file_exists($filePath)) {
|
||||||
throw new Exception("File not found: $filePath");
|
throw new Exception("File not found: $filePath");
|
||||||
@@ -37,23 +37,20 @@
|
|||||||
|
|
||||||
set_time_limit(24 * 60 * 60);
|
set_time_limit(24 * 60 * 60);
|
||||||
|
|
||||||
if (!file_exists($filePath)) {
|
|
||||||
throw new Exception("File not found: {$filePath}");
|
|
||||||
}
|
|
||||||
|
|
||||||
$handle = fopen($filePath, "r");
|
$handle = fopen($filePath, "r");
|
||||||
|
|
||||||
if ($handle !== false) {
|
if ($handle !== false) {
|
||||||
$headers = (new TempArrangement())->getFillable();
|
$headers = (new TempArrangement())->getFillable();
|
||||||
|
|
||||||
while (($row = fgetcsv($handle, 0, ";")) !== false) {
|
while (($row = fgetcsv($handle, 0, "~")) !== false) {
|
||||||
unset($row[0]); // Remove the first empty column if present
|
|
||||||
if (count($headers) === count($row)) {
|
if (count($headers) === count($row)) {
|
||||||
$data = array_combine($headers, $row);
|
$data = array_combine($headers, $row);
|
||||||
TempArrangement::updateOrCreate(
|
if($data['arrangement_id']!== 'arrangement_id') {
|
||||||
['arrangement_id' => $data['arrangement_id']], // key to find existing record
|
TempArrangement::updateOrCreate(
|
||||||
$data // data to update or create
|
['arrangement_id' => $data['arrangement_id']], // key to find existing record
|
||||||
);
|
$data // data to update or create
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
fclose($handle);
|
fclose($handle);
|
||||||
|
|||||||
Reference in New Issue
Block a user