C:\Program Files (x86)\Apache Software Foundation\Apache2.2\htdocs\forum\includes\prune.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php
/***************************************************************************
*                                 prune.php
*                            -------------------
*   begin                : Thursday, June 14, 2001
*   copyright            : (C) 2001 The phpBB Group
*   email                : support@phpbb.com
*
*   $Id: prune.php,v 1.19.2.3 2002/11/29 06:58:37 dougk_ff7 Exp $
*
*
***************************************************************************/

/***************************************************************************
 *
 *   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.
 *
 ***************************************************************************/

if ( !defined('IN_PHPBB') )
{
   die(
"Hacking attempt");
}

require(
$phpbb_root_path 'includes/functions_search.'.$phpEx);

function 
prune($forum_id$prune_date$prune_all false)
{
    global 
$db$lang;

    
$prune_all = ($prune_all) ? '' 'AND t.topic_vote = 0 AND t.topic_type <> ' POST_ANNOUNCE;
    
//
    // Those without polls and announcements ... unless told otherwise!
    //
    
$sql "SELECT t.topic_id 
        FROM " 
POSTS_TABLE " p, " TOPICS_TABLE " t
        WHERE t.forum_id = 
$forum_id
            
$prune_all 
            AND ( p.post_id = t.topic_last_post_id 
                OR t.topic_last_post_id = 0 )"
;
    if ( 
$prune_date != '' )
    {
        
$sql .= " AND p.post_time < $prune_date";
    }

    if ( !(
$result $db->sql_query($sql)) )
    {
        
message_die(GENERAL_ERROR'Could not obtain lists of topics to prune'''__LINE____FILE__$sql);
    }

    
$sql_topics '';
    while( 
$row $db->sql_fetchrow($result) )
    {
        
$sql_topics .= ( ( $sql_topics != '' ) ? ', ' '' ) . $row['topic_id'];
    }
        
    if( 
$sql_topics != '' )
    {
        
$sql "SELECT post_id
            FROM " 
POSTS_TABLE 
            WHERE forum_id = 
$forum_id 
                AND topic_id IN (
$sql_topics)";
        if ( !(
$result $db->sql_query($sql)) )
        {
            
message_die(GENERAL_ERROR'Could not obtain list of posts to prune'''__LINE____FILE__$sql);
        }

        
$sql_post '';
        while ( 
$row $db->sql_fetchrow($result) )
        {
            
$sql_post .= ( ( $sql_post != '' ) ? ', ' '' ) . $row['post_id'];
        }

        if ( 
$sql_post != '' )
        {
            
$sql "DELETE FROM " TOPICS_WATCH_TABLE 
                WHERE topic_id IN (
$sql_topics)";
            if ( !
$db->sql_query($sqlBEGIN_TRANSACTION) )
            {
                
message_die(GENERAL_ERROR'Could not delete watched topics during prune'''__LINE____FILE__$sql);
            }

            
$sql "DELETE FROM " TOPICS_TABLE 
                WHERE topic_id IN (
$sql_topics)";
            if ( !
$db->sql_query($sql) )
            {
                
message_die(GENERAL_ERROR'Could not delete topics during prune'''__LINE____FILE__$sql);
            }

            
$pruned_topics $db->sql_affectedrows();

            
$sql "DELETE FROM " POSTS_TABLE 
                WHERE post_id IN (
$sql_post)";
            if ( !
$db->sql_query($sql) )
            {
                
message_die(GENERAL_ERROR'Could not delete post_text during prune'''__LINE____FILE__$sql);
            }

            
$pruned_posts $db->sql_affectedrows();

            
$sql "DELETE FROM " POSTS_TEXT_TABLE 
                WHERE post_id IN (
$sql_post)";
            if ( !
$db->sql_query($sql) )
            {
                
message_die(GENERAL_ERROR'Could not delete post during prune'''__LINE____FILE__$sql);
            }

            
$sql "DELETE FROM " SEARCH_MATCH_TABLE 
                WHERE post_id IN (
$sql_post)";
            if ( !
$db->sql_query($sql) )
            {
                
message_die(GENERAL_ERROR'Could not delete search matches'''__LINE____FILE__$sql);
            }

            
remove_search_post($sql_post);

            return array (
'topics' => $pruned_topics'posts' => $pruned_posts);
        }
    }

    return array(
'topics' => 0'posts' => 0);
}

//
// 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;

    
$sql "SELECT *
        FROM " 
PRUNE_TABLE "
        WHERE forum_id = 
$forum_id";
    if ( !(
$result $db->sql_query($sql)) )
    {
        
message_die(GENERAL_ERROR'Could not read auto_prune table'''__LINE____FILE__$sql);
    }

    if ( 
$row $db->sql_fetchrow($result) )
    {
        if ( 
$row['prune_freq'] && $row['prune_days'] )
        {
            
$prune_date time() - ( $row['prune_days'] * 86400 );
            
$next_prune time() + ( $row['prune_freq'] * 86400 );

            
prune($forum_id$prune_date);
            
sync('forum'$forum_id);

            
$sql "UPDATE " FORUMS_TABLE 
                SET prune_next = 
$next_prune 
                WHERE forum_id = 
$forum_id";
            if ( !
$db->sql_query($sql) )
            {
                
message_die(GENERAL_ERROR'Could not update forum table'''__LINE____FILE__$sql);
            }
        }
    }

    return;
}

?>