X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FModel%2FPost%2FCategory.php;h=2c35a40ad4b8756adc990ecfe01bce85982ed371;hb=21f172c585aff8c606774a05fde1548ddff1667d;hp=b653f43a754a6bdc2d760a2d4a10b5bd438277a1;hpb=d2ea3eabfb1f70324ff4fa7e7055e2c8a7dbc3d3;p=friendica.git diff --git a/src/Model/Post/Category.php b/src/Model/Post/Category.php index b653f43a75..2c35a40ad4 100644 --- a/src/Model/Post/Category.php +++ b/src/Model/Post/Category.php @@ -1,6 +1,6 @@ $uri_id, 'uid' => $uid]); } + /** + * Delete all categories and files from a given uri-id and user + * + * @param int $uri_id + * @param int $uid + * @return boolean success + * @throws \Exception + */ + public static function deleteFileByURIId(int $uri_id, int $uid, int $type, string $file) + { + $tagid = Tag::getID($file); + if (empty($tagid)) { + return false; + } + + return DBA::delete('post-category', ['uri-id' => $uri_id, 'uid' => $uid, 'type' => $type, 'tid' => $tagid]); + } /** * Generates the legacy item.file field string from an item ID. * Includes only file and category terms. @@ -94,6 +111,11 @@ class Category return array_column($tags, 'name'); } + public static function existsForURIId(int $uri_id, int $uid) + { + return DBA::exists('post-category', ['uri-id' => $uri_id, 'uid' => $uid]); + } + /** * Generates an array of files or categories of a given uri-id * @@ -166,18 +188,23 @@ class Category if (preg_match_all("/\<(.*?)\>/ism", $files, $result)) { foreach ($result[1] as $file) { - $tagid = Tag::getID($file); - if (empty($tagid)) { - continue; - } - - DBA::replace('post-category', [ - 'uri-id' => $uri_id, - 'uid' => $uid, - 'type' => self::CATEGORY, - 'tid' => $tagid - ]); + self::storeFileByURIId($uri_id, $uid, self::CATEGORY, $file); } } } + + public static function storeFileByURIId(int $uri_id, int $uid, int $type, string $file) + { + $tagid = Tag::getID($file); + if (empty($tagid)) { + return false; + } + + return DBA::replace('post-category', [ + 'uri-id' => $uri_id, + 'uid' => $uid, + 'type' => $type, + 'tid' => $tagid + ]); + } }