-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Separate purge logic to allow command line purge
- Loading branch information
1 parent
c18d2cf
commit ee1f0de
Showing
13 changed files
with
339 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
/** | ||
* LiteMage | ||
* | ||
* NOTICE OF LICENSE | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see https://opensource.org/licenses/GPL-3.0 . | ||
* | ||
* @package LiteSpeed_LiteMage | ||
* @copyright Copyright (c) 2016 LiteSpeed Technologies, Inc. (https://www.litespeedtech.com) | ||
* @license https://opensource.org/licenses/GPL-3.0 | ||
*/ | ||
|
||
namespace Litespeed\Litemage\Controller\Shell; | ||
|
||
class Purge extends \Magento\Framework\App\Action\Action | ||
{ | ||
|
||
/** | ||
* @var \Litespeed\Litemage\Model\CacheControl | ||
*/ | ||
protected $litemageCache; | ||
protected $httpHeader; | ||
|
||
|
||
/** | ||
* @param \Magento\Framework\App\Action\Context $context | ||
* @param \Magento\Framework\Translate\InlineInterface $translateInline | ||
* @param \Litespeed\Litemage\Model\CacheControl $litemageCache | ||
*/ | ||
public function __construct( | ||
\Magento\Framework\App\Action\Context $context, | ||
\Magento\Framework\HTTP\Header $httpHeader, | ||
\Litespeed\Litemage\Model\CacheControl $litemageCache | ||
) { | ||
parent::__construct($context); | ||
$this->httpHeader = $httpHeader; | ||
$this->litemageCache = $litemageCache; | ||
} | ||
|
||
/** | ||
* Returns block content as part of ESI request from Varnish | ||
* | ||
* @return void | ||
*/ | ||
public function execute() | ||
{ | ||
if (!$this->litemageCache->moduleEnabled()) { | ||
return $this->_errorExit('Abort: LiteMage is not enabled'); | ||
} | ||
if ( $this->httpHeader->getHttpUserAgent() !== 'litemage_walker') { | ||
return $this->_errorExit('Access denied'); | ||
} | ||
|
||
$tags = []; | ||
$req = $this->getRequest(); | ||
if ($req->getParam('all')) { | ||
$tags[] = '*'; | ||
} | ||
else { | ||
if ($t = $req->getParam('tags')) { | ||
$tags = explode(',', $t); | ||
} | ||
$types = array('P.' => 'products', 'C.' => 'cats', 'S.' => 'stores'); | ||
foreach ($types as $prefix => $type) { | ||
if ($ids = $req->getParam($type)) { | ||
$tids = explode(',', $ids); | ||
foreach ($tids as $id) { | ||
$tags[] = $prefix . $id; | ||
} | ||
} | ||
} | ||
$tags = array_unique($tags); | ||
} | ||
if (empty($tags)) { | ||
$this->_errorExit('Invalid url'); | ||
} | ||
else { | ||
$this->litemageCache->addPurgeTags($tags, 'ShellPurgeController'); | ||
$this->getResponse()->setBody('purged tags ' . implode(',', $tags)); | ||
} | ||
} | ||
|
||
protected function _errorExit($errorMesg) | ||
{ | ||
$resp = $this->getResponse() ; | ||
$resp->setHttpResponseCode(500) ; | ||
$resp->setBody($errorMesg) ; | ||
$this->litemageCache->debugLog('litemage/shell/purge ErrorExit: ' . $errorMesg) ; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,13 +27,6 @@ | |
use Magento\Framework\Filesystem; | ||
use Magento\Framework\Module\Dir; | ||
|
||
/** | ||
* Model is responsible for replacing default vcl template | ||
* file configuration with user-defined from configuration | ||
* | ||
* @author Magento Core Team <[email protected]> | ||
*/ | ||
|
||
/** | ||
* Class Config | ||
* | ||
|
@@ -77,7 +70,13 @@ class Config | |
protected $reader; | ||
protected $_debug = -1; // avail value: -1(not set), true, false | ||
|
||
protected $_moduleEnabled = false; | ||
/** | ||
* @var int moduleStatus bitmask | ||
* 1: SERVER variable set | ||
* 2: FPC enabled | ||
* 4: FPC type is LITEMAGE | ||
*/ | ||
protected $_moduleStatus = 0; | ||
|
||
/** | ||
* @param Filesystem\Directory\ReadFactory $readFactory | ||
|
@@ -88,22 +87,24 @@ class Config | |
public function __construct( | ||
\Magento\Framework\Filesystem\Directory\ReadFactory $readFactory, | ||
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, | ||
\Magento\Framework\App\Cache\StateInterface $cacheState, | ||
\Magento\PageCache\Model\Config $pagecacheConfig, | ||
\Magento\Framework\Module\Dir\Reader $reader, | ||
\Magento\Framework\App\State $state | ||
) { | ||
$this->readFactory = $readFactory; | ||
$this->scopeConfig = $scopeConfig; | ||
$this->reader = $reader; | ||
|
||
if (isset($_SERVER['X-LITEMAGE']) && $_SERVER['X-LITEMAGE']) { | ||
$this->_moduleStatus |= 1; | ||
} | ||
if ($pagecacheConfig->isEnabled()) { | ||
$this->_moduleStatus |= 2; | ||
} | ||
if ($pagecacheConfig->getType() == self::LITEMAGE) { | ||
$this->_moduleStatus |= 4; | ||
} | ||
|
||
if (isset($_SERVER['X-LITEMAGE']) && $_SERVER['X-LITEMAGE']) { | ||
if ($pagecacheConfig->isEnabled() | ||
&& $pagecacheConfig->getType() == self::LITEMAGE | ||
&& $cacheState->isEnabled(\Magento\PageCache\Model\Cache\Type::TYPE_IDENTIFIER)) { | ||
$this->_moduleEnabled = true; | ||
} | ||
} | ||
if ($state->getMode() === \Magento\Framework\App\State::MODE_PRODUCTION) { | ||
// turn off debug for production | ||
$this->_debug = 0; | ||
|
@@ -122,9 +123,14 @@ public function __construct( | |
*/ | ||
public function moduleEnabled() | ||
{ | ||
return $this->_moduleEnabled; | ||
return ($this->_moduleStatus == 7); | ||
} | ||
|
||
public function cliModuleEnabled() | ||
{ | ||
return ($this->_moduleStatus == 6); | ||
} | ||
|
||
public function debugEnabled() | ||
{ | ||
return $this->_debug; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.