Skip to content

Commit

Permalink
Release 1.0.0
Browse files Browse the repository at this point in the history
First release of warm cache extension.
  • Loading branch information
igorppbr committed Sep 9, 2017
0 parents commit d82fe18
Show file tree
Hide file tree
Showing 14 changed files with 618 additions and 0 deletions.
43 changes: 43 additions & 0 deletions Block/Adminhtml/Cache.php
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');
}

}
68 changes: 68 additions & 0 deletions Console/Command/WarmCache.php
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;
}

}
49 changes: 49 additions & 0 deletions Controller/Adminhtml/WarmCache/Run.php
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;
}

}
44 changes: 44 additions & 0 deletions Cron/Run.php
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;
}

}
Loading

0 comments on commit d82fe18

Please sign in to comment.