diff options
author | diosmosis <benaka@piwik.pro> | 2015-10-08 17:03:59 +0300 |
---|---|---|
committer | diosmosis <benaka@piwik.pro> | 2015-10-12 21:05:37 +0300 |
commit | a952cc5a9765da33a7a1f3f575b90d76fbaf5a38 (patch) | |
tree | 64390e0b4d585fb5512b0e2d1dd0f9e98a1ec584 /core | |
parent | c186252bf9a30a54c15330f0f4c88c1a033e7f25 (diff) |
Rename InvalidationResultInfo to InvalidationResult and remove Period::getAllParentPeriods and replace its use in ArchiveInvalidator w/ some small SQL changes.
Diffstat (limited to 'core')
-rw-r--r-- | core/Archive/ArchiveInvalidator.php | 53 | ||||
-rw-r--r-- | core/Archive/ArchiveInvalidator/InvalidationResult.php (renamed from core/Archive/ArchiveInvalidator/InvalidationResultInfo.php) | 2 | ||||
-rw-r--r-- | core/DataAccess/Model.php | 10 | ||||
-rw-r--r-- | core/Period.php | 43 | ||||
-rw-r--r-- | core/Period/Day.php | 2 | ||||
-rw-r--r-- | core/Period/Month.php | 2 | ||||
-rw-r--r-- | core/Period/Range.php | 2 | ||||
-rw-r--r-- | core/Period/Week.php | 2 | ||||
-rw-r--r-- | core/Period/Year.php | 2 | ||||
-rw-r--r-- | core/Piwik.php | 15 |
10 files changed, 59 insertions, 74 deletions
diff --git a/core/Archive/ArchiveInvalidator.php b/core/Archive/ArchiveInvalidator.php index c4fff2bef4..6ecc5b8734 100644 --- a/core/Archive/ArchiveInvalidator.php +++ b/core/Archive/ArchiveInvalidator.php @@ -9,7 +9,7 @@ namespace Piwik\Archive; -use Piwik\Archive\ArchiveInvalidator\InvalidationResultInfo; +use Piwik\Archive\ArchiveInvalidator\InvalidationResult; use Piwik\CronArchive\SitesToReprocessDistributedList; use Piwik\DataAccess\ArchiveTableCreator; use Piwik\DataAccess\Model; @@ -128,12 +128,12 @@ class ArchiveInvalidator * @param $period string * @param $segment Segment * @param bool $cascadeDown - * @return InvalidationResultInfo + * @return InvalidationResult * @throws \Exception */ public function markArchivesAsInvalidated(array $idSites, array $dates, $period, Segment $segment = null, $cascadeDown = false) { - $invalidationInfo = new InvalidationResultInfo(); + $invalidationInfo = new InvalidationResult(); $datesToInvalidate = $this->removeDatesThatHaveBeenPurged($dates, $invalidationInfo); @@ -144,6 +144,8 @@ class ArchiveInvalidator $periods = $this->getPeriodsToInvalidate($datesToInvalidate, $period, $cascadeDown); $periodDates = $this->getPeriodDatesByYearMonthAndPeriodType($periods); } + + $periodDates = $this->getUniqueDates($periodDates); $this->markArchivesInvalidated($idSites, $periodDates, $segment); $yearMonths = array_keys($periodDates); @@ -159,6 +161,21 @@ class ArchiveInvalidator } /** + * @param string[][][] $periodDates + * @return string[][][] + */ + private function getUniqueDates($periodDates) + { + $result = array(); + foreach ($periodDates as $yearMonth => $periodsByYearMonth) { + foreach ($periodsByYearMonth as $periodType => $periods) { + $result[$yearMonth][$periodType] = array_unique($periods); + } + } + return $result; + } + + /** * @param Date[] $dates * @param string $periodType * @param bool $cascadeDown @@ -176,28 +193,18 @@ class ArchiveInvalidator $period = Period\Factory::build($periodType, $date); $periodsToInvalidate[] = $period; - // cascade up since parent archives will no longer be valid - $periodsToInvalidate = array_merge($periodsToInvalidate, $period->getAllParentPeriods()); - if ($cascadeDown) { $periodsToInvalidate = array_merge($periodsToInvalidate, $period->getAllOverlappingChildPeriods()); } - } - return $this->getUniquePeriods($periodsToInvalidate); - } - - /** - * @param Period[] $periods - * @return Period[] - */ - private function getUniquePeriods($periods) - { - $result = array(); - foreach ($periods as $period) { - $result[$period->getRangeString()] = $period; + if ($periodType != 'year' + && $periodType != 'range' + ) { + $periodsToInvalidate[] = Period\Factory::build('year', $date); + } } - return array_values($result); + + return $periodsToInvalidate; } /** @@ -258,10 +265,10 @@ class ArchiveInvalidator /** * @param Date[] $dates - * @param InvalidationResultInfo $invalidationInfo + * @param InvalidationResult $invalidationInfo * @return \Piwik\Date[] */ - private function removeDatesThatHaveBeenPurged($dates, InvalidationResultInfo $invalidationInfo) + private function removeDatesThatHaveBeenPurged($dates, InvalidationResult $invalidationInfo) { $this->findOlderDateWithLogs($invalidationInfo); @@ -281,7 +288,7 @@ class ArchiveInvalidator return $result; } - private function findOlderDateWithLogs(InvalidationResultInfo $info) + private function findOlderDateWithLogs(InvalidationResult $info) { // If using the feature "Delete logs older than N days"... $purgeDataSettings = PrivacyManager::getPurgeDataSettings(); diff --git a/core/Archive/ArchiveInvalidator/InvalidationResultInfo.php b/core/Archive/ArchiveInvalidator/InvalidationResult.php index f57c787dbe..517e113841 100644 --- a/core/Archive/ArchiveInvalidator/InvalidationResultInfo.php +++ b/core/Archive/ArchiveInvalidator/InvalidationResult.php @@ -13,7 +13,7 @@ use Piwik\Date; /** * Information about the result of an archive invalidation operation. */ -class InvalidationResultInfo +class InvalidationResult { /** * Dates that couldn't be invalidated because they are earlier than the configured log diff --git a/core/DataAccess/Model.php b/core/DataAccess/Model.php index e8ec27c7de..4213cd2039 100644 --- a/core/DataAccess/Model.php +++ b/core/DataAccess/Model.php @@ -122,10 +122,16 @@ class Model } $dateConditionsSql = implode(" OR ", $dateConditions); - if (empty($periodType)) { // remove all periods + if (empty($periodType) + || $periodType == Period\Day::PERIOD_ID + ) { + // invalidate all periods if no period supplied or period is day $periodConditions[] = "($dateConditionsSql)"; + } else if ($periodType == Period\Range::PERIOD_ID) { + $periodConditions[] = "(period = " . Period\Range::PERIOD_ID . " AND ($dateConditionsSql))"; } else { - $periodConditions[] = "(period = " . (int)$periodType . " AND ($dateConditionsSql))"; + // for non-day periods, invalidate greater periods, but not range periods + $periodConditions[] = "(period >= " . (int)$periodType . " AND period < " . Period\Range::PERIOD_ID . " AND ($dateConditionsSql))"; } } diff --git a/core/Period.php b/core/Period.php index 8225381ec2..794302fe0e 100644 --- a/core/Period.php +++ b/core/Period.php @@ -402,47 +402,4 @@ abstract class Period $childPeriods = Factory::build($childPeriodType, $dateStart->toString() . ',' . $dateEnd->toString()); return array_merge($childPeriods->getSubperiods(), $childPeriods->getAllOverlappingChildPeriodsInRange($dateStart, $dateEnd)); } - - /** - * Returns all periods of a larger type that contain this period. For example, - * for a week, this will return the month and year containing it. For a day, it will - * return the week, month and year containing it. - * - * @return Period[] - * @ignore - */ - public function getAllParentPeriods() - { - $parentPeriods = $this->getAllParentPeriodsSet(); - return array_values($parentPeriods); - } - - /** - * Helper method required for recursion. - * - * @return Period[] - * @ignore - */ - private function getAllParentPeriodsSet() - { - $parentPeriodType = $this->getParentPeriodLabel(); - if (empty($parentPeriodType)) { - return array(); - } - - $startPeriod = Factory::build($parentPeriodType, $this->getDateStart()); - $endPeriod = Factory::build($parentPeriodType, $this->getDateEnd()); - - $result = array(); - - $result[$startPeriod->getRangeString()] = $startPeriod; - $result = $result + $startPeriod->getAllParentPeriodsSet(); - - if ($startPeriod->getRangeString() != $endPeriod->getRangeString()) { - $result[$endPeriod->getRangeString()] = $endPeriod; - $result = $result + $endPeriod->getAllParentPeriodsSet(); - } - - return $result; - } } diff --git a/core/Period/Day.php b/core/Period/Day.php index 9f20753f93..bcad4cc1a6 100644 --- a/core/Period/Day.php +++ b/core/Period/Day.php @@ -17,6 +17,8 @@ use Piwik\Piwik; */ class Day extends Period { + const PERIOD_ID = 1; + protected $label = 'day'; /** diff --git a/core/Period/Month.php b/core/Period/Month.php index 4335eda6c1..7a52bd06f8 100644 --- a/core/Period/Month.php +++ b/core/Period/Month.php @@ -15,6 +15,8 @@ use Piwik\Period; */ class Month extends Period { + const PERIOD_ID = 3; + protected $label = 'month'; /** diff --git a/core/Period/Range.php b/core/Period/Range.php index b682749be0..0625b2da47 100644 --- a/core/Period/Range.php +++ b/core/Period/Range.php @@ -31,6 +31,8 @@ use Piwik\Piwik; */ class Range extends Period { + const PERIOD_ID = 5; + protected $label = 'range'; protected $today; diff --git a/core/Period/Week.php b/core/Period/Week.php index 40eb62319f..db644be265 100644 --- a/core/Period/Week.php +++ b/core/Period/Week.php @@ -15,6 +15,8 @@ use Piwik\Piwik; */ class Week extends Period { + const PERIOD_ID = 2; + protected $label = 'week'; /** diff --git a/core/Period/Year.php b/core/Period/Year.php index 0fcb24fb20..208c6bbfac 100644 --- a/core/Period/Year.php +++ b/core/Period/Year.php @@ -15,6 +15,8 @@ use Piwik\Period; */ class Year extends Period { + const PERIOD_ID = 4; + protected $label = 'year'; /** diff --git a/core/Piwik.php b/core/Piwik.php index 5ad5071383..9545cff6c8 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -10,6 +10,11 @@ namespace Piwik; use Exception; use Piwik\Container\StaticContainer; +use Piwik\Period\Day; +use Piwik\Period\Month; +use Piwik\Period\Range; +use Piwik\Period\Week; +use Piwik\Period\Year; use Piwik\Plugins\UsersManager\API as APIUsersManager; use Piwik\Translation\Translator; @@ -31,11 +36,11 @@ class Piwik * @var array */ public static $idPeriods = array( - 'day' => 1, - 'week' => 2, - 'month' => 3, - 'year' => 4, - 'range' => 5, + 'day' => Day::PERIOD_ID, + 'week' => Week::PERIOD_ID, + 'month' => Month::PERIOD_ID, + 'year' => Year::PERIOD_ID, + 'range' => Range::PERIOD_ID, ); /** |