aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/Wallabag
diff options
context:
space:
mode:
authorJeremy Benoist <jeremy.benoist@gmail.com>2017-07-24 16:39:29 +0200
committerJeremy Benoist <jeremy.benoist@gmail.com>2017-07-24 17:07:47 +0200
commitff9f89fd2318cfb29a18d941077b5afc859bf0fe (patch)
tree14c18ed4b13ee27bdd849a1c4d6ddba31fc06b82 /src/Wallabag
parentb236d3f627a21bc9b02e7726bbb72d632937a45e (diff)
downloadwallabag-ff9f89fd2318cfb29a18d941077b5afc859bf0fe.tar.gz
wallabag-ff9f89fd2318cfb29a18d941077b5afc859bf0fe.tar.zst
wallabag-ff9f89fd2318cfb29a18d941077b5afc859bf0fe.zip
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`
Diffstat (limited to 'src/Wallabag')
-rw-r--r--src/Wallabag/CoreBundle/Helper/ContentProxy.php12
1 files changed, 9 insertions, 3 deletions
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
122 */ 122 */
123 public function updatePublishedAt(Entry $entry, $value) 123 public function updatePublishedAt(Entry $entry, $value)
124 { 124 {
125 $date = $value instanceof \DateTime ? $value->date : $value; 125 $date = $value;
126 126
127 // is it a timestamp? 127 // is it a timestamp?
128 if (filter_var($date, FILTER_VALIDATE_INT) !== false) { 128 if (filter_var($date, FILTER_VALIDATE_INT) !== false) {
129 $date = '@' . $value; 129 $date = '@' . $date;
130 } 130 }
131 131
132 try { 132 try {
133 $entry->setPublishedAt(new \DateTime($date)); 133 // is it already a DateTime?
134 // (it's inside the try/catch in case of fail to be parse time string)
135 if (!$date instanceof \DateTime) {
136 $date = new \DateTime($date);
137 }
138
139 $entry->setPublishedAt($date);
134 } catch (\Exception $e) { 140 } catch (\Exception $e) {
135 $this->logger->warning('Error while defining date', ['e' => $e, 'url' => $entry->getUrl(), 'date' => $value]); 141 $this->logger->warning('Error while defining date', ['e' => $e, 'url' => $entry->getUrl(), 'date' => $value]);
136 } 142 }