next presentasi ke bu panca
This commit is contained in:
parent
3436f61e8c
commit
1f5ceccc40
@ -1084,25 +1084,23 @@ class DashboardController extends Controller
|
||||
'action_by' => $status && $status === "approved" ? auth()->user()->objectpegawaifk : null,
|
||||
'action_at' => $status && $status === "approved" ? now() : null
|
||||
];
|
||||
$imageName = trim((string) $uploadedFile->getClientOriginalName());
|
||||
if ($imageName === '') {
|
||||
$ext = $uploadedFile->getClientOriginalExtension();
|
||||
$imageName = $ext ? (Str::uuid()->toString() . '.' . $ext) : Str::uuid()->toString();
|
||||
}
|
||||
$fd = FileDirectory::create($payload);
|
||||
$path = "{$nama_unit_kerja}/{$nama_sub_unit_kerja}/{$nama_kategori}";
|
||||
$disk = Storage::disk('s3');
|
||||
|
||||
$imageName = $this->buildStoredFileName(
|
||||
$fd->nama_dokumen ?? null,
|
||||
$fd->file_directory_id,
|
||||
$uploadedFile->getClientOriginalExtension()
|
||||
);
|
||||
$disk->putFileAs(
|
||||
$path,
|
||||
$uploadedFile,
|
||||
$imageName,
|
||||
['visibility' => 'private'] // atau 'public'
|
||||
['visibility' => 'private']
|
||||
);
|
||||
|
||||
$payload['file'] = $path . '/' . $imageName;
|
||||
|
||||
|
||||
$fd = FileDirectory::create($payload);
|
||||
$fd->update([
|
||||
'file' => $path . '/' . $imageName
|
||||
]);
|
||||
|
||||
if(!$isAtasan){
|
||||
$uploaderName = auth()->user()?->dataUser?->namalengkap ?? 'Pengguna';
|
||||
@ -1984,7 +1982,14 @@ class DashboardController extends Controller
|
||||
if ($targetUnit && $targetSub && $targetKategori) {
|
||||
$folderPath = "{$targetUnit}/{$targetSub}/{$targetKategori}";
|
||||
}
|
||||
$imageName = $uploadedFile->getClientOriginalName();
|
||||
$namaDokumenForFile = array_key_exists('nama_dokumen', $payload)
|
||||
? $payload['nama_dokumen']
|
||||
: $data->nama_dokumen;
|
||||
$imageName = $this->buildStoredFileName(
|
||||
$namaDokumenForFile,
|
||||
$data->file_directory_id,
|
||||
$uploadedFile->getClientOriginalExtension()
|
||||
);
|
||||
$path = $folderPath ? "{$folderPath}" : '';
|
||||
$disk = Storage::disk('s3');
|
||||
$oldFile = $data->file;
|
||||
@ -1998,6 +2003,32 @@ class DashboardController extends Controller
|
||||
if ($oldFile && $oldFile !== $payload['file'] && $disk->exists($oldFile)) {
|
||||
$disk->delete($oldFile);
|
||||
}
|
||||
} elseif (array_key_exists('nama_dokumen', $payload)) {
|
||||
$oldFile = (string) $data->file;
|
||||
$fileInfo = pathinfo($oldFile);
|
||||
$folderPath = $fileInfo['dirname'] ?? '';
|
||||
if ($folderPath === '.' || $folderPath === DIRECTORY_SEPARATOR) {
|
||||
$folderPath = '';
|
||||
}
|
||||
$currentExt = $fileInfo['extension'] ?? null;
|
||||
$newFileName = $this->buildStoredFileName(
|
||||
$payload['nama_dokumen'],
|
||||
$data->file_directory_id,
|
||||
$currentExt
|
||||
);
|
||||
$newFilePath = ($folderPath ? $folderPath . '/' : '') . $newFileName;
|
||||
|
||||
if ($oldFile !== '' && $oldFile !== $newFilePath) {
|
||||
$disk = Storage::disk('s3');
|
||||
if ($disk->exists($oldFile)) {
|
||||
if ($disk->exists($newFilePath)) {
|
||||
$disk->delete($newFilePath);
|
||||
}
|
||||
$disk->copy($oldFile, $newFilePath);
|
||||
$disk->delete($oldFile);
|
||||
$payload['file'] = $newFilePath;
|
||||
}
|
||||
}
|
||||
}
|
||||
$payload['status_action'] = 'revised';
|
||||
|
||||
@ -2036,7 +2067,7 @@ class DashboardController extends Controller
|
||||
|
||||
$payloadLog = [
|
||||
'file_directory_id' => $data->file_directory_id,
|
||||
'pegawai_id_entry' => $data->pegawai_nama_entry,
|
||||
'pegawai_id_entry' => $data->pegawai_id_entry,
|
||||
'pegawai_nama_entry' => $data->pegawai_nama_entry,
|
||||
'entry_at' => now(),
|
||||
'file' => $data->file,
|
||||
@ -2064,6 +2095,22 @@ class DashboardController extends Controller
|
||||
}
|
||||
}
|
||||
|
||||
private function buildStoredFileName(?string $namaDokumen, $fileDirectoryId, ?string $extension = null): string
|
||||
{
|
||||
$id = trim((string) $fileDirectoryId);
|
||||
$rawNama = trim((string) ($namaDokumen ?? ''));
|
||||
if ($rawNama !== '') {
|
||||
$safeNama = preg_replace('/[^A-Za-z0-9_-]+/', '_', $rawNama);
|
||||
$safeNama = trim((string) $safeNama, '_');
|
||||
$baseName = ($safeNama !== '' ? $safeNama : $id) . '_' . $id;
|
||||
} else {
|
||||
$baseName = $id;
|
||||
}
|
||||
|
||||
$ext = strtolower(trim((string) ($extension ?? '')));
|
||||
return $ext !== '' ? "{$baseName}.{$ext}" : $baseName;
|
||||
}
|
||||
|
||||
// public function historyPengajuan(){
|
||||
// $data = FileDirectory::where('statusenabled', true)->where('pegawai_id_entry', auth()->user()->objectpegawaifk)->get();
|
||||
// return $data;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user