X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=application%2Fapi%2FApiUtils.php;h=f154bb5274a224130e40d4a495dfb1334323a1b0;hb=7519388dd67430c6d37c495c34934f2d5c5c191e;hp=b8155a3442669e452234e8b41a2bfc780befb130;hpb=4c7045229c94973c1cb83193e69463f426ddc35b;p=github%2Fshaarli%2FShaarli.git 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 ]; return $link; } + + /** + * Update link fields using an updated link object. + * + * @param array $oldLink data + * @param array $newLink data + * + * @return array $oldLink updated with $newLink values + */ + public static function updateLink($oldLink, $newLink) + { + foreach (['title', 'url', 'description', 'tags', 'private'] as $field) { + $oldLink[$field] = $newLink[$field]; + } + $oldLink['updated'] = new \DateTime(); + + if (empty($oldLink['url'])) { + $oldLink['url'] = '?' . $oldLink['shorturl']; + } + + if (empty($oldLink['title'])) { + $oldLink['title'] = $oldLink['url']; + } + + return $oldLink; + } }