mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-28 14:18:52 +00:00
Various updates and changes
git-svn-id: file:///svn/phpbb/trunk@2095 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
0f6a4c9b91
commit
9218b75028
1 changed files with 59 additions and 163 deletions
|
@ -20,12 +20,12 @@
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
|
||||||
|
require($phpbb_root_path . 'includes/search.'.$phpEx);
|
||||||
|
|
||||||
function prune($forum_id, $prune_date)
|
function prune($forum_id, $prune_date)
|
||||||
{
|
{
|
||||||
global $db, $lang;
|
global $db, $lang;
|
||||||
|
|
||||||
$pruned_topic_list = array();
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// Those without polls ...
|
// Those without polls ...
|
||||||
//
|
//
|
||||||
|
@ -35,189 +35,87 @@ function prune($forum_id, $prune_date)
|
||||||
AND t.topic_vote = 0
|
AND t.topic_vote = 0
|
||||||
AND t.topic_type <> " . POST_ANNOUNCE . "
|
AND t.topic_type <> " . POST_ANNOUNCE . "
|
||||||
AND p.post_id = t.topic_last_post_id";
|
AND p.post_id = t.topic_last_post_id";
|
||||||
if ($prune_date != "")
|
if ( $prune_date != "" )
|
||||||
{
|
{
|
||||||
$sql .= " AND p.post_time < $prune_date";
|
$sql .= " AND p.post_time < $prune_date";
|
||||||
}
|
}
|
||||||
|
if ( !($result = $db->sql_query($sql)) )
|
||||||
if(!$result_topics = $db->sql_query($sql))
|
|
||||||
{
|
{
|
||||||
message_die(GENERAL_ERROR, "Couldn't obtain lists of topics to prune.", "", __LINE__, __FILE__, $sql);
|
message_die(GENERAL_ERROR, "Couldn't obtain lists of topics to prune.", "", __LINE__, __FILE__, $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $pruned_topics = $db->sql_numrows($result_topics) )
|
$sql_topics = "";
|
||||||
|
while( $row = $db->sql_fetchrow($result) )
|
||||||
|
{
|
||||||
|
$sql_topics .= ( ( $sql_topics != "" ) ? ", " : "" ) . $row['topic_id'];
|
||||||
|
}
|
||||||
|
|
||||||
|
if( $sql_topics != "" )
|
||||||
{
|
{
|
||||||
$pruned_topic_list = $db->sql_fetchrowset($result_topics);
|
|
||||||
|
|
||||||
$sql_topics = "";
|
|
||||||
for($i = 0; $i < $pruned_topics; $i++)
|
|
||||||
{
|
|
||||||
if($sql_topics != "")
|
|
||||||
{
|
|
||||||
$sql_topics .= ", ";
|
|
||||||
}
|
|
||||||
$sql_topics .= $pruned_topic_list[$i]['topic_id'];
|
|
||||||
}
|
|
||||||
$sql_topics = "topic_id IN (" . $sql_topics . ")";
|
|
||||||
|
|
||||||
$sql = "SELECT post_id
|
$sql = "SELECT post_id
|
||||||
FROM " . POSTS_TABLE . "
|
FROM " . POSTS_TABLE . "
|
||||||
WHERE forum_id = $forum_id
|
WHERE forum_id = $forum_id
|
||||||
AND $sql_topics";
|
AND topic_id IN ($sql_topics)";
|
||||||
if(!$result_posts = $db->sql_query($sql))
|
if ( !($result = $db->sql_query($sql)) )
|
||||||
{
|
{
|
||||||
message_die(GENERAL_ERROR, "Couldn't obtain list of posts to prune.", "", __LINE__, __FILE__, $sql);
|
message_die(GENERAL_ERROR, "Couldn't obtain list of posts to prune.", "", __LINE__, __FILE__, $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
$pruned_posts = $db->sql_numrows($result_posts);
|
|
||||||
$pruned_post_list = $db->sql_fetchrowset($result_posts);
|
|
||||||
|
|
||||||
$sql_post = "";
|
$sql_post = "";
|
||||||
for($i = 0; $i < $pruned_posts; $i++)
|
while ( $row = $db->sql_fetchrow($result) )
|
||||||
{
|
{
|
||||||
$post_id = $pruned_post_list[$i]['post_id'];
|
$sql_post .= ( ( $sql_post != "" ) ? ", " : "" ) . $row['post_id'];
|
||||||
|
}
|
||||||
|
|
||||||
if( $sql_post != "" )
|
if ( $sql_post != "" )
|
||||||
|
{
|
||||||
|
$sql = "DELETE FROM " . TOPICS_TABLE . "
|
||||||
|
WHERE topic_id IN ($sql_topics)";
|
||||||
|
if ( !($result = $db->sql_query($sql, BEGIN_TRANSACTION)) )
|
||||||
{
|
{
|
||||||
$sql_post .= ", ";
|
message_die(GENERAL_ERROR, "Couldn't delete topics during prune.", "", __LINE__, __FILE__, $sql);
|
||||||
}
|
}
|
||||||
$sql_post .= $post_id;
|
|
||||||
}
|
|
||||||
$sql_post = "post_id IN (" . $sql_post . ")";
|
|
||||||
|
|
||||||
$sql = "DELETE FROM " . TOPICS_TABLE . "
|
$pruned_topics = $db->sql_affectedrows();
|
||||||
WHERE $sql_topics";
|
|
||||||
if(!$result = $db->sql_query($sql))
|
$sql = "DELETE FROM " . POSTS_TABLE . "
|
||||||
{
|
WHERE post_id IN ($sql_post)";
|
||||||
message_die(GENERAL_ERROR, "Couldn't delete topics during prune.", "", __LINE__, __FILE__, $sql);
|
if ( !($result = $db->sql_query($sql)) )
|
||||||
}
|
{
|
||||||
|
message_die(GENERAL_ERROR, "Couldn't delete post_text during prune.", "", __LINE__, __FILE__, $sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
$pruned_posts = $db->sql_affectedrows();
|
||||||
|
|
||||||
$sql = "DELETE FROM " . POSTS_TABLE . "
|
|
||||||
WHERE $sql_post";
|
|
||||||
if( $result = $db->sql_query($sql, BEGIN_TRANSACTION) )
|
|
||||||
{
|
|
||||||
$sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
|
$sql = "DELETE FROM " . POSTS_TEXT_TABLE . "
|
||||||
WHERE $sql_post";
|
WHERE post_id IN ($sql_post)";
|
||||||
if( $result = $db->sql_query($sql) )
|
if ( !($result = $db->sql_query($sql)) )
|
||||||
{
|
|
||||||
$sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
|
|
||||||
WHERE $sql_post";
|
|
||||||
if( !$result = $db->sql_query($sql, END_TRANSACTION) )
|
|
||||||
{
|
|
||||||
message_die(GENERAL_ERROR, "Couldn't delete search matches", "", __LINE__, __FILE__, $sql);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
message_die(GENERAL_ERROR, "Couldn't delete post during prune.", "", __LINE__, __FILE__, $sql);
|
message_die(GENERAL_ERROR, "Couldn't delete post during prune.", "", __LINE__, __FILE__, $sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$sql = "DELETE FROM " . SEARCH_MATCH_TABLE . "
|
||||||
|
WHERE post_id IN ($sql_post)";
|
||||||
|
if ( !($result = $db->sql_query($sql)) )
|
||||||
|
{
|
||||||
|
message_die(GENERAL_ERROR, "Couldn't delete search matches", "", __LINE__, __FILE__, $sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
remove_unmatched_words();
|
||||||
|
|
||||||
|
$sql = "UPDATE " . FORUMS_TABLE . "
|
||||||
|
SET forum_topics = forum_topics - $pruned_topics, forum_posts = forum_posts - $pruned_posts
|
||||||
|
WHERE forum_id = $forum_id";
|
||||||
|
if ( !($result = $db->sql_query($sql)) )
|
||||||
|
{
|
||||||
|
message_die(GENERAL_ERROR, "Couldn't update forum data after prune.", "", __LINE__, __FILE__, $sql);
|
||||||
|
}
|
||||||
|
|
||||||
|
return array ("topics" => $pruned_topics, "posts" => $pruned_posts);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
message_die(GENERAL_ERROR, "Couldn't delete post_text during prune.", "", __LINE__, __FILE__, $sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
//
|
|
||||||
// Remove any words in search wordlist which no longer
|
|
||||||
// appear in posts
|
|
||||||
//
|
|
||||||
switch(SQL_LAYER)
|
|
||||||
{
|
|
||||||
case 'postgresql':
|
|
||||||
$sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
|
|
||||||
WHERE word_id NOT IN (
|
|
||||||
SELECT word_id
|
|
||||||
FROM " . SEARCH_MATCH_TABLE . "
|
|
||||||
GROUP BY word_id)";
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
if( !$result )
|
|
||||||
{
|
|
||||||
message_die(GENERAL_ERROR, "Couldn't delete old words from word table", __LINE__, __FILE__, $sql);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'oracle':
|
|
||||||
$sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
|
|
||||||
WHERE word_id IN (
|
|
||||||
SELECT w.word_id
|
|
||||||
FROM " . SEARCH_WORD_TABLE . " w, " . SEARCH_MATCH_TABLE . " m
|
|
||||||
WHERE w.word_id = m.word_id(+)
|
|
||||||
AND m.word_id IS NULL)";
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
if( !$result )
|
|
||||||
{
|
|
||||||
message_die(GENERAL_ERROR, "Couldn't delete old words from word table", __LINE__, __FILE__, $sql);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'mssql':
|
|
||||||
case 'msaccess':
|
|
||||||
$sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
|
|
||||||
WHERE word_id IN (
|
|
||||||
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)";
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
if( !$result )
|
|
||||||
{
|
|
||||||
message_die(GENERAL_ERROR, "Couldn't delete old words from word table", __LINE__, __FILE__, $sql);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 'mysql':
|
|
||||||
case 'mysql4':
|
|
||||||
// 0.07s
|
|
||||||
$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) )
|
|
||||||
{
|
|
||||||
if( $db->sql_numrows($result) )
|
|
||||||
{
|
|
||||||
$rowset = array();
|
|
||||||
while( $row = $db->sql_fetchrow($result) )
|
|
||||||
{
|
|
||||||
$rowset[] = $row['word_id'];
|
|
||||||
}
|
|
||||||
|
|
||||||
$word_id_sql = implode(", ", $rowset);
|
|
||||||
|
|
||||||
if( $word_id_sql )
|
|
||||||
{
|
|
||||||
// 0.07s (about 15-20 words)
|
|
||||||
$sql = "DELETE FROM " . SEARCH_WORD_TABLE . "
|
|
||||||
WHERE word_id IN ($word_id_sql)";
|
|
||||||
$result = $db->sql_query($sql);
|
|
||||||
if( !$result )
|
|
||||||
{
|
|
||||||
message_die(GENERAL_ERROR, "Couldn't delete word list entry", "", __LINE__, __FILE__, $sql);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql = "UPDATE " . FORUMS_TABLE . "
|
|
||||||
SET forum_topics = forum_topics - $pruned_topics, forum_posts = forum_posts - $pruned_posts
|
|
||||||
WHERE forum_id = $forum_id";
|
|
||||||
if(!$result = $db->sql_query($sql))
|
|
||||||
{
|
|
||||||
message_die(GENERAL_ERROR, "Couldn't update forum data after prune.", "", __LINE__, __FILE__, $sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
return array (
|
|
||||||
"topics" => $pruned_topics,
|
|
||||||
"posts" => $pruned_posts);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
return array(
|
|
||||||
"topics" => 0,
|
|
||||||
"posts" => 0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return array("topics" => 0, "posts" => 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/***************************************************************************\
|
/***************************************************************************\
|
||||||
|
@ -234,16 +132,14 @@ function auto_prune($forum_id = 0)
|
||||||
FROM " . PRUNE_TABLE . "
|
FROM " . PRUNE_TABLE . "
|
||||||
WHERE forum_id = $forum_id";
|
WHERE forum_id = $forum_id";
|
||||||
|
|
||||||
if(!$result = $db->sql_query($sql))
|
if ( !($result = $db->sql_query($sql)) )
|
||||||
{
|
{
|
||||||
message_die(GENERAL_ERROR, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
|
message_die(GENERAL_ERROR, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( $db->sql_numrows($result) )
|
if ( $row = $db->sql_fetchrow($result) )
|
||||||
{
|
{
|
||||||
$row = $db->sql_fetchrow($result);
|
if ( $row['prune_freq'] && $row['prune_days'] )
|
||||||
|
|
||||||
if( $row['prune_freq'] && $row['prune_days'] )
|
|
||||||
{
|
{
|
||||||
$prune_date = time() - ( $row['prune_days'] * 86400 );
|
$prune_date = time() - ( $row['prune_days'] * 86400 );
|
||||||
prune($forum_id, $prune_date);
|
prune($forum_id, $prune_date);
|
||||||
|
@ -253,7 +149,7 @@ function auto_prune($forum_id = 0)
|
||||||
$sql = "UPDATE " . FORUMS_TABLE . "
|
$sql = "UPDATE " . FORUMS_TABLE . "
|
||||||
SET prune_next = $next_prune
|
SET prune_next = $next_prune
|
||||||
WHERE forum_id = $forum_id";
|
WHERE forum_id = $forum_id";
|
||||||
if( !$db->sql_query($sql) )
|
if ( !$db->sql_query($sql) )
|
||||||
{
|
{
|
||||||
message_die(GENERAL_ERROR, "Auto-Prune: Couldn't update forum table.", __LINE__, __FILE__);
|
message_die(GENERAL_ERROR, "Auto-Prune: Couldn't update forum table.", __LINE__, __FILE__);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue