From b236d3f627a21bc9b02e7726bbb72d632937a45e Mon Sep 17 00:00:00 2001 From: Simounet Date: Wed, 19 Jul 2017 20:16:23 +0200 Subject: Fix updatePublishedAt on already parsed article's date --- src/Wallabag/CoreBundle/Helper/ContentProxy.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index 656ac6ee..fd97e0ff 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -122,7 +122,7 @@ class ContentProxy */ public function updatePublishedAt(Entry $entry, $value) { - $date = $value; + $date = $value instanceof \DateTime ? $value->date : $value; // is it a timestamp? if (filter_var($date, FILTER_VALIDATE_INT) !== false) { -- cgit v1.2.3 From ff9f89fd2318cfb29a18d941077b5afc859bf0fe Mon Sep 17 00:00:00 2001 From: Jeremy Benoist Date: Mon, 24 Jul 2017 16:39:29 +0200 Subject: Add a test for updatePublishedAt To avoid error when a content is re-submitted and it previously add a published date. Also, fix the `testPostSameEntry` --- src/Wallabag/CoreBundle/Helper/ContentProxy.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'src/Wallabag') diff --git a/src/Wallabag/CoreBundle/Helper/ContentProxy.php b/src/Wallabag/CoreBundle/Helper/ContentProxy.php index fd97e0ff..1ac7ad83 100644 --- a/src/Wallabag/CoreBundle/Helper/ContentProxy.php +++ b/src/Wallabag/CoreBundle/Helper/ContentProxy.php @@ -122,15 +122,21 @@ class ContentProxy */ public function updatePublishedAt(Entry $entry, $value) { - $date = $value instanceof \DateTime ? $value->date : $value; + $date = $value; // is it a timestamp? if (filter_var($date, FILTER_VALIDATE_INT) !== false) { - $date = '@' . $value; + $date = '@' . $date; } try { - $entry->setPublishedAt(new \DateTime($date)); + // is it already a DateTime? + // (it's inside the try/catch in case of fail to be parse time string) + if (!$date instanceof \DateTime) { + $date = new \DateTime($date); + } + + $entry->setPublishedAt($date); } catch (\Exception $e) { $this->logger->warning('Error while defining date', ['e' => $e, 'url' => $entry->getUrl(), 'date' => $value]); } -- cgit v1.2.3