Skip to content

Commit

Permalink
[10.x] Add storage:unlink command (#49795)
Browse files Browse the repository at this point in the history
* Add storage:delete-links command

* Rename to storage:unlink

* Update StorageUnlinkCommand.php

---------

Co-authored-by: Taylor Otwell <taylor@laravel.com>
  • Loading branch information
salkovmx and taylorotwell committed Jan 24, 2024
1 parent 882fed2 commit 76e4931
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/Illuminate/Foundation/Console/StorageUnlinkCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php

namespace Illuminate\Foundation\Console;

use Illuminate\Console\Command;
use Symfony\Component\Console\Attribute\AsCommand;

#[AsCommand(name: 'storage:unlink')]
class StorageUnlinkCommand extends Command
{
/**
* The console command signature.
*
* @var string
*/
protected $signature = 'storage:unlink';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Delete existing symbolic links configured for the application';

/**
* Execute the console command.
*
* @return void
*/
public function handle()
{
foreach ($this->links() as $link => $target) {
if (! file_exists($link) || ! is_link($link)) {
continue;
}

$this->laravel->make('files')->delete($link);

$this->components->info("The [$link] link has been deleted.");
}
}

/**
* Get the symbolic links that are configured for the application.
*
* @return array
*/
protected function links()
{
return $this->laravel['config']['filesystems.links'] ??
[public_path('storage') => storage_path('app/public')];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@
use Illuminate\Foundation\Console\ScopeMakeCommand;
use Illuminate\Foundation\Console\ServeCommand;
use Illuminate\Foundation\Console\StorageLinkCommand;
use Illuminate\Foundation\Console\StorageUnlinkCommand;
use Illuminate\Foundation\Console\StubPublishCommand;
use Illuminate\Foundation\Console\TestMakeCommand;
use Illuminate\Foundation\Console\UpCommand;
Expand Down Expand Up @@ -158,6 +159,7 @@ class ArtisanServiceProvider extends ServiceProvider implements DeferrableProvid
'ScheduleInterrupt' => ScheduleInterruptCommand::class,
'ShowModel' => ShowModelCommand::class,
'StorageLink' => StorageLinkCommand::class,
'StorageUnlink' => StorageUnlinkCommand::class,
'Up' => UpCommand::class,
'ViewCache' => ViewCacheCommand::class,
'ViewClear' => ViewClearCommand::class,
Expand Down

0 comments on commit 76e4931

Please sign in to comment.