Skip to content

Commit

Permalink
Merge pull request #4 from sitegeist/bugfix/preventZombiesToDestroyFr…
Browse files Browse the repository at this point in the history
…omHidingBehindNormalZombies

Bugfix: Prevent zombies to destroy from hiding behind normal zombies
  • Loading branch information
mficzel authored Nov 27, 2024
2 parents 2070028 + 9924bb9 commit 8a7de1b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
17 changes: 13 additions & 4 deletions Classes/Command/ZombieCommandController.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public function detectCommand(?string $siteNode = null, ?string $dimensionValues
$item->getNodeName(),
$dimensionValues ? json_decode($dimensionValues, true, JSON_THROW_ON_ERROR) : []
);
if ($rootNode === null) {
continue;
}
$zombieCount = 0;
$zombiesDueToDestructionCount = 0;

Expand Down Expand Up @@ -143,10 +146,13 @@ public function destroyCommand(?string $siteNode = null, ?string $dimensionValue
$item->getNodeName(),
$dimensionValues ? json_decode($dimensionValues, true, JSON_THROW_ON_ERROR) : []
);
if ($rootNode === null) {
continue;
}
$zombieCount = 0;
$removedZombieCount = 0;

foreach ($this->traverseSubtreeAndYieldZombieNodes($rootNode) as $zombieNode) {
foreach ($this->traverseSubtreeAndYieldZombieNodes($rootNode, true) as $zombieNode) {
$path = $this->renderNodePath($rootNode, $zombieNode);
if ($this->zombieDetector->isZombieThatHasToBeDestroyed($zombieNode)) {
$this->outputLine(sprintf('- %s <info>%s (%s)</info> %s', $this->zombieToDestroyLabel, $zombieNode->getLabel(), $zombieNode->getNodeType()->getLabel(), $path));
Expand Down Expand Up @@ -182,14 +188,17 @@ public function destroyCommand(?string $siteNode = null, ?string $dimensionValue
/**
* @return \Generator<NodeInterface>
*/
private function traverseSubtreeAndYieldZombieNodes(NodeInterface $node): \Generator
private function traverseSubtreeAndYieldZombieNodes(NodeInterface $node, bool $onlyZombiesToDestroy = false): \Generator
{
if ($node->hasChildNodes()) {
foreach ($node->getChildNodes() as $childNode) {
if ($this->zombieDetector->isZombie($childNode)) {
$match = $onlyZombiesToDestroy
? $this->zombieDetector->isZombieThatHasToBeDestroyed($childNode)
: $this->zombieDetector->isZombie($childNode);
if ($match) {
yield $childNode;
} else {
yield from $this->traverseSubtreeAndYieldZombieNodes($childNode);
yield from $this->traverseSubtreeAndYieldZombieNodes($childNode, $onlyZombiesToDestroy);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Classes/Domain/RootNodeDetector.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ class RootNodeDetector
/**
* @param array<string, array<string>> $dimensionValues
*/
public function findRootNode(string $siteNodeName, array $dimensionValues = []): NodeInterface
public function findRootNode(string $siteNodeName, array $dimensionValues = []): ?NodeInterface
{
$context = $this->createContentContext('live', $dimensionValues);
$rootNode = $context->getNode('/sites/' . $siteNodeName);

if (!$rootNode instanceof NodeInterface) {
throw new \DomainException(sprintf('Could not find site node with name %s and dimensionValues %s', $siteNodeName, json_encode($dimensionValues)), 1705939597);
return null;
}

return $rootNode;
Expand Down

0 comments on commit 8a7de1b

Please sign in to comment.