refactor command

This commit is contained in:
Nicolas Le Goff
2012-06-01 11:13:12 +02:00
parent 67fe8fd9e4
commit 49900878c8
24 changed files with 110 additions and 84 deletions

View File

@@ -9,33 +9,36 @@
* file that was distributed with this source code.
*/
namespace Alchemy\Phrasea\Command;
use Symfony\Component\Console\Command\Command as SymfoCommand;
use Symfony\Component\Console\Output\OutputInterface;
/**
* Abstract command which represents a Phraseanet base command
*
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Output\OutputInterface;
abstract class module_console_PhraseanetCommand extends Command
abstract class Command extends SymfoCommand
{
/**
* Tell whether the command requires Phraseanet to be set up to run
* @return boolean
* Tell whether the command requires Phraseanet to be set-up or not
*
* @return Boolean
*/
abstract public function needPhraseaInstalled();
abstract public function requireSetup();
/**
* Check if Phraseanet is set up and if the current commands requires
* Phraseanet to be installed
* Check if Phraseanet is set-up and if the current command requires
* Phraseanet to be set-up
*
* @param \Symfony\Component\Console\Output\OutputInterface $output
* @return boolean
* @return Boolean
*/
public function checkPhraseaInstall(OutputInterface $output)
public function checkSetup(OutputInterface $output)
{
if ($this->needPhraseaInstalled()) {
if ($this->requireSetup()) {
$core = \bootstrap::getCore();
if ( ! $core->getConfiguration()->isInstalled()) {
@@ -47,5 +50,4 @@ abstract class module_console_PhraseanetCommand extends Command
return true;
}
}

View File

@@ -17,8 +17,9 @@
*/
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
class module_console_aboutAuthors extends module_console_PhraseanetCommand
class module_console_aboutAuthors extends Command
{
public function __construct($name = null)
@@ -32,7 +33,7 @@ class module_console_aboutAuthors extends module_console_PhraseanetCommand
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}
@@ -41,7 +42,7 @@ class module_console_aboutAuthors extends module_console_PhraseanetCommand
return 0;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return false;
}

View File

@@ -17,8 +17,9 @@
*/
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
class module_console_aboutLicense extends module_console_PhraseanetCommand
class module_console_aboutLicense extends Command
{
public function __construct($name = null)
@@ -32,7 +33,7 @@ class module_console_aboutLicense extends module_console_PhraseanetCommand
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}
@@ -41,7 +42,7 @@ class module_console_aboutLicense extends module_console_PhraseanetCommand
return 0;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return false;
}

View File

