Skip to content
Extraits de code Groupes Projets
Valider a952cc5a rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Rename InvalidationResultInfo to InvalidationResult and remove...

Rename InvalidationResultInfo to InvalidationResult and remove Period::getAllParentPeriods and replace its use in ArchiveInvalidator w/ some small SQL changes.
parent c186252b
Branches
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
namespace Piwik\Archive; namespace Piwik\Archive;
use Piwik\Archive\ArchiveInvalidator\InvalidationResultInfo; use Piwik\Archive\ArchiveInvalidator\InvalidationResult;
use Piwik\CronArchive\SitesToReprocessDistributedList; use Piwik\CronArchive\SitesToReprocessDistributedList;
use Piwik\DataAccess\ArchiveTableCreator; use Piwik\DataAccess\ArchiveTableCreator;
use Piwik\DataAccess\Model; use Piwik\DataAccess\Model;
...@@ -128,12 +128,12 @@ class ArchiveInvalidator ...@@ -128,12 +128,12 @@ class ArchiveInvalidator
* @param $period string * @param $period string
* @param $segment Segment * @param $segment Segment
* @param bool $cascadeDown * @param bool $cascadeDown
* @return InvalidationResultInfo * @return InvalidationResult
* @throws \Exception * @throws \Exception
*/ */
public function markArchivesAsInvalidated(array $idSites, array $dates, $period, Segment $segment = null, $cascadeDown = false) public function markArchivesAsInvalidated(array $idSites, array $dates, $period, Segment $segment = null, $cascadeDown = false)
{ {
$invalidationInfo = new InvalidationResultInfo(); $invalidationInfo = new InvalidationResult();
$datesToInvalidate = $this->removeDatesThatHaveBeenPurged($dates, $invalidationInfo); $datesToInvalidate = $this->removeDatesThatHaveBeenPurged($dates, $invalidationInfo);
...@@ -144,6 +144,8 @@ class ArchiveInvalidator ...@@ -144,6 +144,8 @@ class ArchiveInvalidator
$periods = $this->getPeriodsToInvalidate($datesToInvalidate, $period, $cascadeDown); $periods = $this->getPeriodsToInvalidate($datesToInvalidate, $period, $cascadeDown);
$periodDates = $this->getPeriodDatesByYearMonthAndPeriodType($periods); $periodDates = $this->getPeriodDatesByYearMonthAndPeriodType($periods);
} }
$periodDates = $this->getUniqueDates($periodDates);
$this->markArchivesInvalidated($idSites, $periodDates, $segment); $this->markArchivesInvalidated($idSites, $periodDates, $segment);
$yearMonths = array_keys($periodDates); $yearMonths = array_keys($periodDates);
...@@ -158,6 +160,21 @@ class ArchiveInvalidator ...@@ -158,6 +160,21 @@ class ArchiveInvalidator
return $invalidationInfo; return $invalidationInfo;
} }
/**
* @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 Date[] $dates
* @param string $periodType * @param string $periodType
...@@ -176,28 +193,18 @@ class ArchiveInvalidator ...@@ -176,28 +193,18 @@ class ArchiveInvalidator
$period = Period\Factory::build($periodType, $date); $period = Period\Factory::build($periodType, $date);
$periodsToInvalidate[] = $period; $periodsToInvalidate[] = $period;
// cascade up since parent archives will no longer be valid
$periodsToInvalidate = array_merge($periodsToInvalidate, $period->getAllParentPeriods());
if ($cascadeDown) { if ($cascadeDown) {
$periodsToInvalidate = array_merge($periodsToInvalidate, $period->getAllOverlappingChildPeriods()); $periodsToInvalidate = array_merge($periodsToInvalidate, $period->getAllOverlappingChildPeriods());
} }
}
return $this->getUniquePeriods($periodsToInvalidate); if ($periodType != 'year'
} && $periodType != 'range'
) {
/** $periodsToInvalidate[] = Period\Factory::build('year', $date);
* @param Period[] $periods }
* @return Period[]
*/
private function getUniquePeriods($periods)
{
$result = array();
foreach ($periods as $period) {
$result[$period->getRangeString()] = $period;
} }
return array_values($result);
return $periodsToInvalidate;
} }
/** /**
...@@ -258,10 +265,10 @@ class ArchiveInvalidator ...@@ -258,10 +265,10 @@ class ArchiveInvalidator
/** /**
* @param Date[] $dates * @param Date[] $dates
* @param InvalidationResultInfo $invalidationInfo * @param InvalidationResult $invalidationInfo
* @return \Piwik\Date[] * @return \Piwik\Date[]
*/ */
private function removeDatesThatHaveBeenPurged($dates, InvalidationResultInfo $invalidationInfo) private function removeDatesThatHaveBeenPurged($dates, InvalidationResult $invalidationInfo)
{ {
$this->findOlderDateWithLogs($invalidationInfo); $this->findOlderDateWithLogs($invalidationInfo);
...@@ -281,7 +288,7 @@ class ArchiveInvalidator ...@@ -281,7 +288,7 @@ class ArchiveInvalidator
return $result; return $result;
} }
private function findOlderDateWithLogs(InvalidationResultInfo $info) private function findOlderDateWithLogs(InvalidationResult $info)
{ {
// If using the feature "Delete logs older than N days"... // If using the feature "Delete logs older than N days"...
$purgeDataSettings = PrivacyManager::getPurgeDataSettings(); $purgeDataSettings = PrivacyManager::getPurgeDataSettings();
......
...@@ -13,7 +13,7 @@ use Piwik\Date; ...@@ -13,7 +13,7 @@ use Piwik\Date;
/** /**
* Information about the result of an archive invalidation operation. * 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 * Dates that couldn't be invalidated because they are earlier than the configured log
......
...@@ -122,10 +122,16 @@ class Model ...@@ -122,10 +122,16 @@ class Model
} }
$dateConditionsSql = implode(" OR ", $dateConditions); $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)"; $periodConditions[] = "($dateConditionsSql)";
} else if ($periodType == Period\Range::PERIOD_ID) {
$periodConditions[] = "(period = " . Period\Range::PERIOD_ID . " AND ($dateConditionsSql))";
} else { } 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))";
} }
} }
......
...@@ -402,47 +402,4 @@ abstract class Period ...@@ -402,47 +402,4 @@ abstract class Period
$childPeriods = Factory::build($childPeriodType, $dateStart->toString() . ',' . $dateEnd->toString()); $childPeriods = Factory::build($childPeriodType, $dateStart->toString() . ',' . $dateEnd->toString());
return array_merge($childPeriods->getSubperiods(), $childPeriods->getAllOverlappingChildPeriodsInRange($dateStart, $dateEnd)); 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;
}
} }
...@@ -17,6 +17,8 @@ use Piwik\Piwik; ...@@ -17,6 +17,8 @@ use Piwik\Piwik;
*/ */
class Day extends Period class Day extends Period
{ {
const PERIOD_ID = 1;
protected $label = 'day'; protected $label = 'day';
/** /**
......
...@@ -15,6 +15,8 @@ use Piwik\Period; ...@@ -15,6 +15,8 @@ use Piwik\Period;
*/ */
class Month extends Period class Month extends Period
{ {
const PERIOD_ID = 3;
protected $label = 'month'; protected $label = 'month';
/** /**
......
...@@ -31,6 +31,8 @@ use Piwik\Piwik; ...@@ -31,6 +31,8 @@ use Piwik\Piwik;
*/ */
class Range extends Period class Range extends Period
{ {
const PERIOD_ID = 5;
protected $label = 'range'; protected $label = 'range';
protected $today; protected $today;
......
...@@ -15,6 +15,8 @@ use Piwik\Piwik; ...@@ -15,6 +15,8 @@ use Piwik\Piwik;
*/ */
class Week extends Period class Week extends Period
{ {
const PERIOD_ID = 2;
protected $label = 'week'; protected $label = 'week';
/** /**
......
...@@ -15,6 +15,8 @@ use Piwik\Period; ...@@ -15,6 +15,8 @@ use Piwik\Period;
*/ */
class Year extends Period class Year extends Period
{ {
const PERIOD_ID = 4;
protected $label = 'year'; protected $label = 'year';
/** /**
......
...@@ -10,6 +10,11 @@ namespace Piwik; ...@@ -10,6 +10,11 @@ namespace Piwik;
use Exception; use Exception;
use Piwik\Container\StaticContainer; 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\Plugins\UsersManager\API as APIUsersManager;
use Piwik\Translation\Translator; use Piwik\Translation\Translator;
...@@ -31,11 +36,11 @@ class Piwik ...@@ -31,11 +36,11 @@ class Piwik
* @var array * @var array
*/ */
public static $idPeriods = array( public static $idPeriods = array(
'day' => 1, 'day' => Day::PERIOD_ID,
'week' => 2, 'week' => Week::PERIOD_ID,
'month' => 3, 'month' => Month::PERIOD_ID,
'year' => 4, 'year' => Year::PERIOD_ID,
'range' => 5, 'range' => Range::PERIOD_ID,
); );
/** /**
......
...@@ -316,10 +316,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ...@@ -316,10 +316,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase
null, null,
true, true,
array( array(
'2014_01' => array( '2014_01' => array(),
'1.2014-01-01.2014-12-31.4.done3736b708e4d20cfc10610e816a1b2341',
'2.2014-01-01.2014-12-31.4.done.VisitsSummary',
),
'2015_03' => array(), '2015_03' => array(),
'2015_04' => array( '2015_04' => array(
'1.2015-04-30.2015-04-30.1.done3736b708e4d20cfc10610e816a1b2341.UserCountry', '1.2015-04-30.2015-04-30.1.done3736b708e4d20cfc10610e816a1b2341.UserCountry',
...@@ -329,12 +326,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ...@@ -329,12 +326,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase
'1.2015-04-01.2015-04-30.3.done3736b708e4d20cfc10610e816a1b2341.UserCountry', '1.2015-04-01.2015-04-30.3.done3736b708e4d20cfc10610e816a1b2341.UserCountry',
'2.2015-04-01.2015-04-30.3.done5447835b0a861475918e79e932abdfd8', '2.2015-04-01.2015-04-30.3.done5447835b0a861475918e79e932abdfd8',
), ),
'2014_12' => array( '2014_12' => array(),
'1.2014-12-29.2015-01-04.2.done3736b708e4d20cfc10610e816a1b2341',
'2.2014-12-29.2015-01-04.2.done.VisitsSummary',
'1.2014-12-01.2014-12-31.3.done5447835b0a861475918e79e932abdfd8',
'2.2014-12-01.2014-12-31.3.done',
),
'2015_01' => array( '2015_01' => array(
'1.2015-01-01.2015-01-01.1.done3736b708e4d20cfc10610e816a1b2341', '1.2015-01-01.2015-01-01.1.done3736b708e4d20cfc10610e816a1b2341',
'2.2015-01-01.2015-01-01.1.done.VisitsSummary', '2.2015-01-01.2015-01-01.1.done.VisitsSummary',
...@@ -342,6 +334,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ...@@ -342,6 +334,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase
'2.2015-01-01.2015-01-31.3.done.VisitsSummary', '2.2015-01-01.2015-01-31.3.done.VisitsSummary',
'1.2015-01-01.2015-12-31.4.done5447835b0a861475918e79e932abdfd8', '1.2015-01-01.2015-12-31.4.done5447835b0a861475918e79e932abdfd8',
'2.2015-01-01.2015-12-31.4.done', '2.2015-01-01.2015-12-31.4.done',
'1.2015-01-01.2015-01-10.5.done.VisitsSummary',
), ),
'2015_02' => array( '2015_02' => array(
'1.2015-02-05.2015-02-05.1.done3736b708e4d20cfc10610e816a1b2341.UserCountry', '1.2015-02-05.2015-02-05.1.done3736b708e4d20cfc10610e816a1b2341.UserCountry',
...@@ -351,10 +344,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ...@@ -351,10 +344,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase
'1.2015-02-01.2015-02-28.3.done.VisitsSummary', '1.2015-02-01.2015-02-28.3.done.VisitsSummary',
'2.2015-02-01.2015-02-28.3.done3736b708e4d20cfc10610e816a1b2341.UserCountry', '2.2015-02-01.2015-02-28.3.done3736b708e4d20cfc10610e816a1b2341.UserCountry',
), ),
'2015_05' => array( '2015_05' => array(),
'1.2015-05-01.2015-05-31.3.done3736b708e4d20cfc10610e816a1b2341',
'2.2015-05-01.2015-05-31.3.done.VisitsSummary',
),
'2015_06' => array(), '2015_06' => array(),
), ),
), ),
...@@ -392,6 +382,10 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ...@@ -392,6 +382,10 @@ class ArchiveInvalidatorTest extends IntegrationTestCase
'2014_01' => array(), '2014_01' => array(),
'2014_12' => array( '2014_12' => array(
'1.2014-12-29.2015-01-04.2.done3736b708e4d20cfc10610e816a1b2341', '1.2014-12-29.2015-01-04.2.done3736b708e4d20cfc10610e816a1b2341',
// doesn't need to be invalidated since the month won't use the week above, but very difficult
// to keep it valid, while keeping invalidation logic simple.
'1.2014-12-01.2014-12-31.3.done5447835b0a861475918e79e932abdfd8',
), ),
'2015_01' => array( '2015_01' => array(
'1.2015-01-01.2015-01-01.1.done3736b708e4d20cfc10610e816a1b2341', '1.2015-01-01.2015-01-01.1.done3736b708e4d20cfc10610e816a1b2341',
...@@ -431,6 +425,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ...@@ -431,6 +425,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase
'1.2015-01-26.2015-02-01.2.done3736b708e4d20cfc10610e816a1b2341.UserCountry', '1.2015-01-26.2015-02-01.2.done3736b708e4d20cfc10610e816a1b2341.UserCountry',
'1.2015-01-01.2015-01-31.3.done3736b708e4d20cfc10610e816a1b2341', '1.2015-01-01.2015-01-31.3.done3736b708e4d20cfc10610e816a1b2341',
'1.2015-01-01.2015-12-31.4.done5447835b0a861475918e79e932abdfd8', '1.2015-01-01.2015-12-31.4.done5447835b0a861475918e79e932abdfd8',
'1.2015-01-01.2015-01-10.5.done.VisitsSummary',
), ),
'2015_02' => array(), '2015_02' => array(),
'2015_03' => array(), '2015_03' => array(),
...@@ -448,15 +443,14 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ...@@ -448,15 +443,14 @@ class ArchiveInvalidatorTest extends IntegrationTestCase
null, null,
true, true,
array( array(
'2014_01' => array( '2014_01' => array(),
'1.2014-01-01.2014-12-31.4.done3736b708e4d20cfc10610e816a1b2341',
),
'2014_12' => array( '2014_12' => array(
'1.2014-12-29.2014-12-29.1.done', '1.2014-12-29.2014-12-29.1.done',
'1.2014-12-30.2014-12-30.1.done3736b708e4d20cfc10610e816a1b2341.UserCountry', '1.2014-12-30.2014-12-30.1.done3736b708e4d20cfc10610e816a1b2341.UserCountry',
'1.2014-12-31.2014-12-31.1.done3736b708e4d20cfc10610e816a1b2341', '1.2014-12-31.2014-12-31.1.done3736b708e4d20cfc10610e816a1b2341',
'1.2014-12-29.2015-01-04.2.done3736b708e4d20cfc10610e816a1b2341', '1.2014-12-29.2015-01-04.2.done3736b708e4d20cfc10610e816a1b2341',
'1.2014-12-01.2014-12-31.3.done5447835b0a861475918e79e932abdfd8', '1.2014-12-01.2014-12-31.3.done5447835b0a861475918e79e932abdfd8',
'1.2014-12-05.2015-01-01.5.done.VisitsSummary',
), ),
'2015_01' => array( '2015_01' => array(
'1.2015-01-01.2015-01-01.1.done3736b708e4d20cfc10610e816a1b2341', '1.2015-01-01.2015-01-01.1.done3736b708e4d20cfc10610e816a1b2341',
...@@ -472,6 +466,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase ...@@ -472,6 +466,7 @@ class ArchiveInvalidatorTest extends IntegrationTestCase
'1.2015-01-26.2015-02-01.2.done3736b708e4d20cfc10610e816a1b2341.UserCountry', '1.2015-01-26.2015-02-01.2.done3736b708e4d20cfc10610e816a1b2341.UserCountry',
'1.2015-01-01.2015-01-31.3.done3736b708e4d20cfc10610e816a1b2341', '1.2015-01-01.2015-01-31.3.done3736b708e4d20cfc10610e816a1b2341',
'1.2015-01-01.2015-12-31.4.done5447835b0a861475918e79e932abdfd8', '1.2015-01-01.2015-12-31.4.done5447835b0a861475918e79e932abdfd8',
'1.2015-01-01.2015-01-10.5.done.VisitsSummary',
), ),
'2015_02' => array( '2015_02' => array(
'1.2015-02-01.2015-02-01.1.done3736b708e4d20cfc10610e816a1b2341', '1.2015-02-01.2015-02-01.1.done3736b708e4d20cfc10610e816a1b2341',
......
...@@ -124,60 +124,6 @@ class PeriodTest extends \PHPUnit_Framework_TestCase ...@@ -124,60 +124,6 @@ class PeriodTest extends \PHPUnit_Framework_TestCase
); );
} }
/**
* @dataProvider getTestDataForGetAllParentPeriods
*/
public function test_getAllParentPeriods_ReturnsCorrectContainingPeriods($periodType, $dateRange, $expectedParentPeriodRanges)
{
$period = Period\Factory::build($periodType, $dateRange);
$parentPeriods = $period->getAllParentPeriods();
$parentPeriods = $this->getPeriodInfoForAssert($parentPeriods);
$this->assertEquals($expectedParentPeriodRanges, $parentPeriods);
}
public function getTestDataForGetAllParentPeriods()
{
return array(
array(
'day',
'2015-01-01',
array(
array('week', '2014-12-29,2015-01-04'),
array('month', '2014-12-01,2014-12-31'),
array('year', '2014-01-01,2014-12-31'),
array('month', '2015-01-01,2015-01-31'),
array('year', '2015-01-01,2015-12-31'),
),
),
array(
'week',
'2015-09-01',
array(
array('month', '2015-08-01,2015-08-31'),
array('year', '2015-01-01,2015-12-31'),
array('month', '2015-09-01,2015-09-30'),
),
),
array(
'month',
'2015-09-10',
array(
array('year', '2015-01-01,2015-12-31'),
),
),
array(
'year',
'2015-09-10',
array(),
),
);
}
/** /**
* @dataProvider getTestDataForGetAllOverlappingChildPeriods * @dataProvider getTestDataForGetAllOverlappingChildPeriods
*/ */
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Veuillez vous inscrire ou vous pour commenter