Verzeichnisstruktur phpBB-2.0.0


Veröffentlicht
03.04.2002

So funktioniert es


Auf das letzte Element klicken. Dies geht jeweils ein Schritt zurück

Auf das Icon klicken, dies öffnet das Verzeichnis. Nochmal klicken schließt das Verzeichnis.
Auf den Verzeichnisnamen klicken, dies zeigt nur das Verzeichnis mit Inhalt an

(Beispiel Datei-Icons)

Auf das Icon klicken um den Quellcode anzuzeigen

prune.php

Zuletzt modifiziert: 09.10.2024, 12:51 - Dateigröße: 4.79 KiB


001  <?php
002  /***************************************************************************
003  *                                 prune.php
004  *                            -------------------
005  *   begin                : Thursday, June 14, 2001
006  *   copyright            : (C) 2001 The phpBB Group
007  *   email                : support@phpbb.com
008  *
009  *   $Id$
010  *
011  *
012  ***************************************************************************/
013   
014  /***************************************************************************
015   *
016   *   This program is free software; you can redistribute it and/or modify
017   *   it under the terms of the GNU General Public License as published by
018   *   the Free Software Foundation; either version 2 of the License, or
019   *   (at your option) any later version.
020   *
021   ***************************************************************************/
022   
023  if ( !defined('IN_PHPBB') )
024  {
025     die("Hacking attempt");
026  }
027   
028  require($phpbb_root_path . 'includes/functions_search.'.$phpEx);
029   
030  function prune($forum_id, $prune_date, $prune_all = false)
031  {
032      global $db, $lang;
033   
034      // Before pruning, lets try to clean up the invalid topic entries
035      $sql = 'SELECT topic_id FROM ' . TOPICS_TABLE . '
036          WHERE topic_last_post_id = 0';
037      if ( !($result = $db->sql_query($sql)) )
038      {
039          message_die(GENERAL_ERROR, 'Could not obtain lists of topics to sync', '', __LINE__, __FILE__, $sql);
040      }
041   
042      while( $row = $db->sql_fetchrow($result) )
043      {
044          sync('topic', $row['topic_id']);
045      }
046   
047      $db->sql_freeresult($result);
048   
049      $prune_all = ($prune_all) ? '' : 'AND t.topic_vote = 0 AND t.topic_type <> ' . POST_ANNOUNCE;
050      //
051      // Those without polls and announcements ... unless told otherwise!
052      //
053      $sql = "SELECT t.topic_id 
054          FROM " . POSTS_TABLE . " p, " . TOPICS_TABLE . " t
055          WHERE t.forum_id = $forum_id
056              $prune_all 
057              AND p.post_id = t.topic_last_post_id";
058      if ( $prune_date != '' )
059      {
060          $sql .= " AND p.post_time < $prune_date";
061      }
062   
063      if ( !($result = $db->sql_query($sql)) )
064      {
065          message_die(GENERAL_ERROR, 'Could not obtain lists of topics to prune', '', __LINE__, __FILE__, $sql);
066      }
067   
068      $sql_topics = '';
069      while( $row = $db->sql_fetchrow($result) )
070      {
071          $sql_topics .= ( ( $sql_topics != '' ) ? ', ' : '' ) . $row['topic_id'];
072      }
073      $db->sql_freeresult($result);
074          
075      if( $sql_topics != '' )
076      {
077          $sql = "SELECT post_id
078              FROM " . POSTS_TABLE . " 
079              WHERE forum_id = $forum_id 
080                  AND topic_id IN ($sql_topics)";
081          if ( !($result = $db->sql_query($sql)) )
082          {
083              message_die(GENERAL_ERROR, 'Could not obtain list of posts to prune', '', __LINE__, __FILE__, $sql);
084          }
085   
086          $sql_post = '';
087          while ( $row = $db->sql_fetchrow($result) )
088          {
089              $sql_post .= ( ( $sql_post != '' ) ? ', ' : '' ) . $row['post_id'];
090          }
091          $db->sql_freeresult($result);
092   
093          if ( $sql_post != '' )
094          {
095              $sql = "DELETE FROM " . TOPICS_WATCH_TABLE . " 
096                  WHERE topic_id IN ($sql_topics)";
097              if ( !$db->sql_query($sql, BEGIN_TRANSACTION) )
098              {
099                  message_die(GENERAL_ERROR, 'Could not delete watched topics during prune', '', __LINE__, __FILE__, $sql);
100              }
101   
102              $sql = "DELETE FROM " . TOPICS_TABLE . " 
103                  WHERE topic_id IN ($sql_topics)";
104              if ( !$db->sql_query($sql) )
105              {
106                  message_die(GENERAL_ERROR, 'Could not delete topics during prune', '', __LINE__, __FILE__, $sql);
107              }
108   
109              $pruned_topics = $db->sql_affectedrows();
110   
111              $sql = "DELETE FROM " . POSTS_TABLE . " 
112                  WHERE post_id IN ($sql_post)";
113              if ( !$db->sql_query($sql) )
114              {
115                  message_die(GENERAL_ERROR, 'Could not delete post_text during prune', '', __LINE__, __FILE__, $sql);
116              }
117   
118              $pruned_posts = $db->sql_affectedrows();
119   
120              $sql = "DELETE FROM " . POSTS_TEXT_TABLE . " 
121                  WHERE post_id IN ($sql_post)";
122              if ( !$db->sql_query($sql) )
123              {
124                  message_die(GENERAL_ERROR, 'Could not delete post during prune', '', __LINE__, __FILE__, $sql);
125              }
126   
127              remove_search_post($sql_post);
128   
129              return array ('topics' => $pruned_topics, 'posts' => $pruned_posts);
130          }
131      }
132   
133      return array('topics' => 0, 'posts' => 0);
134  }
135   
136  //
137  // Function auto_prune(), this function will read the configuration data from
138  // the auto_prune table and call the prune function with the necessary info.
139  //
140  function auto_prune($forum_id = 0)
141  {
142      global $db, $lang;
143   
144      $sql = "SELECT *
145          FROM " . PRUNE_TABLE . "
146          WHERE forum_id = $forum_id";
147      if ( !($result = $db->sql_query($sql)) )
148      {
149          message_die(GENERAL_ERROR, 'Could not read auto_prune table', '', __LINE__, __FILE__, $sql);
150      }
151   
152      if ( $row = $db->sql_fetchrow($result) )
153      {
154          if ( $row['prune_freq'] && $row['prune_days'] )
155          {
156              $prune_date = time() - ( $row['prune_days'] * 86400 );
157              $next_prune = time() + ( $row['prune_freq'] * 86400 );
158   
159              prune($forum_id, $prune_date);
160              sync('forum', $forum_id);
161   
162              $sql = "UPDATE " . FORUMS_TABLE . " 
163                  SET prune_next = $next_prune 
164                  WHERE forum_id = $forum_id";
165              if ( !$db->sql_query($sql) )
166              {
167                  message_die(GENERAL_ERROR, 'Could not update forum table', '', __LINE__, __FILE__, $sql);
168              }
169          }
170      }
171   
172      return;
173  }
174   
175  ?>