@@ -18,8 +18,9 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
class module_console_checkExtension extends module_console_PhraseanetCommand
class module_console_checkExtension extends Command
{
public function __construct($name = null)
@@ -35,14 +36,14 @@ class module_console_checkExtension extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -18,8 +18,9 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
class module_console_fieldsDelete extends module_console_PhraseanetCommand
class module_console_fieldsDelete extends Command
{
public function __construct($name = null)
@@ -34,14 +35,14 @@ class module_console_fieldsDelete extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -17,8 +17,9 @@
*/
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
class module_console_fieldsList extends module_console_PhraseanetCommand
class module_console_fieldsList extends Command
{
public function __construct($name = null)
@@ -30,14 +31,14 @@ class module_console_fieldsList extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -19,8 +19,9 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
class module_console_fieldsMerge extends module_console_PhraseanetCommand
class module_console_fieldsMerge extends Command
{
public function __construct($name = null)
@@ -44,14 +45,14 @@ class module_console_fieldsMerge extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -18,8 +18,9 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
class module_console_fieldsRename extends module_console_PhraseanetCommand
class module_console_fieldsRename extends Command
{
public function __construct($name = null)
@@ -35,14 +36,14 @@ class module_console_fieldsRename extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -21,7 +22,7 @@ use Alchemy\Phrasea\Core;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class module_console_fileEnsureDevSetting extends module_console_PhraseanetCommand
class module_console_fileEnsureDevSetting extends Command
{
const ALERT = 1;
const ERROR = 0;
@@ -54,14 +55,14 @@ class module_console_fileEnsureDevSetting extends module_console_PhraseanetComma
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -13,6 +13,7 @@ use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Core;
/**
@@ -21,7 +22,7 @@ use Alchemy\Phrasea\Core;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class module_console_fileEnsureProductionSetting extends module_console_PhraseanetCommand
class module_console_fileEnsureProductionSetting extends Command
{
const ALERT = 1;
const ERROR = 0;
@@ -54,14 +55,14 @@ class module_console_fileEnsureProductionSetting extends module_console_Phrasean
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -15,12 +15,14 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Monolog\Handler;
use Monolog\Logger;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_schedulerStart extends module_console_PhraseanetCommand
class module_console_schedulerStart extends Command
{
public function __construct($name = null)
@@ -32,14 +34,14 @@ class module_console_schedulerStart extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -15,11 +15,12 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_schedulerState extends module_console_PhraseanetCommand
class module_console_schedulerState extends Command
{
const EXITCODE_SETUP_ERROR = 1;
const EXITCODE_STATE_UNKNOWN = 21;
@@ -48,14 +49,14 @@ class module_console_schedulerState extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return self::EXITCODE_SETUP_ERROR;
}

View File

@@ -15,10 +15,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_schedulerStop extends module_console_PhraseanetCommand
class module_console_schedulerStop extends Command
{
public function __construct($name = null)
@@ -30,14 +31,14 @@ class module_console_schedulerStop extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -15,10 +15,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_sphinxGenerateSuggestion extends module_console_PhraseanetCommand
class module_console_sphinxGenerateSuggestion extends Command
{
public function __construct($name = null)
@@ -31,14 +32,14 @@ class module_console_sphinxGenerateSuggestion extends module_console_PhraseanetC
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -15,10 +15,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemBackupDB extends module_console_PhraseanetCommand
class module_console_systemBackupDB extends Command
{
public function __construct($name = null)
@@ -37,14 +38,14 @@ class module_console_systemBackupDB extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -14,12 +14,13 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemClearCache extends module_console_PhraseanetCommand
class module_console_systemClearCache extends Command
{
public function __construct($name = null)
@@ -31,14 +32,14 @@ class module_console_systemClearCache extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return false;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -16,10 +16,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemConfigCheck extends module_console_PhraseanetCommand
class module_console_systemConfigCheck extends Command
{
public function __construct($name = null)
@@ -31,14 +32,14 @@ class module_console_systemConfigCheck extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return false;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -15,11 +15,12 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemExport extends module_console_PhraseanetCommand
class module_console_systemExport extends Command
{
public function __construct($name = null)
@@ -70,14 +71,14 @@ class module_console_systemExport extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -16,10 +16,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemMailCheck extends module_console_PhraseanetCommand
class module_console_systemMailCheck extends Command
{
public function __construct($name = null)
@@ -36,14 +37,14 @@ class module_console_systemMailCheck extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -15,10 +15,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemTemplateGenerator extends module_console_PhraseanetCommand
class module_console_systemTemplateGenerator extends Command
{
public function __construct($name = null)
@@ -30,14 +31,14 @@ class module_console_systemTemplateGenerator extends module_console_PhraseanetCo
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return false;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -16,10 +16,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemUpgrade extends module_console_PhraseanetCommand
class module_console_systemUpgrade extends Command
{
public function __construct($name = null)
@@ -31,14 +32,14 @@ class module_console_systemUpgrade extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return false;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return 1;
}

View File

@@ -15,12 +15,13 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_taskState extends module_console_PhraseanetCommand
class module_console_taskState extends Command
{
const EXITCODE_SETUP_ERROR = 1;
const EXITCODE_BAD_ARGUMENT = 2;
@@ -56,14 +57,14 @@ class module_console_taskState extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return self::EXITCODE_SETUP_ERROR;
}

View File

@@ -16,10 +16,11 @@
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_tasklist extends module_console_PhraseanetCommand
class module_console_tasklist extends Command
{
public function __construct($name = null)
@@ -31,14 +32,14 @@ class module_console_tasklist extends module_console_PhraseanetCommand
return $this;
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return self::EXITCODE_SETUP_ERROR;
}

View File

@@ -9,6 +9,7 @@
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Command\Command;
use Monolog\Handler;
use Monolog\Logger;
use Symfony\Component\Console\Input\InputArgument;
@@ -22,7 +23,7 @@ use Symfony\Component\Console\Output\OutputInterface;
* @license http://opensource.org/licenses/gpl-3.0 GPLv3
* @link www.phraseanet.com
*/
class module_console_taskrun extends module_console_PhraseanetCommand
class module_console_taskrun extends Command
{
private $task;
private $shedulerPID;
@@ -64,14 +65,14 @@ class module_console_taskrun extends module_console_PhraseanetCommand
}
}
public function needPhraseaInstalled()
public function requireSetup()
{
return true;
}
public function execute(InputInterface $input, OutputInterface $output)
{
if ( ! $this->checkPhraseaInstall($output)) {
if ( ! $this->checkSetup($output)) {
return self::EXITCODE_SETUP_ERROR;
}