update Piwik to version 2.16 (fixes #91)
This commit is contained in:
parent
296343bf3b
commit
d885a4baa9
5833 changed files with 418860 additions and 226988 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - Open source web analytics
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
|
|
@ -8,19 +8,32 @@
|
|||
*/
|
||||
namespace Piwik;
|
||||
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Input\ArgvInput;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
use Piwik\Application\Environment;
|
||||
use Piwik\Config\ConfigNotFoundException;
|
||||
use Piwik\Container\StaticContainer;
|
||||
use Piwik\Plugin\Manager as PluginManager;
|
||||
use Symfony\Bridge\Monolog\Handler\ConsoleHandler;
|
||||
use Symfony\Component\Console\Application;
|
||||
use Symfony\Component\Console\Command\Command;
|
||||
use Symfony\Component\Console\Input\InputInterface;
|
||||
use Symfony\Component\Console\Input\InputOption;
|
||||
use Symfony\Component\Console\Output\OutputInterface;
|
||||
|
||||
class Console extends Application
|
||||
{
|
||||
public function __construct()
|
||||
/**
|
||||
* @var Environment
|
||||
*/
|
||||
private $environment;
|
||||
|
||||
public function __construct(Environment $environment = null)
|
||||
{
|
||||
$this->setServerArgsIfPhpCgi();
|
||||
|
||||
parent::__construct();
|
||||
|
||||
$this->environment = $environment;
|
||||
|
||||
$option = new InputOption('piwik-domain',
|
||||
null,
|
||||
InputOption::VALUE_OPTIONAL,
|
||||
|
|
@ -28,42 +41,60 @@ class Console extends Application
|
|||
);
|
||||
|
||||
$this->getDefinition()->addOption($option);
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
*/
|
||||
public function init()
|
||||
{
|
||||
// TODO: remove
|
||||
$option = new InputOption('xhprof',
|
||||
null,
|
||||
InputOption::VALUE_NONE,
|
||||
'Enable profiling with XHProf'
|
||||
);
|
||||
|
||||
$this->getDefinition()->addOption($option);
|
||||
}
|
||||
|
||||
public function doRun(InputInterface $input, OutputInterface $output)
|
||||
{
|
||||
$this->initPiwikHost($input);
|
||||
$this->initConfig($output);
|
||||
try {
|
||||
self::initPlugins();
|
||||
} catch(\Exception $e) {
|
||||
// Piwik not installed yet, no config file?
|
||||
if ($input->hasParameterOption('--xhprof')) {
|
||||
Profiler::setupProfilerXHProf(true, true);
|
||||
}
|
||||
|
||||
Translate::reloadLanguage('en');
|
||||
$this->initPiwikHost($input);
|
||||
$this->initEnvironment($output);
|
||||
$this->initLoggerOutput($output);
|
||||
|
||||
try {
|
||||
self::initPlugins();
|
||||
} catch (ConfigNotFoundException $e) {
|
||||
// Piwik not installed yet, no config file?
|
||||
Log::warning($e->getMessage());
|
||||
}
|
||||
|
||||
$commands = $this->getAvailableCommands();
|
||||
|
||||
foreach ($commands as $command) {
|
||||
|
||||
if (!class_exists($command)) {
|
||||
Log::warning(sprintf('Cannot add command %s, class does not exist', $command));
|
||||
} elseif (!is_subclass_of($command, 'Piwik\Plugin\ConsoleCommand')) {
|
||||
Log::warning(sprintf('Cannot add command %s, class does not extend Piwik\Plugin\ConsoleCommand', $command));
|
||||
} else {
|
||||
$this->add(new $command);
|
||||
}
|
||||
$this->addCommandIfExists($command);
|
||||
}
|
||||
|
||||
return parent::doRun($input, $output);
|
||||
$self = $this;
|
||||
return Access::doAsSuperUser(function () use ($input, $output, $self) {
|
||||
return call_user_func(array($self, 'Symfony\Component\Console\Application::doRun'), $input, $output);
|
||||
});
|
||||
}
|
||||
|
||||
private function addCommandIfExists($command)
|
||||
{
|
||||
if (!class_exists($command)) {
|
||||
Log::warning(sprintf('Cannot add command %s, class does not exist', $command));
|
||||
} elseif (!is_subclass_of($command, 'Piwik\Plugin\ConsoleCommand')) {
|
||||
Log::warning(sprintf('Cannot add command %s, class does not extend Piwik\Plugin\ConsoleCommand', $command));
|
||||
} else {
|
||||
/** @var Command $commandInstance */
|
||||
$commandInstance = new $command;
|
||||
|
||||
// do not add the command if it already exists; this way we can add the command ourselves in tests
|
||||
if (!$this->has($commandInstance->getName())) {
|
||||
$this->add($commandInstance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -74,11 +105,9 @@ class Console extends Application
|
|||
private function getAvailableCommands()
|
||||
{
|
||||
$commands = $this->getDefaultPiwikCommands();
|
||||
$detected = PluginManager::getInstance()->findMultipleComponents('Commands', 'Piwik\\Plugin\\ConsoleCommand');
|
||||
|
||||
$pluginNames = PluginManager::getInstance()->getLoadedPluginsName();
|
||||
foreach ($pluginNames as $pluginName) {
|
||||
$commands = array_merge($commands, $this->findCommandsInPlugin($pluginName));
|
||||
}
|
||||
$commands = array_merge($commands, $detected);
|
||||
|
||||
/**
|
||||
* Triggered to filter / restrict console commands. Plugins that want to restrict commands
|
||||
|
|
@ -103,52 +132,76 @@ class Console extends Application
|
|||
return $commands;
|
||||
}
|
||||
|
||||
private function findCommandsInPlugin($pluginName)
|
||||
private function setServerArgsIfPhpCgi()
|
||||
{
|
||||
$commands = array();
|
||||
if (Common::isPhpCgiType()) {
|
||||
$_SERVER['argv'] = array();
|
||||
foreach ($_GET as $name => $value) {
|
||||
$argument = $name;
|
||||
if (!empty($value)) {
|
||||
$argument .= '=' . $value;
|
||||
}
|
||||
|
||||
$files = Filesystem::globr(PIWIK_INCLUDE_PATH . '/plugins/' . $pluginName .'/Commands', '*.php');
|
||||
|
||||
foreach ($files as $file) {
|
||||
$klassName = sprintf('Piwik\\Plugins\\%s\\Commands\\%s', $pluginName, basename($file, '.php'));
|
||||
|
||||
if (!class_exists($klassName) || !is_subclass_of($klassName, 'Piwik\\Plugin\\ConsoleCommand')) {
|
||||
continue;
|
||||
$_SERVER['argv'][] = $argument;
|
||||
}
|
||||
|
||||
$klass = new \ReflectionClass($klassName);
|
||||
|
||||
if ($klass->isAbstract()) {
|
||||
continue;
|
||||
if (!defined('STDIN')) {
|
||||
define('STDIN', fopen('php://stdin', 'r'));
|
||||
}
|
||||
|
||||
$commands[] = $klassName;
|
||||
}
|
||||
}
|
||||
|
||||
return $commands;
|
||||
public static function isSupported()
|
||||
{
|
||||
return Common::isPhpCliMode() && !Common::isPhpCgiType();
|
||||
}
|
||||
|
||||
protected function initPiwikHost(InputInterface $input)
|
||||
{
|
||||
$piwikHostname = $input->getParameterOption('--piwik-domain');
|
||||
|
||||
if (empty($piwikHostname)) {
|
||||
$piwikHostname = $input->getParameterOption('--url');
|
||||
}
|
||||
|
||||
$piwikHostname = UrlHelper::getHostFromUrl($piwikHostname);
|
||||
Url::setHost($piwikHostname);
|
||||
}
|
||||
|
||||
protected function initConfig(OutputInterface $output)
|
||||
protected function initEnvironment(OutputInterface $output)
|
||||
{
|
||||
$config = Config::getInstance();
|
||||
try {
|
||||
$config->checkLocalConfigFound();
|
||||
if ($this->environment === null) {
|
||||
$this->environment = new Environment('cli');
|
||||
$this->environment->init();
|
||||
}
|
||||
|
||||
$config = Config::getInstance();
|
||||
return $config;
|
||||
} catch (\Exception $e) {
|
||||
$output->writeln($e->getMessage() . "\n");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the console output into the logger.
|
||||
*
|
||||
* Ideally, this should be done automatically with events:
|
||||
* @see http://symfony.com/fr/doc/current/components/console/events.html
|
||||
* @see Symfony\Bridge\Monolog\Handler\ConsoleHandler::onCommand()
|
||||
* But it would require to install Symfony's Event Dispatcher.
|
||||
*/
|
||||
private function initLoggerOutput(OutputInterface $output)
|
||||
{
|
||||
/** @var ConsoleHandler $consoleLogHandler */
|
||||
$consoleLogHandler = StaticContainer::get('Symfony\Bridge\Monolog\Handler\ConsoleHandler');
|
||||
$consoleLogHandler->setOutput($output);
|
||||
}
|
||||
|
||||
public static function initPlugins()
|
||||
{
|
||||
Plugin\Manager::getInstance()->loadActivatedPlugins();
|
||||
Plugin\Manager::getInstance()->loadPluginTranslations();
|
||||
}
|
||||
|
||||
private function getDefaultPiwikCommands()
|
||||
|
|
@ -156,11 +209,12 @@ class Console extends Application
|
|||
$commands = array(
|
||||
'Piwik\CliMulti\RequestCommand'
|
||||
);
|
||||
|
||||
|
||||
if (class_exists('Piwik\Plugins\EnterpriseAdmin\EnterpriseAdmin')) {
|
||||
$extra = new \Piwik\Plugins\EnterpriseAdmin\EnterpriseAdmin();
|
||||
$extra->addConsoleCommands($commands);
|
||||
}
|
||||
|
||||
return $commands;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue