mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 11:33:17 +00:00
Refactor Commands
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
@@ -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;
|
||||
|
@@ -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();
|
||||
|
@@ -109,7 +109,7 @@ EOF
|
||||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
public function execute(InputInterface $input, OutputInterface $output)
|
||||
protected function doExecute(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->generateUpgradesFromOption($input);
|
||||
|
||||
|
@@ -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;
|
||||
|
@@ -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;
|
||||
|
@@ -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("<error>Missing Extension php-phrasea.</error>");
|
||||
|
||||
|
@@ -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) {
|
||||
|
@@ -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) {
|
||||
|
@@ -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 {
|
||||
|
@@ -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 {
|
||||
|
@@ -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');
|
||||
|
@@ -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');
|
||||
|
@@ -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';
|
||||
|
@@ -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();
|
||||
|
@@ -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);
|
||||
|
@@ -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);
|
||||
|
||||
|
@@ -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());
|
||||
|
@@ -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
|
||||
|
@@ -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('<error>YOU MUST ENABLE GETTEXT SUPPORT TO USE PHRASEANET</error>');
|
||||
$output->writeln('Canceled');
|
||||
|
@@ -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'));
|
||||
|
@@ -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...");
|
||||
|
@@ -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/')
|
||||
|
@@ -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';
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
@@ -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();
|
||||
|
Reference in New Issue
Block a user