diff --git a/lib/Alchemy/Phrasea/Application.php b/lib/Alchemy/Phrasea/Application.php index 3106cdf5a6..0ccac0b365 100644 --- a/lib/Alchemy/Phrasea/Application.php +++ b/lib/Alchemy/Phrasea/Application.php @@ -248,8 +248,8 @@ class Application extends SilexApplication 'swftools.timeout' => 'swftools_timeout', 'unoconv.timeout' => 'unoconv_timeout', ] as $parameter => $key) { - if ($this['conf']->has(['binaries', $key])) { - $configuration[$parameter] = $this['conf']->get(['binaries', $key]); + if ($this['conf']->has(['main', 'binaries', $key])) { + $configuration[$parameter] = $this['conf']->get(['main', 'binaries', $key]); } } @@ -557,7 +557,7 @@ class Application extends SilexApplication { $this['url_generator'] = $this->share($this->extend('url_generator', function ($urlGenerator, $app) { if ($app['configuration.store']->isSetup()) { - $data = parse_url($app['conf']->get(['main', 'servername'])); + $data = parse_url($app['conf']->get('servername')); if (isset($data['scheme'])) { $urlGenerator->getContext()->setScheme($data['scheme']); diff --git a/lib/Alchemy/Phrasea/Core/CLIProvider/CLIDriversServiceProvider.php b/lib/Alchemy/Phrasea/Core/CLIProvider/CLIDriversServiceProvider.php index 51ccd15fb5..ae306b0f29 100644 --- a/lib/Alchemy/Phrasea/Core/CLIProvider/CLIDriversServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/CLIProvider/CLIDriversServiceProvider.php @@ -40,8 +40,8 @@ class CLIDriversServiceProvider implements ServiceProviderInterface return $app['executable-finder']->find($name, null, $extraDirs); } - if ($app['conf']->has(['binaries', $configName])) { - return $app['conf']->get(['binaries', $configName]); + if ($app['conf']->has(['main', 'binaries', $configName])) { + return $app['conf']->get(['main', 'binaries', $configName]); } return $app['executable-finder']->find($name, null, $extraDirs); diff --git a/lib/Alchemy/Phrasea/Core/CLIProvider/PluginServiceProvider.php b/lib/Alchemy/Phrasea/Core/CLIProvider/PluginServiceProvider.php index 282b7a7ce7..55a3ae3516 100644 --- a/lib/Alchemy/Phrasea/Core/CLIProvider/PluginServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/CLIProvider/PluginServiceProvider.php @@ -56,7 +56,7 @@ class PluginServiceProvider implements ServiceProviderInterface }); $app['plugins.composer-installer'] = $app->share(function (Application $app) { - $phpBinary = $app['conf']->get(['binaries', 'php_binary'], null); + $phpBinary = $app['conf']->get(['main', 'binaries', 'php_binary'], null); if (!is_executable($phpBinary)) { $finder = new PhpExecutableFinder(); diff --git a/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php b/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php index 9601fc2caa..b2f3da2dc5 100644 --- a/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php +++ b/lib/Alchemy/Phrasea/Core/Configuration/Configuration.php @@ -26,6 +26,13 @@ class Configuration implements ConfigurationInterface private $compiled; private $autoReload; + /** + * @param Yaml $yaml The Yaml Parser + * @param Compiler $compiler The PHP Compiler + * @param $config The path to the yaml configuration path + * @param $compiled The path to the compiled configuration path + * @param $autoReload Whether to recompile configuration on any change (slow, useful in debug) + */ public function __construct(Yaml $yaml, Compiler $compiler, $config, $compiled, $autoReload) { $this->parser = $yaml; diff --git a/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php index c35f3eb2f4..fb1ff285d7 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/LocaleServiceProvider.php @@ -26,8 +26,8 @@ class LocaleServiceProvider implements ServiceProviderInterface $app['locales.available'] = $app->share(function (Application $app) { $availableLanguages = PhraseaApplication::getAvailableLanguages(); - if ($app['configuration.store']->isSetup() && 0 < count((array) $app['conf']->get(['main', 'languages'], []))) { - $languages = $app['conf']->get(['main', 'languages']); + if ($app['configuration.store']->isSetup() && 0 < count((array) $app['conf']->get('languages', []))) { + $languages = $app['conf']->get('languages'); $enabledLanguages = $availableLanguages; foreach ($enabledLanguages as $code => $language) { diff --git a/lib/Alchemy/Phrasea/Core/Provider/TasksServiceProvider.php b/lib/Alchemy/Phrasea/Core/Provider/TasksServiceProvider.php index 1ef5c9c472..1f678ac3ce 100644 --- a/lib/Alchemy/Phrasea/Core/Provider/TasksServiceProvider.php +++ b/lib/Alchemy/Phrasea/Core/Provider/TasksServiceProvider.php @@ -41,7 +41,7 @@ class TasksServiceProvider implements ServiceProviderInterface 'host' => '127.0.0.1', 'port' => 6660, 'linger' => 500, - ], $app['conf']->get(['task-manager', 'listener'], [])); + ], $app['conf']->get(['main', 'task-manager', 'listener'], [])); }); $app['task-manager.job-factory'] = $app->share(function (Application $app) { diff --git a/lib/Alchemy/Phrasea/Setup/Installer.php b/lib/Alchemy/Phrasea/Setup/Installer.php index b98f213921..44c85499d5 100644 --- a/lib/Alchemy/Phrasea/Setup/Installer.php +++ b/lib/Alchemy/Phrasea/Setup/Installer.php @@ -186,9 +186,9 @@ class Installer $config['main']['database']['driver'] = 'pdo_mysql'; $config['main']['database']['charset'] = 'UTF8'; - $config['binaries'] = $binaryData; + $config['main']['binaries'] = $binaryData; - $config['main']['servername'] = $serverName; + $config['servername'] = $serverName; $config['main']['key'] = md5(mt_rand(100000000, 999999999)); $this->app['phraseanet.registry']->setKey($config['main']['key']); diff --git a/lib/Alchemy/Phrasea/Setup/Probe/BinariesProbe.php b/lib/Alchemy/Phrasea/Setup/Probe/BinariesProbe.php index 4a2c774a30..a441564b18 100644 --- a/lib/Alchemy/Phrasea/Setup/Probe/BinariesProbe.php +++ b/lib/Alchemy/Phrasea/Setup/Probe/BinariesProbe.php @@ -39,6 +39,6 @@ class BinariesProbe extends BinariesRequirements implements ProbeInterface */ public static function create(Application $app) { - return new static($app['conf']->get('binaries')); + return new static($app['conf']->get(['main', 'binaries'])); } } diff --git a/lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php b/lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php index 6b5719feec..19433c77e5 100644 --- a/lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php +++ b/lib/Alchemy/Phrasea/Setup/Version/Migration/Migration38.php @@ -76,7 +76,7 @@ class Migration38 implements MigrationInterface if (is_file($this->binariesYaml)) { $binaries = $this->yaml->parse($this->binariesYaml); foreach ($binaries['binaries'] as $key => $value) { - $conf['binaries'][$key] = $value; + $conf['main']['binaries'][$key] = $value; } } } diff --git a/lib/Alchemy/Phrasea/TaskManager/Job/PhraseanetIndexerJob.php b/lib/Alchemy/Phrasea/TaskManager/Job/PhraseanetIndexerJob.php index b252ad4148..03f12e10c0 100644 --- a/lib/Alchemy/Phrasea/TaskManager/Job/PhraseanetIndexerJob.php +++ b/lib/Alchemy/Phrasea/TaskManager/Job/PhraseanetIndexerJob.php @@ -79,7 +79,7 @@ class PhraseanetIndexerJob extends AbstractJob private function getPhraseanetIndexerPath(Application $app) { - $binaries = $app['conf']->get('binaries'); + $binaries = $app['conf']->get(['main', 'binaries']); if (isset($binaries['phraseanet_indexer'])) { $path = $binaries['phraseanet_indexer']; diff --git a/lib/Alchemy/Phrasea/TaskManager/TaskManagerStatus.php b/lib/Alchemy/Phrasea/TaskManager/TaskManagerStatus.php index 64bf49a223..3b3e70570f 100644 --- a/lib/Alchemy/Phrasea/TaskManager/TaskManagerStatus.php +++ b/lib/Alchemy/Phrasea/TaskManager/TaskManagerStatus.php @@ -64,32 +64,34 @@ class TaskManagerStatus { $this->ensureConfigurationSchema(); - return $this->conf['task-manager']['status']; + return $this->conf['main']['task-manager']['status']; } private function setStatus($status) { $this->ensureConfigurationSchema(); - $managerConf = $this->conf['task-manager']; - $managerConf['status'] = $status; - $this->conf['task-manager'] = $managerConf; + $mainConf = $this->conf['main']; + $mainConf['task-manager']['status'] = $status; + $this->conf['main'] = $mainConf; } private function ensureConfigurationSchema() { - if (!isset($this->conf['task-manager'])) { - $this->conf['task-manager'] = ['status' => static::STATUS_STARTED]; + if (!isset($this->conf['main']['task-manager'])) { + $mainConf = $this->conf['main']; + $mainConf['task-manager'] = ['status' => static::STATUS_STARTED]; + $this->conf['main'] = $mainConf; return; } - if (!isset($this->conf['task-manager']['status'])) { - $conf = $this->conf['task-manager']; - $conf['status'] = static::STATUS_STARTED; - $this->conf['task-manager'] = $conf; - } elseif (!$this->isValidStatus($this->conf['task-manager']['status'])) { - $conf = $this->conf['task-manager']; - $conf['status'] = static::STATUS_STARTED; - $this->conf['task-manager'] = $conf; + if (!isset($this->conf['main']['task-manager']['status'])) { + $mainConf = $this->conf['main']; + $mainConf['task-manager']['status'] = static::STATUS_STARTED; + $this->conf['main'] = $mainConf; + } elseif (!$this->isValidStatus($this->conf['main']['task-manager']['status'])) { + $mainConf = $this->conf['main']; + $mainConf['task-manager']['status'] = static::STATUS_STARTED; + $this->conf['main'] = $mainConf; } } diff --git a/lib/classes/API/V1/adapter.php b/lib/classes/API/V1/adapter.php index dfe83c8e86..bd0c319dd0 100644 --- a/lib/classes/API/V1/adapter.php +++ b/lib/classes/API/V1/adapter.php @@ -307,7 +307,7 @@ class API_V1_adapter extends API_V1_Abstract $ret['phraseanet']['debug'] = $app['debug']; $ret['phraseanet']['maintenance'] = $app['conf']->get(['main', 'maintenance']); $ret['phraseanet']['errorsLog'] = $app['debug']; - $ret['phraseanet']['serverName'] = $app['conf']->get(['main', 'servername']); + $ret['phraseanet']['serverName'] = $app['conf']->get('servername'); return $ret; } @@ -325,7 +325,7 @@ class API_V1_adapter extends API_V1_Abstract $SEStatus = ['error' => $e->getMessage()]; } - $binaries = $app['conf']->get('binaries'); + $binaries = $app['conf']->get(['main', 'binaries']); return [ 'global_values' => [ diff --git a/lib/classes/patch/390alpha10a.php b/lib/classes/patch/390alpha10a.php new file mode 100644 index 0000000000..59e6fb7c14 --- /dev/null +++ b/lib/classes/patch/390alpha10a.php @@ -0,0 +1,127 @@ +release; + } + + /** + * {@inheritdoc} + */ + public function require_all_upgrades() + { + return false; + } + + /** + * {@inheritdoc} + */ + public function concern() + { + return $this->concern; + } + + /** + * {@inheritdoc} + */ + public function getDoctrineMigrations() + { + return []; + } + + /** + * {@inheritdoc} + */ + public function apply(base $appbox, Application $app) + { + $this->upgradeConf($app); + $this->upgradeRegistry($app); + } + + private function upgradeRegistry(Application $app) + { + $sql = 'SELECT `key`, `value`, `type` FROM registry'; + $stmt = $app['phraseanet.appbox']->get_connection()->prepare($sql); + $stmt->execute(); + $rows = $stmt->fetchAll(\PDO::FETCH_ASSOC); + $stmt->closeCursor(); + + $registry = array(); + + foreach ($rows as $row) { + switch ($row['type']) { + case 'boolean': + $value = (Boolean) $row['value']; + break; + case 'integer': + $value = (int) $row['value']; + break; + case 'enum': + case 'string': + case 'text': + case 'timezone': + $value = $row['value']; + break; + case 'binary': + case 'enum_multi': + continue; + break; + } + + $registry[$row['key']] = $value; + } + + $config = $app['configuration']->getConfig(); + + $config['languages']['default'] = isset($registry['GV_default_lng']) ? $registry['GV_default_lng'] : 'fr_FR'; + + $app['configuration']->setConfig($config); + } + + private function upgradeConf(Application $app) + { + $config = $app['configuration']->getConfig(); + + if (isset($config['main']['languages'])) { + $config = array_merge(array('languages' => array('available' => $config['main']['languages'])), $config); + unset($config['main']['languages']); + } + + $config = array_merge(array('servername' => $config['main']['servername']), $config); + unset($config['main']['servername']); + + $config['main']['task-manager'] = $config['task-manager']; + unset($config['task-manager']); + + if (isset($config['binaries'])) { + $binaries = isset($config['main']['binaries']) ? $config['main']['binaries'] : array(); + $config['main']['binaries'] = array_merge($binaries, $config['binaries']); + unset($config['binaries']); + } + + $app['configuration']->setConfig($config); + } +} diff --git a/lib/classes/registry.php b/lib/classes/registry.php index 8b1126f73b..3c76a8d02e 100644 --- a/lib/classes/registry.php +++ b/lib/classes/registry.php @@ -42,7 +42,7 @@ class registry implements registryInterface $this->cache = new ArrayCache(); if ($app['phraseanet.configuration-tester']->isInstalled()) { - $this->cache->save('GV_ServerName', $app['conf']->get(['main', 'servername'])); + $this->cache->save('GV_ServerName', $app['conf']->get('servername')); $this->cache->save('GV_debug', $app['debug']); if ($app['conf']->has(['main', 'key'])) { diff --git a/tests/classes/PhraseanetTestCase.php b/tests/classes/PhraseanetTestCase.php index d35be403dd..37790b3ebf 100644 --- a/tests/classes/PhraseanetTestCase.php +++ b/tests/classes/PhraseanetTestCase.php @@ -258,7 +258,7 @@ abstract class PhraseanetTestCase extends WebTestCase }); $app['url_generator'] = $app->share($app->extend('url_generator', function ($generator, $app) { - $host = parse_url($app['conf']->get(['main', 'servername']), PHP_URL_HOST); + $host = parse_url($app['conf']->get('servername'), PHP_URL_HOST); $generator->setContext(new RequestContext('', 'GET', $host)); return $generator;