Skip to content

Commit

Permalink
Error running twig:unused when cache disabled (#5962)
Browse files Browse the repository at this point in the history
* Throw exception if getCache is false

This assumes that means the cache is disabled. It could be for other
reasons?

* fix coding style
  • Loading branch information
ChrisScrumping authored May 27, 2024
1 parent 6a8e99f commit ae9b954
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Commands/core/TwigCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,12 +74,17 @@ public function unused($searchpaths): RowsOfFields
foreach ($files as $file) {
$relative = Path::makeRelative($file->getRealPath(), Drush::bootstrapManager()->getRoot());
$mainCls = $this->getTwig()->getTemplateClass($relative);
$key = $this->getTwig()->getCache()->generateKey($relative, $mainCls);
if (!$phpstorage->exists($key)) {
$unused[$key] = [
'template' => $relative,
'compiled' => $key,
];
$cache = $this->getTwig()->getCache();
if ($cache) {
$key = $cache->generateKey($relative, $mainCls);
if (!$phpstorage->exists($key)) {
$unused[$key] = [
'template' => $relative,
'compiled' => $key,
];
}
} else {
throw new \Exception('There was a problem, please ensure your twig cache is enabled.');
}
}
$this->logger()->notice(dt('Found !count unused', ['!count' => count($unused)]));
Expand Down

0 comments on commit ae9b954

Please sign in to comment.