diff options
-rwxr-xr-x | console | 13 | ||||
-rw-r--r-- | core/Console.php | 44 |
2 files changed, 42 insertions, 15 deletions
@@ -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); + } } |