Skip to content

Commit 8eb58b6

Browse files
author
Zsolt Gál
committed
Listen to cache:flush events
- if magerun cache:flush runs - if admin is pressing on "flush magento cache" - if admin is pressing on "flush cache storage" Then the DI container files should be removed accordingly. This also fixes a bug when during capistrano deployments, the container were not cleaned up (as 99% of times only magerun cache:flush is called)
1 parent 7f5ba91 commit 8eb58b6

File tree

2 files changed

+37
-12
lines changed

2 files changed

+37
-12
lines changed

app/code/community/Inviqa/SymfonyContainer/Model/Observer.php

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,12 @@ class Inviqa_SymfonyContainer_Model_Observer
1212

1313
public function onCacheRefresh(Varien_Event_Observer $event)
1414
{
15-
if (ConfigurationBuilder::MODEL_ALIAS === $event->getType()) {
16-
$containerFilePath = $this->containerCachePath();
17-
$metaFilePath = $this->containerCacheMetaPath();
18-
19-
if (file_exists($containerFilePath)) {
20-
unlink($containerFilePath);
21-
}
22-
23-
if (file_exists($metaFilePath)) {
24-
unlink($metaFilePath);
25-
}
15+
$eventType = $event->getType();
16+
if ($eventType === ConfigurationBuilder::MODEL_ALIAS || is_null($eventType)) {
17+
$this->clearCache();
2618
}
2719
}
20+
2821
public function onPreDispatch(Varien_Event_Observer $event)
2922
{
3023
$controller = $event->getControllerAction();
@@ -34,6 +27,20 @@ public function onPreDispatch(Varien_Event_Observer $event)
3427
])->setupDependencies($controller);
3528
}
3629

30+
private function clearCache()
31+
{
32+
$containerFilePath = $this->containerCachePath();
33+
$metaFilePath = $this->containerCacheMetaPath();
34+
35+
if (file_exists($containerFilePath)) {
36+
unlink($containerFilePath);
37+
}
38+
39+
if (file_exists($metaFilePath)) {
40+
unlink($metaFilePath);
41+
}
42+
}
43+
3744
private function containerCachePath()
3845
{
3946
return Mage::getBaseDir('cache') . DIRECTORY_SEPARATOR . ConfigurationBuilder::CACHED_CONTAINER;

app/code/community/Inviqa/SymfonyContainer/etc/config.xml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,24 @@
2222
</inviqa_symfonyContainer>
2323
</observers>
2424
</adminhtml_cache_refresh_type>
25+
<adminhtml_cache_flush_all>
26+
<observers>
27+
<inviqa_symfonyContainer>
28+
<class>Inviqa_SymfonyContainer_Model_Observer</class>
29+
<type>singleton</type>
30+
<method>onCacheRefresh</method>
31+
</inviqa_symfonyContainer>
32+
</observers>
33+
</adminhtml_cache_flush_all>
34+
<adminhtml_cache_flush_system>
35+
<observers>
36+
<inviqa_symfonyContainer>
37+
<class>Inviqa_SymfonyContainer_Model_Observer</class>
38+
<type>singleton</type>
39+
<method>onCacheRefresh</method>
40+
</inviqa_symfonyContainer>
41+
</observers>
42+
</adminhtml_cache_flush_system>
2543
<controller_action_predispatch>
2644
<observers>
2745
<inviqa_symfonyContainer>
@@ -43,4 +61,4 @@
4361
</cache>
4462
</global>
4563

46-
</config>
64+
</config>

0 commit comments

Comments
 (0)