Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/matomo-org/matomo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattab <matthieu.aubry@gmail.com>2013-11-06 05:42:01 +0400
committermattab <matthieu.aubry@gmail.com>2013-11-06 05:42:01 +0400
commitf3fcfa6368ba0dcb551043f61dfdb59e2e53f1a5 (patch)
treecdf010e1167a6d4dfe91dc60ce7e45aca385d465
parent742794dd8dd05775aa686a575def21492e021e11 (diff)
Refs #4278 Creating a new class PluginsArchiver to refactor logic out of ArchiveProcessor\Loader
-rw-r--r--core/ArchiveProcessor.php6
-rw-r--r--core/ArchiveProcessor/Loader.php159
-rw-r--r--core/ArchiveProcessor/Parameters.php38
-rw-r--r--core/ArchiveProcessor/PluginsArchiver.php108
-rw-r--r--core/ArchiveProcessor/Rules.php3
-rw-r--r--core/AssetManager.php2
-rw-r--r--core/Common.php3
-rw-r--r--core/Plugin/Archiver.php6
-rw-r--r--libs/pChart2.1.3/index.php6
9 files changed, 179 insertions, 152 deletions
diff --git a/core/ArchiveProcessor.php b/core/ArchiveProcessor.php
index 7587f7d4e6..50f8898512 100644
--- a/core/ArchiveProcessor.php
+++ b/core/ArchiveProcessor.php
@@ -83,7 +83,6 @@ use Piwik\Plugin\Archiver;
*/
class ArchiveProcessor
{
-
/**
* @var \Piwik\DataAccess\ArchiveWriter
*/
@@ -100,6 +99,11 @@ class ArchiveProcessor
public $archive = null;
/**
+ * @var Parameters
+ */
+ protected $params;
+
+ /**
* @var int
*/
protected $numberOfVisits;
diff --git a/core/ArchiveProcessor/Loader.php b/core/ArchiveProcessor/Loader.php
index 8a1e4fd1bc..9ce06802d9 100644
--- a/core/ArchiveProcessor/Loader.php
+++ b/core/ArchiveProcessor/Loader.php
@@ -14,26 +14,18 @@ use Piwik\ArchiveProcessor;
use Piwik\Config;
use Piwik\DataAccess\ArchiveSelector;
use Piwik\DataAccess\ArchiveWriter;
-use Piwik\DataAccess\LogAggregator;
use Piwik\Date;
use Piwik\Log;
use Piwik\Metrics;
use Piwik\Period;
use Piwik\Plugin\Archiver;
-use Piwik\Segment;
-use Piwik\Site;
/**
- * This class manages the ArchiveProcessor
+ * This class manages the ArchiveProcessor and
*/
class Loader
{
/**
- * @var LogAggregator
- */
- private $logAggregator = null;
-
- /**
* @var int Cached number of visits cached
*/
protected $visitsMetricCached = false;
@@ -44,11 +36,6 @@ class Loader
protected $convertedVisitsMetricCached = false;
/**
- * @var string Plugin name which triggered this archive processor
- */
- protected $requestedPlugin = false;
-
- /**
* Is the current archive temporary. ie.
* - today
* - current week / month / year
@@ -98,14 +85,12 @@ class Loader
return $this->convertedVisitsMetricCached;
}
- public function preProcessArchive($requestedPlugin, $enforceProcessCoreMetricsOnly = false)
+ public function preProcessArchive($enforceProcessCoreMetricsOnly = false)
{
$this->idArchive = false;
- $this->setRequestedPlugin($requestedPlugin);
-
if (!$enforceProcessCoreMetricsOnly) {
- $this->idArchive = $this->loadExistingArchiveIdFromDb($requestedPlugin);
+ $this->idArchive = $this->loadExistingArchiveIdFromDb();
if ($this->isArchivingForcedToTrigger()) {
$this->idArchive = false;
$this->setNumberOfVisits(false);
@@ -116,35 +101,33 @@ class Loader
$visitsNotKnownYet = $this->getNumberOfVisits() === false;
- $createAnotherArchiveForVisitsSummary = !$this->doesRequestedPluginIncludeVisitsSummary($requestedPlugin) && $visitsNotKnownYet;
+ $createAnotherArchiveForVisitsSummary = !$this->doesRequestedPluginIncludeVisitsSummary() && $visitsNotKnownYet;
if ($createAnotherArchiveForVisitsSummary) {
// recursive archive creation in case we create another separate one, for VisitsSummary core metrics
// We query VisitsSummary here, as it is needed in the call below ($this->getNumberOfVisits() > 0)
- $requestedPlugin = $this->getRequestedPlugin();
- $this->preProcessArchive('VisitsSummary', $pleaseProcessCoreMetricsOnly = true);
- $this->setRequestedPlugin($requestedPlugin);
+ $requestedPlugin = $this->params->getRequestedPlugin();
+ $this->params->setRequestedPlugin('VisitsSummary');
+
+ $this->preProcessArchive($pleaseProcessCoreMetricsOnly = true);
+
+ $this->params->setRequestedPlugin($requestedPlugin);
if ($this->getNumberOfVisits() === false) {
throw new \Exception("preProcessArchive() is expected to set number of visits to a numeric value.");
}
}
}
- return $this->computeNewArchive($requestedPlugin, $enforceProcessCoreMetricsOnly);
+ return $this->computeNewArchive($enforceProcessCoreMetricsOnly);
}
- protected function doesRequestedPluginIncludeVisitsSummary($requestedPlugin)
+ protected function doesRequestedPluginIncludeVisitsSummary()
{
$processAllReportsIncludingVisitsSummary = Rules::shouldProcessReportsAllPlugins($this->params->getSegment(), $this->params->getPeriod()->getLabel());
- $doesRequestedPluginIncludeVisitsSummary = $processAllReportsIncludingVisitsSummary || $requestedPlugin == 'VisitsSummary';
+ $doesRequestedPluginIncludeVisitsSummary = $processAllReportsIncludingVisitsSummary || $this->params->getRequestedPlugin() == 'VisitsSummary';
return $doesRequestedPluginIncludeVisitsSummary;
}
- protected function setRequestedPlugin($plugin)
- {
- $this->requestedPlugin = $plugin;
- }
-
protected function isArchivingForcedToTrigger()
{
$period = $this->params->getPeriod()->getLabel();
@@ -161,15 +144,15 @@ class Loader
* Returns the idArchive if the archive is available in the database for the requested plugin.
* Returns false if the archive needs to be processed.
*
- * @param $requestedPlugin
* @return int or false
*/
- protected function loadExistingArchiveIdFromDb($requestedPlugin)
+ protected function loadExistingArchiveIdFromDb()
{
$minDatetimeArchiveProcessedUTC = $this->getMinTimeArchiveProcessed();
$site = $this->params->getSite();
$period = $this->params->getPeriod();
$segment = $this->params->getSegment();
+ $requestedPlugin = $this->params->getRequestedPlugin();
$idAndVisits = ArchiveSelector::getArchiveIdAndVisits($site, $period, $segment, $minDatetimeArchiveProcessedUTC, $requestedPlugin);
if (!$idAndVisits) {
@@ -180,20 +163,20 @@ class Loader
return $idArchive;
}
- protected function computeNewArchive($requestedPlugin, $enforceProcessCoreMetricsOnly)
+ protected function computeNewArchive($enforceProcessCoreMetricsOnly)
{
- $archiveWriter = new ArchiveWriter($this->params->getSite()->getId(), $this->params->getSegment(), $this->params->getPeriod(), $requestedPlugin, $this->isArchiveTemporary());
+ $archiveWriter = new ArchiveWriter($this->params->getSite()->getId(), $this->params->getSegment(), $this->params->getPeriod(), $this->params->getRequestedPlugin(), $this->isArchiveTemporary());
$archiveWriter->initNewArchive();
$archiveProcessor = $this->makeArchiveProcessor($archiveWriter);
$visitsNotKnownYet = $this->getNumberOfVisits() === false;
if ($visitsNotKnownYet
- || $this->doesRequestedPluginIncludeVisitsSummary($requestedPlugin)
+ || $this->doesRequestedPluginIncludeVisitsSummary()
|| $enforceProcessCoreMetricsOnly
) {
- if($this->isDayArchive()) {
+ if($this->params->isDayArchive()) {
$metrics = $this->aggregateDayVisitsMetrics($archiveProcessor);
} else {
$metrics = $this->aggregateMultipleVisitMetrics($archiveProcessor);
@@ -205,7 +188,7 @@ class Loader
$this->setNumberOfVisits($metrics['nb_visits'], $metrics['nb_visits_converted']);
}
}
- $this->logStatusDebug($requestedPlugin);
+ $this->logStatusDebug();
$archiveProcessor = $this->makeArchiveProcessor($archiveWriter);
@@ -213,7 +196,8 @@ class Loader
if ($isVisitsToday
&& !$enforceProcessCoreMetricsOnly
) {
- $this->compute($archiveProcessor);
+ $pluginsArchiver = new PluginsArchiver($archiveProcessor);
+ $pluginsArchiver->callPluginsAggregate();
}
$archiveWriter->finalizeArchive();
@@ -291,18 +275,7 @@ class Loader
return $this->temporaryArchive;
}
- /**
- * @return bool
- */
- protected function isDayArchive()
- {
- return $this->params->getPeriod()->getLabel() == 'day';
- }
-
- /**
- * @param $requestedPlugin
- */
- protected function logStatusDebug($requestedPlugin)
+ protected function logStatusDebug()
{
$temporary = 'definitive archive';
if ($this->isArchiveTemporary()) {
@@ -314,95 +287,13 @@ class Loader
$this->params->getSite()->getId(),
$temporary,
$this->params->getSegment()->getString(),
- $requestedPlugin,
+ $this->params->getRequestedPlugin(),
$this->params->getDateStart()->getDateStartUTC(),
$this->params->getDateEnd()->getDateEndUTC()
);
}
/**
- * This methods reads the subperiods if necessary,
- * and computes the archive of the current period.
- */
- protected function compute($archiveProcessor)
- {
- $archivers = $this->getPluginArchivers();
-
- foreach($archivers as $pluginName => $archiverClass) {
- /** @var Archiver $archiver */
- $archiver = new $archiverClass($archiveProcessor);
-
- if($this->shouldProcessReportsForPlugin($pluginName)) {
- if($this->isDayArchive()) {
- $archiver->aggregateDayReport();
- } else {
- $archiver->aggregateMultipleReports();
- }
- }
- }
- }
-
- /**
- * @var Archiver[] $archivers
- */
- private static $archivers = array();
-
-
- /**
- * Loads Archiver class from any plugin that defines one.
- *
- * @return \Piwik\Plugin\Archiver[]
- */
- protected function getPluginArchivers()
- {
- if (empty(static::$archivers)) {
- $pluginNames = \Piwik\Plugin\Manager::getInstance()->getLoadedPluginsName();
- $archivers = array();
- foreach ($pluginNames as $pluginName) {
- $archivers[$pluginName] = self::getPluginArchiverClass($pluginName);
- }
- static::$archivers = array_filter($archivers);
- }
- return static::$archivers;
- }
-
- private static function getPluginArchiverClass($pluginName)
- {
- $klassName = 'Piwik\\Plugins\\' . $pluginName . '\\Archiver';
- if (class_exists($klassName)
- && is_subclass_of($klassName, 'Piwik\\Plugin\\Archiver')) {
- return $klassName;
- }
- return false;
- }
-
- /**
- * Whether the specified plugin's reports should be archived
- * @param string $pluginName
- * @return bool
- */
- protected function shouldProcessReportsForPlugin($pluginName)
- {
- if (Rules::shouldProcessReportsAllPlugins($this->params->getSegment(), $this->params->getPeriod()->getLabel())) {
- return true;
- }
- // If any other segment, only process if the requested report belong to this plugin
- $pluginBeingProcessed = $this->getRequestedPlugin();
- if ($pluginBeingProcessed == $pluginName) {
- return true;
- }
- if (!\Piwik\Plugin\Manager::getInstance()->isPluginLoaded($pluginBeingProcessed)) {
- return true;
- }
- return false;
- }
-
- protected function getRequestedPlugin()
- {
- return $this->requestedPlugin;
- }
-
- /**
* @param $archiveWriter
* @return ArchiveProcessor
*/
@@ -410,7 +301,7 @@ class Loader
{
$archiveProcessor = new ArchiveProcessor($this->params, $archiveWriter, $this->getNumberOfVisits(), $this->getNumberOfVisitsConverted());
- if (!$this->isDayArchive()) {
+ if (!$this->params->isDayArchive()) {
$subPeriods = $this->params->getPeriod()->getSubperiods();
$archiveProcessor->archive = Archive::factory($this->params->getSegment(), $subPeriods, array($this->params->getSite()->getId()));
}
diff --git a/core/ArchiveProcessor/Parameters.php b/core/ArchiveProcessor/Parameters.php
index 591a9585ed..d22ad6c77d 100644
--- a/core/ArchiveProcessor/Parameters.php
+++ b/core/ArchiveProcessor/Parameters.php
@@ -16,13 +16,14 @@ use Piwik\Period;
use Piwik\Segment;
use Piwik\Site;
+/**
+ * An ArchiveProcessor processes data for an Archive determined by these Parameters: website, period and segment.
+ *
+ * @api
+ */
class Parameters
{
-
/**
- * Site of the current archive
- * Can be accessed by plugins (that is why it's public)
- *
* @var Site
*/
private $site = null;
@@ -37,13 +38,28 @@ class Parameters
*/
private $segment = null;
+ /**
+ * @var string Plugin name which triggered this archive processor
+ */
+ private $requestedPlugin = false;
+
public function __construct(Site $site, Period $period, Segment $segment)
{
- $this->period = $period;
$this->site = $site;
+ $this->period = $period;
$this->segment = $segment;
}
+ public function setRequestedPlugin($plugin)
+ {
+ $this->requestedPlugin = $plugin;
+ }
+
+ public function getRequestedPlugin()
+ {
+ return $this->requestedPlugin;
+ }
+
/**
* Returns the period we computing statistics for.
*
@@ -78,6 +94,8 @@ class Parameters
}
/**
+ * Returns the Date end of this period.
+ *
* @return Date
*/
public function getDateEnd()
@@ -86,10 +104,20 @@ class Parameters
}
/**
+ * Returns the Date start of this period.
+ *
* @return Date
*/
public function getDateStart()
{
return $this->getPeriod()->getDateStart()->setTimezone($this->getSite()->getTimezone());
}
+
+ /**
+ * @return bool
+ */
+ public function isDayArchive()
+ {
+ return $this->getPeriod()->getLabel() == 'day';
+ }
} \ No newline at end of file
diff --git a/core/ArchiveProcessor/PluginsArchiver.php b/core/ArchiveProcessor/PluginsArchiver.php
new file mode 100644
index 0000000000..d707701e6c
--- /dev/null
+++ b/core/ArchiveProcessor/PluginsArchiver.php
@@ -0,0 +1,108 @@
+<?php
+/**
+ * Piwik - Open source web analytics
+ *
+ * @link http://piwik.org
+ * @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
+ *
+ * @category Piwik
+ * @package Piwik
+ */
+
+namespace Piwik\ArchiveProcessor;
+
+use Piwik\ArchiveProcessor;
+use Piwik\Plugin\Archiver;
+
+/**
+ * This class creates the Archiver objects found in plugins and will trigger aggregation,
+ * so each plugin can process their reports.
+ */
+class PluginsArchiver
+{
+ /**
+ * @param ArchiveProcessor $archiveProcessor
+ */
+ protected $archiveProcessor;
+
+ /**
+ * @var Archiver[] $archivers
+ */
+ private static $archivers = array();
+
+ public function __construct(ArchiveProcessor $archiveProcessor)
+ {
+ $this->archiveProcessor = $archiveProcessor;
+ }
+
+ public function callPluginsAggregate()
+ {
+ $pluginBeingProcessed = $this->archiveProcessor->getParams()->getRequestedPlugin();
+ $isAggregateForDay = $this->archiveProcessor->getParams()->isDayArchive();
+ $archivers = $this->getPluginArchivers();
+
+ foreach($archivers as $pluginName => $archiverClass) {
+ /** @var Archiver $archiver */
+ $archiver = new $archiverClass($this->archiveProcessor);
+
+ if($this->shouldProcessReportsForPlugin($pluginBeingProcessed, $pluginName)) {
+ if($isAggregateForDay) {
+ $archiver->aggregateDayReport();
+ } else {
+ $archiver->aggregateMultipleReports();
+ }
+ }
+ }
+ }
+
+ /**
+ * Loads Archiver class from any plugin that defines one.
+ *
+ * @return \Piwik\Plugin\Archiver[]
+ */
+ protected function getPluginArchivers()
+ {
+ if (empty(static::$archivers)) {
+ $pluginNames = \Piwik\Plugin\Manager::getInstance()->getLoadedPluginsName();
+ $archivers = array();
+ foreach ($pluginNames as $pluginName) {
+ $archivers[$pluginName] = self::getPluginArchiverClass($pluginName);
+ }
+ static::$archivers = array_filter($archivers);
+ }
+ return static::$archivers;
+ }
+
+ private static function getPluginArchiverClass($pluginName)
+ {
+ $klassName = 'Piwik\\Plugins\\' . $pluginName . '\\Archiver';
+ if (class_exists($klassName)
+ && is_subclass_of($klassName, 'Piwik\\Plugin\\Archiver')) {
+ return $klassName;
+ }
+ return false;
+ }
+
+ /**
+ * Whether the specified plugin's reports should be archived
+ * @param string $pluginName
+ * @return bool
+ */
+ protected function shouldProcessReportsForPlugin($pluginBeingProcessed, $pluginName)
+ {
+ // If any other segment, only process if the requested report belong to this plugin
+ if ($pluginBeingProcessed == $pluginName) {
+ return true;
+ }
+ if (Rules::shouldProcessReportsAllPlugins(
+ $this->archiveProcessor->getParams()->getSegment(),
+ $this->archiveProcessor->getParams()->getPeriod()->getLabel())) {
+ return true;
+ }
+ if (!\Piwik\Plugin\Manager::getInstance()->isPluginLoaded($pluginBeingProcessed)) {
+ return true;
+ }
+ return false;
+ }
+
+} \ No newline at end of file
diff --git a/core/ArchiveProcessor/Rules.php b/core/ArchiveProcessor/Rules.php
index 49a330c720..8e9f763049 100644
--- a/core/ArchiveProcessor/Rules.php
+++ b/core/ArchiveProcessor/Rules.php
@@ -24,7 +24,8 @@ use Piwik\Site;
use Piwik\Tracker\Cache;
/**
- * This class contains Archiving rules/logic which are used in several places
+ * This class contains Archiving rules/logic which are used when creating and processing Archives.
+ *
*/
class Rules
{
diff --git a/core/AssetManager.php b/core/AssetManager.php
index 4c59cadb9f..31a7779847 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -178,7 +178,7 @@ class AssetManager
protected static function makeLess()
{
if (!class_exists("lessc")) {
- throw new Exception("Less was added to composer during 2.0. ==> Execute this command to update composer packages: \$ php composer.phar update");
+ throw new Exception("Less was added to composer during 2.0. ==> Execute this command to update composer packages: \$ php composer.phar install");
}
$less = new lessc;
return $less;
diff --git a/core/Common.php b/core/Common.php
index c956434ada..5d20e7360a 100644
--- a/core/Common.php
+++ b/core/Common.php
@@ -474,7 +474,8 @@ class Common
}
/**
- * Generate random string
+ * Generate random string.
+ * Do not use for security related purposes (the string is not truly random).
*
* @param int $length string length
* @param string $alphabet characters allowed in random string
diff --git a/core/Plugin/Archiver.php b/core/Plugin/Archiver.php
index ac97b24d83..2c93a36339 100644
--- a/core/Plugin/Archiver.php
+++ b/core/Plugin/Archiver.php
@@ -56,13 +56,13 @@ abstract class Archiver
/**
* Constructor.
*
- * @param ArchiveProcessor $processing The ArchiveProcessor instance sent to the archiving
+ * @param ArchiveProcessor $aggregator The ArchiveProcessor instance sent to the archiving
* event observer.
*/
- public function __construct(ArchiveProcessor $processing)
+ public function __construct(ArchiveProcessor $aggregator)
{
$this->maximumRows = PiwikConfig::getInstance()->General['datatable_archiving_maximum_rows_standard'];
- $this->processor = $processing;
+ $this->processor = $aggregator;
}
/**
diff --git a/libs/pChart2.1.3/index.php b/libs/pChart2.1.3/index.php
deleted file mode 100644
index 546ede2757..0000000000
--- a/libs/pChart2.1.3/index.php
+++ /dev/null
@@ -1,6 +0,0 @@
-<?php
- /* If you crawl here, you may want to see the examples */
-
- header('Location: examples/');
- exit();
-?>