mirror of
https://github.com/phpbb/phpbb.git
synced 2025-06-09 21:08:53 +00:00
added auto_prune
git-svn-id: file:///svn/phpbb/trunk@516 89ea8834-ac86-4346-8a33-228a782c2dd0
This commit is contained in:
parent
7d6c996092
commit
bc5c16ae82
5 changed files with 151 additions and 12 deletions
|
@ -6,11 +6,7 @@
|
||||||
* copyright : (C) 2001 The phpBB Group
|
* copyright : (C) 2001 The phpBB Group
|
||||||
* email : support@phpbb.com
|
* email : support@phpbb.com
|
||||||
*
|
*
|
||||||
<<<<<<< common.php
|
|
||||||
* $Id$
|
* $Id$
|
||||||
=======
|
|
||||||
* $Id$
|
|
||||||
>>>>>>> 1.24
|
|
||||||
*
|
*
|
||||||
*
|
*
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
|
@ -125,7 +121,7 @@ else
|
||||||
$board_config['avatar_max_width'] = $config['avatar_max_width'];
|
$board_config['avatar_max_width'] = $config['avatar_max_width'];
|
||||||
$board_config['avatar_max_height'] = $config['avatar_max_height'];
|
$board_config['avatar_max_height'] = $config['avatar_max_height'];
|
||||||
$board_config['avatar_path'] = $config['avatar_path'];
|
$board_config['avatar_path'] = $config['avatar_path'];
|
||||||
|
$board_config['prune_enable'] = $config['prune_enable'];
|
||||||
}
|
}
|
||||||
include('language/lang_'.$board_config['default_lang'].'.'.$phpEx);
|
include('language/lang_'.$board_config['default_lang'].'.'.$phpEx);
|
||||||
|
|
||||||
?>
|
?>
|
|
@ -114,7 +114,8 @@ CREATE TABLE phpbb_config (
|
||||||
default_dateformat varchar(14) DEFAULT 'd M Y H:i' NOT NULL,
|
default_dateformat varchar(14) DEFAULT 'd M Y H:i' NOT NULL,
|
||||||
system_timezone int(11) DEFAULT '0' NOT NULL,
|
system_timezone int(11) DEFAULT '0' NOT NULL,
|
||||||
sys_template varchar(100) DEFAULT 'Default' NOT NULL,
|
sys_template varchar(100) DEFAULT 'Default' NOT NULL,
|
||||||
PRIMARY KEY (config_id),
|
prune_enable tinyint(1) DEFAULT '1' NOT NULL,
|
||||||
|
PRIMARY KEY (config_id),
|
||||||
UNIQUE selected (selected)
|
UNIQUE selected (selected)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -145,6 +146,19 @@ CREATE TABLE phpbb_forum_access (
|
||||||
PRIMARY KEY (forum_id, user_id)
|
PRIMARY KEY (forum_id, user_id)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
# --------------------------------------------------------
|
||||||
|
#
|
||||||
|
# Table structure for table 'phpbb_forum_prune'
|
||||||
|
#
|
||||||
|
DROP TABLE IF EXISTS phpbb_forum_prune;
|
||||||
|
|
||||||
|
CREATE TABLE phpbb_forum_prune (
|
||||||
|
prune_id int(10) NOT NULL auto_increment,
|
||||||
|
forum_id int(11) NOT NULL,
|
||||||
|
prune_days int(3) NOT NULL,
|
||||||
|
prune_freq int(3) NOT NULL,
|
||||||
|
PRIMARY KEY(prune_id)
|
||||||
|
);
|
||||||
|
|
||||||
# --------------------------------------------------------
|
# --------------------------------------------------------
|
||||||
#
|
#
|
||||||
|
@ -174,7 +188,9 @@ CREATE TABLE phpbb_forums (
|
||||||
auth_votecreate tinyint(4) DEFAULT '0' NOT NULL,
|
auth_votecreate tinyint(4) DEFAULT '0' NOT NULL,
|
||||||
auth_vote tinyint(4) DEFAULT '0' NOT NULL,
|
auth_vote tinyint(4) DEFAULT '0' NOT NULL,
|
||||||
auth_attachments tinyint(4) DEFAULT '0' NOT NULL,
|
auth_attachments tinyint(4) DEFAULT '0' NOT NULL,
|
||||||
PRIMARY KEY (forum_id),
|
prune_next int(11),
|
||||||
|
prune_enable tinyint(1) DEFAULT '1' NOT NULL,
|
||||||
|
PRIMARY KEY (forum_id),
|
||||||
KEY forum_id (forum_id),
|
KEY forum_id (forum_id),
|
||||||
KEY forums_order (forum_order),
|
KEY forums_order (forum_order),
|
||||||
KEY cat_id (cat_id)
|
KEY cat_id (cat_id)
|
||||||
|
|
|
@ -135,5 +135,5 @@ define('TOPICS_TABLE', $table_prefix.'topics');
|
||||||
define('USER_GROUP_TABLE', $table_prefix.'user_group');
|
define('USER_GROUP_TABLE', $table_prefix.'user_group');
|
||||||
define('USERS_TABLE', $table_prefix.'users');
|
define('USERS_TABLE', $table_prefix.'users');
|
||||||
define('WORDS_TABLE', $table_prefix.'words');
|
define('WORDS_TABLE', $table_prefix.'words');
|
||||||
|
define('PRUNE_TABLE', $table_prefix.'forum_prune');
|
||||||
?>
|
?>
|
111
phpBB/includes/prune.php
Normal file
111
phpBB/includes/prune.php
Normal file
|
@ -0,0 +1,111 @@
|
||||||
|
<?php
|
||||||
|
/***************************************************************************
|
||||||
|
* prune.php
|
||||||
|
* -------------------
|
||||||
|
* begin : Thursday, June 14, 2001
|
||||||
|
* copyright : (C) 2001 The phpBB Group
|
||||||
|
* email : support@phpbb.com
|
||||||
|
*
|
||||||
|
* $Id$
|
||||||
|
*
|
||||||
|
*
|
||||||
|
***************************************************************************/
|
||||||
|
|
||||||
|
/**************************************************************************\
|
||||||
|
*
|
||||||
|
* This program is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 2 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
\**************************************************************************/
|
||||||
|
|
||||||
|
// I am currently seperating the prune functions from functions.php due to the
|
||||||
|
// fact that they are only really needed in one or two places so I don't see
|
||||||
|
// the need to include them everywhere. If someone else thinks this is a bad
|
||||||
|
// idea I am not opposed to moving them elsewhere ;) Jonathan "The_Systech"
|
||||||
|
|
||||||
|
/***************************************************************************\
|
||||||
|
*
|
||||||
|
* function prune. This function takes as it's arguments the forum id to
|
||||||
|
* perform the prune on, and the date before which topics should be pruned.
|
||||||
|
*
|
||||||
|
* This function returns the number of topics pruned upon success.
|
||||||
|
*
|
||||||
|
\***************************************************************************/
|
||||||
|
function prune($forum_id, $prune_date)
|
||||||
|
{
|
||||||
|
global $db, $lang;
|
||||||
|
$sql = 'SELECT t.topic_id
|
||||||
|
FROM ' . TOPICS_TABLE . ' t, ' . POSTS_TABLE . " p
|
||||||
|
WHERE t.forum_id = $forum_id
|
||||||
|
AND p.post_id = t.topic_last_post_id
|
||||||
|
AND t.topic_type != " . POST_ANNOUNCE . "
|
||||||
|
AND p.post_time < $prune_date";
|
||||||
|
if(!$result = $db->sql_query($sql))
|
||||||
|
{
|
||||||
|
error_die(SQL_QUERY, "Couldn't obtain list of topics to prune.", __LINE__, __FILE__);
|
||||||
|
} // End if(!$result...
|
||||||
|
$pruned_topics = $db->sql_numrows($result);
|
||||||
|
if($pruned_topics > 0)
|
||||||
|
{
|
||||||
|
$prune_posts_sql = 'DELETE FROM ' . POSTS_TABLE . "
|
||||||
|
WHERE forum_id = $forum_id AND (";
|
||||||
|
$prune_topic_sql = 'DELETE FROM ' . TOPICS_TABLE . "
|
||||||
|
WHERE forum_id = $forum_id AND (";
|
||||||
|
// ADD a list ORing all Topic ID's to prune....
|
||||||
|
while($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$prune_posts_sql .= 'topic_id = ' . $row['topic_id'] . ' OR ';
|
||||||
|
$prune_topic_sql .= 'topic_id = ' . $row['topic_id'] . ' OR ';
|
||||||
|
} // End while loop
|
||||||
|
// Remove the final OR...
|
||||||
|
$prune_posts_sql = substr($prune_posts_sql, 0, (strlen($prune_posts_sql) - 4));
|
||||||
|
$prune_topic_sql = substr($prune_topic_sql, 0, strlen($prune_topic_sql) - 4);
|
||||||
|
$prune_posts_sql .= ')';
|
||||||
|
$prune_topic_sql .= ')';
|
||||||
|
if(!$result = $db->sql_query($prune_posts_sql))
|
||||||
|
{
|
||||||
|
error_die(SQL_QUERY, "While Pruning: Couldn't remove affected posts.<br>$prune_posts_sql", __LINE__, __FILE__);
|
||||||
|
} // end if(!$result...
|
||||||
|
if(!$result = $db->sql_query($prune_topic_sql))
|
||||||
|
{
|
||||||
|
error_die(SQL_QUERY, "While Pruning: Couldn't remove affected topics.", __LINE__, __FILE__);
|
||||||
|
} // end if(!$result...
|
||||||
|
} // End if $prune_topics
|
||||||
|
return $pruned_topics;
|
||||||
|
} // End function prune.
|
||||||
|
|
||||||
|
/***************************************************************************\
|
||||||
|
*
|
||||||
|
* Function auto_prune(), this function will read the configuration data from
|
||||||
|
* the auto_prune table and call the prune function with the necessary info.
|
||||||
|
*
|
||||||
|
****************************************************************************/
|
||||||
|
function auto_prune($forum_id = 0)
|
||||||
|
{
|
||||||
|
global $db, $lang;
|
||||||
|
$one_day = 60 * 60 * 24;
|
||||||
|
$sql = 'SELECT *
|
||||||
|
FROM ' . PRUNE_TABLE . "
|
||||||
|
WHERE forum_id = '$forum_id'";
|
||||||
|
|
||||||
|
if(!$result = $db->sql_query($sql))
|
||||||
|
{
|
||||||
|
error_die(SQL_QUERY, "Auto-Prune: Couldn't read auto_prune table.", __LINE__, __FILE__);
|
||||||
|
} // End if(!$result...
|
||||||
|
while($row = $db->sql_fetchrow($result))
|
||||||
|
{
|
||||||
|
$forum_id = $row['forum_id'];
|
||||||
|
$prune_date = time() - ($row['prune_days'] * $one_day);
|
||||||
|
$pruned = prune($forum_id, $prune_date);
|
||||||
|
$next_prune = time() + ($row['prune_freq'] * $one_day);
|
||||||
|
$sql = 'UPDATE ' . FORUMS_TABLE . "
|
||||||
|
SET prune_next = '$next_prune'
|
||||||
|
WHERE forum_id = '$forum_id'";
|
||||||
|
if(!$db->sql_query($sql))
|
||||||
|
{
|
||||||
|
error_die(SQL_QUERY, "Auto-Prune: Couldn't update forum table.", __LINE__, __FILE__);
|
||||||
|
} // End if(!$db->sql..
|
||||||
|
} // End While Loop.
|
||||||
|
} // End auto_prune function.
|
|
@ -56,7 +56,7 @@ init_userprefs($userdata);
|
||||||
//
|
//
|
||||||
if(isset($forum_id))
|
if(isset($forum_id))
|
||||||
{
|
{
|
||||||
$sql = "SELECT f.forum_name, f.forum_topics, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_votecreate, f.auth_vote, u.username, u.user_id
|
$sql = "SELECT f.forum_name, f.forum_topics, f.auth_view, f.auth_read, f.auth_post, f.auth_reply, f.auth_edit, f.auth_delete, f.auth_votecreate, f.auth_vote, u.username, u.user_id, f.prune_enable, f.prune_next
|
||||||
FROM ".FORUMS_TABLE." f, ".USERS_TABLE." u, ".USER_GROUP_TABLE." ug, ".AUTH_ACCESS_TABLE." aa
|
FROM ".FORUMS_TABLE." f, ".USERS_TABLE." u, ".USER_GROUP_TABLE." ug, ".AUTH_ACCESS_TABLE." aa
|
||||||
WHERE f.forum_id = $forum_id
|
WHERE f.forum_id = $forum_id
|
||||||
AND aa.auth_mod = 1
|
AND aa.auth_mod = 1
|
||||||
|
@ -91,6 +91,7 @@ if(!$forum_row)
|
||||||
//
|
//
|
||||||
$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_row[0]);
|
$is_auth = auth(AUTH_ALL, $forum_id, $userdata, $forum_row[0]);
|
||||||
|
|
||||||
|
|
||||||
if(!$is_auth['auth_read'] || !$is_auth['auth_view'])
|
if(!$is_auth['auth_read'] || !$is_auth['auth_view'])
|
||||||
{
|
{
|
||||||
//
|
//
|
||||||
|
@ -115,6 +116,21 @@ if(!$is_auth['auth_read'] || !$is_auth['auth_view'])
|
||||||
// End of auth check
|
// End of auth check
|
||||||
//
|
//
|
||||||
|
|
||||||
|
//
|
||||||
|
// Do the forum Prune
|
||||||
|
//
|
||||||
|
if(($is_auth['auth_mod'] || ($is_auth['auth_admin'})) && ($board_config['prune_enable']))
|
||||||
|
{
|
||||||
|
if(($forum_row[0]['prune_next'] < time()) && ($forum_row[0]['prune_enable']))
|
||||||
|
{
|
||||||
|
include('includes/prune.php');
|
||||||
|
auto_prune($forum_id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
//
|
||||||
|
// End of forum prune
|
||||||
|
//
|
||||||
|
|
||||||
$forum_name = stripslashes($forum_row[0]['forum_name']);
|
$forum_name = stripslashes($forum_row[0]['forum_name']);
|
||||||
if(empty($HTTP_POST_VARS['postdays']))
|
if(empty($HTTP_POST_VARS['postdays']))
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Reference in a new issue