-
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.
- Loading branch information
1 parent
20005ef
commit 3043f93
Showing
11 changed files
with
460 additions
and
149 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,105 @@ | ||
<?php | ||
/** | ||
* LiteMage | ||
* @package LiteSpeed_LiteMage | ||
* @copyright Copyright (c) LiteSpeed Technologies, Inc. All rights reserved. (https://www.litespeedtech.com) | ||
* @license https://opensource.org/licenses/GPL-3.0 | ||
*/ | ||
|
||
namespace Litespeed\Litemage\Console\Command; | ||
|
||
use Symfony\Component\Console\Command\Command; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Magento\Framework\Event\ManagerInterface as EventManagerInterface; | ||
|
||
|
||
/** | ||
* Command for flush litemage cache by tags | ||
*/ | ||
abstract class AbstractLitemageCommand extends Command | ||
{ | ||
/** | ||
* @var \Magento\Framework\Event\ManagerInterface | ||
*/ | ||
protected $eventManager; | ||
|
||
/** | ||
* | ||
* @var string | ||
*/ | ||
protected $type; | ||
/** | ||
* | ||
* @var array | ||
*/ | ||
protected $tags; | ||
/** | ||
* | ||
* @var string | ||
*/ | ||
protected $tag_format; | ||
|
||
/** | ||
* @param EventManagerInterface $eventManager | ||
*/ | ||
public function __construct(EventManagerInterface $eventManager) | ||
{ | ||
$this->eventManager = $eventManager; | ||
parent::__construct(); | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
parent::configure(); | ||
} | ||
|
||
/** | ||
* Perform a cache management action on cache types | ||
* | ||
* @return void | ||
* | ||
abstract protected function performAction(); */ | ||
|
||
/** | ||
* Get display message | ||
* | ||
* @return string | ||
*/ | ||
abstract protected function getDisplayMessage(); | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->getInputList($input); | ||
$param = ['tags' => $this->tags, | ||
'reason' => 'cli command: ' . $this->getName()]; | ||
$this->eventManager->dispatch('litemage_cli_purge', $param); | ||
$output->writeln($this->getDisplayMessage()); | ||
} | ||
|
||
protected function getInputList(InputInterface $input) | ||
{ | ||
$list = $input->getArgument($this->type); | ||
if (!empty($list)) { | ||
$list = array_filter(array_map('trim', $list), 'strlen'); | ||
} | ||
if (empty($list)) { | ||
throw new \InvalidArgumentException( | ||
"Missing the required space-separated list"); | ||
} | ||
foreach ($list as $tag) { | ||
if (!preg_match($this->tag_format, $tag)) { | ||
throw new \InvalidArgumentException( | ||
"Tag [$tag] contains invalid characters."); | ||
} | ||
} | ||
$this->tags = $list; | ||
} | ||
|
||
} |
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,49 @@ | ||
<?php | ||
/** | ||
* LiteMage | ||
* @package LiteSpeed_LiteMage | ||
* @copyright Copyright (c) LiteSpeed Technologies, Inc. All rights reserved. (https://www.litespeedtech.com) | ||
* @license https://opensource.org/licenses/GPL-3.0 | ||
*/ | ||
|
||
namespace Litespeed\Litemage\Console\Command; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
|
||
|
||
/** | ||
* Command for flush litemage cache by category IDs | ||
*/ | ||
class LitemageFlushCats extends AbstractLitemageCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->type = 'cats'; | ||
$this->tag_format = '/^[\d+]+$/'; | ||
$this->setName('cache:litemage:flush:cats'); | ||
$this->setDescription('Flushes LiteMage cache by a list of category IDs'); | ||
$this->addArgument( | ||
'cats', | ||
InputArgument::IS_ARRAY, | ||
'Space-separated list of category IDs (integer).' | ||
); | ||
parent::configure(); | ||
} | ||
|
||
protected function getInputList(InputInterface $input) | ||
{ | ||
parent::getInputList($input); | ||
$this->tags = array_map(function($value) { | ||
return 'C' . $value; | ||
}, $this->tags); | ||
} | ||
|
||
protected function getDisplayMessage() | ||
{ | ||
return 'Flushed LiteMage cache by category IDs.'; | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
/** | ||
* LiteMage | ||
* @package LiteSpeed_LiteMage | ||
* @copyright Copyright (c) LiteSpeed Technologies, Inc. All rights reserved. (https://www.litespeedtech.com) | ||
* @license https://opensource.org/licenses/GPL-3.0 | ||
*/ | ||
|
||
namespace Litespeed\Litemage\Console\Command; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
|
||
|
||
/** | ||
* Command for flush litemage cache by product IDs | ||
*/ | ||
class LitemageFlushProds extends AbstractLitemageCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->type = 'prods'; | ||
$this->tag_format = '/^[\d+]+$/'; | ||
$this->setName('cache:litemage:flush:prods'); | ||
$this->setDescription('Flushes LiteMage cache by a list of product IDs'); | ||
$this->addArgument( | ||
'prods', | ||
InputArgument::IS_ARRAY, | ||
'Space-separated list of product IDs (integer).' | ||
); | ||
parent::configure(); | ||
} | ||
|
||
protected function getInputList(InputInterface $input) | ||
{ | ||
parent::getInputList($input); | ||
$this->tags = array_map(function($value) { | ||
return 'P' . $value; | ||
}, $this->tags); | ||
|
||
} | ||
|
||
protected function getDisplayMessage() | ||
{ | ||
return 'Flushed LiteMage cache by product IDs.'; | ||
} | ||
} |
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,40 @@ | ||
<?php | ||
/** | ||
* LiteMage | ||
* @package LiteSpeed_LiteMage | ||
* @copyright Copyright (c) LiteSpeed Technologies, Inc. All rights reserved. (https://www.litespeedtech.com) | ||
* @license https://opensource.org/licenses/GPL-3.0 | ||
*/ | ||
|
||
namespace Litespeed\Litemage\Console\Command; | ||
|
||
use Symfony\Component\Console\Input\InputArgument; | ||
|
||
|
||
/** | ||
* Command for flush litemage cache by tags | ||
*/ | ||
class LitemageFlushTags extends AbstractLitemageCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->type = 'tags'; | ||
$this->tag_format = '/^[a-zA-Z\d_-]+$/'; | ||
$this->setName('cache:litemage:flush:tags'); | ||
$this->setDescription('Flushes LiteMage cache by a list of tags'); | ||
$this->addArgument( | ||
'tags', | ||
InputArgument::IS_ARRAY, | ||
'Space-separated list of cache tags.' | ||
); | ||
parent::configure(); | ||
} | ||
|
||
protected function getDisplayMessage() | ||
{ | ||
return 'Flushed LiteMage cache by tags.'; | ||
} | ||
} |
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.