aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/api/ApiUtils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2020-08-29 11:45:08 +0200
committerArthurHoaro <arthur@hoa.ro>2020-08-29 11:45:08 +0200
commitb06fc28aa32f477e1785cd998385fdb490bc5ebf (patch)
tree65daa380574c5452a3e3c5679ea438115b4fb3bb /application/api/ApiUtils.php
parentbea062149ebcb4663861edb1cc0a32faf85b273f (diff)
downloadShaarli-b06fc28aa32f477e1785cd998385fdb490bc5ebf.tar.gz
Shaarli-b06fc28aa32f477e1785cd998385fdb490bc5ebf.tar.zst
Shaarli-b06fc28aa32f477e1785cd998385fdb490bc5ebf.zip
REST API: allow override of creation and update dates
Note that if they're not provided, default behaviour will apply: creation and update dates will be autogenerated, and not empty. Fixes #1223
Diffstat (limited to 'application/api/ApiUtils.php')
-rw-r--r--application/api/ApiUtils.php11
1 files changed, 10 insertions, 1 deletions
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php
index faebb8f5..4a6326f0 100644
--- a/application/api/ApiUtils.php
+++ b/application/api/ApiUtils.php
@@ -94,7 +94,7 @@ class ApiUtils
94 * 94 *
95 * @return Bookmark instance. 95 * @return Bookmark instance.
96 */ 96 */
97 public static function buildLinkFromRequest($input, $defaultPrivate) 97 public static function buildBookmarkFromRequest($input, $defaultPrivate): Bookmark
98 { 98 {
99 $bookmark = new Bookmark(); 99 $bookmark = new Bookmark();
100 $url = ! empty($input['url']) ? cleanup_url($input['url']) : ''; 100 $url = ! empty($input['url']) ? cleanup_url($input['url']) : '';
@@ -110,6 +110,15 @@ class ApiUtils
110 $bookmark->setTags(! empty($input['tags']) ? $input['tags'] : []); 110 $bookmark->setTags(! empty($input['tags']) ? $input['tags'] : []);
111 $bookmark->setPrivate($private); 111 $bookmark->setPrivate($private);
112 112
113 $created = \DateTime::createFromFormat(\DateTime::ATOM, $input['created'] ?? '');
114 if ($created instanceof \DateTimeInterface) {
115 $bookmark->setCreated($created);
116 }
117 $updated = \DateTime::createFromFormat(\DateTime::ATOM, $input['updated'] ?? '');
118 if ($updated instanceof \DateTimeInterface) {
119 $bookmark->setUpdated($updated);
120 }
121
113 return $bookmark; 122 return $bookmark;
114 } 123 }
115 124