From b1a4782f9329f4028e1ee9a4aef81d88843d87b4 Mon Sep 17 00:00:00 2001 From: "Paul S. Owen" Date: Sun, 17 Mar 2002 14:07:43 +0000 Subject: [PATCH] Various updates git-svn-id: file:///svn/phpbb/trunk@2301 89ea8834-ac86-4346-8a33-228a782c2dd0 --- phpBB/includes/functions_post.php | 23 +++------ phpBB/includes/functions_search.php | 75 ++++++++++++++++++++--------- 2 files changed, 58 insertions(+), 40 deletions(-) diff --git a/phpBB/includes/functions_post.php b/phpBB/includes/functions_post.php index 6476aec15d..e679401795 100644 --- a/phpBB/includes/functions_post.php +++ b/phpBB/includes/functions_post.php @@ -252,6 +252,10 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ } } } + else if ( $mode == 'editpost' ) + { + $result = remove_search_post($post_id); + } if ( $mode == 'newtopic' || ( $mode == 'editpost' && $post_data['first_post'] ) ) { @@ -286,16 +290,6 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ message_die(GENERAL_ERROR, 'Error in posting', '', __LINE__, __FILE__, $sql); } - if ( $mode == 'editpost' ) - { - $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . " - WHERE post_id = $post_id"; - if ( !($db->sql_query($sql)) ) - { - message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql); - } - } - add_search_words($post_id, stripslashes($post_message), stripslashes($post_subject)); // @@ -367,11 +361,6 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ } } - if ( $mode == 'editpost' ) - { - remove_unmatched_words(); - } - $meta = ''; $message = $lang['Stored'] . '

' . sprintf($lang['Click_view_message'], '', '') . '

' . sprintf($lang['Click_return_forum'], '', ''); @@ -381,7 +370,7 @@ function submit_post($mode, &$post_data, &$message, &$meta, &$forum_id, &$topic_ // // Update post stats and details // -function update_post_stats($mode, &$post_data, &$forum_id, &$topic_id, &$post_id) +function update_post_stats(&$mode, &$post_data, &$forum_id, &$topic_id, &$post_id) { global $db, $userdata; @@ -447,7 +436,7 @@ function update_post_stats($mode, &$post_data, &$forum_id, &$topic_id, &$post_id } else if ( $mode != 'poll_delete' ) { - $forum_update_sql .= ", forum_last_post_id = $post_id" . ( ( $mode = 'newtopic' ) ? ", forum_topics = forum_topics $sign" : "" ); + $forum_update_sql .= ", forum_last_post_id = $post_id" . ( ( $mode == 'newtopic' ) ? ", forum_topics = forum_topics $sign" : "" ); $topic_update_sql = "topic_last_post_id = $post_id" . ( ( $mode == 'reply' ) ? ", topic_replies = topic_replies $sign" : ", topic_first_post_id = $post_id" ); } else diff --git a/phpBB/includes/functions_search.php b/phpBB/includes/functions_search.php index d70e3225c5..325581101a 100644 --- a/phpBB/includes/functions_search.php +++ b/phpBB/includes/functions_search.php @@ -347,57 +347,86 @@ function remove_common($mode, $fraction, $word_id_list = array()) return $word_count; } -function remove_unmatched_words() +function remove_search_post($post_id) { global $db; - switch(SQL_LAYER) + $words_removed = false; + + switch( SQL_LAYER ) { case 'mysql': case 'mysql4': - $sql = "SELECT w.word_id - FROM " . SEARCH_WORD_TABLE . " w - LEFT JOIN " . SEARCH_MATCH_TABLE . " m ON m.word_id = w.word_id - WHERE m.word_id IS NULL"; - if( $result = $db->sql_query($sql) ) + $sql = "SELECT word_id + FROM " . SEARCH_MATCH_TABLE . " + WHERE post_id = $post_id"; + if ( $result = $db->sql_query($sql) ) { - $word_id_sql = ""; + $word_id_sql = ''; while( $row = $db->sql_fetchrow($result) ) { - $word_id_sql .= ( $word_id_sql != "" ) ? ", " . $row['word_id'] : $row['word_id']; + $word_id_sql .= ( $word_id_sql != '' ) ? ', ' . $row['word_id'] : $row['word_id']; } - if( $word_id_sql != "" ) + $sql = "SELECT word_id + FROM " . SEARCH_MATCH_TABLE . " + WHERE word_id IN ($word_id_sql) + GROUP BY word_id + HAVING COUNT(word_id) = 1"; + if ( $result = $db->sql_query($sql) ) { - $sql = "DELETE FROM " . SEARCH_WORD_TABLE . " - WHERE word_id IN ($word_id_sql)"; - if( !($result = $db->sql_query($sql, END_TRANSACTION)) ) + $word_id_sql = ''; + while( $row = $db->sql_fetchrow($result) ) { - message_die(GENERAL_ERROR, "Couldn't delete word list entry", "", __LINE__, __FILE__, $sql); + $word_id_sql .= ( $word_id_sql != '' ) ? ', ' . $row['word_id'] : $row['word_id']; } - return $db->sql_affectedrows(); + if ( $word_id_sql != '' ) + { + $sql = "DELETE FROM " . SEARCH_WORD_TABLE . " + WHERE word_id IN ($word_id_sql)"; + if ( !($result = $db->sql_query($sql, END_TRANSACTION)) ) + { + message_die(GENERAL_ERROR, 'Could not delete word list entry', '', __LINE__, __FILE__, $sql); + } + + $words_removed = $db->sql_affectedrows(); + } } } break; default: $sql = "DELETE FROM " . SEARCH_WORD_TABLE . " - WHERE word_id NOT IN ( - SELECT word_id - FROM " . SEARCH_MATCH_TABLE . " - GROUP BY word_id)"; - if( !($result = $db->sql_query($sql, END_TRANSACTION)) ) + WHERE word_id IN ( + SELECT word_id + FROM " . SEARCH_MATCH_TABLE . " + WHERE word_id IN ( + SELECT word_id + FROM " . SEARCH_MATCH_TABLE . " + WHERE post_id = $post_id + ) + GROUP BY word_id + HAVING COUNT(word_id) = 1 + )"; + if ( !($result = $db->sql_query($sql, END_TRANSACTION)) ) { - message_die(GENERAL_ERROR, "Couldn't delete old words from word table", __LINE__, __FILE__, $sql); + message_die(GENERAL_ERROR, 'Could not delete old words from word table', '', __LINE__, __FILE__, $sql); } - return $db->sql_affectedrows(); + $words_removed = $db->sql_affectedrows(); break; } - return 0; + $sql = "DELETE FROM " . SEARCH_MATCH_TABLE . " + WHERE post_id = $post_id"; + if ( !($db->sql_query($sql)) ) + { + message_die(GENERAL_ERROR, 'Error in deleting post', '', __LINE__, __FILE__, $sql); + } + + return $words_removed; } //