52 lines
1.4 KiB
PHP
52 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
/**
|
|
* Serve the platform folder's public/ at /platform: the link public/platform -> platform_path('public').
|
|
* Like storage:link. deploy.sh runs it; running it again changes nothing.
|
|
*/
|
|
class PlatformLink extends Command
|
|
{
|
|
protected $signature = 'platform:link';
|
|
|
|
protected $description = 'Link public/platform to the platform folder\'s public/ (favicons, logos)';
|
|
|
|
public function handle(): int
|
|
{
|
|
$link = public_path('platform');
|
|
$target = platform_path('public');
|
|
|
|
if (!is_dir($target)) {
|
|
if (is_link($link)) {
|
|
unlink($link);
|
|
$this->info("Removed public/platform: {$target} does not exist.");
|
|
} else {
|
|
$this->line("No platform public files ({$target}): nothing to link.");
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
if (is_link($link)) {
|
|
if (readlink($link) === $target) {
|
|
$this->line("public/platform already links to {$target}.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
unlink($link);
|
|
} elseif (file_exists($link)) {
|
|
$this->error('public/platform exists and is not a link: move it away first.');
|
|
|
|
return self::FAILURE;
|
|
}
|
|
|
|
symlink($target, $link);
|
|
$this->info("Linked public/platform to {$target}.");
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|