Skip to content

Commit cf94ebf

Browse files
authored
Merge pull request #705 from favicode/fix/additional-check-for-purge-observer
Additional check for tag purge
2 parents 7feb1ea + b62baa9 commit cf94ebf

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

Observer/InvalidateVarnishObserver.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ public function execute(\Magento\Framework\Event\Observer $observer): void
8181
continue;
8282
}
8383
$tag = $this->cacheTags->convertCacheTags($tag);
84+
85+
if (!$this->isTagAllowed($tag)) {
86+
continue;
87+
}
88+
8489
if (!in_array($tag, $this->alreadyPurged)) {
8590
$tags[] = $tag;
8691
$this->alreadyPurged[] = $tag;
@@ -113,4 +118,24 @@ private function canPurgeObject(\Magento\Framework\DataObject\IdentityInterface
113118
}
114119
return true;
115120
}
121+
122+
/**
123+
* Additional validation since IdentityInterface can pass canPurgeObject check (e.g. ProductRuleIndexer), but still
124+
* hold tags of products or categories
125+
*
126+
* @param string $tag
127+
* @return bool
128+
*/
129+
private function isTagAllowed(string $tag)
130+
{
131+
if ($tag === \Magento\Catalog\Model\Category::CACHE_TAG && !$this->config->canPurgeCatalogCategory()) {
132+
return false;
133+
}
134+
135+
if ($tag === \Magento\Catalog\Model\Product::CACHE_TAG && !$this->config->canPurgeCatalogProduct()) {
136+
return false;
137+
}
138+
139+
return true;
140+
}
116141
}

0 commit comments

Comments
 (0)