Update console commands

This commit is contained in:
Romain Neutron
2012-09-21 14:53:04 +02:00
parent 0343baf8ba
commit 06b4e6bc6f
13 changed files with 195 additions and 214 deletions

View File

@@ -14,7 +14,8 @@ 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;
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Core\Service\Builder;
/**
* @todo write tests
@@ -63,11 +64,7 @@ class module_console_fileEnsureProductionSetting extends Command
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification();
$environnement = $input->getArgument('conf');
$this->configuration = \Alchemy\Phrasea\Core\Configuration::build($specifications, $environnement);
$this->configuration = $this->container['phraseanet.configuration'];
$this->checkParse($output);
$output->writeln(sprintf("Will Ensure Production Settings on <info>%s</info>", $this->configuration->getEnvironnement()));
@@ -129,13 +126,13 @@ class module_console_fileEnsureProductionSetting extends Command
private function checkParse(OutputInterface $output)
{
if ( ! $this->configuration->getConfigurations()) {
if (!$this->configuration->getConfigurations()) {
throw new \Exception("Unable to load configurations\n");
}
if ( ! $this->configuration->getConnexions()) {
if (!$this->configuration->getConnexions()) {
throw new \Exception("Unable to load connexions\n");
}
if ( ! $this->configuration->getServices()) {
if (!$this->configuration->getServices()) {
throw new \Exception("Unable to load services\n");
}
@@ -151,11 +148,11 @@ class module_console_fileEnsureProductionSetting extends Command
$work_message = '<info>Works !</info>';
} else {
$work_message = '<comment>Cache server recommended</comment>';
$this->alerts ++;
$this->alerts++;
}
} else {
$work_message = '<error>Failed - could not connect !</error>';
$this->errors ++;
$this->errors++;
}
$verification = sprintf("\t--> Verify <info>%s</info> : %s", 'MainCache', $work_message);
@@ -173,11 +170,11 @@ class module_console_fileEnsureProductionSetting extends Command
$work_message = '<info>Works !</info>';
} else {
$work_message = '<comment>Opcode recommended</comment>';
$this->alerts ++;
$this->alerts++;
}
} else {
$work_message = '<error>Failed - could not connect !</error>';
$this->errors ++;
$this->errors++;
}
$verification = sprintf("\t--> Verify <info>%s</info> : %s", 'OpcodeCache', $work_message);
@@ -193,12 +190,13 @@ class module_console_fileEnsureProductionSetting extends Command
$listChecks = false;
try {
$service = Core\Service\Builder::create(\bootstrap::getCore(), $configuration);
echo " at ".__FILE__."\n";
$service = Builder::create($this->container, $configuration);
$work_message = '<info>Works !</info>';
$listChecks = true;
} catch (\Exception $e) {
$work_message = '<error>Failed - could not load Border Manager service !</error>';
$this->errors ++;
$this->errors++;
}
$output->writeln(sprintf("\t--> Verify Border Manager<info>%s</info> : %s", $serviceName, $work_message));
@@ -221,7 +219,7 @@ class module_console_fileEnsureProductionSetting extends Command
foreach ($phraseanet->all() as $conf => $value) {
switch ($conf) {
default:
$this->alerts ++;
$this->alerts++;
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
break;
case 'servername':
@@ -232,15 +230,15 @@ class module_console_fileEnsureProductionSetting extends Command
if (empty($url)) {
$message = "<error>should not be empty</error>";
$this->errors ++;
$this->errors++;
} elseif ($url == 'http://sub.domain.tld/') {
$this->alerts ++;
$this->alerts++;
$message = "<comment>may be wrong</comment>";
} elseif ( ! filter_var($url, FILTER_VALIDATE_URL)) {
} elseif (!filter_var($url, FILTER_VALIDATE_URL)) {
$message = "<error>not valid</error>";
$this->errors ++;
$this->errors++;
} elseif ($parseUrl["scheme"] !== "https") {
$this->alerts ++;
$this->alerts++;
$message = "<comment>should be https</comment>";
} else {
$message = "<info>OK</info>";
@@ -255,7 +253,7 @@ class module_console_fileEnsureProductionSetting extends Command
if ($value !== false) {
$message = '<error>Should be false</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, $value, false, $message);
@@ -268,11 +266,11 @@ class module_console_fileEnsureProductionSetting extends Command
$message = '<info>OK</info>';
} else {
$message = '<error>Connection not available</error>';
$this->errors ++;
$this->errors++;
}
} catch (\Exception $e) {
$message = '<error>Unknown connection</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, $value, false, $message);
break;
@@ -281,7 +279,7 @@ class module_console_fileEnsureProductionSetting extends Command
if (count($required) > 0) {
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
$this->errors ++;
$this->errors++;
}
return;
@@ -297,34 +295,34 @@ class module_console_fileEnsureProductionSetting extends Command
$work_message = '<info>Works !</info>';
} else {
$work_message = '<error>Failed - could not connect !</error>';
$this->errors ++;
$this->errors++;
}
} catch (\Exception $e) {
$work_message = '<error>Failed - could not connect !</error>';
$this->errors ++;
$this->errors++;
}
$output->writeln(sprintf("\t--> Verify connection <info>%s</info> : %s", $connexionName, $work_message));
$required = array('driver');
if ( ! $connexion->has('driver')) {
if (!$connexion->has('driver')) {
$output->writeln("\n<error>Connection has no driver</error>");
$this->errors ++;
$this->errors++;
} elseif ($connexion->get('driver') == 'pdo_mysql') {
$required = array('driver', 'dbname', 'charset', 'password', 'user', 'port', 'host');
} elseif ($connexion->get('driver') == 'pdo_sqlite') {
$required = array('driver', 'path', 'charset');
} else {
$output->writeln("\n<error>Your driver is not managed</error>");
$this->errors ++;
$this->errors++;
}
foreach ($connexion->all() as $conf => $value) {
switch ($conf) {
default:
$this->alerts ++;
$this->alerts++;
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
break;
case 'charset':
@@ -332,7 +330,7 @@ class module_console_fileEnsureProductionSetting extends Command
$message = '<info>OK</info>';
if ($value !== 'UTF8') {
$message = '<comment>Not recognized</comment>';
$this->alerts ++;
$this->alerts++;
}
$this->printConf($output, $conf, $value, false, $message);
break;
@@ -347,9 +345,9 @@ class module_console_fileEnsureProductionSetting extends Command
$required = array_diff($required, array($conf));
$message = '<info>OK</info>';
if ( ! is_scalar($value)) {
if (!is_scalar($value)) {
$message = '<error>Should be scalar</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, $value, false, $message);
@@ -358,9 +356,9 @@ class module_console_fileEnsureProductionSetting extends Command
$required = array_diff($required, array($conf));
$message = '<info>OK</info>';
if ( ! ctype_digit($value)) {
if (!ctype_digit($value)) {
$message = '<error>Should be ctype_digit</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, $value, false, $message);
@@ -369,9 +367,9 @@ class module_console_fileEnsureProductionSetting extends Command
$required = array_diff($required, array($conf));
$message = '<info>OK</info>';
if ( ! is_scalar($value)) {
if (!is_scalar($value)) {
$message = '<error>Should be scalar</error>';
$this->errors ++;
$this->errors++;
}
$value = '***********';
@@ -383,7 +381,7 @@ class module_console_fileEnsureProductionSetting extends Command
if ($value !== 'pdo_mysql') {
$message = '<error>MySQL recommended</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, $value, false, $message);
break;
@@ -392,7 +390,7 @@ class module_console_fileEnsureProductionSetting extends Command
if (count($required) > 0) {
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
$this->errors ++;
$this->errors++;
}
return;
@@ -418,23 +416,24 @@ class module_console_fileEnsureProductionSetting extends Command
$configuration = $this->configuration->getService($templateEngineName);
try {
Core\Service\Builder::create(\bootstrap::getCore(), $configuration);
echo " at ".__FILE__."\n";
Builder::create($this->container, $configuration);
$work_message = '<info>Works !</info>';
} catch (\Exception $e) {
$work_message = '<error>Failed - could not load template engine !</error>';
$this->errors ++;
$this->errors++;
}
$output->writeln(sprintf("\t--> Verify Template engine <info>%s</info> : %s", $templateEngineName, $work_message));
if ( ! $configuration->has('type')) {
if (!$configuration->has('type')) {
$output->writeln("\n<error>Configuration has no type</error>");
$this->errors ++;
$this->errors++;
} elseif ($configuration->get('type') == 'TemplateEngine\\Twig') {
$required = array('debug', 'charset', 'strict_variables', 'autoescape', 'optimizer');
} else {
$output->writeln("\n<error>Your type is not managed</error>");
$this->errors ++;
$this->errors++;
}
foreach ($configuration->all() as $conf => $value) {
@@ -444,7 +443,7 @@ class module_console_fileEnsureProductionSetting extends Command
if ($value !== 'TemplateEngine\\Twig') {
$message = '<error>Not recognized</error>';
$this->alerts ++;
$this->alerts++;
}
$this->printConf($output, $conf, $value, false, $message);
@@ -452,15 +451,15 @@ class module_console_fileEnsureProductionSetting extends Command
case 'options':
$message = '<info>OK</info>';
if ( ! is_array($value)) {
if (!is_array($value)) {
$message = '<error>Should be array</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, 'array()', false, $message);
break;
default:
$this->alerts ++;
$this->alerts++;
$this->printConf($output, $conf, 'unknown', false, '<comment>Not recognized</comment>');
break;
}
@@ -475,7 +474,7 @@ class module_console_fileEnsureProductionSetting extends Command
if ($value !== false) {
$message = '<error>Should be false</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, "\t" . $conf, $value, false, $message);
@@ -487,7 +486,7 @@ class module_console_fileEnsureProductionSetting extends Command
if ($value !== true) {
$message = '<error>Should be true</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, "\t" . $conf, $value, false, $message);
@@ -498,13 +497,13 @@ class module_console_fileEnsureProductionSetting extends Command
if ($value !== 'utf-8') {
$message = '<comment>Not recognized</comment>';
$this->alerts ++;
$this->alerts++;
}
$this->printConf($output, "\t" . $conf, $value, false, $message);
break;
default:
$this->alerts ++;
$this->alerts++;
$this->printConf($output, "\t" . $conf, $value, false, '<comment>Not recognized</comment>');
break;
}
@@ -512,7 +511,7 @@ class module_console_fileEnsureProductionSetting extends Command
if (count($required) > 0) {
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
$this->errors ++;
$this->errors++;
}
return;
@@ -524,23 +523,24 @@ class module_console_fileEnsureProductionSetting extends Command
$configuration = $this->configuration->getService($ormName);
try {
$service = Core\Service\Builder::create(\bootstrap::getCore(), $configuration);
echo " at ".__FILE__."\n";
$service = Builder::create($this->container, $configuration);
$work_message = '<info>Works !</info>';
} catch (\Exception $e) {
$work_message = '<error>Failed - could not connect !</error>';
$this->errors ++;
$this->errors++;
}
$output->writeln(sprintf("\t--> Verify ORM engine <info>%s</info> : %s", $ormName, $work_message));
if ( ! $configuration->has('type')) {
if (!$configuration->has('type')) {
$output->writeln("\n<error>Configuration has no type</error>");
$this->errors ++;
$this->errors++;
} elseif ($configuration->get('type') == 'Orm\\Doctrine') {
$required = array('debug', 'dbal', 'cache');
} else {
$output->writeln("\n<error>Your type is not managed</error>");
$this->errors ++;
$this->errors++;
}
foreach ($configuration->all() as $conf => $value) {
@@ -552,15 +552,15 @@ class module_console_fileEnsureProductionSetting extends Command
case 'options':
$message = '<info>OK</info>';
if ( ! is_array($value)) {
if (!is_array($value)) {
$message = '<error>Should be array</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, 'array()', false, $message);
break;
default:
$this->alerts ++;
$this->alerts++;
$this->printConf($output, $conf, 'unknown', false, '<comment>Not recognized</comment>');
break;
}
@@ -573,7 +573,7 @@ class module_console_fileEnsureProductionSetting extends Command
if ($value !== false) {
$message = '<error>Should be deactivated</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, $value, false, $message);
@@ -582,9 +582,9 @@ class module_console_fileEnsureProductionSetting extends Command
$required = array_diff($required, array($conf));
$message = '<info>OK</info>';
if ( ! is_array($value)) {
if (!is_array($value)) {
$message = '<error>Should be Array</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, 'array()', false, $message);
@@ -601,7 +601,7 @@ class module_console_fileEnsureProductionSetting extends Command
if ($this->recommendedCacheService($output, $value_cache, $server)) {
$work_message = '<info>Works !</info>';
} else {
$this->alerts ++;
$this->alerts++;
if ($server) {
$work_message = '<comment>Cache server recommended</comment>';
} else {
@@ -610,7 +610,7 @@ class module_console_fileEnsureProductionSetting extends Command
}
} else {
$work_message = '<error>Failed - could not connect !</error>';
$this->errors ++;
$this->errors++;
}
$verification = sprintf("\t--> Verify <info>%s</info> : %s", $name, $work_message);
@@ -619,20 +619,20 @@ class module_console_fileEnsureProductionSetting extends Command
$this->verifyCacheOptions($output, $value_cache);
break;
default:
$this->alerts ++;
$this->alerts++;
$this->printConf($output, "\t" . $key_cache, $value_cache, false, '<comment>Not recognized</comment>');
break;
}
if ( ! isset($cache_type['service'])) {
if (!isset($cache_type['service'])) {
$output->writeln('<error>Miss service for %s</error>', $cache_type);
$this->errors ++;
$this->errors++;
}
}
}
if (count($required_caches) > 0) {
$output->writeln(sprintf('<error>Miss required caches %s</error>', implode(', ', $required_caches)));
$this->errors ++;
$this->errors++;
}
break;
case 'debug':
@@ -641,7 +641,7 @@ class module_console_fileEnsureProductionSetting extends Command
if ($value !== false) {
$message = '<error>Should be false</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, $value, false, $message);
@@ -654,12 +654,12 @@ class module_console_fileEnsureProductionSetting extends Command
$message = '<info>OK</info>';
} catch (\Exception $e) {
$message = '<error>Failed</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, $conf, $value, false, $message);
break;
default:
$this->alerts ++;
$this->alerts++;
$this->printConf($output, $conf, $value, false, '<comment>Not recognized</comment>');
break;
}
@@ -667,7 +667,7 @@ class module_console_fileEnsureProductionSetting extends Command
if (count($required) > 0) {
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required)));
$this->errors ++;
$this->errors++;
}
return;
@@ -678,9 +678,8 @@ class module_console_fileEnsureProductionSetting extends Command
try {
$conf = $this->configuration->getService($ServiceName);
$Service = Core\Service\Builder::create(
\bootstrap::getCore(), $conf
);
echo " at ".__FILE__."\n";
$Service = Builder::create($this->container, $conf);
} catch (\Exception $e) {
return false;
}
@@ -704,9 +703,9 @@ class module_console_fileEnsureProductionSetting extends Command
$required_options = array_diff($required_options, array($conf));
$message = '<info>OK</info>';
if ( ! is_scalar($value)) {
if (!is_scalar($value)) {
$message = '<error>Should be scalar</error>';
$this->errors ++;
$this->errors++;
}
$this->printConf($output, "\t\t" . $conf, $value, false, $message);
@@ -715,15 +714,15 @@ class module_console_fileEnsureProductionSetting extends Command
$required_options = array_diff($required_options, array($conf));
$message = '<info>OK</info>';
if ( ! ctype_digit($value)) {
if (!ctype_digit($value)) {
$message = '<comment>Not recognized</comment>';
$this->alerts ++;
$this->alerts++;
}
$this->printConf($output, "\t\t" . $conf, $value, false, $message);
break;
default:
$this->alerts ++;
$this->alerts++;
$this->printConf($output, "\t\t" . $conf, $value, false, '<comment>Not recognized</comment>');
break;
}
@@ -732,7 +731,7 @@ class module_console_fileEnsureProductionSetting extends Command
if (count($required_options) > 0) {
$output->writeln(sprintf('<error>Miss required keys %s</error>', implode(', ', $required_options)));
$this->errors ++;
$this->errors++;
}
}
@@ -741,9 +740,8 @@ class module_console_fileEnsureProductionSetting extends Command
try {
$originalConfiguration = $this->configuration->getService($ServiceName);
$Service = Core\Service\Builder::create(
\bootstrap::getCore(), $originalConfiguration
);
echo " at ".__FILE__."\n";
$Service = Builder::create($this->container, $originalConfiguration);
} catch (\Exception $e) {
return false;
}
@@ -760,7 +758,7 @@ class module_console_fileEnsureProductionSetting extends Command
return false;
break;
case 'memcache':
if ( ! @memcache_connect($Service->getHost(), $Service->getPort())) {
if (!@memcache_connect($Service->getHost(), $Service->getPort())) {
return false;
}
break;
@@ -771,7 +769,7 @@ class module_console_fileEnsureProductionSetting extends Command
$memcached->addServer($Service->getHost(), $Service->getPort());
$stats = $memcached->getStats();
if ( ! isset($stats[$key]) || ! $stats[$key]) {
if (!isset($stats[$key]) || !$stats[$key]) {
throw new \Exception('Unable to connect to memcached server');
}
@@ -809,9 +807,8 @@ class module_console_fileEnsureProductionSetting extends Command
try {
$originalConfiguration = $this->configuration->getService($ServiceName);
$Service = Core\Service\Builder::create(
\bootstrap::getCore(), $originalConfiguration
);
echo " at ".__FILE__."\n";
$Service = Builder::create($this->container, $originalConfiguration);
} catch (\Exception $e) {
return false;
}
@@ -838,7 +835,7 @@ class module_console_fileEnsureProductionSetting extends Command
$value = 'true';
}
$output->writeln(sprintf("\t%s: %s %s", $scope, $value, $message));
} elseif ( ! empty($value)) {
} elseif (!empty($value)) {
$output->writeln(sprintf("\t%s: %s %s", $scope, $value, $message));
}
}