Skip to content

Commit

Permalink
Fix for unexpected zero value last edit dates in segment archiving (#…
Browse files Browse the repository at this point in the history
…21189)

* Check for unexpected zero value last edit dates in segment archiving

* Code tidy

* Updated parameter definition

* Update core/CronArchive/SegmentArchiving.php

Co-authored-by: Stefan Giehl <[email protected]>

---------

Co-authored-by: Stefan Giehl <[email protected]>
  • Loading branch information
bx80 and sgiehl authored Aug 29, 2023
1 parent 7832161 commit 6f18b00
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
14 changes: 11 additions & 3 deletions core/CronArchive/SegmentArchiving.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,14 @@ public function getReArchiveSegmentStartDate($segmentInfo)
}
}

private function getCreatedTimeOfSegment($storedSegment)
/**
* Retrieve the created and last edited time as date objects from the supplied segment array
*
* @param array $storedSegment
*
* @return array
*/
private function getCreatedTimeOfSegment(array $storedSegment): array
{
// check for an earlier ts_created timestamp
$createdTime = empty($storedSegment['ts_created']) ? null : Date::factory($storedSegment['ts_created']);
Expand All @@ -185,9 +192,10 @@ private function getCreatedTimeOfSegment($storedSegment)
}

// check for a later ts_last_edit timestamp
$lastEditTime = empty($storedSegment['ts_last_edit']) ? null : Date::factory($storedSegment['ts_last_edit']);
$lastEditTime = empty($storedSegment['ts_last_edit']) || $storedSegment['ts_last_edit'] === '0000-00-00 00:00:00'
? null : Date::factory($storedSegment['ts_last_edit']);

return array($createdTime, $lastEditTime);
return [$createdTime, $lastEditTime];
}

private function getEarliestVisitTimeFor($idSite)
Expand Down
14 changes: 14 additions & 0 deletions tests/PHPUnit/Integration/CronArchive/SegmentArchivingTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,20 @@ public function getTestDataForGetReArchiveSegmentStartDate()
'2020-04-13',
],

// creation time, last edit time is 0000-00-00,
[
SegmentArchiving::CREATION_TIME,
['ts_created' => '2020-04-12 03:34:55', 'ts_last_edit' => '0000-00-00 00:00:00'],
'2020-04-12',
],

// last edit time, last edit time is 0000-00-00
[
SegmentArchiving::LAST_EDIT_TIME,
['ts_created' => '2020-04-12 03:34:55', 'ts_last_edit' => '0000-00-00 00:00:00'],
null,
],

// last edit time, no edit time in segment
[
SegmentArchiving::LAST_EDIT_TIME,
Expand Down

0 comments on commit 6f18b00

Please sign in to comment.