Location: PHPKode > projects > PapyrusBB > PapyrusBB-0.6/include/tool/maintenance.php
<?php
defined('WikyBlog') or die("Not an entry point...");

	global $rootDir;
	pluginIncludeFile('include/allForumScripts.php');
	pluginIncludeFile('include/admin/adminSync.php');


class forumMaint{
	
	function forumMaint(){
		message('<b>PapyrusBB Maintenance</b> ');
		$this->purge();
		message('<b>End PapyrusBB Maintenance</b>');		
	}
	
	function purge(){
		global $rootDir,$wbTables,$wbNow;
		
		$query = 'SELECT `forum_id`, `stickies`, `age` ';
		$query .= ' FROM '.$wbTables['bb_forums_prune'];
		$query .= ' WHERE `prune` = "1" ';
		$result = wbDB::runQuery($query);
		$unixNow = mktime();
		
		$purgedTopics = 0;
		$forums = array();
		while($row = mysql_fetch_assoc($result)){
			
			$unixDays = (int)$row['age'] * 86400;
			$checkUnix = $unixNow - $unixDays;
			if( $checkUnix < 1 ){
				continue;
			}
			$checkDate = date('Y-m-d H:i:s',$checkUnix);
			
			$query = ' DELETE FROM '.$wbTables['bb_topics'];
			$query .= ' WHERE ';
			$query .= ' `forum_id` = "'.$row['forum_id'].'" ';
			if( $row['stickies'] != '1' ){
				$query .= ' AND `sticky` = "0" ';
			}
			$query .= ' AND `modified` < "'.wbDB::escape($checkDate).'" ';
			$num = wbDB::runQuery($query,true);
			if( $num && $num > 0 ){
				$forums[$row['forum_id']] = true;
				$purgedTopics += $num;
			}
			
			
		}
		
		message('Purged '.$purgedTopics.' topics.');
		if( $purgedTopics < 1 ){
			return;
		}
			
		
		//
		//	delete orphaned posts
		//
		$query = 'DELETE ';
		$query .= $wbTables['bb_posts'];
		$query .= ' FROM ';
		$query .= $wbTables['bb_posts'].' LEFT JOIN '.$wbTables['bb_topics'];
		$query .= ' ON '.$wbTables['bb_posts'].'.`forum_id` = '.$wbTables['bb_topics'].'.`forum_id` ';
		$query .= ' AND '.$wbTables['bb_posts'].'.`file_id` = '.$wbTables['bb_topics'].'.`file_id` ';
		$query .= ' WHERE '.$wbTables['bb_topics'].'.`id` IS NULL ';
		$num = wbDB::runQuery($query,true);
		message('Purged '.$num.' posts');
		
		//
		//	Resync bb_forums
		//
		foreach($forums as $id => $bool){
			forumSync::syncForum($id);
		}
	}
}

new forumMaint();
Return current item: PapyrusBB