option('dead-only') || $url->is_dead) {
$this->checkUrl($url, $progress);
}
});
$this->report();
}
/**
* Check specified url
*/
private function checkUrl(Url $url, $progress)
{
if ($url->check($this->option('force'))) {
$this->updatedCount++;
} else {
$this->notUpdatedCount++;
}
if ($this->option('clean')) {
$bundles = $url->bundlesReferencingUrl();
if (empty($bundles)) {
$this->deleted[] = $url;
$url->delete();
return;
} else {
$url->bundles = $bundles;
}
}
$url->save();
if ($url->is_dead && !in_array($url, $this->dead)) {
$this->dead[] = $url;
}
$progress->hint(sprintf('Checked %s', urldecode($url->initial_url)));
}
/**
* Show a report
*/
private function report()
{
$this->line(sprintf('Updated URLs: %d', $this->updatedCount));
$this->line(sprintf('Update not needed: %d', $this->notUpdatedCount));
$this->reportDead();
$this->reportDeleted();
}
/**
* Show report of dead links
*/
private function reportDead()
{
$count = count($this->dead);
if ($count === 0) {
return;
}
$this->newLine();
$this->line(sprintf('Dead URLs: %s', $count));
foreach ($this->dead as $url) {
$this->newLine();
$this->comment($url->initial_url);
$this->line(sprintf(' > %s', $url->dead_reason));
$this->line('Bundles:');
foreach ($url->bundles ?? [] as $bundlePaths) {
$this->line(sprintf(' - %s', Str::unwrap($bundlePaths, '/')));
}
}
}
/**
* Show report of deleted urls
*/
private function reportDeleted()
{
$count = count($this->deleted);
if ($count === 0) {
return;
}
$this->newLine();
$this->line(sprintf('Deleted URLs: %s', $count));
foreach ($this->deleted as $url) {
$this->newLine();
$this->comment($url->initial_url);
$this->line('Bundles:');
foreach ($url->bundles ?? [] as $bundlePaths) {
$this->line(sprintf(' - %s', $bundlePaths));
}
}
}
}