feat(webstatement): tambah konfigurasi permission direktori dan perbaikan error chown
Perubahan yang dilakukan:
- Menambahkan set permission 0777, chown, dan chgrp pada direktori temp dan storage di berbagai job dan controller.
- Diterapkan di PrintStatementController, ExportStatementJob, ExportStatementPeriodJob, dan GenerateMultiAccountPdfJob.
- Semua direktori yang dibuat memiliki permission 777 untuk akses penuh dan ownership user www-data.
- Menambahkan pengecekan function_exists('chown') dan posix_getuid() === 0 sebelum menjalankan chown/chgrp.
- Menggunakan @ operator untuk suppress error jika operasi chown gagal.
- Menambahkan fallback mechanism agar aplikasi tetap berjalan meskipun tidak memiliki privilege root.
- Mengubah target ownership dari root ke www-data untuk menghindari error "Operation not permitted".
- Menambahkan pengecekan keberadaan direktori sebelum mengatur permission dan ownership.
- Menambahkan error handling yang konsisten dan robust untuk semua operasi file system terkait direktori.
- Memastikan perubahan bekerja untuk local disk maupun storage disk lainnya.
Tujuan perubahan:
- Menjamin direktori yang digunakan oleh sistem memiliki akses dan kepemilikan yang tepat di environment production.
- Mencegah error `chown(): Operation not permitted` saat aplikasi berjalan tanpa akses root.
- Meningkatkan stabilitas proses PDF generation dan file storage, serta kompatibilitas dengan environment server yang terbatas.
This commit is contained in:
@@ -364,14 +364,38 @@
|
||||
? "statements/{$this->client}"
|
||||
: "statements";
|
||||
|
||||
$accountPath = "{$basePath}/{$this->account_number}";
|
||||
|
||||
// Create client directory if it doesn't exist
|
||||
if (!empty($this->client)) {
|
||||
// Di fungsi exportToCsv untuk basePath
|
||||
Storage::disk($this->disk)->makeDirectory($basePath);
|
||||
}
|
||||
// Tambahkan permission dan ownership setelah membuat directory
|
||||
if ($this->disk === 'local') {
|
||||
$fullPath = storage_path("app/{$basePath}");
|
||||
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');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Create account directory
|
||||
$accountPath = "{$basePath}/{$this->account_number}";
|
||||
Storage::disk($this->disk)->makeDirectory($accountPath);
|
||||
// Untuk accountPath
|
||||
Storage::disk($this->disk)->makeDirectory($accountPath);
|
||||
// Tambahkan permission dan ownership setelah membuat directory
|
||||
if ($this->disk === 'local') {
|
||||
$fullPath = storage_path("app/{$accountPath}");
|
||||
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 = "{$accountPath}/{$this->fileName}";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user