Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added overwrite option to storage-link command #215

Merged
merged 2 commits into from
Nov 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/Commands/StorageH5PLinkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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;
}
}
}

Expand Down
5 changes: 4 additions & 1 deletion tests/Api/LibraryApiTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down
Loading