Verzeichnisstruktur phpBB-3.0.0


Veröffentlicht
12.12.2007

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

merge_post_tables.php

Zuletzt modifiziert: 09.10.2024, 12:50 - Dateigröße: 7.63 KiB


001  <?php
002  /***************************************************************************  
003   *                           merge_clean_posts.php  
004   *                            -------------------                         
005   *   begin                : Tuesday, February 25, 2003 
006   *   copyright            : (C) 2003 The phpBB Group        
007   *   email                : support@phpbb.com                           
008   *                                                          
009   *   $Id$
010   * 
011   ***************************************************************************/ 
012   
013  /***************************************************************************  
014   *                                                     
015   *   This program is free software; you can redistribute it and/or modify    
016   *   it under the terms of the GNU General Public License as published by   
017   *   the Free Software Foundation; either version 2 of the License, or  
018   *   (at your option) any later version.                      
019   * 
020   ***************************************************************************/ 
021   
022  //
023  // Security message:
024  //
025  // This script is potentially dangerous.
026  // Remove or comment the next line (die(".... ) to enable this script.
027  // Do NOT FORGET to either remove this script or disable it after you have used it.
028  //
029  die("Please read the first lines of this script for instructions on how to enable it");
030   
031  @set_time_limit(2400);
032   
033  $db = $dbhost = $dbuser = $dbpasswd = $dbport = $dbname = '';
034   
035  define('IN_PHPBB', 1);
036  define('ANONYMOUS', 1);
037  $phpbb_root_path='./../';
038  include($phpbb_root_path . 'extension.inc');
039  include($phpbb_root_path . 'config.'.$phpEx);
040  include($phpbb_root_path . 'includes/functions.'.$phpEx);
041  require($phpbb_root_path . 'includes/acm/cache_' . $acm_type . '.'.$phpEx);
042  include($phpbb_root_path . 'db/' . $dbms . '.'.$phpEx);
043   
044  $cache = new acm();
045  $db = new sql_db($dbhost, $dbuser, $dbpasswd, $dbname, $dbport, false);
046   
047  // Just Do it (tm) 
048  $sql = "RENAME TABLE {$table_prefix}posts TO {$table_prefix}posts_temp";
049  $db->sql_query($sql);
050   
051  $sql = "CREATE TABLE {$table_prefix}posts 
052      SELECT p.*, pt.post_subject, pt.post_text, pt.post_checksum, pt.bbcode_bitfield, pt.bbcode_uid 
053          FROM {$table_prefix}posts_temp p, {$table_prefix}posts_text pt 
054          WHERE pt.post_id = p.post_id";
055  $db->sql_query($sql);
056   
057  switch ($db->sql_layer)
058  {
059      case 'mysql':
060      case 'mysql4':
061          $sql = 'ALTER TABLE ' . $table_prefix . 'posts 
062              ADD PRIMARY KEY (post_id), 
063              ADD INDEX topic_id (topic_id), 
064              ADD INDEX poster_ip (poster_ip), 
065              ADD INDEX post_approved (post_approved), 
066              MODIFY COLUMN post_id mediumint(8) UNSIGNED NOT NULL auto_increment, 
067              ADD COLUMN post_encoding varchar(11) DEFAULT \'iso-8859-15\' NOT NULL'; 
068          break;
069   
070      case 'mssql':
071      case 'mssql-odbc':
072      case 'msaccess':
073          break;
074   
075      case 'postgresql':
076          break;
077  }
078  $db->sql_query($sql);
079   
080  $sql = "UPDATE {$table_prefix}topics SET topic_poster = 1 WHERE topic_poster = 0 OR topic_poster IS NULL";
081  $db->sql_query($sql);
082  $sql = "UPDATE {$table_prefix}topics SET topic_last_poster_id = 1 WHERE topic_last_poster_id = 0 OR topic_last_poster_id IS NULL";
083  $db->sql_query($sql);
084  $sql = "UPDATE {$table_prefix}posts SET poster_id = 1 WHERE poster_id = 0 OR poster_id IS NULL";
085  $db->sql_query($sql);
086  $sql = "UPDATE {$table_prefix}users SET user_id = 1 WHERE user_id = 0";
087  $db->sql_query($sql);
088   
089  $sql = "SELECT t.topic_id 
090      FROM {$table_prefix}topics t 
091      LEFT JOIN {$table_prefix}posts p ON p.topic_id = t.topic_id 
092      WHERE p.topic_id IS NULL";
093  $result = $db->sql_query($sql);
094   
095  if ($row = $db->sql_fetchrow($result))
096  {
097      $del_sql = '';
098      do
099      {
100          $del_sql .= (($del_sql != '') ? ', ' : '') . $row['topic_id'];
101      }
102      while ($row = $db->sql_fetchrow($result));
103   
104      $sql = "DELETE FROM {$table_prefix}topics 
105          WHERE topic_id IN ($del_sql)";
106      $db->sql_query($sql);
107  }
108  $db->sql_freeresult($result);
109   
110  $del_sql = '';
111  $sql = "SELECT topic_id, MIN(post_id) AS first_post_id, MAX(post_id) AS last_post_id, COUNT(post_id) AS total_posts 
112      FROM {$table_prefix}posts 
113      GROUP BY topic_id";
114  $result = $db->sql_query($sql);
115   
116  while ($row = $db->sql_fetchrow($result))
117  {
118      $del_sql .= (($del_sql != '') ? ', ' : '') . $row['topic_id'];
119   
120      $sql = "UPDATE {$table_prefix}topics 
121          SET topic_first_post_id = " . $row['first_post_id'] . ", topic_last_post_id = " . $row['last_post_id'] . ", topic_replies = " . ($row['total_posts'] - 1) . "
122          WHERE topic_id = " . $row['topic_id'];
123      $db->sql_query($sql);
124  }
125  $db->sql_freeresult($result);
126   
127  $sql = "DELETE FROM {$table_prefix}topics WHERE topic_id NOT IN ($del_sql)";
128  $db->sql_query($sql);
129   
130  $topic_count = $post_count = array();
131  $sql = "SELECT forum_id, COUNT(topic_id) AS topics 
132      FROM {$table_prefix}topics 
133      GROUP BY forum_id";
134  $result = $db->sql_query($sql);
135   
136  while ($row = $db->sql_fetchrow($result))
137  {
138      $topic_count[$row['forum_id']] = $row['topics'];
139  }
140  $db->sql_freeresult($result);
141   
142  $sql = "SELECT forum_id, COUNT(post_id) AS posts  
143      FROM {$table_prefix}posts 
144      GROUP BY forum_id";
145  $result = $db->sql_query($sql);
146   
147  while ($row = $db->sql_fetchrow($result))
148  {
149      $post_count[$row['forum_id']] = $row['posts'];
150  }
151  $db->sql_freeresult($result);
152   
153  switch ($db->sql_layer)
154  {
155      case 'oracle':
156          $sql = "SELECT f.*, p.post_time, p.post_username, u.username, u.user_id
157              FROM " . $table_prefix . "forums f, " . $table_prefix . "posts p, " . $table_prefix . "users u
158              WHERE p.post_id = f.forum_last_post_id(+)
159                  AND u.user_id = p.poster_id(+)";
160          break;
161   
162      default:
163          $sql = "SELECT f.forum_id, p.post_time, p.post_username, u.username, u.user_id
164              FROM ((" . $table_prefix . "forums f
165              LEFT JOIN " . $table_prefix . "posts p ON p.post_id = f.forum_last_post_id)
166              LEFT JOIN " . $table_prefix . "users u ON u.user_id = p.poster_id)";
167          break;
168  }
169  $result = $db->sql_query($sql);
170   
171  $sql_ary = array();
172  while ($row = $db->sql_fetchrow($result))
173  {
174      $forum_id = $row['forum_id'];
175   
176      $sql_ary[] = "UPDATE " . $table_prefix . "forums
177          SET forum_last_poster_id = " . ((!empty($row['user_id']) && $row['user_id'] != ANONYMOUS) ? $row['user_id'] : ANONYMOUS) . ", forum_last_poster_name = '" . ((!empty($row['user_id']) && $row['user_id'] !=  ANONYMOUS) ? addslashes($row['username']) : addslashes($row['post_username'])) . "', forum_last_post_time = " . $row['post_time'] . ", forum_posts = " . (($post_count[$forum_id]) ? $post_count[$forum_id] : 0) . ", forum_topics = " . (($topic_count[$forum_id]) ? $topic_count[$forum_id] : 0) . " 
178          WHERE forum_id = $forum_id";
179   
180      $sql = "SELECT t.topic_id, u.username, u.user_id, u2.username as user2, u2.user_id as id2, p.post_username, p2.post_username AS post_username2, p2.post_time
181          FROM " . $table_prefix . "topics t, " . $table_prefix . "users u, " . $table_prefix . "posts p, " . $table_prefix . "posts p2, " . $table_prefix . "users u2
182          WHERE t.forum_id = $forum_id 
183              AND u.user_id = t.topic_poster 
184              AND p.post_id = t.topic_first_post_id
185              AND p2.post_id = t.topic_last_post_id
186              AND u2.user_id = p2.poster_id";
187      $result2 = $db->sql_query($sql);
188   
189      while ($row2 = $db->sql_fetchrow($result2))
190      {
191          $sql_ary[] = "UPDATE " . $table_prefix . "topics
192              SET topic_poster = " . $row2['user_id'] . ", topic_first_poster_name = '" . ((!empty($row2['user_id']) && $row2['user_id'] != ANONYMOUS) ? addslashes($row2['username']) : addslashes($row2['post_username'])) . "', topic_last_poster_id = " . ((!empty($row2['id2']) && $row2['id2'] != ANONYMOUS) ? $row2['id2'] : ANONYMOUS) . ", topic_last_post_time = " . $row2['post_time'] . ", topic_last_poster_name = '" . ((!empty($row2['id2']) && $row2['id2'] !=  ANONYMOUS) ? addslashes($row2['user2']) : addslashes($row2['post_username2'])) . "'
193              WHERE topic_id = " . $row2['topic_id'];
194      }
195      $db->sql_freeresult($result2);
196   
197      unset($row2);
198  }
199  $db->sql_freeresult($result);
200   
201  foreach ($sql_ary as $sql)
202  {
203      $sql . "<br />";
204      $db->sql_query($sql);
205  }
206   
207  echo "<p><b>Done</b></p>\n";
208   
209  ?>