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
|
|
@ -0,0 +1,79 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Application\Kernel;
|
||||
|
||||
use Piwik\Common;
|
||||
use Piwik\Piwik;
|
||||
use Piwik\SettingsServer;
|
||||
use Piwik\Translation\Translator;
|
||||
|
||||
/**
|
||||
* Validates the Piwik environment. This includes making sure the required config files
|
||||
* are present, and triggering the correct behaviour if otherwise.
|
||||
*/
|
||||
class EnvironmentValidator
|
||||
{
|
||||
/**
|
||||
* @var GlobalSettingsProvider
|
||||
*/
|
||||
protected $settingsProvider;
|
||||
|
||||
/**
|
||||
* @var Translator
|
||||
*/
|
||||
protected $translator;
|
||||
|
||||
public function __construct(GlobalSettingsProvider $settingsProvider, Translator $translator)
|
||||
{
|
||||
$this->settingsProvider = $settingsProvider;
|
||||
$this->translator = $translator;
|
||||
}
|
||||
|
||||
public function validate()
|
||||
{
|
||||
$inTrackerRequest = SettingsServer::isTrackerApiRequest();
|
||||
$inConsole = Common::isPhpCliMode();
|
||||
|
||||
$this->checkConfigFileExists($this->settingsProvider->getPathGlobal());
|
||||
$this->checkConfigFileExists($this->settingsProvider->getPathLocal(), $startInstaller = !$inTrackerRequest && !$inConsole);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param $path
|
||||
* @param bool $startInstaller
|
||||
* @throws \Exception
|
||||
*/
|
||||
private function checkConfigFileExists($path, $startInstaller = false)
|
||||
{
|
||||
if (is_readable($path)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$message = $this->translator->translate('General_ExceptionConfigurationFileNotFound', array($path));
|
||||
if (Common::isPhpCliMode()) {
|
||||
$message .= "\n" . $this->translator->translate('General_ExceptionConfigurationFileNotFound2', array($path, get_current_user()));
|
||||
}
|
||||
|
||||
$exception = new \Exception($message);
|
||||
|
||||
if ($startInstaller) {
|
||||
/**
|
||||
* Triggered when the configuration file cannot be found or read, which usually
|
||||
* means Piwik is not installed yet.
|
||||
*
|
||||
* This event can be used to start the installation process or to display a custom error message.
|
||||
*
|
||||
* @param \Exception $exception The exception that was thrown by `Config::getInstance()`.
|
||||
*/
|
||||
Piwik::postEvent('Config.NoConfigurationFile', array($exception), $pending = true);
|
||||
} else {
|
||||
throw $exception;
|
||||
}
|
||||
}
|
||||
}
|
||||
111
www/analytics/core/Application/Kernel/GlobalSettingsProvider.php
Normal file
111
www/analytics/core/Application/Kernel/GlobalSettingsProvider.php
Normal file
|
|
@ -0,0 +1,111 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Application\Kernel;
|
||||
|
||||
use Piwik\Config;
|
||||
use Piwik\Config\IniFileChain;
|
||||
|
||||
/**
|
||||
* Provides global settings. Global settings are organized in sections where
|
||||
* each section contains a list of name => value pairs. Setting values can
|
||||
* be primitive values or arrays of primitive values.
|
||||
*
|
||||
* Uses the config.ini.php, common.ini.php and global.ini.php files to provide global settings.
|
||||
*
|
||||
* At the moment a singleton instance of this class is used in order to get tests to pass.
|
||||
*/
|
||||
class GlobalSettingsProvider
|
||||
{
|
||||
/**
|
||||
* @var IniFileChain
|
||||
*/
|
||||
protected $iniFileChain;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pathGlobal = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pathCommon = null;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
protected $pathLocal = null;
|
||||
|
||||
/**
|
||||
* @param string|null $pathGlobal Path to the global.ini.php file. Or null to use the default.
|
||||
* @param string|null $pathLocal Path to the config.ini.php file. Or null to use the default.
|
||||
* @param string|null $pathCommon Path to the common.ini.php file. Or null to use the default.
|
||||
*/
|
||||
public function __construct($pathGlobal = null, $pathLocal = null, $pathCommon = null)
|
||||
{
|
||||
$this->pathGlobal = $pathGlobal ?: Config::getGlobalConfigPath();
|
||||
$this->pathCommon = $pathCommon ?: Config::getCommonConfigPath();
|
||||
$this->pathLocal = $pathLocal ?: Config::getLocalConfigPath();
|
||||
|
||||
$this->iniFileChain = new IniFileChain();
|
||||
$this->reload();
|
||||
}
|
||||
|
||||
public function reload($pathGlobal = null, $pathLocal = null, $pathCommon = null)
|
||||
{
|
||||
$this->pathGlobal = $pathGlobal ?: $this->pathGlobal;
|
||||
$this->pathCommon = $pathCommon ?: $this->pathCommon;
|
||||
$this->pathLocal = $pathLocal ?: $this->pathLocal;
|
||||
|
||||
$this->iniFileChain->reload(array($this->pathGlobal, $this->pathCommon), $this->pathLocal);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a settings section.
|
||||
*
|
||||
* @param string $name
|
||||
* @return array
|
||||
*/
|
||||
public function &getSection($name)
|
||||
{
|
||||
$section =& $this->iniFileChain->get($name);
|
||||
return $section;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a settings section.
|
||||
*
|
||||
* @param string $name
|
||||
* @param array $value
|
||||
*/
|
||||
public function setSection($name, $value)
|
||||
{
|
||||
$this->iniFileChain->set($name, $value);
|
||||
}
|
||||
|
||||
public function getIniFileChain()
|
||||
{
|
||||
return $this->iniFileChain;
|
||||
}
|
||||
|
||||
public function getPathGlobal()
|
||||
{
|
||||
return $this->pathGlobal;
|
||||
}
|
||||
|
||||
public function getPathLocal()
|
||||
{
|
||||
return $this->pathLocal;
|
||||
}
|
||||
|
||||
public function getPathCommon()
|
||||
{
|
||||
return $this->pathCommon;
|
||||
}
|
||||
}
|
||||
120
www/analytics/core/Application/Kernel/PluginList.php
Normal file
120
www/analytics/core/Application/Kernel/PluginList.php
Normal file
|
|
@ -0,0 +1,120 @@
|
|||
<?php
|
||||
/**
|
||||
* Piwik - free/libre analytics platform
|
||||
*
|
||||
* @link http://piwik.org
|
||||
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace Piwik\Application\Kernel;
|
||||
|
||||
/**
|
||||
* Lists the currently activated plugins. Used when setting up Piwik's environment before
|
||||
* initializing the DI container.
|
||||
*
|
||||
* Uses the [Plugins] section in Piwik's INI config to get the activated plugins.
|
||||
*
|
||||
* Depends on GlobalSettingsProvider being used.
|
||||
*
|
||||
* TODO: parts of Plugin\Manager edit the plugin list; maybe PluginList implementations should be mutable?
|
||||
*/
|
||||
class PluginList
|
||||
{
|
||||
/**
|
||||
* @var GlobalSettingsProvider
|
||||
*/
|
||||
private $settings;
|
||||
|
||||
/**
|
||||
* Plugins bundled with core package, disabled by default
|
||||
* @var array
|
||||
*/
|
||||
private $corePluginsDisabledByDefault = array(
|
||||
'DBStats',
|
||||
'ExampleCommand',
|
||||
'ExampleSettingsPlugin',
|
||||
'ExampleUI',
|
||||
'ExampleVisualization',
|
||||
'ExamplePluginTemplate',
|
||||
'ExampleTracker',
|
||||
'ExampleReport',
|
||||
'MobileAppMeasurable',
|
||||
'Provider'
|
||||
);
|
||||
|
||||
// Themes bundled with core package, disabled by default
|
||||
private $coreThemesDisabledByDefault = array(
|
||||
'ExampleTheme'
|
||||
);
|
||||
|
||||
public function __construct(GlobalSettingsProvider $settings)
|
||||
{
|
||||
$this->settings = $settings;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of plugins that should be loaded. Used by the container factory to
|
||||
* load plugin specific DI overrides.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getActivatedPlugins()
|
||||
{
|
||||
$section = $this->settings->getSection('Plugins');
|
||||
return @$section['Plugins'] ?: array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the list of plugins that are bundled with Piwik.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getPluginsBundledWithPiwik()
|
||||
{
|
||||
$pathGlobal = $this->settings->getPathGlobal();
|
||||
|
||||
$section = $this->settings->getIniFileChain()->getFrom($pathGlobal, 'Plugins');
|
||||
return $section['Plugins'];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the plugins bundled with core package that are disabled by default.
|
||||
*
|
||||
* @return string[]
|
||||
*/
|
||||
public function getCorePluginsDisabledByDefault()
|
||||
{
|
||||
return array_merge($this->corePluginsDisabledByDefault, $this->coreThemesDisabledByDefault);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sorts an array of plugins in the order they should be loaded.
|
||||
*
|
||||
* @params string[] $plugins
|
||||
* @return \string[]
|
||||
*/
|
||||
public function sortPlugins(array $plugins)
|
||||
{
|
||||
$global = $this->getPluginsBundledWithPiwik();
|
||||
if (empty($global)) {
|
||||
return $plugins;
|
||||
}
|
||||
|
||||
// we need to make sure a possibly disabled plugin will be still loaded before any 3rd party plugin
|
||||
$global = array_merge($global, $this->corePluginsDisabledByDefault);
|
||||
|
||||
$global = array_values($global);
|
||||
$plugins = array_values($plugins);
|
||||
|
||||
$defaultPluginsLoadedFirst = array_intersect($global, $plugins);
|
||||
|
||||
$otherPluginsToLoadAfterDefaultPlugins = array_diff($plugins, $defaultPluginsLoadedFirst);
|
||||
|
||||
// sort by name to have a predictable order for those extra plugins
|
||||
sort($otherPluginsToLoadAfterDefaultPlugins);
|
||||
|
||||
$sorted = array_merge($defaultPluginsLoadedFirst, $otherPluginsToLoadAfterDefaultPlugins);
|
||||
|
||||
return $sorted;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue