]> git.mxchange.org Git - friendica.git/commitdiff
New function "dba::update" and changed unique index for the conversations
authorMichael <heluecht@pirati.ca>
Fri, 28 Apr 2017 05:50:27 +0000 (05:50 +0000)
committerMichael <heluecht@pirati.ca>
Fri, 28 Apr 2017 05:50:27 +0000 (05:50 +0000)
database.sql
include/dba.php
include/dbstructure.php
include/items.php

index c8010e1e20f0e449a4deb61dbc2aea91f4ee5a5f..73547b3058da2a83c2fd172468a0296561e061a1 100644 (file)
@@ -1,6 +1,6 @@
 -- ------------------------------------------
 -- Friendica 3.5.2-dev (Asparagus)
--- DB_UPDATE_VERSION 1220
+-- DB_UPDATE_VERSION 1221
 -- ------------------------------------------
 
 
index 8686760eace6e25433a922aa1f1d7f68cf32a2a0..93df40b401c8b9e2f93da6116718a18fafacb847 100644 (file)
@@ -753,6 +753,32 @@ class dba {
                return self::e($sql, $param);
        }
 
+       /**
+        * @brief Updates rows
+        *
+        * @param string $table Table name
+        * @param array $fields contains the fields that are updated
+        * @param array $condition condition array with the key values
+        *
+        * @return boolean was the update successfull?
+        */
+       static public function update($table, $fields, $condition) {
+
+               $sql = "UPDATE `".self::$dbo->escape($table)."` SET `".
+                       implode("` = ?, `", array_keys($fields))."` = ? WHERE `".
+                       implode("` = ? AND `", array_keys($condition))."` = ?";
+
+               $params = array();
+               foreach ($fields AS $value) {
+                       $params[] = $value;
+               }
+               foreach ($condition AS $value) {
+                       $params[] = $value;
+               }
+
+               self::e($sql, $params);
+       }
+
        /**
         * @brief Closes the current statement
         *
index 156d3eb645cb1a50faeb9576a1a961a914547e47..98a4a9c307bb6e52d54583edb3477229c2533d44 100644 (file)
@@ -820,7 +820,7 @@ function db_definition() {
                                        "received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
                                        ),
                        "indexes" => array(
-                                       "PRIMARY" => array("item-uri", "protocol"),
+                                       "PRIMARY" => array("item-uri"),
                                        "conversation-uri" => array("conversation-uri"),
                                        )
                        );
index dcc99e8bd964878bc6e19e4a2c84e5e3160294ca..98b40f1eeb889c836455595272a6014520c4e8e4 100644 (file)
@@ -716,7 +716,15 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
                        $conversation['source'] = $arr['source'];
                }
 
-               dba::insert('conversation', $conversation);
+               $conv = dba::fetch_first("SELECT `protocol` FROM `conversation` WHERE `item-uri` = ?", $conversation['item-uri']);
+               if (dbm::is_result($conv)) {
+                       // Replace the conversation entry when the new one is better
+                       if (($conv['protocol'] == 0) OR ($conv['protocol'] > $conversation['protocol'])) {
+                               dba::update('conversation', $conversation, array('item-uri' => $conversation['item-uri']));
+                       }
+               } else {
+                       dba::insert('conversation', $conversation);
+               }
        }
 
        unset($arr['conversation-uri']);