-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First release of warm cache extension.
- Loading branch information
0 parents
commit d82fe18
Showing
14 changed files
with
618 additions
and
0 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,43 @@ | ||
<?php | ||
|
||
/** | ||
* Warm Cache | ||
* | ||
* Provide a warm cache extension. | ||
* | ||
* @package Igorludgero\WarmCache | ||
* @author Igor Ludgero Miura <[email protected]> | ||
* @copyright Copyright (c) 2017 Igor Ludgero Miura (https://www.igorludgero.com/) | ||
* @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 | ||
*/ | ||
|
||
namespace Igorludgero\WarmCache\Block\Adminhtml; | ||
|
||
class Cache extends \Magento\Backend\Block\Cache | ||
{ | ||
/** | ||
* Cache block constructor. | ||
*/ | ||
protected function _construct() | ||
{ | ||
parent::_construct(); | ||
$message = __('The Warm Cache will access a lot of store urls like product, category and cms pages to rebuild the caches. Do you agree to start now?'); | ||
$this->buttonList->add( | ||
'warm_cache', | ||
[ | ||
'label' => __('Run Warm Cache'), | ||
'onclick' => 'confirmSetLocation(\'' . $message . '\', \'' . $this->getWarmCacheUrl() . '\')', | ||
'class' => 'run-warm-cache' | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* Get warm cache action url. | ||
* @return string | ||
*/ | ||
private function getWarmCacheUrl(){ | ||
return $this->getUrl('warmcache/WarmCache/run'); | ||
} | ||
|
||
} |
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,68 @@ | ||
<?php | ||
|
||
/** | ||
* Warm Cache | ||
* | ||
* Provide a warm cache extension. | ||
* | ||
* @package Igorludgero\WarmCache | ||
* @author Igor Ludgero Miura <[email protected]> | ||
* @copyright Copyright (c) 2017 Igor Ludgero Miura (https://www.igorludgero.com/) | ||
* @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 | ||
*/ | ||
|
||
namespace Igorludgero\WarmCache\Console\Command; | ||
|
||
class WarmCache extends \Symfony\Component\Console\Command\Command | ||
{ | ||
|
||
/** | ||
* @var \Igorludgero\WarmCache\Helper\Data | ||
*/ | ||
protected $_helper; | ||
|
||
/** | ||
* @var \Magento\Framework\App\State | ||
*/ | ||
protected $_appState; | ||
|
||
/** | ||
* WarmCache constructor. | ||
* @param \Igorludgero\WarmCache\Helper\Data $helper | ||
*/ | ||
public function __construct(\Magento\Framework\App\State $appState, | ||
\Igorludgero\WarmCache\Helper\Data $helper) | ||
{ | ||
$this->_helper = $helper; | ||
$this->_appState = $appState; | ||
parent::__construct('igorludgero:warmcache'); | ||
} | ||
|
||
/** | ||
* Configure cli command. | ||
*/ | ||
protected function configure() | ||
{ | ||
$this->setName('igorludgero:warmcache')->setDescription('Run the warm cache and cache all available pages in the store.'); | ||
} | ||
|
||
/** | ||
* Execute cli command. | ||
* @param \Symfony\Component\Console\Input\InputInterface $input | ||
* @param \Symfony\Component\Console\Output\OutputInterface $output | ||
* @return $this | ||
*/ | ||
protected function execute(\Symfony\Component\Console\Input\InputInterface $input, \Symfony\Component\Console\Output\OutputInterface $output) | ||
{ | ||
$this->_appState->setAreaCode('adminhtml'); | ||
if($this->_helper->run()){ | ||
$this->_helper->logMessage("Warm cache process finished."); | ||
$output->writeln('Warm cache process finished.'); | ||
} | ||
else{ | ||
$output->writeln('Was not possible to run the command, please try again later.'); | ||
} | ||
return $this; | ||
} | ||
|
||
} |
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 | ||
|
||
/** | ||
* Warm Cache | ||
* | ||
* Provide a warm cache extension. | ||
* | ||
* @package Igorludgero\WarmCache | ||
* @author Igor Ludgero Miura <[email protected]> | ||
* @copyright Copyright (c) 2017 Igor Ludgero Miura (https://www.igorludgero.com/) | ||
* @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 | ||
*/ | ||
|
||
namespace Igorludgero\WarmCache\Controller\Adminhtml\WarmCache; | ||
|
||
use Magento\Backend\App\Action; | ||
|
||
class Run extends \Magento\Backend\App\Action | ||
{ | ||
|
||
/** | ||
* @var \Igorludgero\WarmCache\Helper\Data | ||
*/ | ||
protected $_helper; | ||
|
||
/** | ||
* Run constructor. | ||
* @param Action\Context $context | ||
* @param \Igorludgero\WarmCache\Helper\Data $helper | ||
*/ | ||
public function __construct(\Magento\Backend\App\Action\Context $context, \Igorludgero\WarmCache\Helper\Data $helper) | ||
{ | ||
parent::__construct($context); | ||
$this->_helper = $helper; | ||
} | ||
|
||
/** | ||
* Start the WarmCache. | ||
*/ | ||
public function execute() | ||
{ | ||
$resultRedirect = $this->resultFactory->create(\Magento\Framework\Controller\ResultFactory::TYPE_REDIRECT); | ||
$this->_helper->run(); | ||
$this->messageManager->addSuccessMessage(__("Warm cache ran successfully!")); | ||
$resultRedirect->setUrl($this->_redirect->getRefererUrl()); | ||
return $resultRedirect; | ||
} | ||
|
||
} |
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,44 @@ | ||
<?php | ||
|
||
/** | ||
* Warm Cache | ||
* | ||
* Provide a warm cache extension. | ||
* | ||
* @package Igorludgero\WarmCache | ||
* @author Igor Ludgero Miura <[email protected]> | ||
* @copyright Copyright (c) 2017 Igor Ludgero Miura (https://www.igorludgero.com/) | ||
* @license https://opensource.org/licenses/OSL-3.0.php Open Software License 3.0 | ||
*/ | ||
|
||
namespace Igorludgero\WarmCache\Cron; | ||
|
||
class Run | ||
{ | ||
|
||
/** | ||
* @var \Igorludgero\WarmCache\Helper\Data | ||
*/ | ||
protected $_helper; | ||
|
||
/** | ||
* Run constructor. | ||
* @param \Igorludgero\WarmCache\Helper\Data $helper | ||
*/ | ||
public function __construct(\Igorludgero\WarmCache\Helper\Data $helper) | ||
{ | ||
$this->_helper = $helper; | ||
} | ||
|
||
/** | ||
* Run the warm cache process. | ||
* @return $this | ||
*/ | ||
public function execute() | ||
{ | ||
|
||
$this->_helper->run(); | ||
return $this; | ||
} | ||
|
||
} |
Oops, something went wrong.