- $fields = ['item-uri', 'reply-to-uri', 'conversation-uri', 'conversation-href', 'protocol', 'source'];
- $old_conv = DBA::selectFirst('conversation', $fields, ['item-uri' => $conversation['item-uri']]);
- if (DBM::is_result($old_conv)) {
- // Don't update when only the source has changed.
- // Only do this when there had been no source before.
- if ($old_conv['source'] != '') {
- unset($old_conv['source']);
- }
- // Update structure data all the time but the source only when its from a better protocol.
- if (isset($conversation['protocol']) && isset($conversation['source']) && ($old_conv['protocol'] < $conversation['protocol']) && ($old_conv['protocol'] != 0)) {
- unset($conversation['protocol']);
- unset($conversation['source']);
- }
- if (!DBA::update('conversation', $conversation, ['item-uri' => $conversation['item-uri']], $old_conv)) {
- logger('Conversation: update for '.$conversation['item-uri'].' from '.$old_conv['protocol'].' to '.$conversation['protocol'].' failed', LOGGER_DEBUG);
- }
- } else {
- if (!DBA::insert('conversation', $conversation, true)) {
- logger('Conversation: insert for '.$conversation['item-uri'].' (protocol '.$conversation['protocol'].') failed', LOGGER_DEBUG);
- }
+ if (!DBA::exists('conversation', ['item-uri' => $conversation['item-uri']])) {
+ DBA::insert('conversation', $conversation, Database::INSERT_IGNORE);