Skip to content

Commit

Permalink
Show helpful message when config file is not readable
Browse files Browse the repository at this point in the history
  • Loading branch information
mattab committed Feb 18, 2014
1 parent ca55552 commit 3973958
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 15 deletions.
13 changes: 1 addition & 12 deletions console
Original file line number Diff line number Diff line change
Expand Up @@ -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();
44 changes: 41 additions & 3 deletions core/Console.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,23 @@

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();
Expand Down Expand Up @@ -55,7 +68,7 @@ private function getAvailableCommands()
* should subscribe to this event and add commands to the incoming array.
*
* **Example**
*
*
* public function addConsoleCommands(&$commands)
* {
* $commands[] = 'Piwik\Plugins\MyPlugin\Commands\MyCommand';
Expand All @@ -67,4 +80,29 @@ private function getAvailableCommands()

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);
}
}

0 comments on commit 3973958

Please sign in to comment.