mirror of
https://github.com/friendica/friendica
synced 2025-04-27 01:10:14 +00:00
Preparations to not store the tags in the item table anymore
This commit is contained in:
parent
a8a189eec4
commit
0ab9f2e265
5 changed files with 67 additions and 32 deletions
|
@ -117,6 +117,11 @@ class Item extends BaseObject
|
|||
}
|
||||
}
|
||||
|
||||
// Build the tag string out of the term entries
|
||||
if (isset($row['id']) && isset($row['tag'])) {
|
||||
$row['tag'] = Term::tagTextFromItemId($row['id']);
|
||||
}
|
||||
|
||||
// We can always comment on posts from these networks
|
||||
if (isset($row['writable']) && !empty($row['network']) &&
|
||||
in_array($row['network'], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
|
||||
|
@ -525,6 +530,11 @@ class Item extends BaseObject
|
|||
*/
|
||||
private static function constructSelectFields($fields, $selected)
|
||||
{
|
||||
// To be able to fetch the tags we need the item id
|
||||
if (in_array('tag', $selected) && !in_array('id', $selected)) {
|
||||
$selected[] = 'id';
|
||||
}
|
||||
|
||||
$selection = [];
|
||||
foreach ($fields as $table => $table_fields) {
|
||||
foreach ($table_fields as $field => $select) {
|
||||
|
@ -622,8 +632,15 @@ class Item extends BaseObject
|
|||
$content_fields['plink'] = $item['plink'];
|
||||
}
|
||||
self::updateContent($content_fields, ['uri' => $item['uri']]);
|
||||
Term::insertFromTagFieldByItemId($item['id']);
|
||||
Term::insertFromFileFieldByItemId($item['id']);
|
||||
|
||||
if (array_key_exists('tag', $fields)) {
|
||||
Term::insertFromTagFieldByItemId($item['id']);
|
||||
}
|
||||
|
||||
if (array_key_exists('file', $fields)) {
|
||||
Term::insertFromFileFieldByItemId($item['id']);
|
||||
}
|
||||
|
||||
self::updateThread($item['id']);
|
||||
|
||||
// We only need to notfiy others when it is an original entry from us.
|
||||
|
@ -1471,8 +1488,13 @@ class Item extends BaseObject
|
|||
* Due to deadlock issues with the "term" table we are doing these steps after the commit.
|
||||
* This is not perfect - but a workable solution until we found the reason for the problem.
|
||||
*/
|
||||
Term::insertFromTagFieldByItemId($current_post);
|
||||
Term::insertFromFileFieldByItemId($current_post);
|
||||
if (array_key_exists('tag', $item)) {
|
||||
Term::insertFromTagFieldByItemId($current_post);
|
||||
}
|
||||
|
||||
if (array_key_exists('file', $item)) {
|
||||
Term::insertFromFileFieldByItemId($current_post);
|
||||
}
|
||||
|
||||
if ($item['parent-uri'] === $item['uri']) {
|
||||
self::addShadow($current_post);
|
||||
|
|
|
@ -15,6 +15,26 @@ require_once 'include/dba.php';
|
|||
|
||||
class Term
|
||||
{
|
||||
public static function tagTextFromItemId($itemid)
|
||||
{
|
||||
$tag_text = '';
|
||||
$condition = ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]];
|
||||
$tags = dba::select('term', [], $condition);
|
||||
while ($tag = dba::fetch($tags)) {
|
||||
if ($tag_text != '') {
|
||||
$tag_text .= ',';
|
||||
}
|
||||
|
||||
if ($tag['type'] == 1) {
|
||||
$tag_text .= '#';
|
||||
} else {
|
||||
$tag_text .= '@';
|
||||
}
|
||||
$tag_text .= '[url=' . $tag['url'] . ']' . $tag['term'] . '[/url]';
|
||||
}
|
||||
return $tag_text;
|
||||
}
|
||||
|
||||
public static function insertFromTagFieldByItemId($itemid)
|
||||
{
|
||||
$profile_base = System::baseUrl();
|
||||
|
@ -57,14 +77,14 @@ class Term
|
|||
$pattern = '/\W\#([^\[].*?)[\s\'".,:;\?!\[\]\/]/ism';
|
||||
if (preg_match_all($pattern, $data, $matches)) {
|
||||
foreach ($matches[1] as $match) {
|
||||
$tags['#' . strtolower($match)] = '';
|
||||
$tags['#' . $match] = '';
|
||||
}
|
||||
}
|
||||
|
||||
$pattern = '/\W([\#@])\[url\=(.*?)\](.*?)\[\/url\]/ism';
|
||||
if (preg_match_all($pattern, $data, $matches, PREG_SET_ORDER)) {
|
||||
foreach ($matches as $match) {
|
||||
$tags[$match[1] . strtolower(trim($match[3], ',.:;[]/\"?!'))] = $match[2];
|
||||
$tags[$match[1] . trim($match[3], ',.:;[]/\"?!')] = $match[2];
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -193,7 +213,7 @@ class Term
|
|||
|
||||
while ($tag = dba::fetch($taglist)) {
|
||||
if ($tag["url"] == "") {
|
||||
$tag["url"] = $searchpath . strtolower($tag["term"]);
|
||||
$tag["url"] = $searchpath . $tag["term"];
|
||||
}
|
||||
|
||||
$orig_tag = $tag["url"];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue