Replace legacy file/category handling

This commit is contained in:
Michael 2021-01-21 07:16:41 +00:00
parent 0668b2dfd5
commit d2ea3eabfb
14 changed files with 103 additions and 253 deletions

View file

@ -22,7 +22,6 @@
namespace Friendica\Model\Post;
use Friendica\Database\DBA;
use Friendica\Model\Item;
use Friendica\Model\Post;
use Friendica\Model\Tag;
@ -38,11 +37,25 @@ class Category
const CATEGORY = 3;
const FILE = 5;
/**
* 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 deleteByURIId(int $uri_id, int $uid)
{
return DBA::delete('post-category', ['uri-id' => $uri_id, 'uid' => $uid]);
}
/**
* Generates the legacy item.file field string from an item ID.
* Includes only file and category terms.
*
* @param int $item_id
* @param int $uri_id
* @param int $uid
* @return string
* @throws \Exception
*/
@ -62,6 +75,58 @@ class Category
return $file_text;
}
/**
* Generates an array of files or categories of a given uri-id
*
* @param int $uid
* @param int $type
* @return array
* @throws \Exception
*/
public static function getArray(int $uid, int $type)
{
$tags = DBA::selectToArray('category-view', ['name'], ['uid' => $uid, 'type' => $type],
['group_by' => ['name'], 'order' => ['name']]);
if (empty($tags)) {
return [];
}
return array_column($tags, 'name');
}
/**
* Generates an array of files or categories of a given uri-id
*
* @param int $uri_id
* @param int $uid
* @param int $type
* @return array
* @throws \Exception
*/
public static function getArrayByURIId(int $uri_id, int $uid, int $type = self::CATEGORY)
{
$tags = DBA::selectToArray('category-view', ['type', 'name'], ['uri-id' => $uri_id, 'uid' => $uid, 'type' => $type]);
if (empty($tags)) {
return [];
}
return array_column($tags, 'name');
}
/**
* Generates a comma separated list of files or categories
*
* @param int $uri_id
* @param int $uid
* @param int $type
* @return string
* @throws \Exception
*/
public static function getCSVByURIId(int $uri_id, int $uid, int $type)
{
return implode(',', self::getArrayByURIId($uri_id, $uid, $type));
}
/**
* Inserts new terms for the provided item ID based on the legacy item.file field BBCode content.
* Deletes all previous file terms for the same item ID.