Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Check for orphaned tree files in stache:doctor command #3902

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/Console/Commands/StacheDoctor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Console\Command;
use Statamic\Console\EnhancesCommands;
use Statamic\Console\RunsInPlease;
use Statamic\Facades\Collection;
use Statamic\Facades\Stache;
use Statamic\Stache\Stores\AggregateStore;
use Statamic\Support\Str;
Expand All @@ -26,6 +27,7 @@ public function handle()

$this->outputDuplicateIds();
$this->outputUnconfiguredIndexes();
$this->outputOrphanedCollectionTrees();
}

protected function outputUnconfiguredIndexes()
Expand Down Expand Up @@ -90,4 +92,24 @@ protected function outputDuplicateIds()

return $duplicates->isNotEmpty();
}

protected function outputOrphanedCollectionTrees()
{
$store = Stache::store('collection-trees');

$orphaned = $store->getItemsFromFiles()->filter(function ($tree) {
return Collection::findByHandle($tree->handle()) === null;
});

if ($orphaned->isEmpty()) {
$this->checkLine('No collection trees without a collection detected.');

return;
}

$orphaned->each(function ($tree) {
$this->line('<fg=red>[✗]</> Found a tree file for missing collection <comment>'.$tree->handle().'</comment>');
});
$this->output->text('The tree files can be found in '.$store->directory());
}
}