Refactor Configuration

This commit is contained in:
Romain Neutron
2012-02-22 18:38:59 +01:00
parent 0dcfec55c8
commit d1412de7ea
4 changed files with 55 additions and 31 deletions

View File

@@ -283,7 +283,7 @@ class Core extends \Pimple
/**
* Getter
*
* @return Core\Configuration
* @return \Alchemy\Phrasea\Core\Configuration
*/
public function getConfiguration()
{

View File

@@ -50,8 +50,15 @@ class Configuration
{
$this->specifications = $specifications;
if ($specifications->isSetup())
{
$configurations = $this->specifications->getConfigurations();
$environment = $environment ? : $configurations[self::KEYWORD_ENV];
}
else
{
$environment = null;
}
$this->setEnvironnement($environment);

View File

@@ -102,18 +102,21 @@ class ApplicationSpecification implements Specification
public function initialize()
{
touch($this->getConnexionsPathFile());
touch($this->getConfigurationsPathFile());
touch($this->getServicesPathFile());
$this->delete();
copy(
$this->getRealRootPath() . "/config/config.sample.yml"
, $this->getRealRootPath() . "/config/config.yml"
$this->getRealRootPath() . "/config/connexions.sample.yml"
, $this->getConnexionsPathFile()
);
copy(
$this->getRealRootPath() . "/config/services.sample.yml"
, $this->getRealRootPath() . "/config/services.yml"
, $this->getServicesPathFile()
);
copy(
$this->getRealRootPath() . "/config/config.sample.yml"
, $this->getConfigurationsPathFile()
);
if (function_exists('chmod'))

View File

@@ -37,6 +37,7 @@ class module_console_systemUpgrade extends Command
public function execute(InputInterface $input, OutputInterface $output)
{
$Core = \bootstrap::getCore();
if (!setup::is_installed())
{
@@ -53,29 +54,40 @@ class module_console_systemUpgrade extends Command
if ($continue == 'y')
{
$file = __DIR__ . "/../../../../config/config.sample.yml";
$file1 = __DIR__ . "/../../../../config/config.yml";
if (!copy($file, $file1))
try
{
throw new \Exception(sprintf("Unable to copy %s", $file1));
}
$Core->getConfiguration()->initialize();
$conn = \connection::getPDOConnection();
$retrieve_old_credentials = function()
{
require __DIR__ . '/../../../../config/connexion.inc';
$credentials = $conn->get_credentials();
return array(
'hostname' => $hostname,
'port' => $port,
'user' => $user,
'password' => $password,
'dbname' => $dbname,
);
};
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
$credentials = $retrieve_old_credentials();
$connexionINI = array();
$connexions = $Core->getConfiguration()->getConnexions();
foreach ($credentials as $key => $value)
{
$key = $key == 'hostname' ? 'host' : $key;
$connexionINI[$key] = (string) $value;
$connexions['main_connexion'][$key] = (string) $value;
}
$configuration->setAllDatabaseConnexion($connexionINI);
$Core->getConfiguration()->setConnexions($connexions);
$Core->getConfiguration()->setEnvironnement('prod');
}
catch (\Exception $e)
{
}
}
else
{
@@ -99,8 +111,9 @@ class module_console_systemUpgrade extends Command
{
try
{
$Core = \bootstrap::getCore();
$output->write('<info>Upgrading...</info>', true);
$appbox = appbox::get_instance(\bootstrap::getCore());
$appbox = appbox::get_instance($Core);
if (count(User_Adapter::get_wrong_email_users($appbox)) > 0)
{
@@ -110,8 +123,9 @@ class module_console_systemUpgrade extends Command
$upgrader = new Setup_Upgrade($appbox);
$advices = $appbox->forceUpgrade($upgrader);
}
catch (Exception $e)
catch (\Exception $e)
{
$output->writeln(sprintf('<error>An error occured while upgrading : %s </error>', $e->getMessage()));
}
}