mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-13 13:03:20 +00:00
add return value for console commands
This commit is contained in:
@@ -39,7 +39,7 @@ class module_console_aboutAuthors extends Command
|
||||
{
|
||||
$output->writeln(file_get_contents(__DIR__ . '/../../../../AUTHORS'));
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -39,7 +39,7 @@ class module_console_aboutLicense extends Command
|
||||
{
|
||||
$output->writeln(file_get_contents(__DIR__ . '/../../../../LICENSE'));
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -66,17 +66,17 @@ class module_console_fileConfigCheck extends Command
|
||||
$output->writeln("");
|
||||
$this->env = $env;
|
||||
|
||||
$this->initTests();
|
||||
$this->initTests($output);
|
||||
|
||||
$this->prepareTests($output);
|
||||
|
||||
$this->runTests($output);
|
||||
}
|
||||
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function initTests()
|
||||
private function initTests(OutputInterface $output)
|
||||
{
|
||||
$spec = new Core\Configuration\Application();
|
||||
$parser = new Core\Configuration\Parser\Yaml();
|
||||
@@ -86,7 +86,8 @@ class module_console_fileConfigCheck extends Command
|
||||
|
||||
if (!$this->configuration->isInstalled())
|
||||
{
|
||||
exit(sprintf("\nPhraseanet is not installed\n"));
|
||||
$output->writeln(sprintf("\nPhraseanet is not installed\n"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,12 +110,14 @@ class module_console_fileConfigCheck extends Command
|
||||
$previous->getMessage() : 'Unknown.'
|
||||
)
|
||||
);
|
||||
exit(sprintf("\nConfig check test suite can not continue please correct FATAL error and relaunch.\n"));
|
||||
$output->writeln(sprintf("\nConfig check test suite can not continue please correct FATAL error and relaunch.\n"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
private function runTests(OutputInterface $output)
|
||||
{
|
||||
$nbErrors = 0;
|
||||
foreach ($this->testSuite as $test)
|
||||
{
|
||||
try
|
||||
@@ -123,6 +126,7 @@ class module_console_fileConfigCheck extends Command
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
$nbErrors++;
|
||||
$previous = $e->getPrevious();
|
||||
|
||||
$output->writeln(sprintf(
|
||||
@@ -134,6 +138,7 @@ class module_console_fileConfigCheck extends Command
|
||||
);
|
||||
}
|
||||
}
|
||||
return (int) ($nbErrors > 0);
|
||||
}
|
||||
|
||||
private function checkParse(OutputInterface $output)
|
||||
|
@@ -25,7 +25,6 @@ use Alchemy\Phrasea\Core;
|
||||
*/
|
||||
class module_console_fileEnsureProductionSetting extends Command
|
||||
{
|
||||
protected $hasErrors = false;
|
||||
|
||||
const ALERT = 1;
|
||||
const ERROR = 0;
|
||||
@@ -61,16 +60,16 @@ class module_console_fileEnsureProductionSetting extends Command
|
||||
$output->writeln("=============================");
|
||||
$output->writeln("");
|
||||
|
||||
$this->initTests();
|
||||
$this->initTests($output);
|
||||
|
||||
$this->prepareTests($output);
|
||||
|
||||
$this->runTests($output);
|
||||
|
||||
exit(1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private function initTests()
|
||||
private function initTests(OutputInterface $output)
|
||||
{
|
||||
$spec = new Core\Configuration\Application();
|
||||
$parser = new Core\Configuration\Parser\Yaml();
|
||||
@@ -80,7 +79,8 @@ class module_console_fileEnsureProductionSetting extends Command
|
||||
|
||||
if (!$this->configuration->isInstalled())
|
||||
{
|
||||
exit(sprintf("\nPhraseanet is not installed\n"));
|
||||
$output->writeln(sprintf("\nPhraseanet is not installed\n"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -103,7 +103,8 @@ class module_console_fileEnsureProductionSetting extends Command
|
||||
$previous->getMessage() : 'Unknown.'
|
||||
)
|
||||
);
|
||||
exit(sprintf("\nCheck test suite can not continue please correct FATAL error and relaunch.\n"));
|
||||
$output->writeln(sprintf("\nCheck test suite can not continue please correct FATAL error and relaunch.\n"));
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -136,6 +137,8 @@ class module_console_fileEnsureProductionSetting extends Command
|
||||
$output->writeln("<info>Your production settings are setted correctly !</info>");
|
||||
$output->writeln("");
|
||||
}
|
||||
|
||||
return (int) ($nbErrors > 0);
|
||||
}
|
||||
|
||||
private function checkParse(OutputInterface $output)
|
||||
|
@@ -1,4 +1,5 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of Phraseanet
|
||||
*
|
||||
@@ -42,15 +43,22 @@ class module_console_schedulerStart extends Command
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
$scheduler = new task_Scheduler();
|
||||
$scheduler->run($output, true);
|
||||
|
||||
return;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -24,6 +24,7 @@ use Symfony\Component\Console\Command\Command;
|
||||
|
||||
class module_console_schedulerState extends Command
|
||||
{
|
||||
|
||||
public function __construct($name = null)
|
||||
{
|
||||
parent::__construct($name);
|
||||
@@ -37,24 +38,35 @@ class module_console_schedulerState extends Command
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
try
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
|
||||
$state = $task_manager->get_scheduler_state();
|
||||
|
||||
if ($state['schedstatus'] == 'started')
|
||||
{
|
||||
$output->writeln(sprintf(
|
||||
'Scheduler is %s on pid %d'
|
||||
, $state['schedstatus']
|
||||
, $state['schedpid']
|
||||
));
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln(sprintf('Scheduler is %s', $state['schedstatus']));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
catch(\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -33,19 +33,28 @@ class module_console_schedulerStop extends Command
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
try
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
|
||||
$task_manager->set_sched_status(task_manager::STATUS_SCHED_TOSTOP);
|
||||
return 0;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
@@ -45,7 +45,8 @@ class module_console_systemBackupDB extends Command
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Argument must be an Id.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
@@ -54,14 +55,16 @@ class module_console_systemBackupDB extends Command
|
||||
|
||||
$appbox = appbox::get_instance();
|
||||
|
||||
$this->dump_base($appbox, $input, $output);
|
||||
$ok = true;
|
||||
|
||||
$ok = $this->dump_base($appbox, $input, $output) && $ok;
|
||||
|
||||
foreach ($appbox->get_databoxes() as $databox)
|
||||
{
|
||||
$this->dump_base($databox, $input, $output);
|
||||
$ok = $this->dump_base($databox, $input, $output) && $ok;
|
||||
}
|
||||
|
||||
return;
|
||||
return (int) !$ok;
|
||||
}
|
||||
|
||||
protected function dump_base(base $base, InputInterface $input, OutputInterface $output)
|
||||
@@ -91,11 +94,17 @@ class module_console_systemBackupDB extends Command
|
||||
system($command);
|
||||
|
||||
if (file_exists($filename) && filesize($filename) > 0)
|
||||
{
|
||||
$output->writeln('OK');
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln('<error>Failed</error>');
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -46,8 +46,8 @@ class module_console_systemClearCache extends Command
|
||||
->in(array(
|
||||
__DIR__ . '/../../../../tmp/cache_minify/'
|
||||
, __DIR__ . '/../../../../tmp/cache_twig/'
|
||||
))
|
||||
;
|
||||
));
|
||||
|
||||
$count = 1;
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
@@ -63,8 +63,8 @@ class module_console_systemClearCache extends Command
|
||||
, __DIR__ . '/../../../../tmp/cache_twig'
|
||||
))
|
||||
->exclude('.git')
|
||||
->exclude('.svn')
|
||||
;
|
||||
->exclude('.svn');
|
||||
|
||||
foreach ($finder as $file)
|
||||
{
|
||||
$dirs[$file->getPathname()] = $file->getPathname();
|
||||
@@ -93,7 +93,7 @@ class module_console_systemClearCache extends Command
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -42,15 +42,17 @@ class module_console_systemConfigCheck extends Command
|
||||
$output->writeln('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
|
||||
$output->writeln('Canceled');
|
||||
|
||||
return;
|
||||
return 1;
|
||||
}
|
||||
|
||||
$ok = true;
|
||||
|
||||
if (setup::is_installed())
|
||||
{
|
||||
$registry = registry::get_instance();
|
||||
|
||||
$output->writeln(_('*** CHECK BINARY CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_binaries($registry), $output);
|
||||
$ok = $this->processConstraints(setup::check_binaries($registry), $output) && $ok;
|
||||
$output->writeln("");
|
||||
}
|
||||
else
|
||||
@@ -58,51 +60,65 @@ class module_console_systemConfigCheck extends Command
|
||||
$registry = new Setup_Registry();
|
||||
}
|
||||
|
||||
|
||||
|
||||
$output->writeln(_('*** FILESYSTEM CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_writability($registry), $output);
|
||||
$ok = $this->processConstraints(setup::check_writability($registry), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE OPCODE ***'));
|
||||
$this->processConstraints(setup::check_cache_opcode(), $output);
|
||||
$ok = $this->processConstraints(setup::check_cache_opcode(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK CACHE SERVER ***'));
|
||||
$this->processConstraints(setup::check_cache_server(), $output);
|
||||
$ok = $this->processConstraints(setup::check_cache_server(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP CONFIGURATION ***'));
|
||||
$this->processConstraints(setup::check_php_configuration(), $output);
|
||||
$ok = $this->processConstraints(setup::check_php_configuration(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHP EXTENSIONS ***'));
|
||||
$this->processConstraints(setup::check_php_extension(), $output);
|
||||
$ok = $this->processConstraints(setup::check_php_extension(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK PHRASEA ***'));
|
||||
$this->processConstraints(setup::check_phrasea(), $output);
|
||||
$ok = $this->processConstraints(setup::check_phrasea(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
$output->writeln(_('*** CHECK SYSTEM LOCALES ***'));
|
||||
$this->processConstraints(setup::check_system_locales(), $output);
|
||||
$ok = $this->processConstraints(setup::check_system_locales(), $output) && $ok;
|
||||
$output->writeln("");
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
return (int)!$ok;
|
||||
}
|
||||
|
||||
protected function processConstraints(Setup_ConstraintsIterator $constraints, OutputInterface &$output)
|
||||
{
|
||||
$hasError = false;
|
||||
foreach ($constraints as $constraint)
|
||||
{
|
||||
$this->processConstraint($constraint, $output);
|
||||
if (!$hasError && !$this->processConstraint($constraint, $output))
|
||||
{
|
||||
$hasError = true;
|
||||
}
|
||||
}
|
||||
return !$hasError;
|
||||
}
|
||||
|
||||
protected function processConstraint(Setup_Constraint $constraint, OutputInterface &$output)
|
||||
{
|
||||
$ok = true;
|
||||
if ($constraint->is_ok())
|
||||
{
|
||||
$output->writeln("\t\t<info>" . $constraint->get_message() . '</info>');
|
||||
}
|
||||
elseif ($constraint->is_blocker())
|
||||
{
|
||||
$output->writeln("\t!!!\t<error>" . $constraint->get_message() . '</error>');
|
||||
$ok = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$output->writeln("\t/!\\\t<comment>" . $constraint->get_message() . '</comment>');
|
||||
|
||||
return;
|
||||
}
|
||||
return $ok;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -65,7 +65,7 @@ class module_console_systemMailCheck extends Command
|
||||
|
||||
$output->write('Finished !', true);
|
||||
|
||||
return;
|
||||
return 0;
|
||||
}
|
||||
|
||||
protected function manage_group($email, $users, $output, $appbox)
|
||||
|
@@ -122,7 +122,7 @@ class module_console_systemTemplateGenerator extends Command
|
||||
|
||||
$output->writeln("");
|
||||
|
||||
return;
|
||||
return $n_error;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -40,7 +40,7 @@ class module_console_systemUpgrade extends Command
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
|
||||
$output->writeln('This version of Phraseanet requires a config/config.inc');
|
||||
$output->writeln('This version of Phraseanet requires a config/config.yml, config/connexion.yml, config/service.yml');
|
||||
$output->writeln('Would you like it to be created based on your settings ?');
|
||||
|
||||
$dialog = $this->getHelperSet()->get('dialog');
|
||||
|
@@ -39,26 +39,34 @@ class module_console_tasklist extends Command
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
|
||||
try
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
$tasks = $task_manager->get_tasks();
|
||||
|
||||
if (count($tasks) === 0)
|
||||
{
|
||||
$output->writeln('No tasks on your install !');
|
||||
}
|
||||
|
||||
foreach ($tasks as $task)
|
||||
{
|
||||
$this->print_task($task, $output);
|
||||
}
|
||||
|
||||
return $this;
|
||||
return 0;
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
protected function print_task(task_abstract $task, OutputInterface &$output)
|
||||
{
|
||||
@@ -67,4 +75,5 @@ class module_console_tasklist extends Command
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -47,7 +47,8 @@ class module_console_taskrun extends Command
|
||||
{
|
||||
if (!setup::is_installed())
|
||||
{
|
||||
throw new RuntimeException('Phraseanet is not set up');
|
||||
$output->writeln('Phraseanet is not set up');
|
||||
return 1;
|
||||
}
|
||||
|
||||
require_once __DIR__ . '/../../../../lib/bootstrap.php';
|
||||
@@ -55,20 +56,32 @@ class module_console_taskrun extends Command
|
||||
$task_id = (int) $input->getArgument('task_id');
|
||||
|
||||
if ($task_id <= 0 || strlen($task_id) !== strlen($input->getArgument('task_id')))
|
||||
throw new \RuntimeException('Argument must be an Id.');
|
||||
{
|
||||
$output->writeln('Argument must be an Id.');
|
||||
return 1;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
$appbox = appbox::get_instance();
|
||||
$task_manager = new task_manager($appbox);
|
||||
$task = $task_manager->get_task($task_id);
|
||||
|
||||
$runner = task_abstract::RUNNER_SCHEDULER;
|
||||
|
||||
if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL)
|
||||
{
|
||||
$runner = task_abstract::RUNNER_MANUAL;
|
||||
}
|
||||
|
||||
$task->run($runner);
|
||||
|
||||
return $this;
|
||||
return 0;
|
||||
}
|
||||
catch (\exception $e)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user