From e5650c6c7876b3d9ffb03ec87008e6bd92c34693 Mon Sep 17 00:00:00 2001 From: Daeng Deni Mardaeni Date: Wed, 29 Jan 2025 19:43:04 +0700 Subject: [PATCH] feat(jobs): tambahkan job untuk memproses data parameter narasi - Menambahkan kelas ProcessStmtNarrParamDataJob untuk memproses file CSV. - Membuat model TempStmtNarrParam untuk menyimpan data parameter narasi. - Menambahkan migrasi untuk membuat tabel temp_stmt_narr_param di database. --- app/Jobs/ProcessStmtNarrParamDataJob.php | 68 +++++++++++++++++++ app/Models/TempStmtNarrParam.php | 23 +++++++ ...1630_create_temp_stmt_narr_param_table.php | 34 ++++++++++ 3 files changed, 125 insertions(+) create mode 100644 app/Jobs/ProcessStmtNarrParamDataJob.php create mode 100644 app/Models/TempStmtNarrParam.php create mode 100644 database/migrations/2025_01_28_051630_create_temp_stmt_narr_param_table.php diff --git a/app/Jobs/ProcessStmtNarrParamDataJob.php b/app/Jobs/ProcessStmtNarrParamDataJob.php new file mode 100644 index 0000000..72a4419 --- /dev/null +++ b/app/Jobs/ProcessStmtNarrParamDataJob.php @@ -0,0 +1,68 @@ +getFillable(); + while (($row = fgetcsv($handle, 0, ";")) !== false) { + if (count($headers) === count($row)) { + $data = array_combine($headers, $row); + + try { + TempStmtNarrParam::updateOrCreate(['_id' => $data['_id']], $data); + } catch (Exception $e) { + Log::error('Error processing stmt narr param: ' . $e->getMessage()); + } + } + } + fclose($handle); + } else { + throw new Exception("Unable to open file: {$filePath}"); + } + } catch (Exception $e) { + Log::error('Error in ProcessStmtNarrParamDataJob: ' . $e->getMessage()); + throw $e; + } + } + } diff --git a/app/Models/TempStmtNarrParam.php b/app/Models/TempStmtNarrParam.php new file mode 100644 index 0000000..7e5721c --- /dev/null +++ b/app/Models/TempStmtNarrParam.php @@ -0,0 +1,23 @@ +id(); + foreach ($fieldsArray as $field) { + $field = trim($field); + $table->string($field)->nullable(); + } + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('temp_stmt_narr_param'); + } +};