From 39739583d8587fa339f7750afe658e263e31d841 Mon Sep 17 00:00:00 2001 From: mattab Date: Tue, 18 Feb 2014 14:03:18 +1300 Subject: Show helpful message when config file is not readable --- console | 13 +------------ core/Console.php | 44 +++++++++++++++++++++++++++++++++++++++++--- 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/console b/console index 065eb736b3..47912e1508 100755 --- a/console +++ b/console @@ -17,17 +17,6 @@ Translate::loadEnglishTranslation(); if (!Common::isPhpCliMode()) { exit; } - -$piwikHostname = CronArchive::getParameterFromCli('piwik-domain', true); -$piwikHostname = UrlHelper::getHostFromUrl($piwikHostname); - -Url::setHost($piwikHostname); - -// load active plugins -$pluginsManager = Plugin\Manager::getInstance(); -$pluginsToLoad = Config::getInstance()->Plugins['Plugins']; -$pluginsManager->loadPlugins($pluginsToLoad); - - $console = new Console(); +$console->init(); $console->run(); \ No newline at end of file diff --git a/core/Console.php b/core/Console.php index 410ffa5eb7..5dd628743b 100644 --- a/core/Console.php +++ b/core/Console.php @@ -14,10 +14,23 @@ use Symfony\Component\Console\Input\InputOption; class Console { + public function init() + { + $this->initPiwikHost(); + $this->initConfig(); + $this->initPlugins(); + } + public function run() { - $console = new Application(); - $option = new InputOption('piwik-domain', null, InputOption::VALUE_OPTIONAL, 'Piwik URL (protocol and domain) eg. "http://piwik.example.org"'); + $console = new Application(); + + $option = new InputOption('piwik-domain', + null, + InputOption::VALUE_OPTIONAL, + 'Piwik URL (protocol and domain) eg. "http://piwik.example.org"' + ); + $console->getDefinition()->addOption($option); $commands = $this->getAvailableCommands(); @@ -55,7 +68,7 @@ class Console * should subscribe to this event and add commands to the incoming array. * * **Example** - * + * * public function addConsoleCommands(&$commands) * { * $commands[] = 'Piwik\Plugins\MyPlugin\Commands\MyCommand'; @@ -67,4 +80,29 @@ class Console return $commands; } + + protected function initPiwikHost() + { + $piwikHostname = CronArchive::getParameterFromCli('piwik-domain', true); + $piwikHostname = UrlHelper::getHostFromUrl($piwikHostname); + Url::setHost($piwikHostname); + } + + protected function initConfig() + { + $config = Config::getInstance(); + try { + $config->checkLocalConfigFound(); + return $config; + } catch (\Exception $e) { + die($e->getMessage() . "\n\n"); + } + } + + protected function initPlugins() + { + $pluginsToLoad = Config::getInstance()->Plugins['Plugins']; + $pluginsManager = Plugin\Manager::getInstance(); + $pluginsManager->loadPlugins($pluginsToLoad); + } } -- cgit v1.2.3