refactor(jobs): hapus manajemen izin file (chmod, chown, chgrp)

Perubahan yang dilakukan:
- ExportStatementJob.php:
  - Menghapus kode chmod(0777), chown, dan chgrp pada direktori basePath dan accountPath.
  - Menyederhanakan fungsi exportToCsv() dengan hanya menggunakan Storage::makeDirectory() tanpa pengaturan izin manual.

- ExportStatementPeriodJob.php:
  - Menghapus proses chmod(0777), chown, dan chgrp dari generatePdf() dan exportToCsv().
  - Mempertahankan mkdir() dengan parameter 0777 untuk kompatibilitas permission default, tanpa manipulasi ownership.
  - Menghapus pengecekan posix_getuid() dan function_exists() yang sebelumnya digunakan untuk memvalidasi chown.

- GenerateMultiAccountPdfJob.php:
  - Menghapus semua proses chmod(0777), chown, dan chgrp pada direktori penyimpanan.
  - Menyederhanakan fungsi generateAccountPdf() dengan menghilangkan pengaturan ownership manual.

Tujuan perubahan:
- Menyederhanakan kode dan menghilangkan proses manajemen izin file yang tidak perlu.
- Menghilangkan ketergantungan pada fungsi sistem operasi terkait chmod, chown, dan chgrp.
- Mengurangi kompleksitas dan meminimalkan potensi error saat runtime.
- Meningkatkan portabilitas aplikasi agar dapat berjalan di berbagai environment seperti Linux, Windows, dan Docker tanpa kendala perizinan file.
- Menghilangkan risiko keamanan akibat perubahan ownership file secara manual.
- Mempermudah deployment dan maintenance dengan kode yang lebih clean dan aman.

Catatan:
- Pembuatan direktori tetap menggunakan Laravel Storage facade atau mkdir() untuk kebutuhan tertentu.
- Tidak ada perubahan pada logika bisnis utama dari proses export PDF dan CSV.
- Semua fitur export tetap berjalan seperti sebelumnya tanpa pengaturan file permission manual.
This commit is contained in:
Daeng Deni Mardaeni
2025-07-15 16:40:04 +07:00
parent 35bb173056
commit e6c46701ce
3 changed files with 21 additions and 79 deletions

View File

@@ -201,25 +201,27 @@ class ExportStatementPeriodJob implements ShouldQueue
$processedData = [];
foreach ($entries as $item) {
$globalSequence++;
$runningBalance += (float) $item->amount_lcy;
$globalSequence++;
$runningBalance += (float) $item->amount_lcy;
$actualDate = $this->formatActualDate($item);
$transactionDate = $this->formatTransactionDate($item);
$actualDate = $this->formatActualDate($item);
$processedData[] = [
'account_number' => $this->account_number,
'period' => $this->period,
'sequence_no' => $globalSequence,
'transaction_date' => $item->booking_date,
'reference_number' => $item->trans_reference,
'transaction_amount' => $item->amount_lcy,
'transaction_type' => $item->amount_lcy < 0 ? 'D' : 'C',
'description' => $this->generateNarrative($item),
'end_balance' => $runningBalance,
'actual_date' => $actualDate,
'created_at' => now(),
'updated_at' => now(),
];
$processedData[] = [
'account_number' => $this->account_number,
'period' => $this->period,
'sequence_no' => $globalSequence,
'transaction_date' => $item->booking_date,
'reference_number' => $item->trans_reference,
'transaction_amount' => $item->amount_lcy,
'transaction_type' => $item->amount_lcy < 0 ? 'D' : 'C',
'description' => $this->generateNarrative($item),
'end_balance' => $runningBalance,
'actual_date' => $actualDate,
'recipt_no' => $item->ft?->recipt_no ?? '-',
'created_at' => now(),
'updated_at' => now(),
];
}
return $processedData;
@@ -480,27 +482,10 @@ class ExportStatementPeriodJob implements ShouldQueue
// Buat direktori temp jika belum ada
if (!is_dir(dirname($tempPath))) {
mkdir(dirname($tempPath), 0777, true);
// Tambahkan pengecekan function dan error handling
if (function_exists('chown') && posix_getuid() === 0) {
@chown(dirname($tempPath), 'www-data'); // Gunakan www-data instead of root
@chgrp(dirname($tempPath), 'www-data');
}
}
// Pastikan direktori storage ada
Storage::makeDirectory($storagePath);
// Tambahkan permission dan ownership setelah membuat directory
if ($this->disk === 'local') {
$fullPath = storage_path("app/{$storagePath}");
if (is_dir($fullPath)) {
chmod($fullPath, 0777);
// Tambahkan pengecekan function dan error handling
if (function_exists('chown') && posix_getuid() === 0) {
@chown($fullPath, 'www-data'); // Gunakan www-data instead of root
@chgrp($fullPath, 'www-data');
}
}
}
$period = $this->period;
@@ -629,17 +614,7 @@ class ExportStatementPeriodJob implements ShouldQueue
$storagePath = "statements/{$this->period}/{$account->branch_code}";
Storage::disk($this->disk)->makeDirectory($storagePath);
// Tambahkan permission dan ownership setelah membuat directory
if ($this->disk === 'local') {
$fullPath = storage_path("app/{$storagePath}");
if (is_dir($fullPath)) {
chmod($fullPath, 0777);
if (function_exists('chown') && posix_getuid() === 0) {
@chown(dirname($fullPath), 'www-data'); // Gunakan www-data instead of root
@chgrp(dirname($fullPath), 'www-data');
}
}
}
$filePath = "{$storagePath}/{$this->fileName}";
// Delete existing file if it exists
@@ -669,7 +644,6 @@ class ExportStatementPeriodJob implements ShouldQueue
// Write to file incrementally to reduce memory usage
Storage::disk($this->disk)->append($filePath, $csvContent);
$csvContent = ''; // Reset content after writing
});
Log::info("Statement exported to {$this->disk} disk: {$filePath}");