Skip to content

Commit 97585e3

Browse files
author
Rafael Grigorian
committed
Fixed GH-7
1 parent ad089cf commit 97585e3

File tree

5 files changed

+55
-15
lines changed

5 files changed

+55
-15
lines changed

src/app/code/JetRails/Varnish/Console/Command/AbstractCommand.php

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
namespace JetRails\Varnish\Console\Command;
44

5+
56
use JetRails\Varnish\Helper\Data;
67
use JetRails\Varnish\Helper\Purger;
78
use JetRails\Varnish\Logger\Logger;
9+
use Magento\Framework\App\Cache\TypeListInterface;
810
use Symfony\Component\Console\Command\Command;
911
use Symfony\Component\Console\Input\InputInterface;
1012
use Symfony\Component\Console\Output\OutputInterface;
@@ -27,27 +29,37 @@ abstract class AbstractCommand extends Command {
2729
* These internal data members include instances of helper classes that are injected into
2830
* the class using dependency injection on runtime. Also a boolean variable is included
2931
* that defines if the action should be run if the feature is disabled in the store config.
32+
* @var TypeListInterface _cacheTypeList Instance of the TypeListInterface class
3033
* @var Data _data Instance of the Data class
3134
* @var Logger _logger Instance of the Logger class
3235
* @var Purger _purger Instance of the Purger class
3336
* @var Boolean _runIfDisabled Execute method if feature isn't on?
3437
*/
38+
protected $_cacheTypeList;
3539
protected $_data;
3640
protected $_logger;
3741
protected $_purger;
3842
protected $_runIfDisabled = true;
3943

44+
4045
/**
4146
* This constructor is overloaded from the parent class in order to use dependency injection
4247
* to get the dependency classes that we need for this module's command actions to execute.
4348
* @param Data data Instance of the Data class
4449
* @param Logger logger Instance of the Logger class
4550
* @param Purger purger Instance of the Purger class
51+
* @param TypeListInterface cacheTypeList Instance of the TypeListInterface class
4652
*/
47-
public function __construct ( Data $data, Logger $logger, Purger $purger ) {
53+
public function __construct (
54+
Data $data,
55+
Logger $logger,
56+
Purger $purger,
57+
TypeListInterface $cacheTypeList
58+
) {
4859
// Call the parent constructor
4960
parent::__construct ();
5061
// Save injected classes internally
62+
$this->_cacheTypeList = $cacheTypeList;
5163
$this->_data = $data;
5264
$this->_logger = $logger;
5365
$this->_purger = $purger;
@@ -154,4 +166,4 @@ protected function execute ( InputInterface $input, OutputInterface $output ) {
154166
*/
155167
protected abstract function runCommand ( InputInterface $input );
156168

157-
}
169+
}

src/app/code/JetRails/Varnish/Console/Command/Status/Set.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22

33
namespace JetRails\Varnish\Console\Command\Status;
44

5+
56
use JetRails\Varnish\Console\Command\AbstractCommand;
7+
use Magento\Framework\App\Cache\Type\Config as ConfigType;
68
use Magento\PageCache\Model\Config;
79
use Symfony\Component\Console\Input\InputArgument;
810
use Symfony\Component\Console\Input\InputInterface;
@@ -53,6 +55,9 @@ protected function runCommand ( InputInterface $input ) {
5355
// Set the state value in the store config
5456
$stateValue = $state ? Config::VARNISH : Config::BUILT_IN;
5557
$this->_data->setCachingApplication ( $stateValue );
58+
$this->_data->setEnable ( $stateValue === Config::VARNISH );
59+
// Clean the config cache so we get the right values when querying for them
60+
$this->_cacheTypeList->cleanType ( ConfigType::TYPE_IDENTIFIER );
5661
// Construct the message and respond to caller
5762
$message = $state ? "Varnish" : "Built-in";
5863
$message = "<options=underscore>" . $message . " Cache</>";
@@ -68,4 +73,4 @@ protected function runCommand ( InputInterface $input ) {
6873
return [ "status" => false, "message" => $message ];
6974
}
7075

71-
}
76+
}

src/app/code/JetRails/Varnish/Helper/Data.php

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44

55
use JetRails\Varnish\Model\Adminhtml\Config\Options\EnableDisable;
66
use JetRails\Varnish\Model\Adminhtml\Config\Options\YesNo;
7-
use Magento\Framework\App\Cache\TypeListInterface;
8-
use Magento\Framework\App\Cache\Type\Config;
97
use Magento\Framework\App\Config\ScopeConfigInterface;
108
use Magento\Framework\App\Config\Storage\WriterInterface;
119
use Magento\Framework\App\Helper\AbstractHelper;
@@ -31,32 +29,27 @@ class Data extends AbstractHelper {
3129
/**
3230
* These internal data members include instances of helper classes that are injected into
3331
* the class using dependency injection on runtime.
34-
* @var TypeListInterface _cacheTypeList Instance of the TypeListInterface
3532
* @var ScopeConfigInterface _configReader Instance of the ScopeConfigInterface
3633
* @var StoreManagerInterface _configWriter Instance of the StoreManagerInterface
3734
* @var WriterInterface _storeManager Instance of the WriterInterface
3835
*/
39-
protected $_cacheTypeList;
4036
protected $_configReader;
4137
protected $_configWriter;
4238
protected $_storeManager;
4339

4440
/**
4541
* This constructor is overloaded from the parent class in order to use dependency injection
4642
* to get the dependency classes that we need for this module's command actions to execute.
47-
* @param TypeListInterface cacheTypeList Instance of the TypeListInterface
4843
* @param ScopeConfigInterface configReader Instance of the ScopeConfigInterface
4944
* @param StoreManagerInterface configWriter Instance of the StoreManagerInterface
5045
* @param WriterInterface storeManager Instance of the WriterInterface
5146
*/
5247
public function __construct (
53-
TypeListInterface $cacheTypeList,
5448
ScopeConfigInterface $configReader,
5549
StoreManagerInterface $storeManager,
5650
WriterInterface $configWriter
5751
) {
5852
// Save the injected class instances
59-
$this->_cacheTypeList = $cacheTypeList;
6053
$this->_configReader = $configReader;
6154
$this->_storeManager = $storeManager;
6255
$this->_configWriter = $configWriter;
@@ -71,8 +64,6 @@ public function __construct (
7164
* @return String The value of the variable
7265
*/
7366
private function _getStoreValue ( $path, $scope = ScopeInterface::SCOPE_STORE ) {
74-
// Clean the config cache so we go the right values
75-
$this->_cacheTypeList->cleanType ( Config::TYPE_IDENTIFIER );
7667
// Ask the config reader to get the value in the store scope
7768
return $this->_configReader->getValue ( $path, $scope );
7869
}
@@ -155,6 +146,20 @@ public function isEnabled () {
155146
return $enabled == CacheConfig::VARNISH;
156147
}
157148

149+
/**
150+
* This method simply takes in a boolean value that represents the enable/disable state of this
151+
* module. It then saves it into the configuration. Note that config cache is not invalidated in
152+
* this method.
153+
* @param boolean status What to set the enable setting to
154+
* @return void
155+
*/
156+
public function setEnable ( $status ) {
157+
// Translate the status into a status state
158+
$value = $status ? EnableDisable::ENABLED : EnableDisable::DISABLED;
159+
// Simply save it into the store config
160+
$this->_configWriter->save ( "jetrails_varnish/general_configuration/status", $value );
161+
}
162+
158163
/**
159164
* This method takes in a class constant from CacheConfig and sets it in the store config.
160165
* @param CacheConfig value Class constant for caching app state
@@ -267,4 +272,4 @@ public function getExcludedRoutes () {
267272
return array_filter ( $routes, function ( $i ) { return $i != ""; });
268273
}
269274

270-
}
275+
}

src/app/code/JetRails/Varnish/Observer/Save/Cache.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace JetRails\Varnish\Observer\Save;
44

55
use JetRails\Varnish\Model\Adminhtml\Config\Options\EnableDisable;
6+
use Magento\Framework\App\Cache\Type\Config;
7+
use Magento\Framework\App\Cache\TypeListInterface;
68
use Magento\Framework\App\Config\ScopeConfigInterface;
79
use Magento\Framework\App\Config\Storage\WriterInterface;
810
use Magento\Framework\Event\Observer;
@@ -26,23 +28,28 @@ class Cache implements ObserverInterface {
2628
/**
2729
* These internal data members include instances of helper classes that are injected into
2830
* the class using dependency injection on runtime.
31+
* @var TypeListInterface _cacheTypeList Instance of the TypeListInterface
2932
* @var ScopeConfigInterface _configReader Instance of ScopeConfigInterface
3033
* @var WriterInterface _configWriter Instance of WriterInterface
3134
*/
35+
protected $_cacheTypeList;
3236
protected $_configReader;
3337
protected $_configWriter;
3438

3539
/**
3640
* This constructor is overloaded from the parent class in order to use dependency injection
3741
* to get the dependency classes that we need for this module's command actions to execute.
42+
* @param TypeListInterface cacheTypeList Instance of the TypeListInterface
3843
* @param ScopeConfigInterface configReader Instance of ScopeConfigInterface
3944
* @param WriterInterface configWriter Instance of WriterInterface
4045
*/
4146
public function __construct (
47+
TypeListInterface $cacheTypeList,
4248
ScopeConfigInterface $configReader,
4349
WriterInterface $configWriter
4450
) {
4551
// Save the injected class instances
52+
$this->_cacheTypeList = $cacheTypeList;
4653
$this->_configReader = $configReader;
4754
$this->_configWriter = $configWriter;
4855
}
@@ -67,6 +74,8 @@ public function execute ( Observer $observer ) {
6774
"jetrails_varnish/general_configuration/status",
6875
$cacheApp == CacheConfig::VARNISH ? EnableDisable::ENABLED : EnableDisable::DISABLED
6976
);
77+
// Clean the config cache so we get the right values when querying for them
78+
$this->_cacheTypeList->cleanType ( Config::TYPE_IDENTIFIER );
7079
}
7180

72-
}
81+
}

src/app/code/JetRails/Varnish/Observer/Save/Config.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace JetRails\Varnish\Observer\Save;
44

55
use JetRails\Varnish\Model\Adminhtml\Config\Options\EnableDisable;
6+
use Magento\Framework\App\Cache\Type\Config as ConfigType;
7+
use Magento\Framework\App\Cache\TypeListInterface;
68
use Magento\Framework\App\Config\ScopeConfigInterface;
79
use Magento\Framework\App\Config\Storage\WriterInterface;
810
use Magento\Framework\Event\Observer;
@@ -29,27 +31,32 @@ class Config implements ObserverInterface {
2931
* These internal data members include instances of helper classes that are injected into
3032
* the class using dependency injection on runtime.
3133
* @var ManagerInterface _message Instance of ManagerInterface
34+
* @var TypeListInterface _cacheTypeList Instance of the TypeListInterface
3235
* @var ScopeConfigInterface _configReader Instance of ScopeConfigInterface
3336
* @var WriterInterface _configWriter Instance of WriterInterface
3437
*/
3538
protected $_message;
39+
protected $_cacheTypeList;
3640
protected $_configReader;
3741
protected $_configWriter;
3842

3943
/**
4044
* This constructor is overloaded from the parent class in order to use dependency injection
4145
* to get the dependency classes that we need for this module's command actions to execute.
4246
* @param ManagerInterface message Instance of ManagerInterface
47+
* @param TypeListInterface cacheTypeList Instance of the TypeListInterface
4348
* @param ScopeConfigInterface configReader Instance of ScopeConfigInterface
4449
* @param WriterInterface configWriter Instance of WriterInterface
4550
*/
4651
public function __construct (
4752
ManagerInterface $message,
53+
TypeListInterface $cacheTypeList,
4854
ScopeConfigInterface $configReader,
4955
WriterInterface $configWriter
5056
) {
5157
// Save the injected class instances
5258
$this->_message = $message;
59+
$this->_cacheTypeList = $cacheTypeList;
5360
$this->_configReader = $configReader;
5461
$this->_configWriter = $configWriter;
5562
}
@@ -181,6 +188,8 @@ public function execute ( Observer $observer ) {
181188
"system/full_page_cache/caching_application",
182189
$status == EnableDisable::ENABLED ? CacheConfig::VARNISH : CacheConfig::BUILT_IN
183190
);
191+
// Clean the config cache so we get the right values when querying for them
192+
$this->_cacheTypeList->cleanType ( ConfigType::TYPE_IDENTIFIER );
184193
}
185194

186-
}
195+
}

0 commit comments

Comments
 (0)