From abae32ca5f95441e7363cdfe93fbceddf5f66b03 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 2 Oct 2013 18:30:48 +0200 Subject: [PATCH] Fix #1489 : Let errors happen when they occur --- bin/console | 107 +++++++++---------- bin/developer | 91 ++++++++-------- bin/setup | 43 ++++---- lib/classes/module/console/systemUpgrade.php | 51 ++++----- 4 files changed, 133 insertions(+), 159 deletions(-) diff --git a/bin/console b/bin/console index c9f2c76fdb..5982037aa6 100755 --- a/bin/console +++ b/bin/console @@ -33,8 +33,7 @@ use Alchemy\Phrasea\Command\Setup\XSendFileConfigurationDumper; require_once __DIR__ . '/../lib/autoload.php'; -try { - $cli = new CLI(" +$cli = new CLI(" _____ _ _ _____ _____ ______ _ _ ______ _______ | __ \| | | | __ \ /\ / ____| ____| /\ | \ | | ____|__ __| | |__) | |__| | |__) | / \ | (___ | |__ / \ | \| | |__ | | @@ -52,60 +51,54 @@ try { under certain conditions; type `about:license' for details.\n\n" . ' KONSOLE KOMMANDER', Version::getName() . ' ' . Version::getNumber()); - if (!$cli['phraseanet.configuration-tester']->isInstalled()) { - throw new \RuntimeException('Phraseanet is not installed, use setup command instead'); - } - if (!$cli['phraseanet.configuration-tester']->isUpToDate()) { - throw new \RuntimeException('Phraseanet is not up-to-date, use setup command instead'); - } - - $cli->command(new \module_console_aboutAuthors('about:authors')); - $cli->command(new \module_console_aboutLicense('about:license')); - - $cli->command(new CheckConfig('check:config')); - $cli->command(new \module_console_checkExtension('check:extension')); - - $cli->command(new UpgradeDBDatas('system:upgrade-datas')); - - $cli->command(new \module_console_sphinxGenerateSuggestion('sphinx:generate-suggestions')); - - $cli->command(new \module_console_systemMailCheck('system:mail-check')); - $cli->command(new \module_console_systemBackupDB('system:backup-db')); - $cli->command(new \module_console_systemClearCache('system:clear-cache')); - $cli->command(new \module_console_systemExport('system:export')); - - $cli->command(new \module_console_taskrun('task:run')); - $cli->command(new \module_console_tasklist('task:list')); - $cli->command(new \module_console_taskState('task:state')); - $cli->command(new \module_console_schedulerState('scheduler:state')); - $cli->command(new \module_console_schedulerStop('scheduler:stop')); - $cli->command(new \module_console_schedulerStart('scheduler:start')); - - $cli->command(new MailTest('mail:test')); - - $cli->command(new \module_console_fieldsList('fields:list')); - $cli->command(new \module_console_fieldsDelete('fields:delete')); - $cli->command(new \module_console_fieldsRename('fields:rename')); - $cli->command(new \module_console_fieldsMerge('fields:merge')); - - $cli->command(new CreateCollection('collection:create')); - - $cli->command(new RecordAdd('records:add')); - $cli->command(new RescanTechnicalDatas('records:rescan-technical-datas')); - $cli->command(new BuildMissingSubdefs('records:build-missing-subdefs')); - - $cli->command(new AddPlugin()); - $cli->command(new RemovePlugin()); - $cli->command(new Configuration()); - $cli->command(new XSendFileConfigurationDumper()); - $cli->command(new XSendFileMappingGenerator()); - - $cli->loadPlugins(); - - $result_code = is_int($cli->run()) ? : 1; -} catch (\Exception $e) { - $result_code = 1; - echo sprintf("\nAn error occured :\n\n\t\033[0;31m%s\033[0;37m\n\n", $e->getMessage()); +if (!$cli['phraseanet.configuration-tester']->isInstalled()) { + throw new \RuntimeException('Phraseanet is not installed, use setup command instead'); +} +if (!$cli['phraseanet.configuration-tester']->isUpToDate()) { + throw new \RuntimeException('Phraseanet is not up-to-date, use setup command instead'); } -exit($result_code); +$cli->command(new \module_console_aboutAuthors('about:authors')); +$cli->command(new \module_console_aboutLicense('about:license')); + +$cli->command(new CheckConfig('check:config')); +$cli->command(new \module_console_checkExtension('check:extension')); + +$cli->command(new UpgradeDBDatas('system:upgrade-datas')); + +$cli->command(new \module_console_sphinxGenerateSuggestion('sphinx:generate-suggestions')); + +$cli->command(new \module_console_systemMailCheck('system:mail-check')); +$cli->command(new \module_console_systemBackupDB('system:backup-db')); +$cli->command(new \module_console_systemClearCache('system:clear-cache')); +$cli->command(new \module_console_systemExport('system:export')); + +$cli->command(new \module_console_taskrun('task:run')); +$cli->command(new \module_console_tasklist('task:list')); +$cli->command(new \module_console_taskState('task:state')); +$cli->command(new \module_console_schedulerState('scheduler:state')); +$cli->command(new \module_console_schedulerStop('scheduler:stop')); +$cli->command(new \module_console_schedulerStart('scheduler:start')); + +$cli->command(new MailTest('mail:test')); + +$cli->command(new \module_console_fieldsList('fields:list')); +$cli->command(new \module_console_fieldsDelete('fields:delete')); +$cli->command(new \module_console_fieldsRename('fields:rename')); +$cli->command(new \module_console_fieldsMerge('fields:merge')); + +$cli->command(new CreateCollection('collection:create')); + +$cli->command(new RecordAdd('records:add')); +$cli->command(new RescanTechnicalDatas('records:rescan-technical-datas')); +$cli->command(new BuildMissingSubdefs('records:build-missing-subdefs')); + +$cli->command(new AddPlugin()); +$cli->command(new RemovePlugin()); +$cli->command(new Configuration()); +$cli->command(new XSendFileConfigurationDumper()); +$cli->command(new XSendFileMappingGenerator()); + +$cli->loadPlugins(); + +exit(is_int($cli->run()) ? : 1); diff --git a/bin/developer b/bin/developer index 0e2f6f3159..38275b527c 100755 --- a/bin/developer +++ b/bin/developer @@ -44,8 +44,7 @@ use Doctrine\ORM\Tools\Console\Command\ValidateSchemaCommand; require_once __DIR__ . '/../lib/autoload.php'; -try { - $cli = new CLI(" +$cli = new CLI(" ___ ___ _ _ ___ __ __ ___ ___ ___ ____ __ __ __ ___ ( \( _)( )( )( _)( ) / \( ,\( _)( ,) (_ _)/ \ / \( ) / __) ) ) )) _) \\// ) _) )(__( () )) _/ ) _) ) \ )( ( () )( () ))(__ \__ \ @@ -57,54 +56,48 @@ try { under certain conditions; type `about:license' for details.\n\n" . ' Phraseanet Developer Tools ', Version::getName() . ' ' . Version::getNumber()); - if ($cli['phraseanet.configuration']->isSetup()) { - $helpers = array( - 'db' => new ConnectionHelper($cli['EM']->getConnection()), - 'em' => new EntityManagerHelper($cli['EM']) - ); +if ($cli['phraseanet.configuration']->isSetup()) { + $helpers = array( + 'db' => new ConnectionHelper($cli['EM']->getConnection()), + 'em' => new EntityManagerHelper($cli['EM']) + ); - $helperSet = $cli['console']->getHelperSet(); - foreach ($helpers as $name => $helper) { - $helperSet->set($helper, $name); - } + $helperSet = $cli['console']->getHelperSet(); + foreach ($helpers as $name => $helper) { + $helperSet->set($helper, $name); } - - $cli->command(new InstallAll()); - $cli->command(new BowerInstall()); - $cli->command(new ComposerInstall()); - $cli->command(new RegenerateSqliteDb()); - $cli->command(new APIRoutesDumper()); - $cli->command(new RoutesDumper()); - $cli->command(new Behat()); - $cli->command(new LessCompiler()); - $cli->command(new JavascriptBuilder()); - $cli->command(new \module_console_systemTemplateGenerator('system:generate-templates')); - - $cli['console']->addCommands(array( - // DBAL Commands - new RunSqlCommand(), - new ImportCommand(), - // ORM Commands - new MetadataCommand(), - new ResultCommand(), - new QueryCommand(), - new CreateCommand(), - new UpdateCommand(), - new DropCommand(), - new EnsureProductionSettingsCommand(), - new ConvertDoctrine1SchemaCommand(), - new GenerateRepositoriesCommand(), - new GenerateEntitiesCommand(), - new GenerateProxiesCommand(), - new ConvertMappingCommand(), - new RunDqlCommand(), - new ValidateSchemaCommand(), - )); - - $cli->runCLI(); -} catch (Exception $e) { - echo "an error occured : " . $e->getMessage(); - exit(1); } -exit(0); +$cli->command(new InstallAll()); +$cli->command(new BowerInstall()); +$cli->command(new ComposerInstall()); +$cli->command(new RegenerateSqliteDb()); +$cli->command(new APIRoutesDumper()); +$cli->command(new RoutesDumper()); +$cli->command(new Behat()); +$cli->command(new LessCompiler()); +$cli->command(new JavascriptBuilder()); +$cli->command(new \module_console_systemTemplateGenerator('system:generate-templates')); + +$cli['console']->addCommands(array( + // DBAL Commands + new RunSqlCommand(), + new ImportCommand(), + // ORM Commands + new MetadataCommand(), + new ResultCommand(), + new QueryCommand(), + new CreateCommand(), + new UpdateCommand(), + new DropCommand(), + new EnsureProductionSettingsCommand(), + new ConvertDoctrine1SchemaCommand(), + new GenerateRepositoriesCommand(), + new GenerateEntitiesCommand(), + new GenerateProxiesCommand(), + new ConvertMappingCommand(), + new RunDqlCommand(), + new ValidateSchemaCommand(), +)); + +exit($cli->runCLI()); diff --git a/bin/setup b/bin/setup index 1a0dfc3440..8bf9f6f669 100755 --- a/bin/setup +++ b/bin/setup @@ -25,8 +25,7 @@ use Alchemy\Phrasea\Command\Setup\CheckEnvironment; require_once __DIR__ . '/../vendor/autoload.php'; -try { - $app = new CLI(" +$app = new CLI(" _____ _ _ _____ _____ ______ _ _ ______ _______ | __ \| | | | __ \ /\ / ____| ____| /\ | \ | | ____|__ __| | |__) | |__| | |__) | / \ | (___ | |__ / \ | \| | |__ | | @@ -46,29 +45,23 @@ try { under certain conditions; type `about:license' for details.\n\n" . ' SETUP', Version::getName() . ' ' . Version::getNumber()); - $app->command(new \module_console_aboutAuthors('about:authors')); - $app->command(new \module_console_aboutLicense('about:license')); +$app->command(new \module_console_aboutAuthors('about:authors')); +$app->command(new \module_console_aboutLicense('about:license')); - if( - $app['phraseanet.configuration-tester']->isMigrable() - || $app['phraseanet.configuration-tester']->isUpgradable() - || $app['phraseanet.configuration-tester']->isInstalled() - ) { - $app->command(new \module_console_systemUpgrade('system:upgrade')); - } - - if ($app['phraseanet.configuration-tester']->isInstalled()) { - $app->command(new UpgradeDBDatas('system:upgrade-datas')); - } - - $app->command(new PluginsReset()); - $app->command(new CheckEnvironment('check:system')); - $app->command(new Install('system:install')); - - $result_code = is_int($app->run()) ? : 1; -} catch (\Exception $e) { - $result_code = 1; - echo sprintf("\nAn error occured :\n\n\t\033[0;31m%s\033[0;37m\n\n", $e->getMessage()); +if( + $app['phraseanet.configuration-tester']->isMigrable() + || $app['phraseanet.configuration-tester']->isUpgradable() + || $app['phraseanet.configuration-tester']->isInstalled() + ) { + $app->command(new \module_console_systemUpgrade('system:upgrade')); } -exit($result_code); +if ($app['phraseanet.configuration-tester']->isInstalled()) { + $app->command(new UpgradeDBDatas('system:upgrade-datas')); +} + +$app->command(new PluginsReset()); +$app->command(new CheckEnvironment('check:system')); +$app->command(new Install('system:install')); + +exit(is_int($app->run()) ? : 1); diff --git a/lib/classes/module/console/systemUpgrade.php b/lib/classes/module/console/systemUpgrade.php index 05827825e9..d419c8946f 100644 --- a/lib/classes/module/console/systemUpgrade.php +++ b/lib/classes/module/console/systemUpgrade.php @@ -64,43 +64,38 @@ class module_console_systemUpgrade extends Command } if ($continue == 'y') { - try { - $output->write('Upgrading...', true); + $output->write('Upgrading...', true); - if (count(User_Adapter::get_wrong_email_users($this->container)) > 0) { - return $output->writeln(sprintf('You have to fix your database before upgrade with the system:mailCheck command ')); - } + if (count(User_Adapter::get_wrong_email_users($this->container)) > 0) { + return $output->writeln(sprintf('You have to fix your database before upgrade with the system:mailCheck command ')); + } - $upgrader = new Setup_Upgrade($this->container, $input->getOption('force')); + $upgrader = new Setup_Upgrade($this->container, $input->getOption('force')); - $queries = $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container); + $queries = $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container); - if ($input->getOption('dump')) { - if (0 < count($queries)) { - $output->writeln("Some SQL queries can be executed to optimize\n"); + if ($input->getOption('dump')) { + if (0 < count($queries)) { + $output->writeln("Some SQL queries can be executed to optimize\n"); - foreach ($queries as $query) { - $output->writeln(" ".$query['sql']); - } - - $output->writeln("\n"); - } else { - $output->writeln("No SQL queries to execute to optimize\n"); + foreach ($queries as $query) { + $output->writeln(" ".$query['sql']); } + + $output->writeln("\n"); + } else { + $output->writeln("No SQL queries to execute to optimize\n"); } + } - foreach ($upgrader->getRecommendations() as $recommendation) { - list($message, $command) = $recommendation; + foreach ($upgrader->getRecommendations() as $recommendation) { + list($message, $command) = $recommendation; - $output->writeln(sprintf('%s', $message)); - $output->writeln(""); - $output->writeln(sprintf("\t\t%s", $command)); - $output->writeln(""); - $output->writeln(""); - } - } catch (\Exception $e) { - - $output->writeln(sprintf('An error occured while upgrading : %s ', $e->getMessage())); + $output->writeln(sprintf('%s', $message)); + $output->writeln(""); + $output->writeln(sprintf("\t\t%s", $command)); + $output->writeln(""); + $output->writeln(""); } } else { $output->write('Canceled', true);