diff --git a/lib/classes/module/console/checkExtension.class.php b/lib/classes/module/console/checkExtension.class.php index 21ed583c27..2498e627b7 100644 --- a/lib/classes/module/console/checkExtension.class.php +++ b/lib/classes/module/console/checkExtension.class.php @@ -49,7 +49,6 @@ class module_console_checkExtension extends Command return 1; } - $Core = $this->getService('phraseanet.core'); $appbox = $this->getService('phraseanet.appbox'); $registry = $appbox->get_registry(); @@ -57,7 +56,7 @@ class module_console_checkExtension extends Command $usrId = $input->getArgument('usr_id'); try { - $TestUser = \User_Adapter::getInstance($usrId, $appbox); + $TestUser = \User_Adapter::getInstance($usrId, $this->container); } catch (\Exception $e) { $output->writeln("Wrong user !"); @@ -78,7 +77,7 @@ class module_console_checkExtension extends Command $output->writeln("$function"); } - $configuration = $Core->getConfiguration(); + $configuration = $this->getService('phraseanet.configuration'); $choosenConnection = $configuration->getPhraseanet()->get('database'); $connexion = $configuration->getConnexion($choosenConnection); $hostname = $connexion->get('host'); @@ -157,7 +156,7 @@ class module_console_checkExtension extends Command $tbases[$kbase]["searchcoll"] = $tcoll; $tbases[$kbase]["mask_xor"] = $tbases[$kbase]["mask_and"] = 0; - $qp = new searchEngine_adapter_phrasea_queryParser(); + $qp = new searchEngine_adapter_phrasea_queryParser($this->container); $treeq = $qp->parsequery($input->getOption('query')); $arrayq = $qp->makequery($treeq); diff --git a/lib/classes/module/console/fileEnsureDevSetting.class.php b/lib/classes/module/console/fileEnsureDevSetting.class.php index 403eb99b82..fd911bec95 100644 --- a/lib/classes/module/console/fileEnsureDevSetting.class.php +++ b/lib/classes/module/console/fileEnsureDevSetting.class.php @@ -14,7 +14,8 @@ 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\Core; +use Alchemy\Phrasea\Application; +use Alchemy\Phrasea\Core\Service\Builder; /** * @todo write tests @@ -63,11 +64,7 @@ class module_console_fileEnsureDevSetting 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 Development Settings on %s", $this->configuration->getEnvironnement())); @@ -131,15 +128,15 @@ class module_console_fileEnsureDevSetting 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"); } @@ -155,11 +152,11 @@ class module_console_fileEnsureDevSetting extends Command $work_message = 'Works !'; } else { $work_message = 'Cache server recommended'; - $this->alerts ++; + $this->alerts++; } } else { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $verification = sprintf("\t--> Verify %s : %s", 'MainCache', $work_message); @@ -177,11 +174,11 @@ class module_console_fileEnsureDevSetting extends Command $work_message = 'Works !'; } else { $work_message = 'No cache required'; - $this->errors ++; + $this->errors++; } } else { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $verification = sprintf("\t--> Verify %s : %s", 'OpcodeCache', $work_message); @@ -197,12 +194,12 @@ class module_console_fileEnsureDevSetting extends Command $listChecks = false; try { - $service = Core\Service\Builder::create(\bootstrap::getCore(), $configuration); + $service = Builder::create($this->container, $configuration); $work_message = 'Works !'; $listChecks = true; } catch (\Exception $e) { $work_message = 'Failed - could not load Border Manager service !'; - $this->errors ++; + $this->errors++; } $output->writeln(sprintf("\t--> Verify Border Manager%s : %s", $serviceName, $work_message)); @@ -225,7 +222,7 @@ class module_console_fileEnsureDevSetting extends Command foreach ($phraseanet->all() as $conf => $value) { switch ($conf) { default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, $value, false, 'Not recognized'); break; case 'servername': @@ -236,13 +233,13 @@ class module_console_fileEnsureDevSetting extends Command if (empty($url)) { $message = "should not be empty"; - $this->errors ++; + $this->errors++; } elseif ($url == 'http://sub.domain.tld/') { - $this->alerts ++; + $this->alerts++; $message = "may be wrong"; - } elseif ( ! filter_var($url, FILTER_VALIDATE_URL)) { + } elseif (!filter_var($url, FILTER_VALIDATE_URL)) { $message = "not valid"; - $this->errors ++; + $this->errors++; } else { $message = "OK"; } @@ -254,7 +251,7 @@ class module_console_fileEnsureDevSetting extends Command if ($value !== false) { $message = 'Should be true'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); @@ -266,7 +263,7 @@ class module_console_fileEnsureDevSetting extends Command if ($value !== true) { $message = 'Should be true'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); @@ -279,11 +276,11 @@ class module_console_fileEnsureDevSetting extends Command $message = 'OK'; } else { $message = 'Connection not available'; - $this->errors ++; + $this->errors++; } } catch (\Exception $e) { $message = 'Unknown connection'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); break; @@ -292,7 +289,7 @@ class module_console_fileEnsureDevSetting extends Command if (count($required) > 0) { $output->writeln(sprintf('Miss required keys %s', implode(', ', $required))); - $this->errors ++; + $this->errors++; } return; @@ -308,34 +305,34 @@ class module_console_fileEnsureDevSetting extends Command $work_message = 'Works !'; } else { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } } catch (\Exception $e) { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $output->writeln(sprintf("\t--> Verify connection %s : %s", $connexionName, $work_message)); $required = array('driver'); - if ( ! $connexion->has('driver')) { + if (!$connexion->has('driver')) { $output->writeln("\nConnection has no driver"); - $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("\nYour driver is not managed"); - $this->errors ++; + $this->errors++; } foreach ($connexion->all() as $conf => $value) { switch ($conf) { default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, $value, false, 'Not recognized'); break; case 'charset': @@ -343,7 +340,7 @@ class module_console_fileEnsureDevSetting extends Command $message = 'OK'; if ($value !== 'UTF8') { $message = 'Not recognized'; - $this->alerts ++; + $this->alerts++; } $this->printConf($output, $conf, $value, false, $message); break; @@ -358,9 +355,9 @@ class module_console_fileEnsureDevSetting extends Command $required = array_diff($required, array($conf)); $message = 'OK'; - if ( ! is_scalar($value)) { + if (!is_scalar($value)) { $message = 'Should be scalar'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); @@ -369,9 +366,9 @@ class module_console_fileEnsureDevSetting extends Command $required = array_diff($required, array($conf)); $message = 'OK'; - if ( ! ctype_digit($value)) { + if (!ctype_digit($value)) { $message = 'Should be ctype_digit'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); @@ -380,9 +377,9 @@ class module_console_fileEnsureDevSetting extends Command $required = array_diff($required, array($conf)); $message = 'OK'; - if ( ! is_scalar($value)) { + if (!is_scalar($value)) { $message = 'Should be scalar'; - $this->errors ++; + $this->errors++; } $value = '***********'; @@ -394,7 +391,7 @@ class module_console_fileEnsureDevSetting extends Command if ($value !== 'pdo_mysql') { $message = 'MySQL recommended'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); break; @@ -403,7 +400,7 @@ class module_console_fileEnsureDevSetting extends Command if (count($required) > 0) { $output->writeln(sprintf('Miss required keys %s', implode(', ', $required))); - $this->errors ++; + $this->errors++; } return; @@ -429,23 +426,23 @@ class module_console_fileEnsureDevSetting extends Command $configuration = $this->configuration->getService($templateEngineName); try { - Core\Service\Builder::create(\bootstrap::getCore(), $configuration); + Builder::create($this->container, $configuration); $work_message = 'Works !'; } catch (\Exception $e) { $work_message = 'Failed - could not load template engine !'; - $this->errors ++; + $this->errors++; } $output->writeln(sprintf("\t--> Verify Template engine %s : %s", $templateEngineName, $work_message)); - if ( ! $configuration->has('type')) { + if (!$configuration->has('type')) { $output->writeln("\nConfiguration has no type"); - $this->errors ++; + $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 ++; + $this->errors++; } foreach ($configuration->all() as $conf => $value) { @@ -455,7 +452,7 @@ class module_console_fileEnsureDevSetting extends Command if ($value !== 'TemplateEngine\\Twig') { $message = 'Not recognized'; - $this->alerts ++; + $this->alerts++; } $this->printConf($output, $conf, $value, false, $message); @@ -463,15 +460,15 @@ class module_console_fileEnsureDevSetting extends Command case 'options': $message = 'OK'; - if ( ! is_array($value)) { + if (!is_array($value)) { $message = 'Should be array'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, 'array()', false, $message); break; default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, 'unknown', false, 'Not recognized'); break; } @@ -486,7 +483,7 @@ class module_console_fileEnsureDevSetting extends Command if ($value !== true) { $message = 'Should be false'; - $this->errors ++; + $this->errors++; } $this->printConf($output, "\t" . $conf, $value, false, $message); @@ -498,7 +495,7 @@ class module_console_fileEnsureDevSetting extends Command if ($value !== true) { $message = 'Should be true'; - $this->errors ++; + $this->errors++; } $this->printConf($output, "\t" . $conf, $value, false, $message); @@ -509,13 +506,13 @@ class module_console_fileEnsureDevSetting extends Command if ($value !== 'utf-8') { $message = 'Not recognized'; - $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, 'Not recognized'); break; } @@ -523,7 +520,7 @@ class module_console_fileEnsureDevSetting extends Command if (count($required) > 0) { $output->writeln(sprintf('Miss required keys %s', implode(', ', $required))); - $this->errors ++; + $this->errors++; } return; @@ -535,23 +532,23 @@ class module_console_fileEnsureDevSetting extends Command $configuration = $this->configuration->getService($ormName); try { - $service = Core\Service\Builder::create(\bootstrap::getCore(), $configuration); + $service = Builder::create($this->container, $configuration); $work_message = 'Works !'; } catch (\Exception $e) { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $output->writeln(sprintf("\t--> Verify ORM engine %s : %s", $ormName, $work_message)); - if ( ! $configuration->has('type')) { + if (!$configuration->has('type')) { $output->writeln("\nConfiguration has no type"); - $this->errors ++; + $this->errors++; } elseif ($configuration->get('type') == 'Orm\\Doctrine') { $required = array('debug', 'dbal', 'cache'); } else { $output->writeln("\nYour type is not managed"); - $this->errors ++; + $this->errors++; } foreach ($configuration->all() as $conf => $value) { @@ -563,15 +560,15 @@ class module_console_fileEnsureDevSetting extends Command case 'options': $message = 'OK'; - if ( ! is_array($value)) { + if (!is_array($value)) { $message = 'Should be array'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, 'array()', false, $message); break; default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, 'unknown', false, 'Not recognized'); break; } @@ -588,9 +585,9 @@ class module_console_fileEnsureDevSetting extends Command $required = array_diff($required, array($conf)); $message = 'OK'; - if ( ! is_array($value)) { + if (!is_array($value)) { $message = 'Should be Array'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, 'array()', false, $message); @@ -607,12 +604,12 @@ class module_console_fileEnsureDevSetting extends Command if ($this->recommendedCacheService($output, $value_cache, $server)) { $work_message = 'Works !'; } else { - $this->errors ++; + $this->errors++; $work_message = 'No cache required'; } } else { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $verification = sprintf("\t--> Verify %s : %s", $name, $work_message); @@ -621,20 +618,20 @@ class module_console_fileEnsureDevSetting extends Command $this->verifyCacheOptions($output, $value_cache); break; default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, "\t" . $key_cache, $value_cache, false, 'Not recognized'); break; } - if ( ! isset($cache_type['service'])) { + if (!isset($cache_type['service'])) { $output->writeln('Miss service for %s', $cache_type); - $this->errors ++; + $this->errors++; } } } if (count($required_caches) > 0) { $output->writeln(sprintf('Miss required caches %s', implode(', ', $required_caches))); - $this->errors ++; + $this->errors++; } break; case 'debug': @@ -643,7 +640,7 @@ class module_console_fileEnsureDevSetting extends Command if ($value !== true) { $message = 'Should be true'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); @@ -656,12 +653,12 @@ class module_console_fileEnsureDevSetting extends Command $message = 'OK'; } catch (\Exception $e) { $message = 'Failed'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); break; default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, $value, false, 'Not recognized'); break; } @@ -669,7 +666,7 @@ class module_console_fileEnsureDevSetting extends Command if (count($required) > 0) { $output->writeln(sprintf('Miss required keys %s', implode(', ', $required))); - $this->errors ++; + $this->errors++; } return; @@ -680,9 +677,7 @@ class module_console_fileEnsureDevSetting extends Command try { $conf = $this->configuration->getService($ServiceName); - $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $conf - ); + $Service = Builder::create($this->container, $conf); } catch (\Exception $e) { return false; } @@ -706,9 +701,9 @@ class module_console_fileEnsureDevSetting extends Command $required_options = array_diff($required_options, array($conf)); $message = 'OK'; - if ( ! is_scalar($value)) { + if (!is_scalar($value)) { $message = 'Should be scalar'; - $this->errors ++; + $this->errors++; } $this->printConf($output, "\t\t" . $conf, $value, false, $message); @@ -717,15 +712,15 @@ class module_console_fileEnsureDevSetting extends Command $required_options = array_diff($required_options, array($conf)); $message = 'OK'; - if ( ! ctype_digit($value)) { + if (!ctype_digit($value)) { $message = 'Not recognized'; - $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, 'Not recognized'); break; } @@ -734,7 +729,7 @@ class module_console_fileEnsureDevSetting extends Command if (count($required_options) > 0) { $output->writeln(sprintf('Miss required keys %s', implode(', ', $required_options))); - $this->errors ++; + $this->errors++; } } @@ -743,9 +738,7 @@ class module_console_fileEnsureDevSetting extends Command try { $originalConfiguration = $this->configuration->getService($ServiceName); - $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $originalConfiguration - ); + $Service = Builder::create($this->container, $originalConfiguration); } catch (\Exception $e) { return false; } @@ -762,7 +755,7 @@ class module_console_fileEnsureDevSetting extends Command return false; break; case 'memcache': - if ( ! @memcache_connect($Service->getHost(), $Service->getPort())) { + if (!@memcache_connect($Service->getHost(), $Service->getPort())) { return false; } break; @@ -773,7 +766,7 @@ class module_console_fileEnsureDevSetting 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'); } @@ -811,9 +804,7 @@ class module_console_fileEnsureDevSetting extends Command try { $originalConfiguration = $this->configuration->getService($ServiceName); - $Service = Core\Service\Builder::create( - \bootstrap::getCore(), $originalConfiguration - ); + $Service = Builder::create($this->container, $originalConfiguration); } catch (\Exception $e) { return false; } @@ -836,7 +827,7 @@ class module_console_fileEnsureDevSetting 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)); } } diff --git a/lib/classes/module/console/fileEnsureProductionSetting.class.php b/lib/classes/module/console/fileEnsureProductionSetting.class.php index 5bae4f943f..3aeacfbfe3 100644 --- a/lib/classes/module/console/fileEnsureProductionSetting.class.php +++ b/lib/classes/module/console/fileEnsureProductionSetting.class.php @@ -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 %s", $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 = 'Works !'; } else { $work_message = 'Cache server recommended'; - $this->alerts ++; + $this->alerts++; } } else { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $verification = sprintf("\t--> Verify %s : %s", 'MainCache', $work_message); @@ -173,11 +170,11 @@ class module_console_fileEnsureProductionSetting extends Command $work_message = 'Works !'; } else { $work_message = 'Opcode recommended'; - $this->alerts ++; + $this->alerts++; } } else { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $verification = sprintf("\t--> Verify %s : %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 = 'Works !'; $listChecks = true; } catch (\Exception $e) { $work_message = 'Failed - could not load Border Manager service !'; - $this->errors ++; + $this->errors++; } $output->writeln(sprintf("\t--> Verify Border Manager%s : %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, 'Not recognized'); break; case 'servername': @@ -232,15 +230,15 @@ class module_console_fileEnsureProductionSetting extends Command if (empty($url)) { $message = "should not be empty"; - $this->errors ++; + $this->errors++; } elseif ($url == 'http://sub.domain.tld/') { - $this->alerts ++; + $this->alerts++; $message = "may be wrong"; - } elseif ( ! filter_var($url, FILTER_VALIDATE_URL)) { + } elseif (!filter_var($url, FILTER_VALIDATE_URL)) { $message = "not valid"; - $this->errors ++; + $this->errors++; } elseif ($parseUrl["scheme"] !== "https") { - $this->alerts ++; + $this->alerts++; $message = "should be https"; } else { $message = "OK"; @@ -255,7 +253,7 @@ class module_console_fileEnsureProductionSetting extends Command if ($value !== false) { $message = 'Should be false'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); @@ -268,11 +266,11 @@ class module_console_fileEnsureProductionSetting extends Command $message = 'OK'; } else { $message = 'Connection not available'; - $this->errors ++; + $this->errors++; } } catch (\Exception $e) { $message = 'Unknown connection'; - $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('Miss required keys %s', implode(', ', $required))); - $this->errors ++; + $this->errors++; } return; @@ -297,34 +295,34 @@ class module_console_fileEnsureProductionSetting extends Command $work_message = 'Works !'; } else { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } } catch (\Exception $e) { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $output->writeln(sprintf("\t--> Verify connection %s : %s", $connexionName, $work_message)); $required = array('driver'); - if ( ! $connexion->has('driver')) { + if (!$connexion->has('driver')) { $output->writeln("\nConnection has no driver"); - $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("\nYour driver is not managed"); - $this->errors ++; + $this->errors++; } foreach ($connexion->all() as $conf => $value) { switch ($conf) { default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, $value, false, 'Not recognized'); break; case 'charset': @@ -332,7 +330,7 @@ class module_console_fileEnsureProductionSetting extends Command $message = 'OK'; if ($value !== 'UTF8') { $message = 'Not recognized'; - $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 = 'OK'; - if ( ! is_scalar($value)) { + if (!is_scalar($value)) { $message = 'Should be scalar'; - $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 = 'OK'; - if ( ! ctype_digit($value)) { + if (!ctype_digit($value)) { $message = 'Should be ctype_digit'; - $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 = 'OK'; - if ( ! is_scalar($value)) { + if (!is_scalar($value)) { $message = 'Should be scalar'; - $this->errors ++; + $this->errors++; } $value = '***********'; @@ -383,7 +381,7 @@ class module_console_fileEnsureProductionSetting extends Command if ($value !== 'pdo_mysql') { $message = 'MySQL recommended'; - $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('Miss required keys %s', 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 = 'Works !'; } catch (\Exception $e) { $work_message = 'Failed - could not load template engine !'; - $this->errors ++; + $this->errors++; } $output->writeln(sprintf("\t--> Verify Template engine %s : %s", $templateEngineName, $work_message)); - if ( ! $configuration->has('type')) { + if (!$configuration->has('type')) { $output->writeln("\nConfiguration has no type"); - $this->errors ++; + $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 ++; + $this->errors++; } foreach ($configuration->all() as $conf => $value) { @@ -444,7 +443,7 @@ class module_console_fileEnsureProductionSetting extends Command if ($value !== 'TemplateEngine\\Twig') { $message = 'Not recognized'; - $this->alerts ++; + $this->alerts++; } $this->printConf($output, $conf, $value, false, $message); @@ -452,15 +451,15 @@ class module_console_fileEnsureProductionSetting extends Command case 'options': $message = 'OK'; - if ( ! is_array($value)) { + if (!is_array($value)) { $message = 'Should be array'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, 'array()', false, $message); break; default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, 'unknown', false, 'Not recognized'); break; } @@ -475,7 +474,7 @@ class module_console_fileEnsureProductionSetting extends Command if ($value !== false) { $message = 'Should be false'; - $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 = 'Should be true'; - $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 = 'Not recognized'; - $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, 'Not recognized'); break; } @@ -512,7 +511,7 @@ class module_console_fileEnsureProductionSetting extends Command if (count($required) > 0) { $output->writeln(sprintf('Miss required keys %s', 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 = 'Works !'; } catch (\Exception $e) { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $output->writeln(sprintf("\t--> Verify ORM engine %s : %s", $ormName, $work_message)); - if ( ! $configuration->has('type')) { + if (!$configuration->has('type')) { $output->writeln("\nConfiguration has no type"); - $this->errors ++; + $this->errors++; } elseif ($configuration->get('type') == 'Orm\\Doctrine') { $required = array('debug', 'dbal', 'cache'); } else { $output->writeln("\nYour type is not managed"); - $this->errors ++; + $this->errors++; } foreach ($configuration->all() as $conf => $value) { @@ -552,15 +552,15 @@ class module_console_fileEnsureProductionSetting extends Command case 'options': $message = 'OK'; - if ( ! is_array($value)) { + if (!is_array($value)) { $message = 'Should be array'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, 'array()', false, $message); break; default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, 'unknown', false, 'Not recognized'); break; } @@ -573,7 +573,7 @@ class module_console_fileEnsureProductionSetting extends Command if ($value !== false) { $message = 'Should be deactivated'; - $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 = 'OK'; - if ( ! is_array($value)) { + if (!is_array($value)) { $message = 'Should be Array'; - $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 = 'Works !'; } else { - $this->alerts ++; + $this->alerts++; if ($server) { $work_message = 'Cache server recommended'; } else { @@ -610,7 +610,7 @@ class module_console_fileEnsureProductionSetting extends Command } } else { $work_message = 'Failed - could not connect !'; - $this->errors ++; + $this->errors++; } $verification = sprintf("\t--> Verify %s : %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, 'Not recognized'); break; } - if ( ! isset($cache_type['service'])) { + if (!isset($cache_type['service'])) { $output->writeln('Miss service for %s', $cache_type); - $this->errors ++; + $this->errors++; } } } if (count($required_caches) > 0) { $output->writeln(sprintf('Miss required caches %s', implode(', ', $required_caches))); - $this->errors ++; + $this->errors++; } break; case 'debug': @@ -641,7 +641,7 @@ class module_console_fileEnsureProductionSetting extends Command if ($value !== false) { $message = 'Should be false'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); @@ -654,12 +654,12 @@ class module_console_fileEnsureProductionSetting extends Command $message = 'OK'; } catch (\Exception $e) { $message = 'Failed'; - $this->errors ++; + $this->errors++; } $this->printConf($output, $conf, $value, false, $message); break; default: - $this->alerts ++; + $this->alerts++; $this->printConf($output, $conf, $value, false, 'Not recognized'); break; } @@ -667,7 +667,7 @@ class module_console_fileEnsureProductionSetting extends Command if (count($required) > 0) { $output->writeln(sprintf('Miss required keys %s', 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 = 'OK'; - if ( ! is_scalar($value)) { + if (!is_scalar($value)) { $message = 'Should be scalar'; - $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 = 'OK'; - if ( ! ctype_digit($value)) { + if (!ctype_digit($value)) { $message = 'Not recognized'; - $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, 'Not recognized'); break; } @@ -732,7 +731,7 @@ class module_console_fileEnsureProductionSetting extends Command if (count($required_options) > 0) { $output->writeln(sprintf('Miss required keys %s', 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)); } } diff --git a/lib/classes/module/console/schedulerState.class.php b/lib/classes/module/console/schedulerState.class.php index de978e42e8..3b434b5637 100644 --- a/lib/classes/module/console/schedulerState.class.php +++ b/lib/classes/module/console/schedulerState.class.php @@ -62,8 +62,7 @@ class module_console_schedulerState extends Command return self::EXITCODE_SETUP_ERROR; } - $appbox = $this->getService('phraseanet.appbox'); - $task_manager = new task_manager($appbox); + $task_manager = new task_manager($this->container); $exitCode = 0; $state = $task_manager->getSchedulerState(); diff --git a/lib/classes/module/console/schedulerStop.class.php b/lib/classes/module/console/schedulerStop.class.php index a81c1b6cdd..7395ee1f8b 100644 --- a/lib/classes/module/console/schedulerStop.class.php +++ b/lib/classes/module/console/schedulerStop.class.php @@ -39,8 +39,7 @@ class module_console_schedulerStop extends Command protected function doExecute(InputInterface $input, OutputInterface $output) { try { - $appbox = $this->getService('phraseanet.appbox'); - $task_manager = new task_manager($appbox); + $task_manager = new task_manager($this->container); $task_manager->setSchedulerState(task_manager::STATE_TOSTOP); return 0; diff --git a/lib/classes/module/console/sphinxGenerateSuggestion.class.php b/lib/classes/module/console/sphinxGenerateSuggestion.class.php index f97c7e8fed..d12603810f 100644 --- a/lib/classes/module/console/sphinxGenerateSuggestion.class.php +++ b/lib/classes/module/console/sphinxGenerateSuggestion.class.php @@ -44,7 +44,7 @@ class module_console_sphinxGenerateSuggestion extends Command $appbox = $this->getService('phraseanet.appbox'); $registry = $appbox->get_registry(); - $params = phrasea::sbas_params(); + $params = phrasea::sbas_params($this->container); foreach ($params as $sbas_id => $p) { $index = crc32( @@ -77,7 +77,7 @@ class module_console_sphinxGenerateSuggestion extends Command exec($cmd); try { - $connbas = connection::getPDOConnection($sbas_id); + $connbas = connection::getPDOConnection($this->container, $sbas_id); } catch (Exception $e) { continue; } diff --git a/lib/classes/module/console/systemClearCache.class.php b/lib/classes/module/console/systemClearCache.class.php index 9f03ade0ff..e22fef74fa 100644 --- a/lib/classes/module/console/systemClearCache.class.php +++ b/lib/classes/module/console/systemClearCache.class.php @@ -54,8 +54,7 @@ class module_console_systemClearCache extends Command $filesystem->remove($finder); if (setup::is_installed()) { - $Core = \bootstrap::getCore(); - $Core['CacheService']->flushAll(); + $this->getService('phraseanet.cache-service')->flushAll(); } $output->write('Finished !', true); diff --git a/lib/classes/module/console/systemConfigCheck.class.php b/lib/classes/module/console/systemConfigCheck.class.php index 25881142b7..3aeea34689 100644 --- a/lib/classes/module/console/systemConfigCheck.class.php +++ b/lib/classes/module/console/systemConfigCheck.class.php @@ -49,7 +49,7 @@ class module_console_systemConfigCheck extends Command $ok = true; if (setup::is_installed()) { - $registry = registry::get_instance(); + $registry = $this->container['phraseanet.registry']; $output->writeln(_('*** CHECK BINARY CONFIGURATION ***')); $ok = $this->processConstraints(setup::check_binaries($registry), $output) && $ok; @@ -77,7 +77,7 @@ class module_console_systemConfigCheck extends Command $ok = $this->processConstraints(setup::check_phrasea(), $output) && $ok; $output->writeln(""); $output->writeln(_('*** CHECK SYSTEM LOCALES ***')); - $ok = $this->processConstraints(setup::check_system_locales(), $output) && $ok; + $ok = $this->processConstraints(setup::check_system_locales($this->container), $output) && $ok; $output->writeln(""); $output->write('Finished !', true); diff --git a/lib/classes/module/console/systemMailCheck.class.php b/lib/classes/module/console/systemMailCheck.class.php index aac196f750..a4a6910120 100644 --- a/lib/classes/module/console/systemMailCheck.class.php +++ b/lib/classes/module/console/systemMailCheck.class.php @@ -48,7 +48,7 @@ class module_console_systemMailCheck extends Command $output->writeln("Processing..."); - $bad_users = User_Adapter::get_wrong_email_users($appbox); + $bad_users = User_Adapter::get_wrong_email_users($this->container); foreach ($bad_users as $email => $users) { if ($input->getOption('list')) { @@ -91,7 +91,7 @@ class module_console_systemMailCheck extends Command $id = $dialog->ask($output, 'Which id ?', ''); try { - $tmp_user = User_Adapter::getInstance($id, $appbox); + $tmp_user = User_Adapter::getInstance($id, $this->container); if ($tmp_user->get_email() != $email) { throw new Exception('Invalid user'); diff --git a/lib/classes/module/console/systemUpgrade.class.php b/lib/classes/module/console/systemUpgrade.class.php index b260d6b0a4..576756dffa 100644 --- a/lib/classes/module/console/systemUpgrade.class.php +++ b/lib/classes/module/console/systemUpgrade.class.php @@ -46,7 +46,6 @@ class module_console_systemUpgrade extends Command require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php'; $interactive = !$input->getOption('yes'); - $Core = $this->getService('phraseanet.core'); if (!$Core->getConfiguration()->isInstalled() && \setup::needUpgradeConfigurationFile()) { @@ -71,7 +70,7 @@ class module_console_systemUpgrade extends Command $connexionInc = new \SplFileInfo(__DIR__ . '/../../../../config/connexion.inc'); $configInc = new \SplFileInfo(__DIR__ . '/../../../../config/config.inc'); - $Core->getConfiguration()->upgradeFromOldConf($configInc, $connexionInc); + $this->getService('phraseanet.configuration')->upgradeFromOldConf($configInc, $connexionInc); } catch (\Exception $e) { throw new RuntimeException('Error while upgrading : ' . $e->getMessage()); } @@ -80,7 +79,7 @@ class module_console_systemUpgrade extends Command } } - if (!$Core->getConfiguration()->isInstalled()) { + if ( ! $this->getService('phraseanet.configuration')->isInstalled()) { throw new \RuntimeException('Phraseanet must be set-up (no connexion.inc / no config.inc)'); } @@ -101,7 +100,7 @@ class module_console_systemUpgrade extends Command $output->write('Upgrading...', true); $appbox = $this->getService('phraseanet.appbox'); - if (count(User_Adapter::get_wrong_email_users($appbox)) > 0) { + if (count(User_Adapter::get_wrong_email_users($this->container)) > 0) { return $output->writeln(sprintf('You have to fix your database before upgrade with the system:mailCheck command ')); } diff --git a/lib/classes/module/console/taskState.class.php b/lib/classes/module/console/taskState.class.php index c8dd41243c..c7a7fb9a32 100644 --- a/lib/classes/module/console/taskState.class.php +++ b/lib/classes/module/console/taskState.class.php @@ -77,15 +77,14 @@ class module_console_taskState extends Command return self::EXITCODE_BAD_ARGUMENT; } - $appbox = $this->getService('phraseanet.appbox'); - $task_manager = new task_manager($appbox); + $task_manager = new task_manager($this->container); $taskPID = $taskState = NULL; $exitCode = 0; $task = NULL; try { - $task = $task_manager->getTask($this->container, $task_id); + $task = $task_manager->getTask($task_id); $taskPID = $task->getPID(); $taskState = $task->getState(); } catch (Exception_NotFound $e) { diff --git a/lib/classes/module/console/tasklist.class.php b/lib/classes/module/console/tasklist.class.php index 3d639db352..e9941d9f03 100644 --- a/lib/classes/module/console/tasklist.class.php +++ b/lib/classes/module/console/tasklist.class.php @@ -47,8 +47,8 @@ class module_console_tasklist extends Command try { $appbox = $this->getService('phraseanet.appbox'); - $task_manager = new task_manager($appbox); - $tasks = $task_manager->getTasks($this->container); + $task_manager = new task_manager($this->container); + $tasks = $task_manager->getTasks(); if (count($tasks) === 0) { $output->writeln('No tasks on your install !'); diff --git a/lib/classes/module/console/taskrun.class.php b/lib/classes/module/console/taskrun.class.php index e00298a2fc..820aada16e 100644 --- a/lib/classes/module/console/taskrun.class.php +++ b/lib/classes/module/console/taskrun.class.php @@ -82,7 +82,7 @@ class module_console_taskrun extends Command } $appbox = $this->getService('phraseanet.appbox'); - $task_manager = new task_manager($appbox); + $task_manager = new task_manager($this->container); if ($input->getOption('runner') === task_abstract::RUNNER_MANUAL) { $schedStatus = $task_manager->getSchedulerState(); @@ -107,9 +107,8 @@ class module_console_taskrun extends Command $logfile = __DIR__ . '/../../../../logs/task_' . $task_id . '.log'; $handler = new Handler\RotatingFileHandler($logfile, 10); - $this->container['phraseanet.core']['monolog']->pushHandler($handler); - $logger = $this->container['phraseanet.core']['monolog']; - $this->task = $task_manager->getTask($task_id, $logger); + $this->container['monolog']->pushHandler($handler); + $this->task = $task_manager->getTask($task_id, $this->container['monolog']); register_tick_function(array($this, 'tick_handler'), true); declare(ticks = 1);