Command to list dead links
This commit is contained in:
parent
3f7660c377
commit
6472a36fed
62
app/Console/Commands/Bundle/DeadLinks.php
Normal file
62
app/Console/Commands/Bundle/DeadLinks.php
Normal file
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace App\Console\Commands\Bundle;
|
||||
|
||||
use App\Classes\Bundle;
|
||||
use Illuminate\Console\Command;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class DeadLinks extends Command
|
||||
{
|
||||
/**
|
||||
* The name and signature of the console command.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'bundle:dead-links { --r|recursive : Also check sub-bundles } { path? : Specific bundle for which to find dead links }';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Find dead links in bundles';
|
||||
|
||||
/**
|
||||
* Execute the console command.
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$disk = Storage::disk(env('CONTENT_DISK'));
|
||||
$path = $this->argument('path') ?? '/';
|
||||
|
||||
if ($this->option('recursive')) {
|
||||
$bundles = Bundle::findBundles($disk, $path, true);
|
||||
} else {
|
||||
$bundles = [new Bundle($path, $disk)];
|
||||
}
|
||||
|
||||
foreach ($bundles as $bundle) {
|
||||
$bundle->load();
|
||||
|
||||
$deadLinks = [];
|
||||
|
||||
foreach ($bundle->metadata('links')->all() as $url => $data) {
|
||||
if ($data['isDead']) {
|
||||
$deadLinks[$url] = $data['reason'];
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($deadLinks)) {
|
||||
$this->output->write(sprintf('Looking in %s... ', $bundle->getPath()));
|
||||
$this->error('Dead links');
|
||||
|
||||
foreach ($deadLinks as $url => $reason) {
|
||||
$this->line(sprintf(' - [%s]: %s', $url, $reason));
|
||||
}
|
||||
|
||||
$this->newLine();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user