aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/api/ApiUtils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-05-07 15:55:38 +0200
committerGitHub <noreply@github.com>2017-05-07 15:55:38 +0200
commit77de24876ff542e3770aa2845e993c58f87e37df (patch)
tree9eca13b3718eeba2d69fe262a8b6b35ba2596ea5 /application/api/ApiUtils.php
parenteb6e729808e1c3d9787ad1183aa61ab2e375a537 (diff)
parentcf9181dddf8b6113b1b017e4bcb21fac0a0b1c83 (diff)
downloadShaarli-77de24876ff542e3770aa2845e993c58f87e37df.tar.gz
Shaarli-77de24876ff542e3770aa2845e993c58f87e37df.tar.zst
Shaarli-77de24876ff542e3770aa2845e993c58f87e37df.zip
Merge pull request #840 from ArthurHoaro/api/putLink
REST API: implement PUT method
Diffstat (limited to 'application/api/ApiUtils.php')
-rw-r--r--application/api/ApiUtils.php26
1 files changed, 26 insertions, 0 deletions
diff --git a/application/api/ApiUtils.php b/application/api/ApiUtils.php
index b8155a34..f154bb52 100644
--- a/application/api/ApiUtils.php
+++ b/application/api/ApiUtils.php
@@ -108,4 +108,30 @@ class ApiUtils
108 ]; 108 ];
109 return $link; 109 return $link;
110 } 110 }
111
112 /**
113 * Update link fields using an updated link object.
114 *
115 * @param array $oldLink data
116 * @param array $newLink data
117 *
118 * @return array $oldLink updated with $newLink values
119 */
120 public static function updateLink($oldLink, $newLink)
121 {
122 foreach (['title', 'url', 'description', 'tags', 'private'] as $field) {
123 $oldLink[$field] = $newLink[$field];
124 }
125 $oldLink['updated'] = new \DateTime();
126
127 if (empty($oldLink['url'])) {
128 $oldLink['url'] = '?' . $oldLink['shorturl'];
129 }
130
131 if (empty($oldLink['title'])) {
132 $oldLink['title'] = $oldLink['url'];
133 }
134
135 return $oldLink;
136 }
111} 137}