Refactor Commands

This commit is contained in:
Romain Neutron
2012-06-21 13:48:21 +02:00
parent 8e8949e8bb
commit d4d9dd2cee
27 changed files with 59 additions and 79 deletions

View File

@@ -47,16 +47,14 @@ class BuildMissingSubdefs extends Command
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$core = \bootstrap::getCore(); $core = \bootstrap::getCore();
$this->appbox = \appbox::get_instance($core); $this->appbox = \appbox::get_instance($core);
if ($input->getOption('verbose')) { if ($input->getOption('verbose')) {
$logger = $this->getLogger(); $logger = $this->getLogger();
$handler = new Handler\StreamHandler(fopen('php://stdout', 'a')); $handler = new Handler\StreamHandler('php://stdout');
$logger->pushHandler($handler); $logger->pushHandler($handler);
$this->setLogger($logger); $this->setLogger($logger);
} }

View File

@@ -12,7 +12,10 @@
namespace Alchemy\Phrasea\Command; namespace Alchemy\Phrasea\Command;
use Monolog\Logger; use Monolog\Logger;
use Monolog\Handler\StreamHandler;
use Symfony\Component\Console\Command\Command as SymfoCommand; use Symfony\Component\Console\Command\Command as SymfoCommand;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
/** /**
* Abstract command which represents a Phraseanet base command * Abstract command which represents a Phraseanet base command
@@ -81,6 +84,25 @@ abstract class Command extends SymfoCommand
} }
} }
/**
* {@inheritdoc}
*/
public function execute(InputInterface $input, OutputInterface $output)
{
$this->checkSetup();
$core = \bootstrap::getCore();
if($input->getOption('verbose')) {
$handler = new StreamHandler('php://stdout');
$this->logger->pushHandler($handler);
}
return $this->doExecute($input, $output);
}
abstract protected function doExecute(InputInterface $input, OutputInterface $output);
/** /**
* Format a duration in seconds to human readable * Format a duration in seconds to human readable
* *
@@ -92,13 +114,11 @@ abstract class Command extends SymfoCommand
$duration = ceil($seconds) . ' seconds'; $duration = ceil($seconds) . ' seconds';
if ($duration > 60) { if ($duration > 60) {
$duration = round($duration / 60 , 1) . ' minutes'; $duration = round($duration / 60, 1) . ' minutes';
} } elseif ($duration > 3600) {
elseif ($duration > 3600) { $duration = round($duration / (60 * 60), 1) . ' hours';
$duration = round($duration / (60 * 60) , 1) . ' hours'; } elseif ($duration > (24 * 60 * 60)) {
} $duration = round($duration / (24 * 60 * 60), 1) . ' days';
elseif ($duration > (24 * 60 * 60)) {
$duration = round($duration / (24 * 60 * 60) , 1) . ' days';
} }
return $duration; return $duration;

View File

@@ -55,10 +55,8 @@ class RescanTechnicalDatas extends Command
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$this->appbox = \appbox::get_instance(\bootstrap::getCore()); $this->appbox = \appbox::get_instance(\bootstrap::getCore());
$quantity = $this->computeQuantity(); $quantity = $this->computeQuantity();

View File

@@ -109,7 +109,7 @@ EOF
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->generateUpgradesFromOption($input); $this->generateUpgradesFromOption($input);

View File

@@ -31,10 +31,8 @@ class module_console_aboutAuthors extends Command
return $this; return $this;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS')); $output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS'));
return 0; return 0;

View File

@@ -31,10 +31,8 @@ class module_console_aboutLicense extends Command
return $this; return $this;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE')); $output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE'));
return 0; return 0;

View File

@@ -41,10 +41,8 @@ class module_console_checkExtension extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
if ( ! extension_loaded('phrasea2')) { if ( ! extension_loaded('phrasea2')) {
$output->writeln("<error>Missing Extension php-phrasea.</error>"); $output->writeln("<error>Missing Extension php-phrasea.</error>");

View File

@@ -40,10 +40,8 @@ class module_console_fieldsDelete extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
try { try {
$databox = \databox::get_instance((int) $input->getArgument('sbas_id')); $databox = \databox::get_instance((int) $input->getArgument('sbas_id'));
} catch (\Exception $e) { } catch (\Exception $e) {

View File

@@ -36,10 +36,8 @@ class module_console_fieldsList extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$appbox = \appbox::get_instance(\bootstrap::getCore()); $appbox = \appbox::get_instance(\bootstrap::getCore());
foreach ($appbox->get_databoxes() as $databox) { foreach ($appbox->get_databoxes() as $databox) {

View File

@@ -50,10 +50,8 @@ class module_console_fieldsMerge extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$output->writeln(""); $output->writeln("");
try { try {

View File

@@ -41,10 +41,8 @@ class module_console_fieldsRename extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$new_name = $input->getArgument('name'); $new_name = $input->getArgument('name');
try { try {

View File

@@ -61,10 +61,8 @@ class module_console_fileEnsureDevSetting extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification(); $specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();
$environnement = $input->getArgument('conf'); $environnement = $input->getArgument('conf');

View File

@@ -61,10 +61,8 @@ class module_console_fileEnsureProductionSetting extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification(); $specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();
$environnement = $input->getArgument('conf'); $environnement = $input->getArgument('conf');

View File

@@ -39,13 +39,11 @@ class module_console_schedulerStart extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$logger = new Logger('Task logger'); $logger = new Logger('Task logger');
$streamHandler = new Handler\StreamHandler(fopen('php://stdout', 'a'), $input->getOption('verbose') ? Logger::DEBUG : Logger::WARNING); $streamHandler = new Handler\StreamHandler('php://stdout', $input->getOption('verbose') ? Logger::DEBUG : Logger::WARNING);
$logger->pushHandler($streamHandler); $logger->pushHandler($streamHandler);
$logfile = __DIR__ . '/../../../../logs/scheduler.log'; $logfile = __DIR__ . '/../../../../logs/scheduler.log';

View File

@@ -51,10 +51,10 @@ class module_console_schedulerState extends Command
public function requireSetup() public function requireSetup()
{ {
return true; return false;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
try { try {
$this->checkSetup(); $this->checkSetup();

View File

@@ -36,10 +36,8 @@ class module_console_schedulerStop extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
try { try {
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$task_manager = new task_manager($appbox); $task_manager = new task_manager($appbox);

View File

@@ -36,10 +36,8 @@ class module_console_sphinxGenerateSuggestion extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
define('FREQ_THRESHOLD', 10); define('FREQ_THRESHOLD', 10);
define('SUGGEST_DEBUG', 0); define('SUGGEST_DEBUG', 0);

View File

@@ -43,10 +43,8 @@ class module_console_systemBackupDB extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$output->write('Phraseanet is going to be backup...', true); $output->write('Phraseanet is going to be backup...', true);
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());

View File

@@ -37,10 +37,8 @@ class module_console_systemClearCache extends Command
return false; return false;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$finder = new Finder(); $finder = new Finder();
$finder $finder

View File

@@ -37,10 +37,8 @@ class module_console_systemConfigCheck extends Command
return false; return false;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
if ( ! function_exists('_')) { if ( ! function_exists('_')) {
$output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>'); $output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
$output->writeln('Canceled'); $output->writeln('Canceled');

View File

@@ -76,10 +76,8 @@ class module_console_systemExport extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$core = \bootstrap::getCore(); $core = \bootstrap::getCore();
$docPerDir = max(1, (int) $input->getOption('docperdir')); $docPerDir = max(1, (int) $input->getOption('docperdir'));

View File

@@ -42,10 +42,8 @@ class module_console_systemMailCheck extends Command
return true; return true;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());
$output->writeln("Processing..."); $output->writeln("Processing...");

View File

@@ -36,10 +36,8 @@ class module_console_systemTemplateGenerator extends Command
return false; return false;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$this->checkSetup();
$tplDirs = array( $tplDirs = array(
realpath(__DIR__ . '/../../../../templates/web/'), realpath(__DIR__ . '/../../../../templates/web/'),
realpath(__DIR__ . '/../../../../templates/mobile/') realpath(__DIR__ . '/../../../../templates/mobile/')

View File

@@ -37,7 +37,7 @@ class module_console_systemUpgrade extends Command
return false; return false;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
$old_connexion_file = __DIR__ . '/../../../../config/connexion.inc'; $old_connexion_file = __DIR__ . '/../../../../config/connexion.inc';
$old_config_file = __DIR__ . '/../../../../config/config.inc'; $old_config_file = __DIR__ . '/../../../../config/config.inc';

View File

@@ -59,10 +59,10 @@ class module_console_taskState extends Command
public function requireSetup() public function requireSetup()
{ {
return true; return false;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
try { try {
$this->checkSetup(); $this->checkSetup();

View File

@@ -34,10 +34,10 @@ class module_console_tasklist extends Command
public function requireSetup() public function requireSetup()
{ {
return true; return false;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
try { try {
$this->checkSetup(); $this->checkSetup();

View File

@@ -65,10 +65,10 @@ class module_console_taskrun extends Command
public function requireSetup() public function requireSetup()
{ {
return true; return false;
} }
public function execute(InputInterface $input, OutputInterface $output) protected function doExecute(InputInterface $input, OutputInterface $output)
{ {
try { try {
$this->checkSetup(); $this->checkSetup();