mirror of
https://github.com/archtechx/tenancy.git
synced 2026-02-05 22:04:04 +00:00
Merge branch 'master' of https://github.com/archtechx/tenancy into add-skip-failing-options-to-migrate
This commit is contained in:
commit
5c7a2c26ad
24 changed files with 828 additions and 35 deletions
73
src/Commands/Link.php
Normal file
73
src/Commands/Link.php
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Stancl\Tenancy\Commands;
|
||||
|
||||
use Exception;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\LazyCollection;
|
||||
use Stancl\Tenancy\Actions\CreateStorageSymlinksAction;
|
||||
use Stancl\Tenancy\Actions\RemoveStorageSymlinksAction;
|
||||
use Stancl\Tenancy\Concerns\HasATenantsOption;
|
||||
|
||||
class Link extends Command
|
||||
{
|
||||
use HasATenantsOption;
|
||||
|
||||
/**
|
||||
* The console command signature.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'tenants:link
|
||||
{--tenants=* : The tenant(s) to run the command for. Default: all}
|
||||
{--relative : Create the symbolic link using relative paths}
|
||||
{--force : Recreate existing symbolic links}
|
||||
{--remove : Remove symbolic links}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Create or remove tenant symbolic links.';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$tenants = $this->getTenants();
|
||||
|
||||
try {
|
||||
if ($this->option('remove')) {
|
||||
$this->removeLinks($tenants);
|
||||
} else {
|
||||
$this->createLinks($tenants);
|
||||
}
|
||||
} catch (Exception $exception) {
|
||||
$this->error($exception->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
protected function removeLinks(LazyCollection $tenants): void
|
||||
{
|
||||
RemoveStorageSymlinksAction::handle($tenants);
|
||||
|
||||
$this->info('The links have been removed.');
|
||||
}
|
||||
|
||||
protected function createLinks(LazyCollection $tenants): void
|
||||
{
|
||||
CreateStorageSymlinksAction::handle(
|
||||
$tenants,
|
||||
$this->option('relative') ?? false,
|
||||
$this->option('force') ?? false,
|
||||
);
|
||||
|
||||
$this->info('The links have been created.');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue