Changeset View
Changeset View
Standalone View
Standalone View
branches/5.3.x/core/kernel/Console/Command/ResetCacheCommand.php
Property | Old Value | New Value |
---|---|---|
svn:eol-style | null | LF |
<?php | |||||
/** | |||||
* @version $Id$ | |||||
* @package In-Portal | |||||
* @copyright Copyright (C) 1997 - 2015 Intechnic. All rights reserved. | |||||
* @license GNU/GPL | |||||
* In-Portal is Open Source software. | |||||
* This means that this software may have been modified pursuant | |||||
* the GNU General Public License, and as distributed it includes | |||||
* or is derivative of works licensed under the GNU General Public License | |||||
* or other free or open source software licenses. | |||||
* See http://www.in-portal.org/license for copyright notices and details. | |||||
*/ | |||||
namespace Intechnic\InPortal\Core\kernel\Console\Command; | |||||
use Symfony\Component\Console\Input\InputInterface; | |||||
use Symfony\Component\Console\Input\InputOption; | |||||
use Symfony\Component\Console\Output\OutputInterface; | |||||
defined('FULL_PATH') or die('restricted access!'); | |||||
class ResetCacheCommand extends AbstractCommand | |||||
{ | |||||
/** | |||||
* Determines what options will execute what events. | |||||
* | |||||
* @var array | |||||
*/ | |||||
protected $optionMap = array( | |||||
'unit-data' => array( | |||||
'short' => 'd', | |||||
'description' => 'Reset Parsed and Cached System Data', | |||||
'event' => 'adm:OnResetParsedData', | |||||
), | |||||
'unit-files' => array( | |||||
'short' => 'f', | |||||
'description' => 'Reset Configs Files Cache and Parsed System Data', | |||||
'event' => 'adm:OnResetConfigsCache', | |||||
), | |||||
'admin-sections' => array( | |||||
'short' => 's', | |||||
'description' => 'Reset Admin Console Sections', | |||||
'event' => 'adm:OnResetSections', | |||||
), | |||||
'mod-rewrite' => array( | |||||
'short' => 'r', | |||||
'description' => 'Reset ModRewrite Cache', | |||||
'event' => 'adm:OnResetModRwCache', | |||||
), | |||||
'sms-menu' => array( | |||||
'short' => 'm', | |||||
'description' => 'Reset SMS Menu Cache', | |||||
'event' => 'c:OnResetCMSMenuCache', | |||||
), | |||||
'templates' => array( | |||||
'short' => 't', | |||||
'description' => 'Clear Templates Cache', | |||||
'event' => 'adm:OnDeleteCompiledTemplates', | |||||
), | |||||
'all-keys' => array( | |||||
'short' => 'k', | |||||
'description' => 'Reset All Keys', | |||||
'event' => 'adm:OnResetMemcache', | |||||
), | |||||
); | |||||
/** | |||||
* Configures the current command. | |||||
* | |||||
* @return void | |||||
*/ | |||||
protected function configure() | |||||
{ | |||||
$this | |||||
->setName('cache:reset') | |||||
->setDescription('Resets the cache'); | |||||
foreach ( $this->optionMap as $option_name => $option_data ) { | |||||
$this->addOption( | |||||
$option_name, | |||||
$option_data['short'], | |||||
InputOption::VALUE_NONE, | |||||
$option_data['description'] | |||||
); | |||||
} | |||||
} | |||||
/** | |||||
* Executes the current command. | |||||
* | |||||
* @param InputInterface $input An InputInterface instance. | |||||
* @param OutputInterface $output An OutputInterface instance. | |||||
* | |||||
* @return null|integer | |||||
*/ | |||||
protected function execute(InputInterface $input, OutputInterface $output) | |||||
{ | |||||
$success_count = 0; | |||||
$error_count = 0; | |||||
foreach ( $this->optionMap as $option_name => $option_data ) { | |||||
if ( !$input->getOption($option_name) ) { | |||||
continue; | |||||
} | |||||
$success_count++; | |||||
$output->write('- ' . $option_data['description'] . ' ... '); | |||||
$event = new \kEvent($option_data['event']); | |||||
$this->Application->HandleEvent($event); | |||||
if ( $event->getRedirectParam('action_completed') ) { | |||||
$output->writeln('<info>OK</info>'); | |||||
} | |||||
else { | |||||
$error_count++; | |||||
$output->writeln('<error>FAILED</error>'); | |||||
} | |||||
} | |||||
if ( $success_count === 0 ) { | |||||
throw new \RuntimeException('Please specify at least one reset option'); | |||||
} | |||||
return $error_count == 0 ? 0 : 64; | |||||
} | |||||
} |