mirror of
https://github.com/alchemy-fr/Phraseanet.git
synced 2025-10-10 19:43:16 +00:00
Refactor Upgrade
This commit is contained in:
@@ -24,176 +24,69 @@ require_once __DIR__ . '/../../../bootstrap.php';
|
||||
* @link www.phraseanet.com
|
||||
*/
|
||||
return call_user_func(function()
|
||||
{
|
||||
$app = new \Silex\Application();
|
||||
{
|
||||
$app = new \Silex\Application();
|
||||
|
||||
$app['Core'] = \bootstrap::getCore();
|
||||
$app['Core'] = \bootstrap::getCore();
|
||||
|
||||
$app['install'] = false;
|
||||
$app['upgrade'] = false;
|
||||
$app['install'] = false;
|
||||
$app['upgrade'] = false;
|
||||
|
||||
$app->before(function($a) use ($app)
|
||||
{
|
||||
if (\setup::is_installed())
|
||||
{
|
||||
$appbox = \appbox::get_instance($app['Core']);
|
||||
$app->before(function($a) use ($app)
|
||||
{
|
||||
if (\setup::is_installed())
|
||||
{
|
||||
$appbox = \appbox::get_instance($app['Core']);
|
||||
|
||||
if (!$appbox->need_major_upgrade())
|
||||
{
|
||||
throw new \Exception_Setup_PhraseaAlreadyInstalled();
|
||||
}
|
||||
if (!$appbox->need_major_upgrade())
|
||||
{
|
||||
throw new \Exception_Setup_PhraseaAlreadyInstalled();
|
||||
}
|
||||
|
||||
$app['upgrade'] = true;
|
||||
}
|
||||
elseif (\setup::needUpgradeConfigurationFile())
|
||||
{
|
||||
//copy config sample
|
||||
$configSampleFile = __DIR__ . "/../../../../config/config.sample.yml";
|
||||
$configFile = __DIR__ . "/../../../../config/config.yml";
|
||||
$app['upgrade'] = true;
|
||||
}
|
||||
elseif (\setup::needUpgradeConfigurationFile())
|
||||
{
|
||||
$connexionInc = new \SplFileObject(__DIR__ . '/../../../../config/connexion.inc');
|
||||
$configInc = new \SplFileObject(__DIR__ . '/../../../../config/config.inc');
|
||||
|
||||
if (!copy($configSampleFile, $configFile))
|
||||
{
|
||||
throw new \Exception(sprintf("Unable to copy %s", $configSampleFile));
|
||||
}
|
||||
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
|
||||
$configuration->upgradeFromOldConf($configInc, $connexionInc);
|
||||
|
||||
//copy service sample
|
||||
$serviceSampleFile = __DIR__ . "/../../../../config/services.sample.yml";
|
||||
$serviceFile = __DIR__ . "/../../../../config/services.yml";
|
||||
$app['install'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$app['install'] = true;
|
||||
}
|
||||
|
||||
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));
|
||||
}
|
||||
|
||||
$configuration = \Alchemy\Phrasea\Core\Configuration::build();
|
||||
|
||||
//refactor credentials
|
||||
$connexionINI = array();
|
||||
|
||||
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() . '/';
|
||||
|
||||
//write credentials to connexion file
|
||||
$connexionFile = $appConf->getConnexionFile();
|
||||
|
||||
$connexion = array(
|
||||
'main_connexion' => $connexionINI,
|
||||
'test_connexion' => array(
|
||||
'driver' => 'pdo_sqlite',
|
||||
'path' => realpath(__DIR__ . '/../../../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()));
|
||||
}
|
||||
|
||||
$cacheService = "array_cache";
|
||||
|
||||
if (extension_loaded('apc'))
|
||||
{
|
||||
$cacheService = "apc_cache";
|
||||
}
|
||||
elseif (extension_loaded('xcache'))
|
||||
{
|
||||
$cacheService = "xcache_cache";
|
||||
}
|
||||
|
||||
//rewrite service file
|
||||
$serviceFile = $appConf->getServicesFile();
|
||||
$services = $configuration->getConfigurationHandler()->getParser()->parse($serviceFile);
|
||||
|
||||
foreach ($services as $serviceName => $service)
|
||||
{
|
||||
if ($serviceName === "doctrine_prod")
|
||||
{
|
||||
|
||||
$services["doctrine_prod"]["options"]["orm"]["cache"] = array(
|
||||
"query" => $cacheService,
|
||||
"result" => $cacheService,
|
||||
"metadata" => $cacheService
|
||||
);
|
||||
}
|
||||
}
|
||||
$yaml = $configuration->getConfigurationHandler()->getParser()->dump($services, 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;
|
||||
}
|
||||
|
||||
if (is_array($value) && $key === 'prod')
|
||||
{
|
||||
$arrayConf[$key]["cache"] = $cacheService;
|
||||
}
|
||||
}
|
||||
|
||||
$app['install'] = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
$app['install'] = true;
|
||||
}
|
||||
|
||||
return;
|
||||
});
|
||||
return;
|
||||
});
|
||||
|
||||
|
||||
$app->get('/', function() use ($app)
|
||||
{
|
||||
if ($app['install'] === true)
|
||||
return $app->redirect('/setup/installer/');
|
||||
if ($app['upgrade'] === true)
|
||||
return $app->redirect('/setup/upgrader/');
|
||||
});
|
||||
$app->get('/', function() use ($app)
|
||||
{
|
||||
if ($app['install'] === true)
|
||||
return $app->redirect('/setup/installer/');
|
||||
if ($app['upgrade'] === true)
|
||||
return $app->redirect('/setup/upgrader/');
|
||||
});
|
||||
|
||||
|
||||
$app->mount('/installer/', new Controller\Installer());
|
||||
$app->mount('/upgrader/', new Controller\Upgrader());
|
||||
$app->mount('/test', new ControllerUtils\PathFileTest());
|
||||
$app->mount('/connection_test', new ControllerUtils\ConnectionTest());
|
||||
$app->mount('/installer/', new Controller\Installer());
|
||||
$app->mount('/upgrader/', new Controller\Upgrader());
|
||||
$app->mount('/test', new ControllerUtils\PathFileTest());
|
||||
$app->mount('/connection_test', new ControllerUtils\ConnectionTest());
|
||||
|
||||
$app->error(function($e) use ($app)
|
||||
{
|
||||
if ($e instanceof \Exception_Setup_PhraseaAlreadyInstalled)
|
||||
{
|
||||
return $app->redirect('/login/');
|
||||
}
|
||||
$app->error(function($e) use ($app)
|
||||
{
|
||||
if ($e instanceof \Exception_Setup_PhraseaAlreadyInstalled)
|
||||
{
|
||||
return $app->redirect('/login/');
|
||||
}
|
||||
|
||||
return new Response('Internal Server Error', 500);
|
||||
});
|
||||
return new Response('Internal Server Error', 500);
|
||||
});
|
||||
|
||||
return $app;
|
||||
});
|
||||
return $app;
|
||||
});
|
||||
|
@@ -37,6 +37,12 @@ class Configuration
|
||||
*/
|
||||
private $environment;
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Configuration\ApplicationSpecification $specifications
|
||||
* @param type $environment
|
||||
* @return \Alchemy\Phrasea\Core\Configuration
|
||||
*/
|
||||
public static function build($specifications = null, $environment = null)
|
||||
{
|
||||
if (!$specifications)
|
||||
@@ -46,6 +52,12 @@ class Configuration
|
||||
return new self($specifications, $environment);
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param Configuration\Specification $specifications
|
||||
* @param type $environment
|
||||
* @return \Alchemy\Phrasea\Core\Configuration
|
||||
*/
|
||||
public function __construct(Configuration\Specification $specifications, $environment = null)
|
||||
{
|
||||
$this->specifications = $specifications;
|
||||
@@ -65,6 +77,94 @@ class Configuration
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function upgradeFromOldConf(\SplFileObject $configInc, \SplFileObject $connexionInc)
|
||||
{
|
||||
$this->initialize();
|
||||
|
||||
$cacheService = "array_cache";
|
||||
|
||||
if (extension_loaded('apc'))
|
||||
{
|
||||
$cacheService = "apc_cache";
|
||||
}
|
||||
elseif (extension_loaded('xcache'))
|
||||
{
|
||||
$cacheService = "xcache_cache";
|
||||
}
|
||||
|
||||
$retrieve_old_credentials = function(\SplFileObject $connexionInc)
|
||||
{
|
||||
require $connexionInc->getPathname();
|
||||
|
||||
return array(
|
||||
'hostname' => $hostname,
|
||||
'port' => $port,
|
||||
'user' => $user,
|
||||
'password' => $password,
|
||||
'dbname' => $dbname,
|
||||
);
|
||||
};
|
||||
|
||||
$credentials = $retrieve_old_credentials($connexionInc);
|
||||
|
||||
$connexions = $this->getConnexions();
|
||||
|
||||
foreach ($credentials as $key => $value)
|
||||
{
|
||||
$key = $key == 'hostname' ? 'host' : $key;
|
||||
$connexions['main_connexion'][$key] = (string) $value;
|
||||
}
|
||||
|
||||
$this->setConnexions($connexions);
|
||||
|
||||
|
||||
$configs = $this->getConfigurations();
|
||||
|
||||
$retrieve_old_parameters = function(\SplFileObject $configInc)
|
||||
{
|
||||
require $configInc->getPathname();
|
||||
|
||||
return array(
|
||||
'servername' => $servername
|
||||
);
|
||||
};
|
||||
|
||||
$old_parameters = $retrieve_old_parameters($configInc);
|
||||
|
||||
foreach ($configs as $env => $conf)
|
||||
{
|
||||
if (isset($configs[$env]['phraseanet']))
|
||||
{
|
||||
$configs[$env]['phraseanet']['servername'] = $old_parameters['servername'];
|
||||
}
|
||||
|
||||
if ($env === 'prod' && isset($configs[$env]['cache']))
|
||||
{
|
||||
$configs[$env]["cache"] = $cacheService;
|
||||
}
|
||||
if ($env === 'prod' && isset($configs[$env]['opcodecache']))
|
||||
{
|
||||
$configs[$env]["opcodecache"] = $cacheService;
|
||||
}
|
||||
}
|
||||
$this->setConfigurations($configs);
|
||||
|
||||
$services = $this->getServices();
|
||||
|
||||
if (isset($services['Orm']["doctrine_prod"]["options"]["cache"]))
|
||||
{
|
||||
$services['Orm']["doctrine_prod"]["options"]["cache"]['query']['service'] = $cacheService;
|
||||
$services['Orm']["doctrine_prod"]["options"]["cache"]['result']['service'] = $cacheService;
|
||||
$services['Orm']["doctrine_prod"]["options"]["cache"]['metadata']['service'] = $cacheService;
|
||||
}
|
||||
|
||||
$this->setServices($services);
|
||||
|
||||
$this->setEnvironnement('prod');
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current used environnement
|
||||
*
|
||||
@@ -89,7 +189,7 @@ class Configuration
|
||||
{
|
||||
$configurations = $this->specifications->getConfigurations();
|
||||
|
||||
if(!isset($configurations[$this->environment]))
|
||||
if (!isset($configurations[$this->environment]))
|
||||
{
|
||||
throw new \Exception('Requested environnment is not available');
|
||||
}
|
||||
|
@@ -53,60 +53,12 @@ class module_console_systemUpgrade extends Command
|
||||
|
||||
if ($continue == 'y')
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
$Core->getConfiguration()->initialize();
|
||||
$connexionInc = new \SplFileObject(__DIR__ . '/../../../../config/connexion.inc');
|
||||
$configInc = new \SplFileObject(__DIR__ . '/../../../../config/config.inc');
|
||||
|
||||
$retrieve_old_credentials = function()
|
||||
{
|
||||
require __DIR__ . '/../../../../config/connexion.inc';
|
||||
|
||||
return array(
|
||||
'hostname' => $hostname,
|
||||
'port' => $port,
|
||||
'user' => $user,
|
||||
'password' => $password,
|
||||
'dbname' => $dbname,
|
||||
);
|
||||
};
|
||||
|
||||
$credentials = $retrieve_old_credentials();
|
||||
|
||||
$connexions = $Core->getConfiguration()->getConnexions();
|
||||
|
||||
foreach ($credentials as $key => $value)
|
||||
{
|
||||
$key = $key == 'hostname' ? 'host' : $key;
|
||||
$connexions['main_connexion'][$key] = (string) $value;
|
||||
}
|
||||
|
||||
$Core->getConfiguration()->setConnexions($connexions);
|
||||
|
||||
|
||||
$configs = $Core->getConfiguration()->getConfigurations();
|
||||
|
||||
$retrieve_old_parameters = function()
|
||||
{
|
||||
require __DIR__ . '/../../../../config/config.inc';
|
||||
|
||||
return array(
|
||||
'servername' => $servername
|
||||
);
|
||||
};
|
||||
|
||||
$old_parameters = $retrieve_old_parameters();
|
||||
|
||||
foreach ($configs as $env => $conf)
|
||||
{
|
||||
if (isset($configs[$env]['phraseanet']))
|
||||
{
|
||||
$configs[$env]['phraseanet']['servername'] = $old_parameters['servername'];
|
||||
}
|
||||
}
|
||||
$Core->getConfiguration()->setConfigurations($configs);
|
||||
|
||||
$Core->getConfiguration()->setEnvironnement('prod');
|
||||
$Core->getConfiguration()->upgradeFromOldConf($configInc, $connexionInc);
|
||||
}
|
||||
catch (\Exception $e)
|
||||
{
|
||||
|
Reference in New Issue
Block a user