Add upgrade recommendations

This commit is contained in:
Romain Neutron
2012-06-20 16:21:22 +02:00
parent 6355f5f7e2
commit 05576b11c2
4 changed files with 53 additions and 6 deletions

View File

@@ -58,6 +58,7 @@ try {
$app->add(new module_console_checkExtension('check:extension'));
$app->add(new module_console_systemUpgrade('system:upgrade'));
$app->add(new \Alchemy\Phrasea\Command\UpgradeDBDatas('system:upgrade-datas'));
$app->add(new module_console_sphinxGenerateSuggestion('sphinx:generate-suggestions'));
@@ -85,7 +86,7 @@ try {
$app->add(new Alchemy\Phrasea\Command\RescanTechnicalDatas('records:rescan-technical-datas'));
$app->add(new Alchemy\Phrasea\Command\BuildMissingSubdefs('records:build-missing-subdefs'));
$result_code = is_int($app->run()) ? : 1;
} catch (Exception $e) {
echo sprintf("an error occured : %s", $e->getMessage());

View File

@@ -31,6 +31,11 @@ class Setup_Upgrade
* @var string
*/
protected $message;
/**
*
* @var array
*/
protected $recommendations = array();
/**
*
@@ -119,6 +124,21 @@ class Setup_Upgrade
return $this;
}
/**
*
* @param type $recommendation
* @param type $command
*/
public function addRecommendation($recommendation, $command = null)
{
$this->recommendations[] = array($recommendation, $command);
}
public function getRecommendations()
{
return $this->recommendations;
}
/**
*
* @return float

View File

@@ -274,6 +274,8 @@ class appbox extends base
public function forceUpgrade(Setup_Upgrade &$upgrader)
{
$from_version = $this->get_version();
$upgrader->add_steps(7 + count($this->get_databoxes()));
$registry = $this->get_registry();
@@ -358,6 +360,17 @@ class appbox extends base
$upgrader->add_steps_complete(1);
if(version_compare($from_version, '3.1') < 0) {
$upgrader->addRecommendation(_('Your install requires data migration, please execute the following command'), 'bin/upgrader --from=3.1');
} elseif (version_compare($from_version, '3.5') < 0) {
$upgrader->addRecommendation(_('Your install requires data migration, please execute the following command'), 'bin/upgrader --from=3.5');
}
if (version_compare($from_version, '3.7') < 0) {
$upgrader->addRecommendation(_('Your install might need to re-read technical datas'), 'bin/console records:rescan-technical-datas');
$upgrader->addRecommendation(_('Your install might need to re-read technical datas'), 'bin/console records:build-missing-subdefs');
}
return $advices;
}

View File

@@ -27,7 +27,7 @@ class module_console_systemUpgrade extends Command
{
parent::__construct($name);
$this->setDescription('Upgrade Phraseanet to the lastest version');
$this->setDescription('Upgrade Phraseanet to the latest version');
return $this;
}
@@ -39,11 +39,12 @@ class module_console_systemUpgrade extends Command
public function execute(InputInterface $input, OutputInterface $output)
{
$this->checkSetup();
$old_connexion_file = __DIR__ . '/../../../../config/connexion.inc';
$old_config_file = __DIR__ . '/../../../../config/config.inc';
$Core = \bootstrap::getCore();
if ( ! setup::is_installed()) {
if ( ! $Core->getConfiguration()->isInstalled() && file_exists($old_config_file) && file_exists($old_connexion_file)) {
$output->writeln('This version of Phraseanet requires a config/config.yml, config/connexion.yml, config/service.yml');
$output->writeln('Would you like it to be created based on your settings ?');
@@ -55,8 +56,8 @@ class module_console_systemUpgrade extends Command
if ($continue == 'y') {
try {
$connexionInc = new \SplFileInfo(__DIR__ . '/../../../../config/connexion.inc', true);
$configInc = new \SplFileInfo(__DIR__ . '/../../../../config/config.inc', true);
$connexionInc = new \SplFileInfo($old_connexion_file, true);
$configInc = new \SplFileInfo($old_config_file, true);
$Core->getConfiguration()->upgradeFromOldConf($configInc, $connexionInc);
} catch (\Exception $e) {
@@ -67,6 +68,8 @@ class module_console_systemUpgrade extends Command
}
}
$this->checkSetup();
$output->write('Phraseanet is going to be upgraded', true);
$dialog = $this->getHelperSet()->get('dialog');
@@ -86,6 +89,16 @@ class module_console_systemUpgrade extends Command
$upgrader = new Setup_Upgrade($appbox);
$appbox->forceUpgrade($upgrader);
foreach ($upgrader->getRecommendations() as $recommendation) {
list($message, $command) = $recommendation;
$output->writeln(sprintf('<info>%s</info>', $message));
$output->writeln("");
$output->writeln(sprintf("\t\t%s", $command));
$output->writeln("");
$output->writeln("");
}
} catch (\Exception $e) {
$output->writeln(sprintf('<error>An error occured while upgrading : %s </error>', $e->getMessage()));