refactor commands

This commit is contained in:
Nicolas Le Goff
2012-06-01 11:39:58 +02:00
parent be1f81d39b
commit 20fc38bb5d
24 changed files with 34 additions and 81 deletions

View File

@@ -33,21 +33,17 @@ abstract class Command extends SymfoCommand
* Check if Phraseanet is set-up and if the current command requires * Check if Phraseanet is set-up and if the current command requires
* Phraseanet to be set-up * Phraseanet to be set-up
* *
* @param \Symfony\Component\Console\Output\OutputInterface $output * @throws \RuntimeException
* @return Boolean * @return Boolean
*/ */
public function checkSetup(OutputInterface $output) public function checkSetup()
{ {
if ($this->requireSetup()) { if ($this->requireSetup()) {
$core = \bootstrap::getCore(); $core = \bootstrap::getCore();
if ( ! $core->getConfiguration()->isInstalled()) { if ( ! $core->getConfiguration()->isInstalled()) {
$output->writeln("<error>Phraseanet is not set up</error>"); throw new \RuntimeException('Phraseanet must be set-up');
return false;
} }
} }
return true;
} }
} }

View File

@@ -33,9 +33,7 @@ class module_console_aboutAuthors extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS')); $output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS'));

View File

@@ -33,9 +33,7 @@ class module_console_aboutLicense extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE')); $output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE'));

View File

@@ -43,9 +43,7 @@ class module_console_checkExtension extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
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

@@ -42,9 +42,7 @@ class module_console_fieldsDelete extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
try { try {
$databox = \databox::get_instance((int) $input->getArgument('sbas_id')); $databox = \databox::get_instance((int) $input->getArgument('sbas_id'));

View File

@@ -38,9 +38,7 @@ class module_console_fieldsList extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$appbox = \appbox::get_instance(\bootstrap::getCore()); $appbox = \appbox::get_instance(\bootstrap::getCore());

View File

@@ -52,9 +52,7 @@ class module_console_fieldsMerge extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$output->writeln(""); $output->writeln("");

View File

@@ -43,9 +43,7 @@ class module_console_fieldsRename extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$new_name = $input->getArgument('name'); $new_name = $input->getArgument('name');

View File

@@ -62,9 +62,7 @@ class module_console_fileEnsureDevSetting extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification(); $specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();

View File

@@ -62,9 +62,7 @@ class module_console_fileEnsureProductionSetting extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification(); $specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();

View File

@@ -41,9 +41,7 @@ class module_console_schedulerStart extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$logger = new Logger('Task logger'); $logger = new Logger('Task logger');

View File

@@ -56,8 +56,9 @@ class module_console_schedulerState extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { try{
$this->checkSetup();
} catch (\RuntimeException $e){
return self::EXITCODE_SETUP_ERROR; return self::EXITCODE_SETUP_ERROR;
} }

View File

@@ -38,10 +38,7 @@ class module_console_schedulerStop extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
require_once __DIR__ . '/../../../../lib/bootstrap.php'; require_once __DIR__ . '/../../../../lib/bootstrap.php';

View File

@@ -39,10 +39,7 @@ class module_console_sphinxGenerateSuggestion extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
define('FREQ_THRESHOLD', 10); define('FREQ_THRESHOLD', 10);
define('SUGGEST_DEBUG', 0); define('SUGGEST_DEBUG', 0);

View File

@@ -45,10 +45,7 @@ class module_console_systemBackupDB extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$output->write('Phraseanet is going to be backup...', true); $output->write('Phraseanet is going to be backup...', true);

View File

@@ -39,10 +39,7 @@ class module_console_systemClearCache extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$finder = new Finder(); $finder = new Finder();

View File

@@ -39,10 +39,7 @@ class module_console_systemConfigCheck extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
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>');

View File

@@ -78,10 +78,7 @@ class module_console_systemExport extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$core = \bootstrap::getCore(); $core = \bootstrap::getCore();

View File

@@ -44,10 +44,7 @@ class module_console_systemMailCheck extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$appbox = appbox::get_instance(\bootstrap::getCore()); $appbox = appbox::get_instance(\bootstrap::getCore());

View File

@@ -38,10 +38,7 @@ class module_console_systemTemplateGenerator extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$tplDirs = array( $tplDirs = array(
realpath(__DIR__ . '/../../../../templates/web/'), realpath(__DIR__ . '/../../../../templates/web/'),

View File

@@ -39,10 +39,7 @@ class module_console_systemUpgrade extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { $this->checkSetup();
return 1;
}
$Core = \bootstrap::getCore(); $Core = \bootstrap::getCore();

View File

@@ -64,8 +64,9 @@ class module_console_taskState extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { try{
$this->checkSetup();
} catch (\RuntimeException $e){
return self::EXITCODE_SETUP_ERROR; return self::EXITCODE_SETUP_ERROR;
} }

View File

@@ -39,8 +39,9 @@ class module_console_tasklist extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { try{
$this->checkSetup();
} catch (\RuntimeException $e){
return self::EXITCODE_SETUP_ERROR; return self::EXITCODE_SETUP_ERROR;
} }

View File

@@ -72,8 +72,9 @@ class module_console_taskrun extends Command
public function execute(InputInterface $input, OutputInterface $output) public function execute(InputInterface $input, OutputInterface $output)
{ {
if ( ! $this->checkSetup($output)) { try{
$this->checkSetup();
} catch (\RuntimeException $e){
return self::EXITCODE_SETUP_ERROR; return self::EXITCODE_SETUP_ERROR;
} }