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
path: root/core
diff options
context:
space:
mode:
authordiosmosis <benaka@piwik.pro>2015-09-20 08:19:17 +0300
committerdiosmosis <benaka@piwik.pro>2015-10-12 21:05:35 +0300
commit13e9db553be041ee9b072ab0e7186c30cee0595f (patch)
treec50c262409ac6e0d27dfe6845288605ebac03767 /core
parentf6f444ec6a9a2af341812d460c97c189cb5ee04e (diff)
Make ArchiveInvalidator an immutable service and add it to DI. markArchivesAsInvalidated (or whatever it's called) now returns an instance instead of an array of output messages.
Diffstat (limited to 'core')
-rw-r--r--core/Archive.php13
-rw-r--r--core/Archive/ArchiveInvalidator.php37
-rw-r--r--core/Archive/ArchiveInvalidator/InvalidationResultInfo.php56
-rw-r--r--core/CronArchive.php8
-rw-r--r--core/Tracker/Visit.php9
5 files changed, 88 insertions, 35 deletions
diff --git a/core/Archive.php b/core/Archive.php
index 5413393972..80ef151f38 100644
--- a/core/Archive.php
+++ b/core/Archive.php
@@ -11,6 +11,7 @@ namespace Piwik;
use Piwik\Archive\Parameters;
use Piwik\ArchiveProcessor\Rules;
use Piwik\Archive\ArchiveInvalidator;
+use Piwik\Container\StaticContainer;
use Piwik\DataAccess\ArchiveSelector;
use Piwik\Period\Factory as PeriodFactory;
@@ -167,6 +168,11 @@ class Archive
private static $cache;
/**
+ * @var ArchiveInvalidator
+ */
+ private $invalidator;
+
+ /**
* @param Parameters $params
* @param bool $forceIndexedBySite Whether to force index the result of a query by site ID.
* @param bool $forceIndexedByDate Whether to force index the result of a query by period.
@@ -177,6 +183,8 @@ class Archive
$this->params = $params;
$this->forceIndexedBySite = $forceIndexedBySite;
$this->forceIndexedByDate = $forceIndexedByDate;
+
+ $this->invalidator = StaticContainer::get('Piwik\Archive\ArchiveInvalidator');
}
/**
@@ -539,8 +547,7 @@ class Archive
return; // all requested site ids were already handled
}
- $invalidator = new ArchiveInvalidator();
- $sitesPerDays = $invalidator->getRememberedArchivedReportsThatShouldBeInvalidated();
+ $sitesPerDays = $this->invalidator->getRememberedArchivedReportsThatShouldBeInvalidated();
foreach ($sitesPerDays as $date => $siteIds) {
if (empty($siteIds)) {
@@ -554,7 +561,7 @@ class Archive
}
try {
- $invalidator->markArchivesAsInvalidated($siteIdsToActuallyInvalidate, array(Date::factory($date)), false);
+ $this->invalidator->markArchivesAsInvalidated($siteIdsToActuallyInvalidate, array(Date::factory($date)), false);
} catch (\Exception $e) {
Site::clearCache();
throw $e;
diff --git a/core/Archive/ArchiveInvalidator.php b/core/Archive/ArchiveInvalidator.php
index d89a2911e9..0839654ce5 100644
--- a/core/Archive/ArchiveInvalidator.php
+++ b/core/Archive/ArchiveInvalidator.php
@@ -9,6 +9,7 @@
namespace Piwik\Archive;
+use Piwik\Archive\ArchiveInvalidator\InvalidationResultInfo;
use Piwik\CronArchive\SitesToReprocessDistributedList;
use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\DataAccess\Model;
@@ -45,10 +46,6 @@ use Piwik\Period\Week;
*/
class ArchiveInvalidator
{
- private $warningDates = array();
- private $processedDates = array();
- private $minimumDateWithLogs = false;
-
private $rememberArchivedReportIdStart = 'report_to_invalidate_';
public function rememberToInvalidateArchivedReportsLater($idSite, Date $date)
@@ -120,14 +117,15 @@ class ArchiveInvalidator
* @param $idSites int[]
* @param $dates Date[]
* @param $period string
- * @return array
+ * @return InvalidationResultInfo
* @throws \Exception
*/
public function markArchivesAsInvalidated(array $idSites, $dates, $period)
{
- $dates = $this->removeDatesThatHaveBeenPurged($dates);
+ $invalidationInfo = new InvalidationResultInfo();
- $datesByMonth = $this->getDatesByYearMonth($dates);
+ $dates = $this->removeDatesThatHaveBeenPurged($dates);
+ $datesByMonth = $this->getDatesByYearMonth($dates, $invalidationInfo);
$this->markArchivesInvalidatedFor($idSites, $period, $datesByMonth);
$this->persistInvalidatedArchives($idSites, $datesByMonth);
@@ -138,7 +136,7 @@ class ArchiveInvalidator
}
}
- return $this->makeOutputLogs();
+ return $invalidationInfo;
}
/**
@@ -197,7 +195,7 @@ class ArchiveInvalidator
{
// If using the feature "Delete logs older than N days"...
$purgeDataSettings = PrivacyManager::getPurgeDataSettings();
- $logsDeletedWhenOlderThanDays = $purgeDataSettings['delete_logs_older_than'];
+ $logsDeletedWhenOlderThanDays = (int)$purgeDataSettings['delete_logs_older_than'];
$logsDeleteEnabled = $purgeDataSettings['delete_logs_enable'];
if ($logsDeleteEnabled
@@ -213,11 +211,11 @@ class ArchiveInvalidator
* @param $datesToInvalidate Date[]
* @return array
*/
- private function getDatesByYearMonth(array $datesToInvalidate)
+ private function getDatesByYearMonth($datesToInvalidate, InvalidationResultInfo $invalidationInfo)
{
$datesByMonth = array();
foreach ($datesToInvalidate as $date) {
- $this->processedDates[] = $date->toString();
+ $invalidationInfo->processedDates[] = $date->toString();
$month = $date->toString('Y_m');
// For a given date, we must invalidate in the monthly archive table
@@ -237,23 +235,6 @@ class ArchiveInvalidator
}
/**
- * @return array
- */
- private function makeOutputLogs()
- {
- $output = array();
- if ($this->warningDates) {
- $output[] = 'Warning: the following Dates have not been invalidated, because they are earlier than your Log Deletion limit: ' .
- implode(", ", $this->warningDates) .
- "\n The last day with logs is " . $this->minimumDateWithLogs . ". " .
- "\n Please disable 'Delete old Logs' or set it to a higher deletion threshold (eg. 180 days or 365 years).'.";
- }
-
- $output[] = "Success. The following dates were invalidated successfully: " . implode(", ", $this->processedDates);
- return $output;
- }
-
- /**
* @param $period
* @return int|null
*/
diff --git a/core/Archive/ArchiveInvalidator/InvalidationResultInfo.php b/core/Archive/ArchiveInvalidator/InvalidationResultInfo.php
new file mode 100644
index 0000000000..f57c787dbe
--- /dev/null
+++ b/core/Archive/ArchiveInvalidator/InvalidationResultInfo.php
@@ -0,0 +1,56 @@
+<?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\Archive\ArchiveInvalidator;
+
+use Piwik\Date;
+
+/**
+ * Information about the result of an archive invalidation operation.
+ */
+class InvalidationResultInfo
+{
+ /**
+ * Dates that couldn't be invalidated because they are earlier than the configured log
+ * deletion limit.
+ *
+ * @var array
+ */
+ public $warningDates = array();
+
+ /**
+ * Dates that were successfully invalidated.
+ *
+ * @var array
+ */
+ public $processedDates = array();
+
+ /**
+ * The day of the oldest log entry.
+ *
+ * @var Date|bool
+ */
+ public $minimumDateWithLogs = false;
+
+ /**
+ * @return string[]
+ */
+ public function makeOutputLogs()
+ {
+ $output = array();
+ if ($this->warningDates) {
+ $output[] = 'Warning: the following Dates have not been invalidated, because they are earlier than your Log Deletion limit: ' .
+ implode(", ", $this->warningDates) .
+ "\n The last day with logs is " . $this->minimumDateWithLogs . ". " .
+ "\n Please disable 'Delete old Logs' or set it to a higher deletion threshold (eg. 180 days or 365 years).'.";
+ }
+
+ $output[] = "Success. The following dates were invalidated successfully: " . implode(", ", $this->processedDates);
+ return $output;
+ }
+} \ No newline at end of file
diff --git a/core/CronArchive.php b/core/CronArchive.php
index e33b918154..b1fb1ddcf4 100644
--- a/core/CronArchive.php
+++ b/core/CronArchive.php
@@ -238,6 +238,11 @@ class CronArchive
private $urlToPiwik = null;
/**
+ * @var ArchiveInvalidator
+ */
+ private $invalidator;
+
+ /**
* Returns the option name of the option that stores the time core:archive was last executed.
*
* @param int $idSite
@@ -1069,8 +1074,7 @@ class CronArchive
public function invalidateArchivedReportsForSitesThatNeedToBeArchivedAgain()
{
- $invalidator = new ArchiveInvalidator();
- $sitesPerDays = $invalidator->getRememberedArchivedReportsThatShouldBeInvalidated();
+ $sitesPerDays = $this->invalidator->getRememberedArchivedReportsThatShouldBeInvalidated();
foreach ($sitesPerDays as $date => $siteIds) {
$listSiteIds = implode(',', $siteIds);
diff --git a/core/Tracker/Visit.php b/core/Tracker/Visit.php
index fc11d0cc3f..84b702449e 100644
--- a/core/Tracker/Visit.php
+++ b/core/Tracker/Visit.php
@@ -69,12 +69,18 @@ class Visit implements VisitInterface
*/
private $visitorRecognizer;
+ /**
+ * @var ArchiveInvalidator
+ */
+ private $invalidator;
+
public function __construct()
{
$this->requestProcessors = StaticContainer::get('tracker.request.processors');
$this->visitorRecognizer = StaticContainer::get('Piwik\Tracker\VisitorRecognizer');
$this->visitProperties = null;
$this->userSettings = StaticContainer::get('Piwik\Tracker\Settings');
+ $this->invalidator = StaticContainer::get('Piwik\Archive\ArchiveInvalidator');
}
/**
@@ -566,8 +572,7 @@ class Visit implements VisitInterface
$date = Date::factory((int)$time, $timezone);
if (!$date->isToday()) { // we don't have to handle in case date is in future as it is not allowed by tracker
- $invalidReport = new ArchiveInvalidator();
- $invalidReport->rememberToInvalidateArchivedReportsLater($idSite, $date);
+ $this->invalidator->rememberToInvalidateArchivedReportsLater($idSite, $date);
}
}