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:
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/Archive
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/Archive')
-rw-r--r--core/Archive/ArchiveInvalidator.php37
-rw-r--r--core/Archive/ArchiveInvalidator/InvalidationResultInfo.php56
2 files changed, 65 insertions, 28 deletions
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