diff --git a/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php b/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php index ca34f5a96d..b9002f5fca 100644 --- a/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php +++ b/lib/Alchemy/Phrasea/Command/BuildMissingSubdefs.php @@ -47,16 +47,14 @@ class BuildMissingSubdefs extends Command /** * {@inheritdoc} */ - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $core = \bootstrap::getCore(); $this->appbox = \appbox::get_instance($core); if ($input->getOption('verbose')) { $logger = $this->getLogger(); - $handler = new Handler\StreamHandler(fopen('php://stdout', 'a')); + $handler = new Handler\StreamHandler('php://stdout'); $logger->pushHandler($handler); $this->setLogger($logger); } diff --git a/lib/Alchemy/Phrasea/Command/Command.php b/lib/Alchemy/Phrasea/Command/Command.php index 6c18d290b8..54c324775b 100644 --- a/lib/Alchemy/Phrasea/Command/Command.php +++ b/lib/Alchemy/Phrasea/Command/Command.php @@ -12,7 +12,10 @@ namespace Alchemy\Phrasea\Command; use Monolog\Logger; +use Monolog\Handler\StreamHandler; 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 @@ -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 * @@ -92,13 +114,11 @@ abstract class Command extends SymfoCommand $duration = ceil($seconds) . ' seconds'; if ($duration > 60) { - $duration = round($duration / 60 , 1) . ' minutes'; - } - elseif ($duration > 3600) { - $duration = round($duration / (60 * 60) , 1) . ' hours'; - } - elseif ($duration > (24 * 60 * 60)) { - $duration = round($duration / (24 * 60 * 60) , 1) . ' days'; + $duration = round($duration / 60, 1) . ' minutes'; + } elseif ($duration > 3600) { + $duration = round($duration / (60 * 60), 1) . ' hours'; + } elseif ($duration > (24 * 60 * 60)) { + $duration = round($duration / (24 * 60 * 60), 1) . ' days'; } return $duration; diff --git a/lib/Alchemy/Phrasea/Command/RescanTechnicalDatas.php b/lib/Alchemy/Phrasea/Command/RescanTechnicalDatas.php index 18ff1d8bb7..9943e34faa 100644 --- a/lib/Alchemy/Phrasea/Command/RescanTechnicalDatas.php +++ b/lib/Alchemy/Phrasea/Command/RescanTechnicalDatas.php @@ -55,10 +55,8 @@ class RescanTechnicalDatas extends Command /** * {@inheritdoc} */ - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $this->appbox = \appbox::get_instance(\bootstrap::getCore()); $quantity = $this->computeQuantity(); diff --git a/lib/Alchemy/Phrasea/Command/UpgradeDBDatas.php b/lib/Alchemy/Phrasea/Command/UpgradeDBDatas.php index b34474efe6..968831cc29 100644 --- a/lib/Alchemy/Phrasea/Command/UpgradeDBDatas.php +++ b/lib/Alchemy/Phrasea/Command/UpgradeDBDatas.php @@ -109,7 +109,7 @@ EOF /** * {@inheritdoc} */ - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { $this->generateUpgradesFromOption($input); diff --git a/lib/classes/module/console/aboutAuthors.class.php b/lib/classes/module/console/aboutAuthors.class.php index 00fb2f38d1..6a93e9fbb4 100644 --- a/lib/classes/module/console/aboutAuthors.class.php +++ b/lib/classes/module/console/aboutAuthors.class.php @@ -31,10 +31,8 @@ class module_console_aboutAuthors extends Command 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')); return 0; diff --git a/lib/classes/module/console/aboutLicense.class.php b/lib/classes/module/console/aboutLicense.class.php index 9cf4e94114..eed159d345 100644 --- a/lib/classes/module/console/aboutLicense.class.php +++ b/lib/classes/module/console/aboutLicense.class.php @@ -31,10 +31,8 @@ class module_console_aboutLicense extends Command 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')); return 0; diff --git a/lib/classes/module/console/checkExtension.class.php b/lib/classes/module/console/checkExtension.class.php index cc38fa092e..6f7f743efd 100644 --- a/lib/classes/module/console/checkExtension.class.php +++ b/lib/classes/module/console/checkExtension.class.php @@ -41,10 +41,8 @@ class module_console_checkExtension extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - if ( ! extension_loaded('phrasea2')) { $output->writeln("Missing Extension php-phrasea."); diff --git a/lib/classes/module/console/fieldsDelete.class.php b/lib/classes/module/console/fieldsDelete.class.php index 785da3efc0..8cbdd1a56f 100644 --- a/lib/classes/module/console/fieldsDelete.class.php +++ b/lib/classes/module/console/fieldsDelete.class.php @@ -40,10 +40,8 @@ class module_console_fieldsDelete extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - try { $databox = \databox::get_instance((int) $input->getArgument('sbas_id')); } catch (\Exception $e) { diff --git a/lib/classes/module/console/fieldsList.class.php b/lib/classes/module/console/fieldsList.class.php index 26d8128f62..db49c695dc 100644 --- a/lib/classes/module/console/fieldsList.class.php +++ b/lib/classes/module/console/fieldsList.class.php @@ -36,10 +36,8 @@ class module_console_fieldsList extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $appbox = \appbox::get_instance(\bootstrap::getCore()); foreach ($appbox->get_databoxes() as $databox) { diff --git a/lib/classes/module/console/fieldsMerge.class.php b/lib/classes/module/console/fieldsMerge.class.php index 83330fec05..f42121c98a 100644 --- a/lib/classes/module/console/fieldsMerge.class.php +++ b/lib/classes/module/console/fieldsMerge.class.php @@ -50,10 +50,8 @@ class module_console_fieldsMerge extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $output->writeln(""); try { diff --git a/lib/classes/module/console/fieldsRename.class.php b/lib/classes/module/console/fieldsRename.class.php index 9077f44de7..aeacab007f 100644 --- a/lib/classes/module/console/fieldsRename.class.php +++ b/lib/classes/module/console/fieldsRename.class.php @@ -41,10 +41,8 @@ class module_console_fieldsRename extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $new_name = $input->getArgument('name'); try { diff --git a/lib/classes/module/console/fileEnsureDevSetting.class.php b/lib/classes/module/console/fileEnsureDevSetting.class.php index c7febef6b4..403eb99b82 100644 --- a/lib/classes/module/console/fileEnsureDevSetting.class.php +++ b/lib/classes/module/console/fileEnsureDevSetting.class.php @@ -61,10 +61,8 @@ class module_console_fileEnsureDevSetting extends Command 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(); $environnement = $input->getArgument('conf'); diff --git a/lib/classes/module/console/fileEnsureProductionSetting.class.php b/lib/classes/module/console/fileEnsureProductionSetting.class.php index 8813affa78..5bae4f943f 100644 --- a/lib/classes/module/console/fileEnsureProductionSetting.class.php +++ b/lib/classes/module/console/fileEnsureProductionSetting.class.php @@ -61,10 +61,8 @@ class module_console_fileEnsureProductionSetting extends Command 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(); $environnement = $input->getArgument('conf'); diff --git a/lib/classes/module/console/schedulerStart.class.php b/lib/classes/module/console/schedulerStart.class.php index 03b6e45c8f..8ab78efb1b 100644 --- a/lib/classes/module/console/schedulerStart.class.php +++ b/lib/classes/module/console/schedulerStart.class.php @@ -39,13 +39,11 @@ class module_console_schedulerStart extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $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); $logfile = __DIR__ . '/../../../../logs/scheduler.log'; diff --git a/lib/classes/module/console/schedulerState.class.php b/lib/classes/module/console/schedulerState.class.php index 530e78692c..ca98f318ed 100644 --- a/lib/classes/module/console/schedulerState.class.php +++ b/lib/classes/module/console/schedulerState.class.php @@ -51,10 +51,10 @@ class module_console_schedulerState extends Command public function requireSetup() { - return true; + return false; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { try { $this->checkSetup(); diff --git a/lib/classes/module/console/schedulerStop.class.php b/lib/classes/module/console/schedulerStop.class.php index 0437324c3c..1fa8266b8b 100644 --- a/lib/classes/module/console/schedulerStop.class.php +++ b/lib/classes/module/console/schedulerStop.class.php @@ -36,10 +36,8 @@ class module_console_schedulerStop extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - try { $appbox = appbox::get_instance(\bootstrap::getCore()); $task_manager = new task_manager($appbox); diff --git a/lib/classes/module/console/sphinxGenerateSuggestion.class.php b/lib/classes/module/console/sphinxGenerateSuggestion.class.php index f5fcf733e5..725b2ecb51 100644 --- a/lib/classes/module/console/sphinxGenerateSuggestion.class.php +++ b/lib/classes/module/console/sphinxGenerateSuggestion.class.php @@ -36,10 +36,8 @@ class module_console_sphinxGenerateSuggestion extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - define('FREQ_THRESHOLD', 10); define('SUGGEST_DEBUG', 0); diff --git a/lib/classes/module/console/systemBackupDB.class.php b/lib/classes/module/console/systemBackupDB.class.php index 9042e75fa3..2f615ae1f5 100644 --- a/lib/classes/module/console/systemBackupDB.class.php +++ b/lib/classes/module/console/systemBackupDB.class.php @@ -43,10 +43,8 @@ class module_console_systemBackupDB extends Command 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); $appbox = appbox::get_instance(\bootstrap::getCore()); diff --git a/lib/classes/module/console/systemClearCache.class.php b/lib/classes/module/console/systemClearCache.class.php index f5c4e2a4e8..9f03ade0ff 100644 --- a/lib/classes/module/console/systemClearCache.class.php +++ b/lib/classes/module/console/systemClearCache.class.php @@ -37,10 +37,8 @@ class module_console_systemClearCache extends Command return false; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $finder = new Finder(); $finder diff --git a/lib/classes/module/console/systemConfigCheck.class.php b/lib/classes/module/console/systemConfigCheck.class.php index 18203b8347..25881142b7 100644 --- a/lib/classes/module/console/systemConfigCheck.class.php +++ b/lib/classes/module/console/systemConfigCheck.class.php @@ -37,10 +37,8 @@ class module_console_systemConfigCheck extends Command return false; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - if ( ! function_exists('_')) { $output->writeln('YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET'); $output->writeln('Canceled'); diff --git a/lib/classes/module/console/systemExport.class.php b/lib/classes/module/console/systemExport.class.php index d5045ab9e3..e0268724c6 100644 --- a/lib/classes/module/console/systemExport.class.php +++ b/lib/classes/module/console/systemExport.class.php @@ -76,10 +76,8 @@ class module_console_systemExport extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $core = \bootstrap::getCore(); $docPerDir = max(1, (int) $input->getOption('docperdir')); diff --git a/lib/classes/module/console/systemMailCheck.class.php b/lib/classes/module/console/systemMailCheck.class.php index e0ac4e71c9..514849c616 100644 --- a/lib/classes/module/console/systemMailCheck.class.php +++ b/lib/classes/module/console/systemMailCheck.class.php @@ -42,10 +42,8 @@ class module_console_systemMailCheck extends Command return true; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $appbox = appbox::get_instance(\bootstrap::getCore()); $output->writeln("Processing..."); diff --git a/lib/classes/module/console/systemTemplateGenerator.class.php b/lib/classes/module/console/systemTemplateGenerator.class.php index ca43a1f982..ef28bda2b2 100644 --- a/lib/classes/module/console/systemTemplateGenerator.class.php +++ b/lib/classes/module/console/systemTemplateGenerator.class.php @@ -36,10 +36,8 @@ class module_console_systemTemplateGenerator extends Command return false; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { - $this->checkSetup(); - $tplDirs = array( realpath(__DIR__ . '/../../../../templates/web/'), realpath(__DIR__ . '/../../../../templates/mobile/') diff --git a/lib/classes/module/console/systemUpgrade.class.php b/lib/classes/module/console/systemUpgrade.class.php index 81ff69ee04..730b214d42 100644 --- a/lib/classes/module/console/systemUpgrade.class.php +++ b/lib/classes/module/console/systemUpgrade.class.php @@ -37,7 +37,7 @@ class module_console_systemUpgrade extends Command return false; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { $old_connexion_file = __DIR__ . '/../../../../config/connexion.inc'; $old_config_file = __DIR__ . '/../../../../config/config.inc'; diff --git a/lib/classes/module/console/taskState.class.php b/lib/classes/module/console/taskState.class.php index d31d1eb221..2d954cc25a 100644 --- a/lib/classes/module/console/taskState.class.php +++ b/lib/classes/module/console/taskState.class.php @@ -59,10 +59,10 @@ class module_console_taskState extends Command public function requireSetup() { - return true; + return false; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { try { $this->checkSetup(); diff --git a/lib/classes/module/console/tasklist.class.php b/lib/classes/module/console/tasklist.class.php index 4cd66d8ffe..eec1b67ec8 100644 --- a/lib/classes/module/console/tasklist.class.php +++ b/lib/classes/module/console/tasklist.class.php @@ -34,10 +34,10 @@ class module_console_tasklist extends Command public function requireSetup() { - return true; + return false; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { try { $this->checkSetup(); diff --git a/lib/classes/module/console/taskrun.class.php b/lib/classes/module/console/taskrun.class.php index 2495974e36..5289b7313d 100644 --- a/lib/classes/module/console/taskrun.class.php +++ b/lib/classes/module/console/taskrun.class.php @@ -65,10 +65,10 @@ class module_console_taskrun extends Command public function requireSetup() { - return true; + return false; } - public function execute(InputInterface $input, OutputInterface $output) + protected function doExecute(InputInterface $input, OutputInterface $output) { try { $this->checkSetup();