Skip to content

Commit 246d3d9

Browse files
author
Rafael Grigorian
committed
Fixed GH-15
1 parent 993398e commit 246d3d9

File tree

6 files changed

+34
-5
lines changed

6 files changed

+34
-5
lines changed

src/app/code/JetRails/Varnish/Observer/AutoPurge.php

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@ abstract class AutoPurge implements ObserverInterface {
3232
* @var ManagerInterface _messageManager Instance of the ManagerInterface
3333
* @var Purger _purger Instance of the Purger helper class
3434
* @var StoreManager _storeManager Instance of the StoreManager
35+
* @var Array _messages Saved messages for dumping together
3536
*/
3637
protected $_data;
3738
protected $_logger;
3839
protected $_messageManager;
3940
protected $_purger;
4041
protected $_storeManager;
42+
protected $_messages;
4143

4244
/**
4345
* This constructor is overloaded from the parent class in order to use dependency injection
@@ -61,6 +63,7 @@ public function __construct (
6163
$this->_messageManager = $messageManager;
6264
$this->_purger = $purger;
6365
$this->_storeManager = $storeManager;
66+
$this->_messages = [];
6467
}
6568

6669
/**
@@ -98,7 +101,6 @@ protected function _purgeOnAllServers ( $target, $purgeChildren = false ) {
98101
return $noErrors;
99102
}
100103

101-
102104
/**
103105
* This method takes in a route and it looks through the rewrites table for all urls that lead
104106
* to said url. It uses a passed store object to determine the base url to use.
@@ -121,14 +123,26 @@ protected function _purgeUsingStoreObject ( $route, $store ) {
121123
$success &= $this->_purgeOnAllServers ( rtrim ( $target, "/" ) . "?", true );
122124
if ( $success ) {
123125
// Add success response message
124-
$targetHtml = "<font color='#79A22E' ><b>$target</b></font>";
125-
$serverHtml = "<font color='#79A22E' ><b>all varnish servers</b></font>";
126-
$message = "Successfully purged varnish cache for $targetHtml on $serverHtml";
127-
$this->_messageManager->addSuccess ( $message );
126+
array_push ( $this->_messages, $target );
128127
}
129128
}
130129
}
131130

131+
/**
132+
* This method takes in some header text and appends all the saved messages to it. It then
133+
* uses the message manager to send the message together.
134+
* @param String header The header to append to the message\
135+
* @return void
136+
*/
137+
protected function _dumpCombinedMessages ( $header ) {
138+
if ( count ( $this->_messages ) > 0 ) {
139+
$header = "<font color='#79A22E' ><b>$header</b></font>";
140+
array_unshift ( $this->_messages, $header );
141+
$this->_messageManager->addSuccess ( implode ( "</br>", $this->_messages ) );
142+
$this->_messages = [];
143+
}
144+
}
145+
132146
/**
133147
* This method takes in a route and determines if the current scope is the "All Stores Scope".
134148
* If it is, then all store views are purged, otherwise just the current one is purged.

src/app/code/JetRails/Varnish/Observer/AutoPurge/Category.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public function execute ( Observer $observer ) {
3232
$cid = $observer->getCategory ()->getId ();
3333
if ( $cid !== null ) {
3434
$this->_purgeUsingRoute ("catalog/category/view/id/$cid");
35+
$this->_dumpCombinedMessages ("Purged varnish cache on all configured servers:");
3536
}
3637
}
3738
}

src/app/code/JetRails/Varnish/Observer/AutoPurge/Page.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ public function execute ( Observer $observer ) {
3131
$pid = $observer->getPage ()->getId ();
3232
if ( $pid !== null ) {
3333
$this->_purgeUsingRoute ("cms/page/view/page_id/$pid");
34+
$this->_dumpCombinedMessages ("Purged varnish cache on all configured servers:");
3435
}
3536
}
3637
}

src/app/code/JetRails/Varnish/Observer/AutoPurge/Product.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ public function execute ( Observer $observer ) {
3535
foreach ( $observer->getProduct ()->getCategoryIds () as $cid ) {
3636
$this->_purgeUsingRoute ("catalog/category/view/id/$cid");
3737
}
38+
$this->_dumpCombinedMessages ("Purged varnish cache on all configured servers:");
3839
}
3940
}
4041
}

src/app/code/JetRails/Varnish/etc/adminhtml/system.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,17 @@
2828
showInStore="1" >
2929
<label>General Configuration</label>
3030
<attribute type="expanded" >1</attribute>
31+
<field
32+
id="version"
33+
translate="label"
34+
type="label"
35+
sortOrder="0"
36+
showInDefault="1"
37+
showInWebsite="1"
38+
showInStore="1" >
39+
<label>Version</label>
40+
<comment>Currently installed extension version</comment>
41+
</field>
3142
<field
3243
id="status"
3344
translate="label"

src/app/code/JetRails/Varnish/etc/config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<default>
77
<jetrails_varnish>
88
<general_configuration>
9+
<version>1.1.5</version>
910
<status>0</status>
1011
<debug>0</debug>
1112
<servers>127.0.0.1:80</servers>

0 commit comments

Comments
 (0)