aboutsummaryrefslogtreecommitdiffhomepage
path: root/application/api/ApiUtils.php
diff options
context:
space:
mode:
authorArthurHoaro <arthur@hoa.ro>2017-04-01 11:11:25 +0200
committerArthurHoaro <arthur@hoa.ro>2017-05-07 15:49:16 +0200
commitcf9181dddf8b6113b1b017e4bcb21fac0a0b1c83 (patch)
treed8426d3b7b61dbd5f9d849e1114c3ee64d102db3 /application/api/ApiUtils.php
parent4b385d6c344c4a0a0b424622833bc72974c21cb5 (diff)
downloadShaarli-cf9181dddf8b6113b1b017e4bcb21fac0a0b1c83.tar.gz
Shaarli-cf9181dddf8b6113b1b017e4bcb21fac0a0b1c83.tar.zst
Shaarli-cf9181dddf8b6113b1b017e4bcb21fac0a0b1c83.zip
REST API: implement PUT method
* Related to #609 * Documentation: http://shaarli.github.io/api-documentation/#links-link-put
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}