From e3e5d97851bff72eb8ed986429cd410509aedb3e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Witold=20Wi=C5=9Bniewski?= <58150098+daVitekPL@users.noreply.github.com> Date: Fri, 8 Nov 2024 11:34:37 +0100 Subject: [PATCH] Added overwrite option to storage-link command (#215) * Added overwrite option to storage-link command * fix --- src/Commands/StorageH5PLinkCommand.php | 17 ++++++++++------- tests/Api/LibraryApiTest.php | 5 ++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/Commands/StorageH5PLinkCommand.php b/src/Commands/StorageH5PLinkCommand.php index f2e71c0..3fdd52c 100644 --- a/src/Commands/StorageH5PLinkCommand.php +++ b/src/Commands/StorageH5PLinkCommand.php @@ -14,7 +14,7 @@ class StorageH5PLinkCommand extends Command * * @var string */ - protected $signature = 'h5p:storage-link {--relative : Create the symbolic link using relative paths}'; + protected $signature = 'h5p:storage-link {--relative : Create the symbolic link using relative paths} {--overwrite : Overwrite files if they existed before}'; /** * The console command description. @@ -31,16 +31,19 @@ class StorageH5PLinkCommand extends Command public function handle() { $relative = $this->option('relative'); + $overwrite = $this->option('overwrite'); $links = $this->links(); foreach ($links as $link => $target) { - if (Storage::directoryExists($link)) { - try { - Storage::assertDirectoryEmpty($link); - } catch (ExpectationFailedException $e) { - $this->error("The [$link] link already exists."); - continue; + if (!$overwrite) { + if (Storage::directoryExists($link)) { + try { + Storage::assertDirectoryEmpty($link); + } catch (ExpectationFailedException $e) { + $this->error("The [$link] link already exists."); + continue; + } } } diff --git a/tests/Api/LibraryApiTest.php b/tests/Api/LibraryApiTest.php index 3660de1..9017d0a 100644 --- a/tests/Api/LibraryApiTest.php +++ b/tests/Api/LibraryApiTest.php @@ -314,8 +314,11 @@ public function test_reinstall_library_dependencies() $libraryDependencies = H5PLibraryDependency::where('library_id', $library->getKey()); $libraryDependenciesCount = $libraryDependencies->count(); + if ($libraryDependencies->count() > 0) { + $libraryDependencies->first()->delete(); - $libraryDependencies->first()->delete(); + $this->assertNotEquals($libraryDependenciesCount, $libraryDependencies->count()); + } $this->assertNotEquals($libraryDependenciesCount, $libraryDependencies->count());