Skip to content

Commit

Permalink
Merge pull request netz98#605 from ktomk/bugfix/issue-584-cookie-domain
Browse files Browse the repository at this point in the history
Improvements on Checks
  • Loading branch information
tkn98 committed Jun 29, 2015
2 parents aefed02 + 125145f commit 102eff3
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 27 deletions.
7 changes: 7 additions & 0 deletions src/N98/Magento/Command/System/Check/ResultCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,13 @@

namespace N98\Magento\Command\System\Check;

use Traversable;

/**
* Class ResultCollection
*
* @package N98\Magento\Command\System\Check
*/
class ResultCollection implements \IteratorAggregate
{
/**
Expand Down
5 changes: 5 additions & 0 deletions src/N98/Magento/Command/System/Check/SimpleCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

namespace N98\Magento\Command\System\Check;

/**
* Interface SimpleCheck
*
* @package N98\Magento\Command\System\Check
*/
interface SimpleCheck
{
/**
Expand Down
10 changes: 9 additions & 1 deletion src/N98/Magento/Command/System/Check/StoreCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

namespace N98\Magento\Command\System\Check;

/**
* Interface StoreCheck
*
* @package N98\Magento\Command\System\Check
*/
interface StoreCheck
{
/**
* @param ResultCollection $results
* @param ResultCollection $results
* @param \Mage_Core_Model_Store $store
*
* @return
*/
public function check(ResultCollection $results, \Mage_Core_Model_Store $store);
}
10 changes: 9 additions & 1 deletion src/N98/Magento/Command/System/Check/WebsiteCheck.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

namespace N98\Magento\Command\System\Check;

/**
* Interface WebsiteCheck
*
* @package N98\Magento\Command\System\Check
*/
interface WebsiteCheck
{
/**
* @param ResultCollection $results
* @param ResultCollection $results
* @param \Mage_Core_Model_Website $website
*
* @return
*/
public function check(ResultCollection $results, \Mage_Core_Model_Website $website);
}
99 changes: 74 additions & 25 deletions src/N98/Magento/Command/System/CheckCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;

/**
* Class CheckCommand
*
* @package N98\Magento\Command\System
*/
class CheckCommand extends AbstractMagentoCommand
{
const UNICODE_CHECKMARK_CHAR = 10004;
Expand Down Expand Up @@ -76,35 +81,45 @@ protected function execute(InputInterface $input, OutputInterface $output)

/**
* @param ResultCollection $results
* @param mixed $checkGroupClass
* @internal param ResultCollection $resultCollection
* @param string $checkGroupClass name
*/
protected function _invokeCheckClass(ResultCollection $results, $checkGroupClass)
{
$check = new $checkGroupClass();
if ($check instanceof CommandAware) {
$check->setCommand($this);
}
if ($check instanceof CommandConfigAware) {
$check->setCommandConfig($this->_config);
}
$check = $this->_createCheck($checkGroupClass);

if ($check instanceof Check\SimpleCheck) {
$check->check($results);
} elseif ($check instanceof Check\StoreCheck) {
foreach (\Mage::app()->getStores() as $store) {
$check->check($results, $store);
}
} elseif ($check instanceof Check\WebsiteCheck) {
foreach (\Mage::app()->getWebsites() as $website) {
$check->check($results, $website);
}
switch (true) {
case $check instanceof Check\SimpleCheck:
$check->check($results);
break;

case $check instanceof Check\StoreCheck:
if (!$stores = \Mage::app()->getStores()) {
$this->_markCheckWarning($results, 'stores', $checkGroupClass);
}
foreach ($stores as $store) {
$check->check($results, $store);
}
break;

case $check instanceof Check\WebsiteCheck:
if (!$websites = \Mage::app()->getWebsites()) {
$this->_markCheckWarning($results, 'websites', $checkGroupClass);
}
foreach ($websites as $website) {
$check->check($results, $website);
}
break;

default:
throw new \LogicException(
sprintf('Unhandled check-class "%s"', $checkGroupClass)
);
}
}

/**
* @param OutputInterface $output
* @param Result $result
* @param OutputInterface $output
* @param ResultCollection $results
*/
protected function _printResults(OutputInterface $output, ResultCollection $results)
{
Expand All @@ -120,8 +135,8 @@ protected function _printResults(OutputInterface $output, ResultCollection $resu
$output->write('<error>' . \N98\Util\Unicode\Charset::convertInteger(Charset::UNICODE_CROSS_CHAR) . '</error> ');
break;

default:
case Result::STATUS_OK:
default:
$output->write('<info>' . \N98\Util\Unicode\Charset::convertInteger(Charset::UNICODE_CHECKMARK_CHAR) . '</info> ');
break;
}
Expand All @@ -133,9 +148,9 @@ protected function _printResults(OutputInterface $output, ResultCollection $resu
}

/**
* @param InputInterface $input
* @param OutputInterface $output
* @param Result $result
* @param InputInterface $input
* @param OutputInterface $output
* @param ResultCollection $results
*/
protected function _printTable(InputInterface $input, OutputInterface $output, ResultCollection $results)
{
Expand All @@ -153,4 +168,38 @@ protected function _printTable(InputInterface $input, OutputInterface $output, R
->setHeaders(array('Group', 'Message', 'Result'))
->renderByFormat($output, $table, $input->getOption('format'));
}

/**
* @param string $checkGroupClass
*
* @return object
*/
private function _createCheck($checkGroupClass)
{
$check = new $checkGroupClass();

if ($check instanceof CommandAware) {
$check->setCommand($this);
}
if ($check instanceof CommandConfigAware) {
$check->setCommandConfig($this->_config);

return $check;
}

return $check;
}

/**
* @param ResultCollection $results
* @param string $context
* @param string $checkGroupClass
*/
private function _markCheckWarning(ResultCollection $results, $context, $checkGroupClass)
{
$result = $results->createResult();
$result->setMessage('<error>No ' . $context . ' configured to run store check:</error> <comment>' . basename($checkGroupClass) . '</comment>');
$result->setStatus($result::STATUS_WARNING);
$results->addResult($result);
}
}

0 comments on commit 102eff3

Please sign in to comment.