feat(attachment): implement deletion of cropped attachments alongside original and update README

This commit is contained in:
2026-08-18 12:20:47 -03:00
parent 460ed528cf
commit 58cc35fd61
6 changed files with 37 additions and 4 deletions

View File

@@ -108,13 +108,23 @@ class AttachmentService
public function delete(Attachment $attachment): void
{
$deleted = Storage::disk('s3')->delete($attachment->path);
$croppedAttachment = $attachment->croppedAttachment;
$paths = array_values(array_filter([
$attachment->path,
$croppedAttachment?->path,
]));
$deleted = Storage::disk('s3')->delete(
count($paths) === 1 ? $paths[0] : $paths
);
if (! $deleted) {
throw new AttachmentStorageException('No se pudo eliminar el archivo del disco s3.');
throw new AttachmentStorageException('No se pudieron eliminar los archivos del disco s3.');
}
$attachment->delete();
DB::transaction(function () use ($attachment, $croppedAttachment): void {
$attachment->delete();
$croppedAttachment?->delete();
});
}
public function copy(Attachment $source, string $path): Attachment