diff --git a/lib/classes/module/console/fileEnsureProductionSetting.class.php b/lib/classes/module/console/fileEnsureProductionSetting.class.php index c539a1b04d..b9ed08de2f 100644 --- a/lib/classes/module/console/fileEnsureProductionSetting.class.php +++ b/lib/classes/module/console/fileEnsureProductionSetting.class.php @@ -35,7 +35,6 @@ class module_console_fileEnsureProductionSetting extends Command * @var \Alchemy\Phrasea\Core\Configuration */ protected $configuration; - protected $env; protected $testSuite = array( 'checkPhraseanetScope' , 'checkDatabaseScope' @@ -44,7 +43,7 @@ class module_console_fileEnsureProductionSetting extends Command , 'checkCacheService' , 'checkOpcodeCacheService' ); - protected $connexionOk = false; + protected $errors = 0; public function __construct($name = null) { @@ -52,16 +51,26 @@ class module_console_fileEnsureProductionSetting extends Command $this->setDescription('Ensure production settings'); - //$this->addArgument('conf', InputArgument::OPTIONAL, 'The file to check'); + $this->addArgument('conf', InputArgument::OPTIONAL, 'The file to check', null); return $this; } public function execute(InputInterface $input, OutputInterface $output) { - $this->initTests($output); + $specifications = new \Alchemy\Phrasea\Core\Configuration\ApplicationSpecification(); - $this->prepareTests($output); + $environnement = $input->getArgument('conf'); + + $this->configuration = \Alchemy\Phrasea\Core\Configuration::build($specifications, $environnement); + + if (!$this->configuration->isInstalled()) + { + $output->writeln(sprintf("\nPhraseanet is not installed\n")); + } + + $this->checkParse($output); + $output->writeln(sprintf("Will Ensure Production Settings on %s", $this->configuration->getEnvironnement())); $this->runTests($output); @@ -69,68 +78,30 @@ class module_console_fileEnsureProductionSetting extends Command return 0; } - private function initTests(OutputInterface $output) - { - $this->configuration = Core\Configuration::build(); - - if (!$this->configuration->isInstalled()) - { - $output->writeln(sprintf("\nPhraseanet is not installed\n")); - - return 1; - } - } - - private function prepareTests(OutputInterface $output) - { - try - { - $this->checkParse($output); - $this->checkGetSelectedEnvironement($output); - $this->checkGetSelectedEnvironementFromFile($output); - } - catch (\Exception $e) - { - $previous = $e->getPrevious(); - $previousMessage = $previous instanceof \Exception ? $previous->getMessage() : 'Unknown.'; - - $output->writeln(sprintf( - "Error while loading : %s (%s)" - , $e->getMessage() - , $previousMessage - ) - ); - - return 1; - } - } - private function runTests(OutputInterface $output) { - $nbErrors = 0; - foreach ($this->testSuite as $test) { $display = ""; switch ($test) { case 'checkPhraseanetScope' : - $display = "Phraseanet Scope Configuration"; + $display = "Phraseanet Configuration"; break; case 'checkDatabaseScope' : - $display = "Database configuration & connexion"; + $display = "Database"; break; case 'checkTeamplateEngineService' : - $display = "Template Engine Service"; + $display = "Template Engine"; break; case 'checkOrmService' : - $display = "ORM Service"; + $display = "ORM"; break; case 'checkCacheService' : - $display = "Cache Service"; + $display = "Cache"; break; case 'checkOpcodeCacheService' : - $display = "Opcode Cache Service"; + $display = "Opcode"; break; default: throw new \Exception('Unknown test'); @@ -139,33 +110,17 @@ class module_console_fileEnsureProductionSetting extends Command $output->writeln(sprintf("\n||| %s", mb_strtoupper($display))); - try - { - call_user_func(array($this, $test), $output); - } - catch (\Exception $e) - { - $nbErrors++; - $previous = $e->getPrevious(); - - $output->writeln(sprintf( - "%s FAILED : %s" - , $e->getMessage() - , $previous instanceof \Exception ? $previous->getMessage() : 'Unknown' - ) - ); - $output->writeln(""); - } + call_user_func(array($this, $test), $output); } - if (!$nbErrors) - { - $output->writeln("\nYour production settings are setted correctly ! Enjoy"); - } - else + if ($this->errors) { $output->writeln("\nSome errors found in your conf"); } - return (int) ($nbErrors > 0); + else + { + $output->writeln("\nYour production settings are setted correctly ! Enjoy"); + } + return $this->errors; } private function checkParse(OutputInterface $output) @@ -190,434 +145,621 @@ class module_console_fileEnsureProductionSetting extends Command private function checkCacheService(OutputInterface $output) { $cache = $this->configuration->getCache(); - $this->probeCacheService($output, 'MainCache', $cache); + + + if ($this->probeCacheService($output, $cache)) + { + if ($this->recommendedCacheService($output, $cache, true)) + { + $work_message = 'Works !'; + } + else + { + $work_message = 'Cache server recommended'; + } + } + else + { + $work_message = 'Failed - could not connect !'; + $this->errors++; + } + + $verification = sprintf("\t--> Verify %s : %s", 'MainCache', $work_message); + + + $this->printConf($output, "\t" . 'service', $cache, false, $verification); + $this->verifyCacheOptions($output, $cache); } private function checkOpcodeCacheService(OutputInterface $output) { $cache = $this->configuration->getOpcodeCache(); - $this->probeCacheService($output, 'MainOpcodeCache', $cache); - } - private function checkGetSelectedEnvironement(OutputInterface $output) - { - try + + if ($this->probeCacheService($output, $cache)) { - $this->configuration->getConfiguration(); + if ($this->recommendedCacheService($output, $cache, false)) + { + $work_message = 'Works !'; + } + else + { + $work_message = 'Opcode recommended'; + } } - catch (\Exception $e) + else { - throw new \Exception(sprintf("Error getting configuration\n"), null, $e); + $work_message = 'Failed - could not connect !'; + $this->errors++; } - return; - } + $verification = sprintf("\t--> Verify %s : %s", 'OpcodeCache', $work_message); - private function checkGetSelectedEnvironementFromFile(OutputInterface $output) - { - $configuration = Core\Configuration::build(); - try - { - $configuration->getConfiguration(); - } - catch (\Exception $e) - { - throw new \Exception(sprintf("Error getting environment\n"), null, $e); - } - - $output->writeln(sprintf("Will Ensure Production Settings on %s", $configuration->getEnvironnement())); - return; + $this->printConf($output, "\t" . 'service', $cache, false, $verification); + $this->verifyCacheOptions($output, $cache); } private function checkPhraseanetScope(OutputInterface $output) { - try + $required = array('servername', 'maintenance', 'debug', 'display_errors', 'database'); + + $phraseanet = $this->configuration->getPhraseanet(); + + foreach ($phraseanet->all() as $conf => $value) { - $phraseanet = $this->configuration->getPhraseanet(); - - foreach($phraseanet->all() as $conf=>$value) + switch ($conf) { - switch($conf) - { - default: - $this->printConf($output, $conf, $value); - break; - case 'servername': - $url = $value; + default: + $this->printConf($output, $conf, $value, false, 'Not recognized'); + break; + case 'servername': + $url = $value; + $required = array_diff($required, array($conf)); - $parseUrl = parse_url($url); + $parseUrl = parse_url($url); - if (empty($url)) + if (empty($url)) + { + $message = "should not be empty"; + $this->errors++; + } + elseif ($url == 'http://sub.domain.tld/') + { + $message = "may be wrong"; + } + elseif (!filter_var($url, FILTER_VALIDATE_URL)) + { + $message = "not valid"; + $this->errors++; + } + elseif ($parseUrl["scheme"] !== "https") + { + $message = "should be https"; + } + else + { + $message = "OK"; + } + $this->printConf($output, $conf, $value, false, $message); + break; + case 'maintenance': + case 'debug': + case 'display_errors': + $required = array_diff($required, array($conf)); + $message = $value ? 'Should be false' : 'OK'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'database': + $required = array_diff($required, array($conf)); + try + { + $service = $this->configuration->getConnexion($value); + if ($this->verifyDatabaseConnexion($service)) { - $message = "should not be empty"; - } - elseif (!filter_var($url, FILTER_VALIDATE_URL)) - { - $message = "not valid"; - } - elseif ($parseUrl["scheme"] !== "https") - { - $message = "should be https"; + $message = 'OK'; } else { - $message = "OK"; + $message = 'Connection not available'; + $this->errors++; } - $this->printConf($output, $conf, $value, false, $message); - break; - case 'maintenance': - case 'debug': - case 'display_errors': - $message = $value ? 'Should be false' : 'OK'; - $this->printConf($output, $conf, $value, false, $message); - break; - } - } -// $this->printConf($output, 'phraseanet', $phraseanet->all()); - -// $url = $phraseanet->get("servername"); - - - - if (!$phraseanet->has("debug")) - { - $output->writeln(sprintf("You should give debug a value", $url)); - } - elseif ($phraseanet->get("debug") !== false) - { - throw new \Exception("phraseanet:debug must be initialized to false"); - } - - if ($phraseanet->get("display_errors") !== false) - { - throw new \Exception("Display errors should be false"); - } - - if ($phraseanet->get("maintenance") === true) - { - throw new \Exception("phraseanet:warning maintenance is set to false"); + } + catch (\Exception $e) + { + $message = 'Unknown connection'; + $this->errors++; + } + $this->printConf($output, $conf, $value, false, $message); + break; } } - catch (\Exception $e) + + if (count($required) > 0) { - throw new \Exception(sprintf("Check Phraseanet Scope\n"), null, $e); + $output->writeln(sprintf('Miss required keys %s', implode(', ', $required))); + $this->errors++; } - $output->writeln(""); - $output->writeln("Phraseanet scope is correctly setted"); - $output->writeln(""); return; } private function checkDatabaseScope(OutputInterface $output) { + $connexionName = $this->configuration->getPhraseanet()->get('database'); + $connexion = $this->configuration->getConnexion($connexionName); + try { - $connexionName = $this->configuration->getPhraseanet()->get('database'); - $connexion = $this->configuration->getConnexion($connexionName); - - $output->writeln(sprintf("Current connexion is '%s'", $connexionName)); - $output->writeln(""); - foreach ($connexion->all() as $key => $element) + if ($this->verifyDatabaseConnexion($connexion)) { - $output->writeln(sprintf("%s: %s", $key, $element)); + $work_message = 'Works !'; } - - if ($connexion->get("driver") === "pdo_sqlite") + else { - throw new \Exception("A sqlite database is not recommanded for production environment"); + $work_message = 'Failed - could not connect !'; + $this->errors++; } - - try - { - $config = new \Doctrine\DBAL\Configuration(); - $conn = \Doctrine\DBAL\DriverManager::getConnection( - $connexion->all() - , $config - ); - unset($conn); - $this->connexionOk = true; - } - catch (\Exception $e) - { - throw new \Exception(sprintf( - "Unable to connect to database declared in connexion '%s' for the following reason %s" - , $connexionName - , $e->getMessage() - ) - ); - } - - $output->writeln(""); - $output->writeln(sprintf("'%s' successfully connect to database", $connexionName)); - $output->writeln(""); } catch (\Exception $e) { - throw new \Exception(sprintf("CHECK Database Scope\n"), null, $e); + + $work_message = 'Failed - could not connect !'; + $this->errors++; + } + + $output->writeln(sprintf("\t--> Verify connection %s : %s", $connexionName, $work_message)); + + $required = array('driver'); + + if (!$connexion->has('driver')) + { + $output->writeln("\nConnection has no driver"); + $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("\nYour driver is not managed"); + $this->errors++; + } + + foreach ($connexion->all() as $conf => $value) + { + switch ($conf) + { + default: + $this->printConf($output, $conf, $value, false, 'Not recognized'); + break; + case 'charset': + $required = array_diff($required, array($conf)); + $message = $value == 'UTF8' ? 'OK' : 'Not recognized'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'path': + $required = array_diff($required, array($conf)); + $message = is_writable(dirname($value)) ? 'OK' : 'Not writeable'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'dbname': + case 'user': + case 'host': + $required = array_diff($required, array($conf)); + $message = is_scalar($value) ? 'OK' : 'Should be scalar'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'port': + $required = array_diff($required, array($conf)); + $message = ctype_digit($value) ? 'OK' : 'Should be scalar'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'password': + $required = array_diff($required, array($conf)); + $message = is_scalar($value) ? 'OK' : 'Should be scalar'; + $value = '***********'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'driver': + $required = array_diff($required, array($conf)); + $message = $value === 'pdo_mysql' ? 'OK' : 'MySQL recommended'; + $this->printConf($output, $conf, $value, false, $message); + break; + } + } + + if (count($required) > 0) + { + $output->writeln(sprintf('Miss required keys %s', implode(', ', $required))); + $this->errors++; } return; } - private function checkTeamplateEngineService(OutputInterface $output) + protected function verifyDatabaseConnexion(\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag $connexion) { try { - $templateEngineName = $this->configuration->getTemplating(); -// $output->writeln(sprintf("Current template engine service is '%s' ", $templateEngineName)); -// $output->writeln(""); - try - { - $configuration = $this->configuration->getService($templateEngineName); - $this->printConf($output, $templateEngineName, $configuration->all()); - } - catch (\Exception $e) - { - $message = sprintf( - "%s called from %s in %s:template_engine scope" - , $e->getMessage() - , $this->configuration->getFile()->getFilename() - , "PROD" - , $templateEngineName - ); - $e = new \Exception($message); - throw $e; - } - - $service = Core\Service\Builder::create( - \bootstrap::getCore() - , $templateEngineName - , $configuration - ); - - if ($service->getType() === 'twig') - { - $twig = $service->getDriver(); - - if ($twig->isDebug()) - { - throw new \Exception(sprintf("%s service should not be in debug mode", $service->getName())); - } - - if ($twig->isStrictVariables()) - { - throw new \Exception(sprintf("%s service should not be set in strict variables mode", $service->getName())); - } - } + $config = new \Doctrine\DBAL\Configuration(); + $conn = \Doctrine\DBAL\DriverManager::getConnection($connexion->all(), $config); + return true; } catch (\Exception $e) { - if ($e instanceof \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException) - { - if ($e->getKey() === 'template_engine') - { - $e = new \Exception(sprintf( - "Missing parameter %s " - , $e->getKey() - ) - ); - } - else - { - $e = new \Exception(sprintf( - "Missing parameter %s for %s service" - , $e->getKey() - , $templateEngineName - ) - ); - } - } - throw new \Exception(sprintf("Check Template Service\n"), null, $e); } - $output->writeln(sprintf("'%s' template engine service is correctly setted ", $templateEngineName)); - $output->writeln(""); + + return false; + } + + private function checkTeamplateEngineService(OutputInterface $output) + { + $templateEngineName = $this->configuration->getTemplating(); + $configuration = $this->configuration->getService($templateEngineName); + + try + { + Core\Service\Builder::create(\bootstrap::getCore(), $templateEngineName, $configuration); + $work_message = 'Works !'; + } + catch (\Exception $e) + { + $work_message = 'Failed - could not connect !'; + $this->errors++; + } + + $output->writeln(sprintf("\t--> Verify Template engine %s : %s", $templateEngineName, $work_message)); + + if (!$configuration->has('type')) + { + $output->writeln("\nConfiguration has no type"); + $this->errors++; + } + elseif ($configuration->get('type') == 'TemplateEngine\\Twig') + { + $required = array('debug', 'charset', 'strict_variables', 'autoescape', 'optimizer'); + } + else + { + $output->writeln("\nYour type is not managed"); + $this->errors++; + } + + + + foreach ($configuration->all() as $conf => $value) + { + switch ($conf) + { + case 'type': + $message = $value == 'TemplateEngine\\Twig' ? 'OK' : 'Not recognized'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'options': + $message = is_array($value) ? 'OK' : 'Should be array'; + $this->printConf($output, $conf, 'array()', false, $message); + break; + default: + $this->printConf($output, $conf, 'unknown', false, 'Not recognized'); + break; + } + } + + foreach ($configuration->get('options') as $conf => $value) + { + switch ($conf) + { + case 'debug'; + case 'strict_variables'; + $required = array_diff($required, array($conf)); + $message = $value == false ? 'OK' : 'Should be false'; + $this->printConf($output, "\t" . $conf, $value, false, $message); + break; + case 'autoescape'; + case 'optimizer'; + $required = array_diff($required, array($conf)); + $message = $value == true ? 'OK' : 'Should be true'; + $this->printConf($output, "\t" . $conf, $value, false, $message); + break; + case 'charset'; + $required = array_diff($required, array($conf)); + $message = $value == 'utf-8' ? 'OK' : 'Not recognized'; + $this->printConf($output, "\t" . $conf, $value, false, $message); + break; + default: + $this->printConf($output, "\t" . $conf, $value, false, 'Not recognized'); + break; + } + } + + if (count($required) > 0) + { + $output->writeln(sprintf('Miss required keys %s', implode(', ', $required))); + $this->errors++; + } + return; } private function checkOrmService(OutputInterface $output) { - if (!$this->connexionOk) - { - $output->writeln("As ORM service test depends on database test success, it is not executed"); - - return; - } + $ormName = $this->configuration->getOrm(); + $configuration = $this->configuration->getService($ormName); try { - $ormName = $this->configuration->getOrm(); - - $output->writeln(sprintf("Current ORM service is '%s'", $ormName)); - $output->writeln(""); - try - { - $configuration = $this->configuration->getService($ormName); - $this->printConf($output, $ormName, $configuration->all()); - } - catch (\Exception $e) - { - $message = sprintf( - "%s called from %s in %s scope" - , $e->getMessage() - , $this->configuration->getFile()->getFilename() - , $ormName - ); - $e = new \Exception($message); - throw $e; - } - $registry = \registry::get_instance(); - - $service = Core\Service\Builder::create( - \bootstrap::getCore() - , $ormName - , $configuration - ); - - if ($service->getType() === 'doctrine') - { - $output->writeln(""); - - $caches = $service->getCacheServices()->all(); - - if ($service->isDebug()) - { - throw new \Exception(sprintf( - "%s service should not be in debug mode" - , $service->getName() - ) - ); - } - - $output->writeln(""); - - $options = $configuration->get("options"); - - if (!isset($options['orm']['cache'])) - { - - throw new \Exception(sprintf( - "%s:doctrine:orm:cache must not be empty. In production environment the cache is highly recommanded." - , $service->getName() - ) - ); - } - - foreach ($caches as $key => $cache) - { - $ServiceName = $options['orm']['cache'][$key]; - - $this->probeCacheService($output, $key, $ServiceName); - } - - try - { - $logServiceName = $options['log']; - $configuration = $this->configuration->getService($logServiceName); - $serviceLog = Core\Service\Builder::create( - \bootstrap::getCore() - , $logServiceName - , $configuration - ); - - $exists = true; - } - catch (\Exception $e) - { - $exists = false; - } - - if ($exists) - { - throw new \Exception(sprintf( - "doctrine:orm:log %s service should not be enable" - , $serviceLog->getName() - ) - ); - } - } + $service = Core\Service\Builder::create(\bootstrap::getCore(), $ormName, $configuration); + $work_message = 'Works !'; } catch (\Exception $e) { - if ($e instanceof \Symfony\Component\DependencyInjection\Exception\ParameterNotFoundException) - { - if ($e->getKey() === 'orm') - { - $e = new \Exception(sprintf( - "Missing parameter %s for service %s" - , $e->getKey() - , $service->getName() - ) - ); - } - else - { - $e = new \Exception(sprintf( - "Missing parameter %s for %s service declared" - , $e->getKey() - , $service->getName() - ) - ); - } - } - - throw new \Exception(sprintf("Check ORM Service : "), null, $e); + $work_message = 'Failed - could not connect !'; + $this->errors++; } - $output->writeln(""); - $output->writeln(sprintf("'%s' ORM service is correctly setted ", $ormName)); - $output->writeln(""); + $output->writeln(sprintf("\t--> Verify ORM engine %s : %s", $ormName, $work_message)); + + + + if (!$configuration->has('type')) + { + $output->writeln("\nConfiguration has no type"); + $this->errors++; + } + elseif ($configuration->get('type') == 'Orm\\Doctrine') + { + $required = array('debug', 'dbal', 'cache'); + } + else + { + $output->writeln("\nYour type is not managed"); + $this->errors++; + } + + + + foreach ($configuration->all() as $conf => $value) + { + switch ($conf) + { + case 'type': + $message = $value == 'Orm\\Doctrine' ? 'OK' : 'Not recognized'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'options': + $message = is_array($value) ? 'OK' : 'Should be array'; + $this->printConf($output, $conf, 'array()', false, $message); + break; + default: + $this->printConf($output, $conf, 'unknown', false, 'Not recognized'); + break; + } + } + + + foreach ($configuration->get('options') as $conf => $value) + { + switch ($conf) + { + case 'log': + $message = $value == false ? 'OK' : 'Should be deactivated'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'cache': + $required = array_diff($required, array($conf)); + $message = is_array($value) ? 'OK' : 'Should be Array'; + $this->printConf($output, $conf, 'array()', false, $message); + + $required_caches = array('query', 'result', 'metadata'); + foreach ($value as $name => $cache_type) + { + $required_caches = array_diff($required_caches, array($name)); + + foreach ($cache_type as $key_cache => $value_cache) + { + switch ($key_cache) + { + case 'service': + if ($this->probeCacheService($output, $value_cache)) + { + $server = $name === 'result'; + if ($this->recommendedCacheService($output, $value_cache, $server)) + { + $work_message = 'Works !'; + } + else + { + if ($server) + { + $work_message = 'Cache server recommended'; + } + else + { + $work_message = 'Opcode cache recommended'; + } + } + } + else + { + $work_message = 'Failed - could not connect !'; + $this->errors++; + } + + $verification = sprintf("\t--> Verify %s : %s", $name, $work_message); + + + $this->printConf($output, "\t" . $key_cache, $value_cache, false, $verification); + $this->verifyCacheOptions($output, $value_cache); + break; + default: + $this->printConf($output, "\t" . $key_cache, $value_cache, false, 'Not recognized'); + break; + } + if (!isset($cache_type['service'])) + { + $output->writeln('Miss service for %s', $cache_type); + $this->errors++; + } + } + } + + if (count($required_caches) > 0) + { + $output->writeln(sprintf('Miss required caches %s', implode(', ', $required_caches))); + $this->errors++; + } + break; + case 'debug': + $required = array_diff($required, array($conf)); + $message = $value == false ? 'OK' : 'Should be false'; + $this->printConf($output, $conf, $value, false, $message); + break; + case 'dbal': + $required = array_diff($required, array($conf)); + try + { + $connexion = $this->configuration->getConnexion($value); + $this->verifyDatabaseConnexion($connexion); + $message = 'OK'; + } + catch (\Exception $e) + { + $message = 'Failed'; + $this->errors++; + } + $this->printConf($output, $conf, $value, false, $message); + break; + default: + $this->printConf($output, $conf, $value, false, 'Not recognized'); + break; + } + } + + if (count($required) > 0) + { + $output->writeln(sprintf('Miss required keys %s', implode(', ', $required))); + $this->errors++; + } return; } - protected function probeCacheService(OutputInterface $output, $cacheName, $ServiceName) + protected function verifyCacheOptions(OutputInterface $output, $ServiceName) { - $originalConfiguration = $this->configuration->getService($ServiceName); - $options = $originalConfiguration->all(); - - if (!empty($options)) + try { - $output->writeln(sprintf("%s cache service", $ServiceName)); - $this->printConf($output, $cacheName . ":" . $ServiceName, $options); + $conf = $this->configuration->getService($ServiceName); + + $Service = Core\Service\Builder::create( + \bootstrap::getCore(), $ServiceName, $conf + ); + } + catch (\Exception $e) + { + return false; + } + + $required_options = array(); + + switch ($Service->getType()) + { + default: + break; + case 'memcache': + $required_options = array('host', 'port'); + break; + } + + if ($required_options) + { + foreach ($conf->get('options') as $conf => $value) + { + switch ($conf) + { + case 'host'; + $required_options = array_diff($required_options, array($conf)); + $message = is_scalar($value) ? 'OK' : 'Should be scalar'; + $this->printConf($output, "\t\t" . $conf, $value, false, $message); + break; + case 'port'; + $required_options = array_diff($required_options, array($conf)); + $message = ctype_digit($value) ? 'OK' : 'Not recognized'; + $this->printConf($output, "\t\t" . $conf, $value, false, $message); + break; + default: + $this->printConf($output, "\t\t" . $conf, $value, false, 'Not recognized'); + break; + } + } + } + + if (count($required_options) > 0) + { + $output->writeln(sprintf('Miss required keys %s', implode(', ', $required_options))); + $this->errors++; + } + } + + protected function probeCacheService(OutputInterface $output, $ServiceName) + { + try + { + $originalConfiguration = $this->configuration->getService($ServiceName); + + $Service = Core\Service\Builder::create( + \bootstrap::getCore(), $ServiceName, $originalConfiguration + ); + } + catch (\Exception $e) + { + return false; } - $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $ServiceName, $originalConfiguration - ); if ($Service->getDriver()->isServer()) { switch ($Service->getType()) { default: - $output->writeln(sprintf("Unable to check %s", $Service->getType())); + return false; break; case 'memcache': if (!memcache_connect($Service->getHost(), $Service->getPort())) { - $output->writeln( - sprintf( - "Unable to connect to memcache service %s with host '%s' and port '%s'" - , $Service->getName() - , $Service->getHost() - , $Service->getPort() - ) - ); + return false; } break; } } - if ($Service->getType() === 'array') + + return true; + } + + protected function recommendedCacheService(OutputInterface $output, $ServiceName, $server) + { + try { - $output->writeln( - sprintf( - "doctrine:orm:%s %s service should not be an array cache type" - , $Service->getName() - , $cacheName - ) + $originalConfiguration = $this->configuration->getService($ServiceName); + + $Service = Core\Service\Builder::create( + \bootstrap::getCore(), $ServiceName, $originalConfiguration ); } + catch (\Exception $e) + { + return false; + } + + if ($Service->getType() === 'array') + { + return false; + } + return $server === $Service->getDriver()->isServer(); } private function printConf($output, $scope, $value, $scopage = false, $message = '') diff --git a/lib/classes/module/console/systemUpgrade.class.php b/lib/classes/module/console/systemUpgrade.class.php index 9685bdb1fc..4861a04155 100644 --- a/lib/classes/module/console/systemUpgrade.class.php +++ b/lib/classes/module/console/systemUpgrade.class.php @@ -77,11 +77,35 @@ class module_console_systemUpgrade extends Command foreach ($credentials as $key => $value) { - $key = $key == 'hostname' ? 'host' : $key; - $connexions['main_connexion'][$key] = (string) $value; + $key = $key == 'hostname' ? 'host' : $key; + $connexions['main_connexion'][$key] = (string) $value; } $Core->getConfiguration()->setConnexions($connexions); + + + $configs = $Core->getConfiguration()->getConfigurations(); + + $retrieve_old_parameters = function() + { + require __DIR__ . '/../../../../config/config.inc'; + + return array( + 'servername' => $servername + ); + }; + + $old_parameters = $retrieve_old_parameters(); + + foreach ($configs as $env => $conf) + { + if (isset($configs[$env]['phraseanet'])) + { + $configs[$env]['phraseanet']['servername'] = $old_parameters['servername']; + } + } + $Core->getConfiguration()->setConfigurations($configs); + $Core->getConfiguration()->setEnvironnement('prod'); } catch (\Exception $e) @@ -111,7 +135,7 @@ class module_console_systemUpgrade extends Command { try { - $Core = \bootstrap::getCore(); + $Core = \bootstrap::getCore(); $output->write('Upgrading...', true); $appbox = appbox::get_instance($Core);