diff --git a/core/CronArchive/SegmentArchiving.php b/core/CronArchive/SegmentArchiving.php index 3d30055f9d8..5a045802d29 100644 --- a/core/CronArchive/SegmentArchiving.php +++ b/core/CronArchive/SegmentArchiving.php @@ -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']); @@ -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) diff --git a/tests/PHPUnit/Integration/CronArchive/SegmentArchivingTest.php b/tests/PHPUnit/Integration/CronArchive/SegmentArchivingTest.php index 2fe383acecf..9a919e555cc 100644 --- a/tests/PHPUnit/Integration/CronArchive/SegmentArchivingTest.php +++ b/tests/PHPUnit/Integration/CronArchive/SegmentArchivingTest.php @@ -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,