We don't store tags in the item table anymore
authorMichael <heluecht@pirati.ca>
Sat, 30 Jun 2018 15:21:32 +0000 (15:21 +0000)
committerMichael <heluecht@pirati.ca>
Sat, 30 Jun 2018 15:21:32 +0000 (15:21 +0000)
src/Model/Item.php
src/Model/Term.php

index c6e4e13..2cc9041 100644 (file)
@@ -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)) {
index 53c9da8..85b1417 100644 (file)
@@ -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]]);