diff --git a/bin/doctrine b/bin/doctrine index 82f657c4f2..c2e5b8d14a 100755 --- a/bin/doctrine +++ b/bin/doctrine @@ -34,13 +34,26 @@ try new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); + + $serviceName = $configuration->getOrm(); + $confService = $configuration->getService($serviceName); + + if($confService->get("type") !== 'doctrine') + { + exit(sprintf("Doctrine is not declared as your ORM but %s is", $confService->get("type"))); + } - $doctrine = new Phrasea\Core\Service\Doctrine($configuration->getDoctrine()->all()); + $ormService = \Alchemy\Phrasea\Core\ServiceBuilder::build( + $serviceName + , \Alchemy\Phrasea\Core\ServiceBuilder::ORM + , $confService->get("type") + , $confService->get("options") + ); - $app = new Application("Phraseanet Doctrine Console", $doctrine->getVersion()); + $em = $ormService->getService(); + /* @var $em \Doctrine\ORM\EntityManager */ - - $em = $doctrine->getEntityManager(); + $app = new Application("Phraseanet Doctrine Console", $ormService->getVersion()); $helpers = array( 'db' => new \Doctrine\DBAL\Tools\Console\Helper\ConnectionHelper($em->getConnection()), diff --git a/config/config.sample.yml b/config/config.sample.yml index da429f3104..f8d70ebd59 100644 --- a/config/config.sample.yml +++ b/config/config.sample.yml @@ -4,7 +4,7 @@ environment : dev -#declare all your environment configuration +#Declare all your environment configurations ################# # DEVELOPPEMENT # @@ -16,81 +16,16 @@ dev: maintenance: false debug: true display_errors: true - #Configure your phraseanet application connection - database: - host: - port: - dbname: - user: - password: + + #Assign your phraseanet application connection + #Connections are defined in connexions.yml configuration file + database: main_connexion + + #Assign your template engine service & ORM service + #Services are defined in service.yml configuration file + template_engine: twig_debug + orm: doctrine_dev - # Doctrine scope refers to Doctrine configuration - # Pls refer to Doctrine documentation abstraction layer for database connection configuration - # DBAL connection : http://www.doctrine-project.org/docs/dbal/2.1/en/reference/configuration.html - doctrine: - #configure the doctrine database connection - dbal: - driver: - host: - port: - dbname: - user: - password: - charset: UTF8 - #configure orm - orm: - #Available cache driver [memcached, apc, array] - #Query cache : is used to cache the transformation of a DQL query to its SQL counterpart - #Result cache : is used to cache the results of your queries - #Metadata cache : is used to cache entity class metadatas - cache: - query: array - result: array - metadata: array - - #Configure how to log SQL query - #Available type values [echo , monolog] - # echo : logs to the standard output using echo/var_dump. - # monolog : logs with monolog service using different log handler - log: - #Active logs - enable: false - #Define how logs are handling - #Available type values [echo , monolog] - # echo : logs to the standard output using echo/var_dump. - # monolog : logs with monolog service using different log handler - type: monolog - #Define which handler to use see monolog configuration scope - handler: rotate - #Define output of logs - #Available output [normal, json, yaml] - # normal : output logs in a var_dump formatted style - # json : output logs in json - # yml : output logs yml - output: json - #Define the logs filename - filename: dev-doctrine-query.log - #Define how many day of logs is keeping. Override default value - max_day: 2 - - # Monolog Service Configuration - # Handlers type [stream, rotatingFile] - # stream : store logs to a single file - # rotatingFile: logs to files that are rotated every day and a limited number of files are kept - monolog: - #Define default ouput - output: yaml - #Define handlers - #Only stream & rotating file are currently available - handlers: - main: - type: stream - #Rotate handler is used to rotate logs every day in a new file - #max_day is used to keep the defined number of day logs - rotate: - type: rotatingFile - max_day: 10 - ############## # PRODUCTION # ############## @@ -100,42 +35,10 @@ prod: maintenance: false debug: false display_errors: false - database: - host: - port: - dbname: - user: - password: - - doctrine: - dbal: - driver: - host: - port: - dbname: - user: - password: - charset: UTF8 - orm: - cache: - query: apc - result: apc - metadata: apc - log: - enable: true - type: monolog - handler: rotate - output: json - filename: prod-doctrine-query.log - - monolog: - output: yaml - handlers: - main: - type: stream - rotate: - type: rotatingFile - max_day: 10 + database: main_connexion + + template_engine: twig + orm: doctrine_prod ############## # TEST # @@ -146,37 +49,9 @@ test: maintenance: false debug: true display_errors: true - database: - host: - port: - dbname: - user: - password: - #doctrine use a sqlite base to run tests - doctrine: - dbal: - driver: pdo_sqlite - path: - charset: UTF8 - orm: - cache: - query: array - result: array - metadata: array - log: - enable: true - type: monolog - handler: rotate - output: json - filename: test-doctrine-query.log - monolog: - output: yaml - handlers: - main: - type: stream - rotate: - type: rotatingFile - max_day: 10 - + database: main_connexion + + template_engine: twig_debug + orm: doctrine_dev \ No newline at end of file diff --git a/config/connexions.sample.yml b/config/connexions.sample.yml new file mode 100644 index 0000000000..6370779763 --- /dev/null +++ b/config/connexions.sample.yml @@ -0,0 +1,19 @@ +#Here you can define many connexions configurations +#Please refer to Doctrine documentation abstraction layer for database connection configuration +#DBAL connection : http://www.doctrine-project.org/docs/dbal/2.1/en/reference/configuration.html + +#Define a connexion to MYSQL database named main_connexion +main_connexion: + host: + port: + user: + password: + dbname: + driver: pdo_mysql + charset: UTF8 + +#Define a connexion to a SQLite database named test_connexion +test_connexion: + driver: pdo_sqlite + path: /PATH/TO/SQLITE/DATABASE + charset: UTF8 diff --git a/config/service.yml b/config/service.yml deleted file mode 100644 index 0e510e4f85..0000000000 --- a/config/service.yml +++ /dev/null @@ -1,7 +0,0 @@ -#Twig services options -twig: - options: - charset: utf-8 - strict_variables: true - autoescape: true - optimizer: true \ No newline at end of file diff --git a/config/services.sample.yml b/config/services.sample.yml new file mode 100644 index 0000000000..3541abae8a --- /dev/null +++ b/config/services.sample.yml @@ -0,0 +1,113 @@ +#Define a template engine service +#Only Twig is avalaible as a template engine service +#see http://twig.sensiolabs.org/ + +#Define the service name first +twig: + #Template engine type + type: twig + options: + #When set to true, the generated templates have a __toString() method that you can use to display the generated nodes + debug: false + #The charset used by the templates + charset: utf-8 + #Twig will silently ignore invalid variables (variables and or attributes/methods that do not exist) + #And replace them with a null value. When set to true, Twig throws an exception instead (default to false) + strict_variables: true + #Escaper adds automatic output escaping to Twig. It defines a new tag, autoescape, and a new filter, raw + autoescape: true + #Optimize the node tree before compilation + optimizer: true + +twig_debug: + type: twig + options: + debug: true + charset: utf-8 + strict_variables: true + autoescape: true + optimizer: true + +#Doctrine developement service options +#Service name +doctrine_dev: + type: doctrine + options: + #Set automatically propers values for debug + #Query & result caches are setted to Array cache + #Auto-generating Proxy Classes is setted to false + debug: true + #Assign a connexion from connexions.yml to the DataBase Abstraction Layer + dbal: main_connexion + orm: + #Available cache driver [memcached, apc, array] + #Query cache : is used to cache the transformation of a DQL query to its SQL counterpart + #Result cache : is used to cache the results of your queries + #Metadata cache : is used to cache entity class metadatas + cache: + query: array + result: array + metadata: array + # Assign a service to log doctrine queries + log: query_logger + +# Doctrine test service options +doctrine_test: + type: doctrine + options: + debug: true + #Doctrine use a different connection configuration base to run tests + dbal: test_connexion + orm: + cache: + query: array + result: array + metadata: array + log: query_logger + +# Doctrine production service options +doctrine_prod: + type: doctrine + options: + debug: false + dbal: main_connexion + orm: + cache: + query: apc + result: apc + metadata: apc + log: query_logger + + +# Define a Log service +# This one is defined to handle the logs of doctrine queries +# Only Monolog is available as a logger service +# Please Notice that for doctrine ONLY a echo logger service is available, see below +# Monolog logger use the PHP Monolog library to handle logs using differents handlers +query_logger: + type: monolog + options: + #You can precise the output format + #This option is only available when log are used to log doctrine queries + #Available output [normal, json, yaml] + # normal : output logs in a var_dump formatted style + # json : output logs in json + # yml : output logs yml + output: json + #Name used for the Monolog channel + channel: query-logger + #Define how the logs will be handled + #Avalaibale Handler are [rotate, stream] + #Rotate handler is used to stores logs to files that are rotated every day + #And a limited number of files are kept by defining the max_day value + #Stream handler is used to stores logs in a single local file + handler: rotate + max_day: 2 + #Name of the file where logs are written + filename: doctrine-query.log + +# Define a echo log service for Doctrine +# echo logger logs doctrine queries to the standard output using echo/var_dump +# Notice that echo logger do not have options +sql_logger: + type: echo \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Application/Setup.php b/lib/Alchemy/Phrasea/Application/Setup.php index 03b89545de..c9d681a32e 100644 --- a/lib/Alchemy/Phrasea/Application/Setup.php +++ b/lib/Alchemy/Phrasea/Application/Setup.php @@ -46,39 +46,99 @@ return call_user_func(function() } elseif (\setup::needUpgradeConfigurationFile()) { - //copy sample - $file = __DIR__ . "/../../../../config/config.sample.yml"; - $file1 = __DIR__ . "/../../../../config/config.yml"; - if (!copy($file, $file1)) + $registry = \registry::get_instance(); + + //copy config sample + $configSampleFile = __DIR__ . "/../../../../config/config.sample.yml"; + $configFile = __DIR__ . "/../../../../config/config.yml"; + + if (!copy($configSampleFile, $configFile)) { - throw new \Exception(sprintf("Unable to copy %s", $file1)); + throw new \Exception(sprintf("Unable to copy %s", $configSampleFile)); } - //get connexion credentials - $conn = \connection::getPDOConnection(); - $credentials = $conn->get_credentials(); + //copy service sample + $serviceSampleFile = __DIR__ . "/../../../../config/services.sample.yml"; + $serviceFile = __DIR__ . "/../../../../config/services.yml"; + + if (!copy($serviceSampleFile, $serviceFile)) + { + throw new \Exception(sprintf("Unable to copy %s", $serviceSampleFile)); + } + + //copy connexion sample + $connexionSampleFile = __DIR__ . "/../../../../config/connexions.sample.yml"; + $connexionFile = __DIR__ . "/../../../../config/connexions.yml"; + + if (!copy($connexionSampleFile, $connexionFile)) + { + throw new \Exception(sprintf("Unable to copy %s", $connexionFile)); + } //get configuration object - $app = new \Alchemy\Phrasea\Core\Configuration\Application(); + $appConf = new \Alchemy\Phrasea\Core\Configuration\Application(); $parser = new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml(); - $handler = new \Alchemy\Phrasea\Core\Configuration\Handler($app, $parser); + $handler = new \Alchemy\Phrasea\Core\Configuration\Handler($appConf, $parser); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); //refactor credentials $connexionINI = array(); - foreach ($credentials as $key => $value) - { - $key = $key == 'hostname' ? 'host' : $key; - $connexionINI[$key] = (string) $value; - } - //write credentials to config file - $configuration->setAllDatabaseConnexion($connexionINI); + + require __DIR__ . "/../../../../config/connexion.inc"; + + $connexionINI['host'] = $hostname; + $connexionINI['port'] = $port; + $connexionINI['user'] = $user; + $connexionINI['password'] = $password; + $connexionINI['dbname'] = $dbname; + $connexionINI['driver'] = 'pdo_mysql'; + $connexionINI['charset'] = 'UTF8'; + $request = $app["request"]; //write servername $serverName = $request->getScheme() . '://' . $request->getHttpHost() . '/'; - $configuration->setServerName($serverName); - $app->redirect("/"); + //write credentials to connexion file + $connexionFile = $appConf->getConnexionFile(); + + $connexion = array( + 'main_connexion' => $connexionINI, + 'test_connexion' => array( + 'driver' => 'pdo_sqlite', + 'path' => $registry->get("GV_RootPath") . 'lib/unitTest/tests.sqlite', + 'charset' => 'UTF8' + )); + + $yaml = $configuration->getConfigurationHandler()->getParser()->dump($connexion, 2); + + if (!file_put_contents($connexionFile->getPathname(), $yaml) !== false) + { + throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $connexionFile->getPathname())); + } + + //rewrite service file + $serviceFile = $appConf->getServiceFile(); + $service = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile); + $yaml = $configuration->getConfigurationHandler()->getParser()->dump($service, 5); + + if (!file_put_contents($serviceFile->getPathname(), $yaml) !== false) + { + throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $serviceFile->getPathname())); + } + $arrayConf = $configuration->all(); + + //rewrite main conf + foreach ($arrayConf as $key => $value) + { + if (is_array($value) && array_key_exists('phraseanet', $value)) + { + $arrayConf[$key]["phraseanet"]["servername"] = $serverName; + } + } + + $configuration->write($arrayConf); + + $app->redirect("/setup/installer/"); } else { diff --git a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php index 5652909f98..eb7ba825f0 100644 --- a/lib/Alchemy/Phrasea/Controller/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Controller/Setup/Installer.php @@ -98,10 +98,9 @@ class Installer implements ControllerProviderInterface \phrasea::use_i18n(\Session_Handler::get_locale()); $ld_path = array(__DIR__ . '/../../../../../templates/web'); - $loader = new \Twig_Loader_Filesystem($ld_path); - $twig = new \Twig_Environment($loader); + $twig = new \Twig_Environment($loader); $twig->addExtension(new \Twig_Extensions_Extension_I18n()); $request = $app['request']; @@ -180,23 +179,34 @@ class Installer implements ControllerProviderInterface new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); + if ($configuration->isInstalled()) { - // Get Entity Manager using the new configuration - $doctrineConf = $configuration->getDoctrine()->all(); - $doctrine = new \Alchemy\Phrasea\Core\Service\Doctrine($doctrineConf); + $serviceName = $configuration->getOrm(); + $confService = $configuration->getService($serviceName); - $em = $doctrine->getEntityManager(); - /* @var $em \Doctrine\ORM\EntityManager */ + $ormService = \Alchemy\Phrasea\Core\ServiceBuilder::build( + $serviceName + , \Alchemy\Phrasea\Core\ServiceBuilder::ORM + , $confService->get("type") + , $confService->get("options") + ); - $metadatas = $em->getMetadataFactory()->getAllMetadata(); - - if (!empty($metadatas)) + if ($ormService->getType() === 'doctrine') { - // Create SchemaTool - $tool = new \Doctrine\ORM\Tools\SchemaTool($em); - // Create schema - $tool->createSchema($metadatas); + /* @var $em \Doctrine\ORM\EntityManager */ + + $em = $ormService->getService(); + + $metadatas = $em->getMetadataFactory()->getAllMetadata(); + + if (!empty($metadatas)) + { + // Create SchemaTool + $tool = new \Doctrine\ORM\Tools\SchemaTool($em); + // Create schema + $tool->createSchema($metadatas); + } } } diff --git a/lib/Alchemy/Phrasea/Core.php b/lib/Alchemy/Phrasea/Core.php index b98a110580..2588c35e91 100644 --- a/lib/Alchemy/Phrasea/Core.php +++ b/lib/Alchemy/Phrasea/Core.php @@ -50,13 +50,11 @@ class Core extends \Pimple static::initAutoloads(); - $handler = new \Alchemy\Phrasea\Core\Configuration\Handler( - new \Alchemy\Phrasea\Core\Configuration\Application(), - new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() + $handler = new Core\Configuration\Handler( + new Core\Configuration\Application(), + new Core\Configuration\Parser\Yaml() ); - $this->configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - - $this->configuration->setEnvironnement($environement); + $this->configuration = new Core\Configuration($handler, $environement); /** * Set version @@ -66,21 +64,35 @@ class Core extends \Pimple return new Core\Version(); }); + $core = $this; + /** * Set Entity Manager using configuration */ - $doctrineConf = $this->configuration->getDoctrine()->all(); - $this['EM'] = $this->share(function() use ($doctrineConf) + $this['EM'] = $this->share(function() use ($core) { - $doctrine = new Core\Service\Doctrine($doctrineConf); - return $doctrine->getEntityManager(); + $serviceName = $core->getConfiguration()->getOrm(); + + $service = $core->getService( + $serviceName + , Core\ServiceBuilder::ORM + ); + + return $service->getService(); }); - $twigConf = $this->configuration->getServices()->get('twig'); - $this["Twig"] = $this->share(function() use ($twigConf) + + + $this["Twig"] = $this->share(function() use ($core) { - $twig = new Core\Service\Twig($twigConf); - return $twig->getTwig(); + $serviceName = $core->getConfiguration()->getTemplating(); + + $service = $core->getService( + $serviceName + , Core\ServiceBuilder::TEMPLATE_ENGINE + ); + + return $service->getService(); }); if (\setup::is_installed()) @@ -149,11 +161,9 @@ class Core extends \Pimple * * @param type $environnement */ - private function init($environnement) + private function init() { - $this->loadConf($environnement); - - if ($this->getConfiguration()->displayErrors()) + if ($this->getConfiguration()->isDisplayingErrors()) { ini_set('display_errors', 1); error_reporting(E_ALL); @@ -204,7 +214,7 @@ class Core extends \Pimple { return $this['Twig']; } - + /** * Getter * @@ -375,7 +385,6 @@ class Core extends \Pimple public static function initAutoloads() { require_once __DIR__ . '/../../vendor/symfony/src/Symfony/Component/ClassLoader/UniversalClassLoader.php'; - require_once __DIR__ . '/../../vendor/Twig/lib/Twig/Autoloader.php'; require_once __DIR__ . '/../../vendor/Twig-extensions/lib/Twig/Extensions/Autoloader.php'; @@ -388,13 +397,11 @@ class Core extends \Pimple $loader->registerNamespaces(array( 'Alchemy' => __DIR__ . '/../..', - 'Symfony\\Component\\Yaml' => realpath(__DIR__ . '/../../vendor/symfony/src'), - 'Symfony\\Component\\Console' => realpath(__DIR__ . '/../../vendor/symfony/src'), - 'Symfony\\Component\\Serializer' => realpath(__DIR__ . '/../../vendor/symfony/src'), - 'Symfony\\Component\\DependencyInjection' => realpath(__DIR__ . '/../../vendor/symfony/src'), + 'Symfony' => realpath(__DIR__ . '/../../vendor/symfony/src'), 'Doctrine\\ORM' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib'), 'Doctrine\\DBAL' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib'), 'Doctrine\\Common' => realpath(__DIR__ . '/../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib'), + 'Doctrine\\Common\\DataFixtures' => realpath(__DIR__ . '/../../vendor/data-fixtures/lib'), 'Entities' => realpath(__DIR__ . '/../../Doctrine/'), 'Repositories' => realpath(__DIR__ . '/../../Doctrine/'), 'Proxies' => realpath(__DIR__ . '/../../Doctrine/'), @@ -440,4 +447,16 @@ class Core extends \Pimple return $this->conf->getEnvironnement(); } + public function getService($serviceName, $serviceScope) + { + $configuration = $this->configuration->getService($serviceName); + + return Core\ServiceBuilder::build( + $serviceName + , $serviceScope + , $configuration->get('type') + , $configuration->get('options') + ); + } + } diff --git a/lib/Alchemy/Phrasea/Core/Configuration.php b/lib/Alchemy/Phrasea/Core/Configuration.php index 51f755b6c6..b1c1ea7a2c 100644 --- a/lib/Alchemy/Phrasea/Core/Configuration.php +++ b/lib/Alchemy/Phrasea/Core/Configuration.php @@ -24,7 +24,7 @@ use Alchemy\Phrasea\Core\Configuration\Parser as ConfigurationParser; */ class Configuration { - + /** * The finale configuration values as an array * @var ParameterBag\ParameterBag @@ -47,11 +47,12 @@ class Configuration * * @param type $envName the name of the loaded environnement */ - public function __construct(Configuration\Handler $handler) + public function __construct(Configuration\Handler $handler, $environment = null) { $this->configurationHandler = $handler; $this->installed = false; - + $this->environment = $environment; + try { $handler->getSpecification()->getConfigurationFile(); @@ -89,7 +90,7 @@ class Configuration */ public function getEnvironnement() { - if( null === $this->environment) + if (null === $this->environment && $this->isInstalled()) { $this->getConfiguration(); } @@ -106,37 +107,6 @@ class Configuration $this->environment = $environement; } - /** - * Return the DBAL Doctrine configuration - * - * @return ParameterBag - */ - public function getDoctrine() - { - $doctrine = $this->getConfiguration()->get('doctrine', array()); //get doctrine scope - - if (count($doctrine) > 0) - { - $doctrine["debug"] = $this->isDebug(); //set debug - - if (!!$doctrine["log"]['enable']) - { - $logger = isset($doctrine["log"]["type"]) ? $doctrine["log"]["type"] : 'monolog'; - - if (!in_array($doctrine["log"]["type"], $this->getAvailableDoctrineLogger())) - { - throw new \Exception(sprintf('Unknow logger %s', $logger)); - } - - $doctrineLogger = $this->getConfiguration()->get($logger); //set logger - - $doctrine["logger"] = $doctrineLogger; - } - } - - return new ParameterBag($doctrine); - } - /** * Check if current environnement is on debug mode * Default to false @@ -182,7 +152,7 @@ class Configuration * Default to false * @return boolean */ - public function displayErrors() + public function isDisplayingErrors() { $phraseanet = $this->getPhraseanet(); @@ -204,7 +174,7 @@ class Configuration */ public function getPhraseanet() { - $phraseanetConf = $this->getConfiguration()->get('phraseanet', array()); + $phraseanetConf = $this->getConfiguration()->get('phraseanet'); return new ParameterBag($phraseanetConf); } @@ -227,13 +197,13 @@ class Configuration { if (null === $this->configuration) { - $this->configuration = new Configuration\Parameter(); + $this->configuration = new ParameterBag(); if ($this->installed) { $configuration = $this->configurationHandler->handle($this->environment); $this->environment = $this->configurationHandler->getSelectedEnvironnment(); - $this->configuration = new Configuration\Parameter($configuration); + $this->configuration = new ParameterBag($configuration); } } @@ -255,9 +225,39 @@ class Configuration * * @return ParameterBag */ - public function getConnexion() + public function getConnexion($name = 'main_connexion') { - return new ParameterBag($this->getPhraseanet()->get('database')); + $connexions = $this->getConnexions(); + + try + { + $conn = $connexions->get($name); + } + catch (\Exception $e) + { + throw new \Exception(sprintf('Unknow connexion name %s declared in %s' + , $name + , $this->configurationHandler + ->getSpecification() + ->getConnexionFile() + ->getPathname() + ) + ); + } + + return new Parameterbag($conn); + } + + /** + * Return all connexions defined in connexions.yml + * @return ParameterBag + */ + public function getConnexions() + { + return new ParameterBag($this->configurationHandler->getParser()->parse( + $this->configurationHandler->getSpecification()->getConnexionFile() + ) + ); } /** @@ -282,96 +282,15 @@ class Configuration } /** - * Write into the main file connexion credentials defined in $connexion - * @param array $connexion Array of connexion credentials - * @return Configuration - */ - public function setAllDatabaseConnexion(Array $connexion) - { - $arrayConf = $this->all(); - - foreach ($arrayConf as $key => $value) - { - if (is_array($value) && array_key_exists('phraseanet', $value)) - { - foreach ($arrayConf[$key]['phraseanet'] as $kee => $value) - { - if ($kee === 'database') - { - $arrayConf[$key]['phraseanet']['database'] = $connexion; - } - } - } - } - - $connexion["driver"] = 'pdo_mysql'; - $connexion['charset'] = 'UTF8'; - - foreach ($arrayConf as $key => $value) - { - if (is_array($value) && array_key_exists('phraseanet', $value)) - { - foreach ($arrayConf[$key]['doctrine'] as $kee => $value) - { - if ($kee === 'dbal') - { - if ($key == 'test') - { - $arrayConf[$key]['doctrine']['dbal'] = $this->getTestDBCredentials(); - } - else - { - $arrayConf[$key]['doctrine']['dbal'] = $connexion; - } - break; - } - } - } - } - - $this->write($arrayConf, FILE_APPEND, true); - - return $this; - } - - /** - * Return all services defined in service.yml + * Return all services defined in services.yml * @return ParameterBag */ public function getServices() { - $serviceFile = $this->configurationHandler->getSpecification()->getServiceFile(); - $services = $this->configurationHandler->getParser()->parse($serviceFile); - - return new ParameterBag($services); - } - - /** - * Write into the main file the serverName - * @param type $serverName - * @return Configuration - */ - public function setServerName($serverName) - { - $arrayConf = $this->all(); - - foreach ($arrayConf as $key => $value) - { - if (is_array($value) && array_key_exists('phraseanet', $value)) - { - foreach ($arrayConf[$key]['phraseanet'] as $kee => $value) - { - if ($kee === 'servername') - { - $arrayConf[$key]['phraseanet']['servername'] = $serverName; - } - } - } - } - - $this->write($arrayConf, FILE_APPEND, true); - - return $this; + return new ParameterBag($this->configurationHandler->getParser()->parse( + $this->getServiceFile() + ) + ); } /** @@ -427,16 +346,97 @@ class Configuration } /** - * Return the test database credentials - * @return Array + * Return configuration service for template_engine + * @return string */ - private function getTestDBCredentials() + public function getTemplating() { - return array( - 'driver' => 'pdo_sqlite', - 'path' => __DIR__ . '/../../../unitTest/tests.sqlite', - 'charset' => 'UTF8' - ); + return $this->getConfiguration()->get('template_engine'); + } + + /** + * Return configuration service for orm + * @return string + */ + public function getOrm() + { + return $this->getConfiguration()->get('orm'); + } + + /** + * Return the selected service configuration + * + * @param type $name + * @return ParameterBag + */ + public function getService($name = 'twig') + { + $services = $this->getServices(); + + try + { + $template = $services->get($name); + } + catch (\Exception $e) + { + throw new \Exception(sprintf('Unknow service name %s declared in %s' + , $name + , $this->configurationHandler + ->getSpecification() + ->getServiceFile() + ->getPathname() + ) + ); + } + + return new ParameterBag($template); + } + + /** + * return the service file + * @return \SplFileObject + */ + public function getServiceFile() + { + return $this->configurationHandler->getSpecification()->getServiceFile(); + } + + /** + * Return the connexion file + * @return \SplFileObject + */ + public function getConnexionFile() + { + return $this->configurationHandler->getSpecification()->getConnexionFile(); + } + + /** + * Refresh the configuration + * @return Configuration + */ + public function refresh() + { + try + { + $this->configurationHandler->getSpecification()->getConfigurationFile(); + + $this->installed = true; + } + catch (\Exception $e) + { + $this->installed = false; + } + + $this->configuration = new ParameterBag(); + + if ($this->installed) + { + $configuration = $this->configurationHandler->handle($this->environment); + $this->environment = $this->configurationHandler->getSelectedEnvironnment(); + $this->configuration = new ParameterBag($configuration); + } + + return $this; } } \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/Configuration/Application.php b/lib/Alchemy/Phrasea/Core/Configuration/Application.php index f18e1dc0d2..f0be6f3da4 100644 --- a/lib/Alchemy/Phrasea/Core/Configuration/Application.php +++ b/lib/Alchemy/Phrasea/Core/Configuration/Application.php @@ -89,15 +89,25 @@ class Application implements Specification { return new \SplFileObject($this->getConfigurationPathName()); } - - /** + + /** * Return the main configuration file * * @return \SplFileObject */ public function getServiceFile() { - return new \SplFileObject(__DIR__ . '/../../../../../config/service.yml'); + return new \SplFileObject(__DIR__ . '/../../../../../config/services.yml'); + } + + /** + * Return the main configuration file + * + * @return \SplFileObject + */ + public function getConnexionFile() + { + return new \SplFileObject(__DIR__ . '/../../../../../config/connexions.yml'); } } diff --git a/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Monolog.php b/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Monolog.php new file mode 100644 index 0000000000..7a4044b2a4 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Monolog.php @@ -0,0 +1,54 @@ +options["output"]) ? $this->options["output"] : self::JSON_OUTPUT; + + if (!in_array($output, $this->outputs)) + { + throw new \Exception(sprintf('Unknow log output class %s', $output)); + } + + return new MonologSQLLogger($this->monolog, $output); + } + + public function getType() + { + return 'doctrine_monolog'; + } + +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Normal.php b/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Normal.php new file mode 100644 index 0000000000..b4b74806e4 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Service/Log/Doctrine/Normal.php @@ -0,0 +1,48 @@ + 'RotatingFile' + ,'stream' => 'Stream' + ); + + /** + * + * @var \Monolog\Logger + */ + protected $monolog; + + public function __construct($name, Array $options) + { + parent::__construct($name, $options); + + //defaut to main handler + $handler = isset($options["handler"]) ? $options["handler"] : false; + + if (!$handler) + { + throw new \Exception("You must specify at least one monolog handler"); + } + + if (!array_key_exists($handler, $this->handlers)) + { + throw new \Exception(sprintf('Unknow monolog handler %s'), $handlerType); + } + + $handlerName = $this->handlers[$handler]; + + $handlerClassName = sprintf('\Monolog\Handler\%sHandler', $handlerName); + + if (!class_exists($handlerClassName)) + { + throw new \Exception(sprintf('Unknow monolog handler class %s', $handlerClassName)); + } + + if (!isset($options["filename"])) + { + throw new \Exception('you must specify a file to write "filename: my_filename"'); + } + + $logPath = __DIR__ . '/../../../../logs'; + + $file = sprintf('%s/%s', $logPath, $options["filename"]); + + if ($handler == 'rotate') + { + $maxDay = isset($options["max_day"]) ? (int) $options["max_day"] : self::DEFAULT_MAX_DAY; + + $handlerInstance = new $handlerClassName($file, $maxDay); + } + else + { + $handlerInstance = new $handlerClassName($file); + } + + $channel = isset($options["channel"]) ? $options["channel"] : false; + + $monologLogger = new \Monolog\Logger($channel); + + $monologLogger->pushHandler($handlerInstance); + + $this->monolog = $monologLogger; + } + + public function getService() + { + return $this->monolog; + } + + public function getType() + { + return 'monolog'; + } + + public function getScope() + { + return 'log'; + } + +} + diff --git a/lib/Alchemy/Phrasea/Core/Service/Doctrine.php b/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php similarity index 53% rename from lib/Alchemy/Phrasea/Core/Service/Doctrine.php rename to lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php index a462ccc32c..8dfdea6d1f 100644 --- a/lib/Alchemy/Phrasea/Core/Service/Doctrine.php +++ b/lib/Alchemy/Phrasea/Core/Service/Orm/Doctrine.php @@ -9,10 +9,15 @@ * file that was distributed with this source code. */ -namespace Alchemy\Phrasea\Core\Service; +namespace Alchemy\Phrasea\Core\Service\Orm; -use Doctrine\DBAL\Types\Type; -use Doctrine\Common\Cache\AbstractCache; +use Alchemy\Phrasea\Core, + Alchemy\Phrasea\Core\Service, + Alchemy\Phrasea\Core\Service\ServiceAbstract, + Alchemy\Phrasea\Core\Service\ServiceInterface; + +use Doctrine\DBAL\Types\Type, + Doctrine\Common\Cache\AbstractCache; /** * @@ -20,38 +25,43 @@ use Doctrine\Common\Cache\AbstractCache; * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ -class Doctrine +class Doctrine extends ServiceAbstract implements ServiceInterface { const MEMCACHED = 'memcached'; const ARRAYCACHE = 'array'; const APC = 'apc'; + protected $outputs = array( + 'json', 'yaml', 'normal' + ); + protected $loggers = array( + 'monolog', 'echo' + ); protected $entityManager; - public function __construct(Array $doctrineConfiguration = array()) + public function __construct($name, Array $options = array()) { - require_once __DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php'; + parent::__construct($name, $options); static::loadClasses(); - + $config = new \Doctrine\ORM\Configuration(); + $handler = new Core\Configuration\Handler( + new Core\Configuration\Application(), + new Core\Configuration\Parser\Yaml() + ); + + $phraseaConfig = new Core\Configuration($handler); + /* * debug mode */ - $debug = isset($doctrineConfiguration["debug"]) ? : false; + $debug = isset($options["debug"]) ? : false; /* * doctrine cache */ - $cache = isset($doctrineConfiguration["orm"]["cache"]) ? $doctrineConfiguration["orm"]["cache"] : false; - /* - * doctrine log configuration - */ - $log = isset($doctrineConfiguration["log"]) ? $doctrineConfiguration["log"] : false; - /* - * service logger configuration - */ - $logger = !isset($doctrineConfiguration['logger']) ? : $doctrineConfiguration['logger']; + $cache = isset($options["orm"]["cache"]) ? $options["orm"]["cache"] : false; /* * default query cache & meta chache @@ -59,10 +69,17 @@ class Doctrine $metaCache = $this->getCache(); $queryCache = $this->getCache(); + //Handle logs + $logServiceName = isset($options["log"]) ? $options["log"] : false; + + if ($logServiceName) + { + $serviceConf = $phraseaConfig->getService($logServiceName); + $this->handleLogs($config, $logServiceName, $serviceConf->all()); + } + //handle cache $this->handleCache($metaCache, $queryCache, $cache, $debug); - //Handle logs - $this->handleLogs($config, $log, $logger); //set caches $config->setMetadataCacheImpl($metaCache); @@ -74,7 +91,7 @@ class Doctrine $chainDriverImpl = new \Doctrine\ORM\Mapping\Driver\DriverChain(); $driverYaml = new \Doctrine\ORM\Mapping\Driver\YamlDriver( - array(__DIR__ . '/../../../../conf.d/Doctrine') + array(__DIR__ . '/../../../../../conf.d/Doctrine') ); $chainDriverImpl->addDriver($driverYaml, 'Entities'); @@ -83,15 +100,24 @@ class Doctrine $config->setMetadataDriverImpl($chainDriverImpl); - $config->setProxyDir(realpath(__DIR__ . '/../../../../Doctrine/Proxies')); + $config->setProxyDir(realpath(__DIR__ . '/../../../../../Doctrine/Proxies')); $config->setProxyNamespace('Proxies'); - $dbalConf = isset($doctrineConfiguration["dbal"]) ? $doctrineConfiguration["dbal"] : false; + $connexion = isset($options["dbal"]) ? $options["dbal"] : false; - if (!$dbalConf) + if(!$connexion) { - throw new \Exception("Unable to read dbal configuration"); + throw new \Exception("Missing dbal connexion for doctrine"); + } + + try + { + $dbalConf = $phraseaConfig->getConnexion($connexion)->all(); + } + catch(\Exception $e) + { + throw new \Exception(sprintf("Unable to read %s configuration", $connexion)); } $evm = new \Doctrine\Common\EventManager(); @@ -117,52 +143,54 @@ class Doctrine protected static function loadClasses() { + require_once __DIR__ . '/../../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib/Doctrine/Common/ClassLoader.php'; + $classLoader = new \Doctrine\Common\ClassLoader( 'Doctrine\ORM' - , realpath(__DIR__ . '/../../../../vendor/doctrine2-orm/lib') + , realpath(__DIR__ . '/../../../../../vendor/doctrine2-orm/lib') ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'Doctrine\DBAL' - , realpath(__DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib') - ); - $classLoader->register(); - - $classLoader = new \Doctrine\Common\ClassLoader( - 'Doctrine\Common\DataFixtures' - , realpath(__DIR__ . '/../../../../vendor/data-fixtures/lib') - ); - $classLoader->register(); - - $classLoader = new \Doctrine\Common\ClassLoader( - 'PhraseaFixture' - , realpath(__DIR__ . '/../../../../conf.d/') + , realpath(__DIR__ . '/../../../../../vendor/doctrine2-orm/lib/vendor/doctrine-dbal/lib') ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'Doctrine\Common' - , realpath(__DIR__ . '/../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib') + , realpath(__DIR__ . '/../../../../../vendor/doctrine2-orm/lib/vendor/doctrine-common/lib') + ); + $classLoader->register(); + + $classLoader = new \Doctrine\Common\ClassLoader( + 'Doctrine\Common\DataFixtures' + , realpath(__DIR__ . '/../../../../../vendor/data-fixtures/lib') + ); + $classLoader->register(); + + $classLoader = new \Doctrine\Common\ClassLoader( + 'PhraseaFixture' + , realpath(__DIR__ . '/../../../../../conf.d/') ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'Entities' - , realpath(__DIR__ . '/../../../../Doctrine') + , realpath(__DIR__ . '/../../../../../Doctrine') ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'Repositories' - , realpath(__DIR__ . '/../../../../Doctrine') + , realpath(__DIR__ . '/../../../../../Doctrine') ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'Proxies' - , realpath(__DIR__ . '/../../../../Doctrine') + , realpath(__DIR__ . '/../../../../../Doctrine') ); $classLoader->register(); @@ -175,34 +203,34 @@ class Doctrine $classLoader = new \Doctrine\Common\ClassLoader( 'Doctrine\Logger' - , realpath(__DIR__ . '/../../../../') + , realpath(__DIR__ . '/../../../../../../../') ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'Monolog' - , realpath(__DIR__ . '/../../../../vendor/Silex/vendor/monolog/src') + , realpath(__DIR__ . '/../../../../../vendor/Silex/vendor/monolog/src') ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'Types' - , realpath(__DIR__ . '/../../../../Doctrine') + , realpath(__DIR__ . '/../../../../../Doctrine') ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'Gedmo' - , __DIR__ . "/../../../../vendor/doctrine2-gedmo/lib" + , __DIR__ . "/../../../../../vendor/doctrine2-gedmo/lib" ); $classLoader->register(); $classLoader = new \Doctrine\Common\ClassLoader( 'DoctrineExtensions' - , __DIR__ . "/../../../../vendor/doctrine2-beberlei/lib" + , __DIR__ . "/../../../../../vendor/doctrine2-beberlei/lib" ); $classLoader->register(); @@ -215,14 +243,25 @@ class Doctrine $platform = $this->entityManager->getConnection()->getDatabasePlatform(); - if(!Type::hasType('blob')) + if (!Type::hasType('blob')) + { Type::addType('blob', 'Types\Blob'); - if(!Type::hasType('enum')) + } + + if (!Type::hasType('enum')) + { Type::addType('enum', 'Types\Enum'); - if(!Type::hasType('longblob')) + } + + if (!Type::hasType('longblob')) + { Type::addType('longblob', 'Types\LongBlob'); - if(!Type::hasType('varbinary')) + } + + if (!Type::hasType('varbinary')) + { Type::addType('varbinary', 'Types\VarBinary'); + } $platform->registerDoctrineTypeMapping('enum', 'enum'); $platform->registerDoctrineTypeMapping('blob', 'blob'); @@ -285,99 +324,53 @@ class Doctrine * @param type $log * @param type $logger */ - private function handleLogs(\Doctrine\ORM\Configuration &$config, $log, $logger) + private function handleLogs(\Doctrine\ORM\Configuration &$config, $serviceName, Array $serviceConf) { - $logEnable = isset($log["enable"]) ? !!$log["enable"] : false; - - if ($logEnable) + $logType = $serviceConf['type']; + $logService = null; + + switch ($logType) { - $loggerService = isset($log["type"]) ? $log["type"] : ''; + case 'monolog': + $logService = Core\ServiceBuilder::build( + $serviceName + , Core\ServiceBuilder::LOG + , $logType + , $serviceConf['options'] + , 'doctrine' + ); + break; + case 'echo': + default: + $logService = Core\ServiceBuilder::build( + $serviceName + , Core\ServiceBuilder::LOG + , 'normal' + , array() + , 'doctrine' + ); + break; + } - switch ($loggerService) - { - case 'monolog': - //defaut to main handler - $doctrineHandler = isset($log["handler"]) ? $log["handler"] : 'main'; - - if (!isset($logger["handlers"])) - { - throw new \Exception("You must specify at least on monolog handler"); - } - - if (!array_key_exists($doctrineHandler, $logger["handlers"])) - { - throw new \Exception(sprintf('Unknow monolog handler %s'), $handlerType); - } - - $handlerName = ucfirst($logger["handlers"][$doctrineHandler]["type"]); - - $handlerClassName = sprintf('\Monolog\Handler\%sHandler', $handlerName); - - if (!class_exists($handlerClassName)) - { - throw new \Exception(sprintf('Unknow monolog handler class %s', $handlerClassName)); - } - - if (!isset($log["filename"])) - { - throw new \Exception('you must specify a file to write "filename: my_filename"'); - } - - $logPath = __DIR__ . '/../../../../../logs'; - $file = sprintf('%s/%s', $logPath, $log["filename"]); - - if ($doctrineHandler == 'rotate') - { - $maxDay = isset($log["max_day"]) ? (int) $log["max_day"] : false; - - if(!$maxDay && isset($logger["handlers"]['rotate']["max_day"])) - { - $maxDay = (int) $logger["handlers"]['rotate']["max_day"]; - } - else - { - $maxDay = 10; - } - $handlerInstance = new $handlerClassName($file, $maxDay); - } - else - { - $handlerInstance = new $handlerClassName($file); - } - - $monologLogger = new \Monolog\Logger('query-logger'); - $monologLogger->pushHandler($handlerInstance); - - if (isset($log["output"])) - { - $output = $log["output"]; - } - elseif (isset($logger["output"])) - { - $output = $logger["output"]; - } - else - { - $output = null; - } - - if (null === $output) - { - $sqlLogger = new \Doctrine\Logger\MonologSQLLogger($monologLogger); - } - else - { - $sqlLogger = new \Doctrine\Logger\MonologSQLLogger($monologLogger, $output); - } - - $config->setSQLLogger($sqlLogger); - break; - case 'echo': - default: - $config->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger); - break; - } + if ($logService instanceof Alchemy\Phrasea\Core\Service\ServiceAbstract) + { + $config->setSQLLogger($logService->getService()); } } -} \ No newline at end of file + public function getService() + { + return $this->entityManager; + } + + public function getType() + { + return 'doctrine'; + } + + public function getScope() + { + return 'orm'; + } + +} diff --git a/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php b/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php new file mode 100644 index 0000000000..3900d5c6fc --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Service/ServiceAbstract.php @@ -0,0 +1,58 @@ +name = $name; + $this->options = $options; + } + + /** + * + * @return string + */ + public function getName() + { + return $this->name; + } + + /** + * + * @return Array + */ + public function getOptions() + { + return $this->options; + } + + /** + * + * @return string + */ + public function getVersion() + { + return 'Unknow'; + } +} \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/Service/ServiceInterface.php b/lib/Alchemy/Phrasea/Core/Service/ServiceInterface.php new file mode 100644 index 0000000000..0189b5ab23 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/Service/ServiceInterface.php @@ -0,0 +1,32 @@ +options = $this->resolveOptions($configuration); + parent::__construct($name, $options); + $this->options = $this->resolveOptions($options); $this->templatesPath = $this->resolvePaths(); try @@ -194,41 +197,34 @@ class Twig */ private function resolveOptions(Array $configuration) { - if (isset($configuration['options'])) - { - $options = $configuration['options']; - $options["optimizer"] = !!$options["optimizer"] ? -1 : 0; - } - else - { - $options = array( - 'cache' => $registry->get('GV_RootPath') . 'tmp/cache_twig', - 'debug' => false, - 'strict_variables' => false, - 'trim_blocks' => true, - 'charset' => 'utf-8' - ); - } + $registry = \registry::get_instance(); + $options = $configuration; - $confApp = new Core\Configuration\Application(); - $confParser = new Core\Configuration\Parser\Yaml(); - $handler = new Core\Configuration\Handler($confApp, $confParser); - $configuration = new Core\Configuration($handler); + $options["optimizer"] = !!$options["optimizer"] ? -1 : 0; + $options['cache'] = $registry->get('GV_RootPath') . 'tmp/cache_twig'; + $options['charset'] = 'utf-8'; - if ($configuration->isDebug()) + if (!!$options["debug"]) { - $options["debug"] = true; unset($options["cache"]); } - else - { - $options["debug"] = false; - $options["cache"] = $registry->get('GV_RootPath') . 'tmp/cache_twig'; - } - - return $options; } + public function getService() + { + return $this->twig; + } + + public function getType() + { + return 'twig'; + } + + public function getScope() + { + return 'template_engine'; + } + } \ No newline at end of file diff --git a/lib/Alchemy/Phrasea/Core/ServiceBuilder.php b/lib/Alchemy/Phrasea/Core/ServiceBuilder.php new file mode 100644 index 0000000000..4f2cea3819 --- /dev/null +++ b/lib/Alchemy/Phrasea/Core/ServiceBuilder.php @@ -0,0 +1,75 @@ + 1) + { + $scope = ""; + foreach ($composedScope as $word) + { + $scope .= ucfirst($word); + } + $serviceScope = $scope; + } + + if (is_string($namespace)) + { + $scope = sprintf("%s\%s", ucfirst($namespace), ucfirst($serviceScope)); + } + + $className = sprintf( + "\Alchemy\Phrasea\Core\Service\%s\%s" + , ucfirst($serviceScope) + , ucfirst($serviceType) + ); + + if (class_exists($className)) + { + return new $className($serviceName, $options); + } + else + { + throw new \Exception(sprintf( + 'Unknow service %s for %s scopes looked for classname %s' + , str_replace('/', '_', $serviceType) + , $serviceScope + , $className) + ); + } + } + +} \ No newline at end of file diff --git a/lib/classes/appbox.class.php b/lib/classes/appbox.class.php index f28be2961c..521cd861b7 100644 --- a/lib/classes/appbox.class.php +++ b/lib/classes/appbox.class.php @@ -81,7 +81,9 @@ class appbox extends base ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - $connexion = $configuration->getConnexion(); + $choosenConnexion = $configuration->getPhraseanet()->get('database'); + + $connexion = $configuration->getConnexion($choosenConnexion); $this->host = $connexion->get('host'); $this->port = $connexion->get('port'); @@ -415,34 +417,99 @@ class appbox extends base $credentials['dbname'] = $dbname; } - $file = __DIR__ . "/../../config/config.sample.yml"; - $file1 = __DIR__ . "/../../config/config.yml"; - - if (!copy($file, $file1)) - { - throw new \Exception(sprintf("Unable to copy %s", $file1)); - } - - $handler = new \Alchemy\Phrasea\Core\Configuration\Handler( - new \Alchemy\Phrasea\Core\Configuration\Application(), - new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() - ); - $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - - $connexionINI = array(); - foreach ($credentials as $key => $value) { $key = $key == 'hostname' ? 'host' : $key; $connexionINI[$key] = (string) $value; } - $serverName = $registry->get('GV_ServerName'); - $configuration->setServerName($serverName); - $configuration->setAllDatabaseConnexion($connexionINI); + $connexionINI['driver'] = 'pdo_mysql'; + $connexionINI['charset'] = 'UTF8'; + $serverName = $registry->get('GV_ServerName'); + + $root = __DIR__ . '/../../'; + + //copy config sample + $configSampleFile = $root . "config/config.sample.yml"; + $configFile = $root . "config/config.yml"; + + if (!copy($configSampleFile, $configFile)) + { + throw new \Exception(sprintf("Unable to copy %s", $configSampleFile)); + } + + //copy service sample + $serviceSampleFile = $root . "config/services.sample.yml"; + $serviceFile = $root . "config/services.yml"; + + if (!copy($serviceSampleFile, $serviceFile)) + { + throw new \Exception(sprintf("Unable to copy %s", $serviceSampleFile)); + } + + //copy connexion sample + $connexionSampleFile = $root . "config/connexions.sample.yml"; + $connexionFile = $root . "config/connexions.yml"; + + if (!copy($connexionSampleFile, $connexionFile)) + { + throw new \Exception(sprintf("Unable to copy %s", $serviceSampleFile)); + } + + //get configuration object + $appConf = new \Alchemy\Phrasea\Core\Configuration\Application(); + $parser = new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml(); + $handler = new \Alchemy\Phrasea\Core\Configuration\Handler($appConf, $parser); + $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); + + //write credentials to config file + $connexionFile = $appConf->getConnexionFile(); + + $connexion = array( + 'main_connexion' => $connexionINI, + 'test_connexion' => array( + 'driver' => 'pdo_sqlite', + 'path' => $root . 'lib/unitTest/tests.sqlite', + 'charset' => 'UTF8' + )); + + $yaml = $configuration->getConfigurationHandler()->getParser()->dump($connexion, 2); + + if (!file_put_contents($connexionFile->getPathname(), $yaml) !== false) + { + throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $connexionFile->getPathname())); + } + + //rewrite service file + $serviceFile = $appConf->getServiceFile(); + $service = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile); + $yaml = $configuration->getConfigurationHandler()->getParser()->dump($service, 5); + + if (!file_put_contents($serviceFile->getPathname(), $yaml) !== false) + { + throw new \Exception(sprintf(_('Impossible d\'ecrire dans le fichier %s'), $serviceFile->getPathname())); + } + + //rewrite servername in main config file + $arrayConf = $configuration->all(); + + foreach ($arrayConf as $key => $value) + { + if (is_array($value) && array_key_exists('phraseanet', $value)) + { + $arrayConf[$key]["phraseanet"]["servername"] = $serverName; + } + } + + $configuration->write($arrayConf); + + + if (function_exists('chmod')) { chmod($configuration->getFile()->getPathname(), 0700); + chmod($serviceFile->getPathname(), 0700); + chmod($connexionFile->getPathname(), 0700); } } try diff --git a/lib/classes/binaryAdapter/image/resize/gd.class.php b/lib/classes/binaryAdapter/image/resize/gd.class.php index 0cafa4af9c..194d9f6308 100644 --- a/lib/classes/binaryAdapter/image/resize/gd.class.php +++ b/lib/classes/binaryAdapter/image/resize/gd.class.php @@ -93,13 +93,19 @@ class binaryAdapter_image_resize_gd extends binaryAdapter_processorAbstract $size = $this->options['size']; - if (!is_null($size) && !$origine->is_raw_image() - && $tech_datas[system_file::TC_DATAS_WIDTH] < $size && $tech_datas[system_file::TC_DATAS_HEIGHT] < $size) + if ( + !is_null($size) + && isset($tech_datas[system_file::TC_DATAS_WIDTH]) + && isset($tech_datas[system_file::TC_DATAS_HEIGHT]) + && !$origine->is_raw_image() + && $tech_datas[system_file::TC_DATAS_WIDTH] < $size + && $tech_datas[system_file::TC_DATAS_HEIGHT] < $size + ) { $size = max($tech_datas[system_file::TC_DATAS_WIDTH], $tech_datas[system_file::TC_DATAS_HEIGHT]); } - - switch($origine->get_mime()) + + switch ($origine->get_mime()) { case "image/jpeg" : $imag_original = imagecreatefromjpeg($origine->getPathname()); @@ -114,7 +120,7 @@ class binaryAdapter_image_resize_gd extends binaryAdapter_processorAbstract return $this; break; } - + if ($imag_original) { @@ -134,8 +140,7 @@ class binaryAdapter_image_resize_gd extends binaryAdapter_processorAbstract $w_sub = (int) (($w_doc / $h_doc) * ($h_sub = $size)); $img_mini = imagecreatetruecolor($w_sub, $h_sub); - imagecopyresampled($img_mini, $imag_original, 0, 0, 0, 0, - $w_sub, $h_sub, $w_doc, $h_doc); + imagecopyresampled($img_mini, $imag_original, 0, 0, 0, 0, $w_sub, $h_sub, $w_doc, $h_doc); } if ($this->options['autorotate']) diff --git a/lib/classes/connection.class.php b/lib/classes/connection.class.php index 12f4382cb4..65344ac08d 100755 --- a/lib/classes/connection.class.php +++ b/lib/classes/connection.class.php @@ -142,7 +142,9 @@ class connection ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - $connexion = $configuration->getConnexion(); + $choosenConnexion = $configuration->getPhraseanet()->get('database'); + + $connexion = $configuration->getConnexion($choosenConnexion); $hostname = $connexion->get('host'); $port = $connexion->get('port'); diff --git a/lib/classes/phrasea.class.php b/lib/classes/phrasea.class.php index 40aa30357e..ffb863da85 100644 --- a/lib/classes/phrasea.class.php +++ b/lib/classes/phrasea.class.php @@ -111,7 +111,9 @@ class phrasea ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - $connexion = $configuration->getConnexion(); + $choosenConnexion = $configuration->getPhraseanet()->get('database'); + + $connexion = $configuration->getConnexion($choosenConnexion); $hostname = $connexion->get('host'); $port = $connexion->get('port'); diff --git a/lib/classes/registry.class.php b/lib/classes/registry.class.php index 4e4bf39708..1ab18eecf4 100644 --- a/lib/classes/registry.class.php +++ b/lib/classes/registry.class.php @@ -63,12 +63,14 @@ class registry implements registryInterface new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - $phraseanet = $configuration->getPhraseanet(); - $this->cache->set('GV_RootPath', dirname(dirname(__DIR__)) . '/'); - $this->cache->set('GV_ServerName', $phraseanet->get('servername')); - $this->cache->set('GV_debug', $configuration->isDebug()); - $this->cache->set('GV_maintenance', $configuration->isMaintained()); + $this->cache->set('GV_RootPath', dirname(dirname(__DIR__)) . '/'); + if ($configuration->isInstalled()) + { + $this->cache->set('GV_ServerName', $configuration->getPhraseanet()->get('servername')); + $this->cache->set('GV_debug', $configuration->isDebug()); + $this->cache->set('GV_maintenance', $configuration->isMaintained()); + } return $this; } diff --git a/lib/classes/setup.class.php b/lib/classes/setup.class.php index 3a22c14349..9e197f6885 100644 --- a/lib/classes/setup.class.php +++ b/lib/classes/setup.class.php @@ -69,14 +69,24 @@ class setup public static function is_installed() { $appConf = new \Alchemy\Phrasea\Core\Configuration\Application(); - - return is_file($appConf->getConfigurationPathName()); + $installed = false; + try + { + $appConf->getConfigurationFile(); + $appConf->getConnexionFile(); + $appConf->getServiceFile(); + $installed = true; + } + catch(\Exception $e) + { + } + return $installed; } public static function needUpgradeConfigurationFile() { - return (is_file(__DIR__ . "/../../conf/connexion.inc") - && is_file(__DIR__ . "/../../config.inc")); + return (is_file(__DIR__ . "/../../config/connexion.inc") + && is_file(__DIR__ . "/../../config/config.inc")); } function create_global_values(registryInterface &$registry, $datas=array()) diff --git a/lib/classes/task/Scheduler.class.php b/lib/classes/task/Scheduler.class.php index 746eb87f77..116961b6f6 100644 --- a/lib/classes/task/Scheduler.class.php +++ b/lib/classes/task/Scheduler.class.php @@ -51,7 +51,9 @@ class task_Scheduler ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - $connexion = $configuration->getConnexion(); + $choosenConnexion = $configuration->getPhraseanet()->get('database'); + + $connexion = $configuration->getConnexion($choosenConnexion); $hostname = $connexion->get('host'); $port = $connexion->get('port'); @@ -287,12 +289,12 @@ class task_Scheduler * Launch task that are not yet launched */ $runningtask = 0; - + $common_status = array( task_abstract::STATUS_STARTED , task_abstract::RETURNSTATUS_STOPPED ); - + foreach ($ttask as $tkey => $tv) { if (!in_array($ttask[$tkey]["task"]->get_status(), $common_status)) diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/ConfigurationTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/ConfigurationTest.php index e8372be895..53f26664ea 100644 --- a/lib/unitTest/Alchemy/Phrasea/Core/Configuration/ConfigurationTest.php +++ b/lib/unitTest/Alchemy/Phrasea/Core/Configuration/ConfigurationTest.php @@ -58,14 +58,13 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract $this->assertEquals('prod', $configuration->getEnvironnement()); $this->assertTrue($configuration->isInstalled()); $this->assertInstanceOf( - 'Alchemy\Phrasea\Core\Configuration\Parameter' + '\Symfony\Component\DependencyInjection\ParameterBag\ParameterBag' , $configuration->getConfiguration() ); $this->assertFalse($configuration->isDebug()); - $this->assertFalse($configuration->displayErrors()); + $this->assertFalse($configuration->isDisplayingErrors()); $this->assertFalse($configuration->isMaintained()); $this->assertTrue(is_array($configuration->getPhraseanet()->all())); - $this->assertTrue(is_array($configuration->getDoctrine()->all())); } public function testInstalled() @@ -83,10 +82,17 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract $configuration = new PhraseaCore\Configuration($handler); $configuration->setEnvironnement('prod'); - + $this->assertFalse($configuration->isInstalled()); - $this->assertTrue(is_array($configuration->getPhraseanet()->all())); - $this->assertTrue(is_array($configuration->getDoctrine()->all())); + try + { + $configuration->getPhraseanet(); + $this->fail("should raise an exception because application is not yet installed"); + } + catch (\Exception $e) + { + + } } public function testGetAvailableLogger() @@ -96,14 +102,14 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract $configuration = new PhraseaCore\Configuration($handler); $configuration->setEnvironnement('prod'); - + $availableLogger = $configuration->getAvailableDoctrineLogger(); - + $this->assertTrue(is_array($availableLogger)); $this->assertContains('monolog', $availableLogger); $this->assertContains('echo', $availableLogger); } - + public function testGetHandler() { $spec = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application'); @@ -111,10 +117,10 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract $configuration = new PhraseaCore\Configuration($handler); $configuration->setEnvironnement('prod'); - + $this->assertInstanceOf('\Alchemy\Phrasea\Core\Configuration\Handler', $configuration->getConfigurationHandler()); } - + public function testSetHandler() { $spec = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application'); @@ -122,9 +128,9 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract $configuration = new PhraseaCore\Configuration($handler); $configuration->setEnvironnement('prod'); - + $spec2 = $this->getMock('\Alchemy\Phrasea\Core\Configuration\Application'); - + $spec2->expects($this->any()) ->method('getConfigurationFile') ->will( @@ -132,44 +138,44 @@ class ConfigurationTest extends PhraseanetPHPUnitAuthenticatedAbstract 'test' ) ); - + $newHandler = new Configuration\Handler($spec2, new Configuration\Parser\Yaml()); - + $configuration->setConfigurationHandler($newHandler); - + $this->assertEquals('test', $configuration->getConfigurationHandler()->getSpecification()->getConfigurationFile()); } - public function testBadDoctrineLogger() - { - $spec = $this->getMock( - '\Alchemy\Phrasea\Core\Configuration\Application' - , array('getConfigurationFile') - ); - - $fileName = __DIR__ . '/confTestFiles/bad_doctrine_logger.yml'; - - $spec->expects($this->any()) - ->method('getConfigurationFile') - ->will( - $this->returnValue( - new \SplFileObject($fileName) - ) - ); - - $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); - - $configuration = new PhraseaCore\Configuration($handler); - $configuration->setEnvironnement('prod'); - - try - { - $configuration->getDoctrine(); - $this->fail('An exception should be raised'); - } - catch(Exception $e) - { - - } - } +// public function testBadDoctrineLogger() +// { +// $spec = $this->getMock( +// '\Alchemy\Phrasea\Core\Configuration\Application' +// , array('getConfigurationFile') +// ); +// +// $fileName = __DIR__ . '/confTestFiles/bad_doctrine_logger.yml'; +// +// $spec->expects($this->any()) +// ->method('getConfigurationFile') +// ->will( +// $this->returnValue( +// new \SplFileObject($fileName) +// ) +// ); +// +// $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); +// +// $configuration = new PhraseaCore\Configuration($handler); +// $configuration->setEnvironnement('prod'); +// +// try +// { +// $configuration->getDoctrine(); +// $this->fail('An exception should be raised'); +// } +// catch(Exception $e) +// { +// +// } +// } } \ No newline at end of file diff --git a/lib/unitTest/Alchemy/Phrasea/Core/Service/DoctrineTest.php b/lib/unitTest/Alchemy/Phrasea/Core/Service/DoctrineTest.php deleted file mode 100644 index c0e06da916..0000000000 --- a/lib/unitTest/Alchemy/Phrasea/Core/Service/DoctrineTest.php +++ /dev/null @@ -1,139 +0,0 @@ -getMock( - '\Alchemy\Phrasea\Core\Configuration\Application' - , array('getConfigurationFile') - ); - - $fileName = __DIR__ . '/../Configuration/confTestFiles/good.yml'; - - $spec->expects($this->any()) - ->method('getConfigurationFile') - ->will( - $this->returnValue( - new SplFileObject($fileName) - ) - ); - - $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); - - $configuration = new PhraseaCore\Configuration($handler); - $configuration->setEnvironnement('prod'); - - $doctrineService = new Doctrine($configuration->getDoctrine()->all()); - } - catch (Exception $e) - { - $this->fail($e->getMessage()); - } - } - - public function testNoDbalConf() - { - try - { - $doctrineService = new Doctrine(); - $this->fail("should raised an exception"); - } - catch (\Exception $e) - { - - } - } - - public function testGetVersion() - { - $spec = $this->getMock( - '\Alchemy\Phrasea\Core\Configuration\Application' - , array('getConfigurationFile') - ); - - $fileName = __DIR__ . '/../Configuration/confTestFiles/good.yml'; - - $spec->expects($this->any()) - ->method('getConfigurationFile') - ->will( - $this->returnValue( - new SplFileObject($fileName) - ) - ); - - $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); - - $configuration = new PhraseaCore\Configuration($handler); - $configuration->setEnvironnement('prod'); - - $doctrineService = new Doctrine($configuration->getDoctrine()->all()); - $this->assertTrue(is_string($doctrineService->getVersion())); - } - - public function testGetEntityManager() - { - $spec = $this->getMock( - '\Alchemy\Phrasea\Core\Configuration\Application' - , array('getConfigurationFile') - ); - - $fileName = __DIR__ . '/../Configuration/confTestFiles/good.yml'; - - $spec->expects($this->any()) - ->method('getConfigurationFile') - ->will( - $this->returnValue( - new SplFileObject($fileName) - ) - ); - - $handler = new Configuration\Handler($spec, new Configuration\Parser\Yaml()); - - $configuration = new PhraseaCore\Configuration($handler); - $configuration->setEnvironnement('prod'); - - $doctrineService = new Doctrine($configuration->getDoctrine()->all()); - $this->assertInstanceOf('\Doctrine\ORM\EntityManager', $doctrineService->getEntityManager()); - } - -} \ No newline at end of file diff --git a/lib/unitTest/Bridge/Bridge_datas.inc b/lib/unitTest/Bridge/Bridge_datas.inc index 6cdb6a1f50..e7d9f5525f 100644 --- a/lib/unitTest/Bridge/Bridge_datas.inc +++ b/lib/unitTest/Bridge/Bridge_datas.inc @@ -2,6 +2,11 @@ require_once __DIR__ . '/../../bootstrap.php'; +$new_include_path = __DIR__ . "/../../vendor/" . PATH_SEPARATOR . get_include_path(); +set_include_path($new_include_path); + +require_once __DIR__ . "/../../vendor/Phlickr/Api.php"; + /* * This file is part of Phraseanet * diff --git a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc index 24465dd90b..cf260ab2c4 100644 --- a/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc +++ b/lib/unitTest/PhraseanetPHPUnitAbstract.class.inc @@ -11,19 +11,21 @@ require_once __DIR__ . "/../../lib/classes/bootstrap.class.php"; +use Silex\WebTestCase; +use Symfony\Component\HttpKernel\Client; +use Symfony\Component\HttpFoundation\Response; +use Doctrine\Common\DataFixtures\Loader; +use PhraseaFixture\Basket as MyFixture; + /** * * @package * @license http://opensource.org/licenses/gpl-3.0 GPLv3 * @link www.phraseanet.com */ + bootstrap::execute('test'); -use Silex\WebTestCase; -use Symfony\Component\HttpKernel\Client; -use Symfony\Component\HttpFoundation\Response; -use Doctrine\Common\DataFixtures\Loader; -use PhraseaFixture\Basket as MyFixture; abstract class PhraseanetPHPUnitAbstract extends WebTestCase { @@ -394,7 +396,7 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase self::$time_start = microtime(true); echo "\033[1;35m\n==Start==\033[0;37m\r\n"; } - + self::updateTablesSchema(); self::createSetOfUserTests(); @@ -730,8 +732,22 @@ abstract class PhraseanetPHPUnitAbstract extends WebTestCase */ protected function resetTwig() { - $serviceTwig = new \Alchemy\Phrasea\Core\Service\Twig(array()); - $this->app['Core']["Twig"] = $serviceTwig->getTwig(); + $handler = new \Alchemy\Phrasea\Core\Configuration\Handler( + new \Alchemy\Phrasea\Core\Configuration\Application(), + new \Alchemy\Phrasea\Core\Configuration\Parser\Yaml() + ); + $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); + + $serviceName = $configuration->getTemplating(); + $confService = $configuration->getService($serviceName); + + $templateService = \Alchemy\Phrasea\Core\ServiceBuilder::build( + $serviceName + , \Alchemy\Phrasea\Core\ServiceBuilder::TEMPLATE_ENGINE + , $confService->get("type") + , $confService->get("options") + ); + $this->app['Core']["Twig"] = $templateService->getService(); } /** diff --git a/lib/unitTest/supertwigTest.php b/lib/unitTest/supertwigTest.php deleted file mode 100644 index c80e20a3e7..0000000000 --- a/lib/unitTest/supertwigTest.php +++ /dev/null @@ -1,54 +0,0 @@ -object = new supertwig(); - } - - public function testAddFilter() - { - $this->object->addFilter(array('nl2br'=>'nl2br')); - try - { - $this->object->addFilter(array('prout'=>'prout')); - $this->fail(); - } - catch(Exception $e) - { - - } - } - - public function testRender() - { - $this->object->addFilter(array('nl2br'=>'nl2br')); - $this->assertEquals('mon beau camion', $this->object->render('test.html', array('test_string'=>'mon beau camion'))); - $string = "mon\nBEAU CAMION\n"; - $this->assertEquals("mon
\nBEAU CAMION
\n", $this->object->render('test.html', array('test_string'=>"mon\nBEAU CAMION\n"))); - } - - public function testDisplay() - { - ob_start(); - - $this->object->addFilter(array('nl2br'=>'nl2br')); - $this->object->display('test.html', array('test_string'=>'mon beau camion')); - - $out = ob_get_clean(); - $this->assertEquals('mon beau camion', $out); - } - -} - diff --git a/templates/web/login/index_layout_displaycooliris.twig b/templates/web/login/index_layout_displaycooliris.twig index c0755a7a3f..f1dc19c870 100644 --- a/templates/web/login/index_layout_displaycooliris.twig +++ b/templates/web/login/index_layout_displaycooliris.twig @@ -27,7 +27,7 @@ {% trans 'Vous etes maintenant deconnecte. A bientot.' %} {% endif %} - {{errorWarning}}{{confirmWarning}} + {{errorWarning|raw}}{{confirmWarning|raw}}
{% trans 'admin::compte-utilisateur identifiant' %}
diff --git a/templates/web/login/index_layout_displayscroll.twig b/templates/web/login/index_layout_displayscroll.twig index 7d926b8291..c0fc73fdf6 100644 --- a/templates/web/login/index_layout_displayscroll.twig +++ b/templates/web/login/index_layout_displayscroll.twig @@ -25,7 +25,7 @@ {% trans 'Vous etes maintenant deconnecte. A bientot.' %}
{% endif %} - {{errorWarning}}{{confirmWarning}} + {{errorWarning|raw}}{{confirmWarning|raw}}
{% trans 'admin::compte-utilisateur identifiant' %}
diff --git a/templates/web/login/index_layout_displayx1.twig b/templates/web/login/index_layout_displayx1.twig index e24b2d10a3..08187e08e7 100644 --- a/templates/web/login/index_layout_displayx1.twig +++ b/templates/web/login/index_layout_displayx1.twig @@ -27,7 +27,7 @@ {% trans 'Vous etes maintenant deconnecte. A bientot.' %}
{% endif %} - {{errorWarning}}{{confirmWarning}} + {{errorWarning|raw}}{{confirmWarning|raw}}
{% trans 'admin::compte-utilisateur identifiant' %}
diff --git a/www/admin/databases.php b/www/admin/databases.php index caa7fc0cfa..a9d7ca3274 100644 --- a/www/admin/databases.php +++ b/www/admin/databases.php @@ -105,7 +105,9 @@ phrasea::headers(); ); $configuration = new \Alchemy\Phrasea\Core\Configuration($handler); - $connexion = $configuration->getConnexion(); + $choosenConnexion = $configuration->getPhraseanet()->get('database'); + + $connexion = $configuration->getConnexion($choosenConnexion); $hostname = $connexion->get('host'); $port = $connexion->get('port');