From 5ba14278066ce7a398c0aabb41e1c86fe12ea7d8 Mon Sep 17 00:00:00 2001 From: Michael Date: Sat, 30 Jun 2018 15:21:32 +0000 Subject: [PATCH] We don't store tags in the item table anymore --- src/Model/Item.php | 26 ++++++++++++++++++++------ src/Model/Term.php | 6 ++++-- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/Model/Item.php b/src/Model/Item.php index c6e4e131ca..2cc9041bf9 100644 --- a/src/Model/Item.php +++ b/src/Model/Item.php @@ -118,7 +118,7 @@ class Item extends BaseObject } // Build the tag string out of the term entries - if (isset($row['id']) && isset($row['tag'])) { + if (isset($row['id']) && array_key_exists('tag', $row)) { $row['tag'] = Term::tagTextFromItemId($row['id']); } @@ -614,6 +614,13 @@ class Item extends BaseObject } } + if (array_key_exists('tag', $fields)) { + $tags = $fields['tag']; + unset($fields['tag']); + } else { + $tags = ''; + } + if (!empty($fields)) { $success = dba::update('item', $fields, $condition); @@ -633,8 +640,8 @@ class Item extends BaseObject } self::updateContent($content_fields, ['uri' => $item['uri']]); - if (array_key_exists('tag', $fields)) { - Term::insertFromTagFieldByItemId($item['id']); + if (!empty($tags)) { + Term::insertFromTagFieldByItemId($item['id'], $tags); } if (array_key_exists('file', $fields)) { @@ -777,7 +784,7 @@ class Item extends BaseObject 'object' => '', 'target' => '', 'tag' => '', 'postopts' => '', 'attach' => '', 'file' => '']; dba::update('item', $item_fields, ['id' => $item['id']]); - Term::insertFromTagFieldByItemId($item['id']); + Term::insertFromTagFieldByItemId($item['id'], ''); Term::insertFromFileFieldByItemId($item['id']); self::deleteThread($item['id'], $item['parent-uri']); @@ -1357,6 +1364,13 @@ class Item extends BaseObject logger('' . print_r($item,true), LOGGER_DATA); + if (array_key_exists('tag', $item)) { + $tags = $item['tag']; + unset($item['tag']); + } else { + $tags = ''; + } + // We are doing this outside of the transaction to avoid timing problems self::insertContent($item); @@ -1488,8 +1502,8 @@ 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. */ - if (array_key_exists('tag', $item)) { - Term::insertFromTagFieldByItemId($current_post); + if (!empty($tags)) { + Term::insertFromTagFieldByItemId($current_post, $tags); } if (array_key_exists('file', $item)) { diff --git a/src/Model/Term.php b/src/Model/Term.php index 53c9da8aac..85b14174ae 100644 --- a/src/Model/Term.php +++ b/src/Model/Term.php @@ -35,7 +35,7 @@ class Term return $tag_text; } - public static function insertFromTagFieldByItemId($itemid) + public static function insertFromTagFieldByItemId($itemid, $tags) { $profile_base = System::baseUrl(); $profile_data = parse_url($profile_base); @@ -43,12 +43,14 @@ class Term $profile_base_friendica = $profile_data['host'] . $profile_path . '/profile/'; $profile_base_diaspora = $profile_data['host'] . $profile_path . '/u/'; - $fields = ['guid', 'uid', 'id', 'edited', 'deleted', 'created', 'received', 'title', 'body', 'tag', 'parent']; + $fields = ['guid', 'uid', 'id', 'edited', 'deleted', 'created', 'received', 'title', 'body', 'parent']; $message = Item::selectFirst($fields, ['id' => $itemid]); if (!DBM::is_result($message)) { return; } + $message['tag'] = $tags; + // Clean up all tags dba::delete('term', ['otype' => TERM_OBJ_POST, 'oid' => $itemid, 'type' => [TERM_HASHTAG, TERM_MENTION]]); -- 2.39.5