(file) Return to prune.php CVS log (file) (dir) Up to [RizwankCVS] / geekymedia_web / phpBB2 / includes

  1 rizwank 1.1 <?php
  2             /***************************************************************************
  3             *                                 prune.php
  4             *                            -------------------
  5             *   begin                : Thursday, June 14, 2001
  6             *   copyright            : (C) 2001 The phpBB Group
  7             *   email                : support@phpbb.com
  8             *
  9             *   $Id: prune.php,v 1.19.2.3 2002/11/29 06:58:37 dougk_ff7 Exp $
 10             *
 11             *
 12             ***************************************************************************/
 13             
 14             /***************************************************************************
 15              *
 16              *   This program is free software; you can redistribute it and/or modify
 17              *   it under the terms of the GNU General Public License as published by
 18              *   the Free Software Foundation; either version 2 of the License, or
 19              *   (at your option) any later version.
 20              *
 21              ***************************************************************************/
 22 rizwank 1.1 
 23             if ( !defined('IN_PHPBB') )
 24             {
 25                die("Hacking attempt");
 26             }
 27             
 28             require($phpbb_root_path . 'includes/functions_search.'.$phpEx);
 29             
 30             function prune($forum_id, $prune_date, $prune_all = false)
 31             {
 32             	global $db, $lang;
 33             
 34             	$prune_all = ($prune_all) ? '' : 'AND t.topic_vote = 0 AND t.topic_type <> ' . POST_ANNOUNCE;
 35             	//
 36             	// Those without polls and announcements ... unless told otherwise!
 37             	//
 38             	$sql = "SELECT t.topic_id 
 39             		FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
 40             		WHERE t.forum_id = $forum_id
 41             			$prune_all 
 42             			AND ( p.post_id = t.topic_last_post_id 
 43 rizwank 1.1 				OR t.topic_last_post_id = 0 )";
 44             	if ( $prune_date != '' )
 45             	{
 46             		$sql .= " AND p.post_time < $prune_date";
 47             	}
 48             
 49             	if ( !($result = $db->sql_query($sql)) )
 50             	{
 51             		message_die(GENERAL_ERROR, 'Could not obtain lists of topics to prune', '', __LINE__, __FILE__, $sql);
 52             	}
 53             
 54             	$sql_topics = '';
 55             	while( $row = $db->sql_fetchrow($result) )
 56             	{
 57             		$sql_topics .= ( ( $sql_topics != '' ) ? ', ' : '' ) . $row['topic_id'];
 58             	}
 59             		
 60             	if( $sql_topics != '' )
 61             	{
 62             		$sql = "SELECT post_id
 63             			FROM " . POSTS_TABLE . " 
 64 rizwank 1.1 			WHERE forum_id = $forum_id 
 65             				AND topic_id IN ($sql_topics)";
 66             		if ( !($result = $db->sql_query($sql)) )
 67             		{
 68             			message_die(GENERAL_ERROR, 'Could not obtain list of posts to prune', '', __LINE__, __FILE__, $sql);
 69             		}
 70             
 71             		$sql_post = '';
 72             		while ( $row = $db->sql_fetchrow($result) )
 73             		{
 74             			$sql_post .= ( ( $sql_post != '' ) ? ', ' : '' ) . $row['post_id'];
 75             		}
 76             
 77             		if ( $sql_post != '' )
 78             		{
 79             			$sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " 
 80             				WHERE topic_id IN ($sql_topics)";
 81             			if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
 82             			{
 83             				message_die(GENERAL_ERROR, 'Could not delete watched topics during prune', '', __LINE__, __FILE__, $sql);
 84             			}
 85 rizwank 1.1 
 86             			$sql = "DELETE FROM " . TOPICS_TABLE . " 
 87             				WHERE topic_id IN ($sql_topics)";
 88             			if ( !$db->sql_query($sql) )
 89             			{
 90             				message_die(GENERAL_ERROR, 'Could not delete topics during prune', '', __LINE__, __FILE__, $sql);
 91             			}
 92             
 93             			$pruned_topics = $db->sql_affectedrows();
 94             
 95             			$sql = "DELETE FROM " . POSTS_TABLE . " 
 96             				WHERE post_id IN ($sql_post)";
 97             			if ( !$db->sql_query($sql) )
 98             			{
 99             				message_die(GENERAL_ERROR, 'Could not delete post_text during prune', '', __LINE__, __FILE__, $sql);
100             			}
101             
102             			$pruned_posts = $db->sql_affectedrows();
103             
104             			$sql = "DELETE FROM " . POSTS_TEXT_TABLE . " 
105             				WHERE post_id IN ($sql_post)";
106 rizwank 1.1 			if ( !$db->sql_query($sql) )
107             			{
108             				message_die(GENERAL_ERROR, 'Could not delete post during prune', '', __LINE__, __FILE__, $sql);
109             			}
110             
111             			$sql = "DELETE FROM " . SEARCH_MATCH_TABLE . " 
112             				WHERE post_id IN ($sql_post)";
113             			if ( !$db->sql_query($sql) )
114             			{
115             				message_die(GENERAL_ERROR, 'Could not delete search matches', '', __LINE__, __FILE__, $sql);
116             			}
117             
118             			remove_search_post($sql_post);
119             
120             			return array ('topics' => $pruned_topics, 'posts' => $pruned_posts);
121             		}
122             	}
123             
124             	return array('topics' => 0, 'posts' => 0);
125             }
126             
127 rizwank 1.1 //
128             // Function auto_prune(), this function will read the configuration data from
129             // the auto_prune table and call the prune function with the necessary info.
130             //
131             function auto_prune($forum_id = 0)
132             {
133             	global $db, $lang;
134             
135             	$sql = "SELECT *
136             		FROM " . PRUNE_TABLE . "
137             		WHERE forum_id = $forum_id";
138             	if ( !($result = $db->sql_query($sql)) )
139             	{
140             		message_die(GENERAL_ERROR, 'Could not read auto_prune table', '', __LINE__, __FILE__, $sql);
141             	}
142             
143             	if ( $row = $db->sql_fetchrow($result) )
144             	{
145             		if ( $row['prune_freq'] && $row['prune_days'] )
146             		{
147             			$prune_date = time() - ( $row['prune_days'] * 86400 );
148 rizwank 1.1 			$next_prune = time() + ( $row['prune_freq'] * 86400 );
149             
150             			prune($forum_id, $prune_date);
151             			sync('forum', $forum_id);
152             
153             			$sql = "UPDATE " . FORUMS_TABLE . " 
154             				SET prune_next = $next_prune 
155             				WHERE forum_id = $forum_id";
156             			if ( !$db->sql_query($sql) )
157             			{
158             				message_die(GENERAL_ERROR, 'Could not update forum table', '', __LINE__, __FILE__, $sql);
159             			}
160             		}
161             	}
162             
163             	return;
164             }
165             
166             ?>

Rizwan Kassim
Powered by
ViewCVS 0.9.2