New function "dba::update" and changed unique index for the conversations
This commit is contained in:
parent
3b5e1bbfc3
commit
782783aa52
|
@ -1,6 +1,6 @@
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
-- Friendica 3.5.2-dev (Asparagus)
|
-- Friendica 3.5.2-dev (Asparagus)
|
||||||
-- DB_UPDATE_VERSION 1220
|
-- DB_UPDATE_VERSION 1221
|
||||||
-- ------------------------------------------
|
-- ------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -753,6 +753,32 @@ class dba {
|
||||||
return self::e($sql, $param);
|
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
|
* @brief Closes the current statement
|
||||||
*
|
*
|
||||||
|
|
|
@ -820,7 +820,7 @@ function db_definition() {
|
||||||
"received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
|
"received" => array("type" => "datetime", "not null" => "1", "default" => NULL_DATE),
|
||||||
),
|
),
|
||||||
"indexes" => array(
|
"indexes" => array(
|
||||||
"PRIMARY" => array("item-uri", "protocol"),
|
"PRIMARY" => array("item-uri"),
|
||||||
"conversation-uri" => array("conversation-uri"),
|
"conversation-uri" => array("conversation-uri"),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
|
|
@ -716,8 +716,16 @@ function item_store($arr, $force_parent = false, $notify = false, $dontcache = f
|
||||||
$conversation['source'] = $arr['source'];
|
$conversation['source'] = $arr['source'];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$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);
|
dba::insert('conversation', $conversation);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
unset($arr['conversation-uri']);
|
unset($arr['conversation-uri']);
|
||||||
unset($arr['conversation-href']);
|
unset($arr['conversation-href']);
|
||||||
|
|
Loading…
Reference in a new issue