From 72ff12ecd45be70b7d2b9353f51218cd8d6e8818 Mon Sep 17 00:00:00 2001 From: brufdev Date: Sun, 23 Feb 2025 18:42:51 +0000 Subject: [PATCH] Add the "move nodes" feature --- app/Actions/UpdateVaultNode.php | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/app/Actions/UpdateVaultNode.php b/app/Actions/UpdateVaultNode.php index 5aea94f..17e8be0 100644 --- a/app/Actions/UpdateVaultNode.php +++ b/app/Actions/UpdateVaultNode.php @@ -11,11 +11,11 @@ final readonly class UpdateVaultNode { /** * @param array{ - * parent_id: int|null, - * is_file: bool, - * name: string, - * extension: string|null, - * content: string|null + * parent_id?: int|null, + * is_file?: bool, + * name?: string, + * extension?: string|null, + * content?: string|null * } $attributes */ public function handle(VaultNode $node, array $attributes): void @@ -30,12 +30,16 @@ final readonly class UpdateVaultNode Storage::disk('local')->put($originalPath, $attributes['content'] ?? ''); } - if (!$node->wasChanged('name')) { - return; + // Rename node on disk + if ($node->wasChanged('name')) { + $path = new GetPathFromVaultNode()->handle($node); + Storage::disk('local')->move($originalPath, $path); } - // Rename node on disk - $path = new GetPathFromVaultNode()->handle($node); - Storage::disk('local')->move($originalPath, $path); + // Move node on disk + if ($node->wasChanged('parent_id')) { + $path = new GetPathFromVaultNode()->handle($node); + Storage::disk('local')->move($originalPath, $path); + } } }