Move main "languages" and "servername" to top level, "task-manager" and "binaries" to main configuration

This commit is contained in:
Romain Neutron
2013-11-18 15:15:44 +01:00
parent af807431b1
commit c3df531f59
15 changed files with 168 additions and 32 deletions

View File

@@ -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']);

View File

@@ -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);

View File

@@ -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();

View File

@@ -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;

View File

@@ -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) {

View File

@@ -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) {

View File

@@ -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']);

View File

@@ -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']));
}
}

View File

@@ -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;
}
}
}

View File

@@ -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'];

View File

@@ -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;
}
}

View File

@@ -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' => [

View File

@@ -0,0 +1,127 @@
<?php
/*
* This file is part of Phraseanet
*
* (c) 2005-2013 Alchemy
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
use Alchemy\Phrasea\Application;
use Alchemy\Phrasea\Model\Entities\Task;
class patch_390alpha10a implements patchInterface
{
/** @var string */
private $release = '3.9.0-alpha.10';
/** @var array */
private $concern = array(base::APPLICATION_BOX);
/**
* {@inheritdoc}
*/
public function get_release()
{
return $this->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);
}
}

View File

@@ -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'])) {

View File

@@ -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;