Forum AideInfo.com Index du Forum

Ajouter cette page sur un site de bookmarks
scoopeo  fuzz  tapemoi  nuouz  bookeet  pioche  Partagez sur del.icio.us  Partagez sur digg.com  Partagez sur furl.net  Partagez sur Yahoo! Mon Web 2.0  Partagez sur StumbleUpon  Partagez sur Google Bookmarks  Partagez sur Technorati  Partagez sur blinklist  Partagez sur Newsvine  Partagez sur ma.gnolia  spurl  simpy

Rechercher Liste des Membres Groupes d'utilisateurs Profil Connexion S'enregistrer Messagerie privéeMessagerie privée   Règles du forum Retour au siteRetour au site
  Poster un nouveau sujet Répondre au sujet Forum AideInfo.com Index du Forum » (MOD) Tutoriaux sur les mods et programmes/scripts tiers   
[SCRIPT] Script de régénération de phpbb_topics
Auteur Message
AideInfo
Administrateur
Expert phpBB


Inscrit le: 11 Juin 2002
Messages: 3919

MessagePosté le: 05 Oct 2005 10:10
MessageSujet du message: [SCRIPT] Script de régénération de phpbb_topics
Répondre en citant

Ce script permet de régénérer la table phpbb_topics si celle-ci a été perdue.

Créez un fichier rebuild_topics.php dans lequel vous collez le code
suivant, puis uploadez le fichier rebuild_topics.php à la racine de votre forum et exécutez-le par votre navigateur.

Code:
<?php
/***************************************************************************
 *                                  rebuild_topics.php
 *                            -------------------
 *   begin                : Sunday, Mar 28, 2004
 *   copyright            : (C) 2004 Adan "R45" Alkins
 *   email                : phpbb AT rasadam DOT COM
 *    website           : http://phpbb.rasadam.com
 *
 *   $Id: rebuild_topics.php,v 1.1 2004/03/28 13:43:27 rasadam 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.
 *
 ***************************************************************************/

define('IN_PHPBB', true);
$phpbb_root_path = './';
include($phpbb_root_path . 'extension.inc');
include($phpbb_root_path . 'common.'.$phpEx);

//
// Start session management
//
$userdata = session_pagestart($user_ip, PAGE_FAQ);
init_userprefs($userdata);
//
// End session management
//

// if user isn't logged in
if( !$userdata['session_logged_in'] )
{
   // redirect to login page,
   header('Location: ' . append_sid($phpbb_root_path."login.$phpEx?redirect=rebuild_topics.$phpEx", true));
}

// see if user is an Admin or not
if( $userdata['user_level'] != ADMIN )
{
   // use the default lang not authorised message
   message_die(GENERAL_MESSAGE, $lang['Not_Authorised']);
}

// We start off by selecting all the posts
$sql = "SELECT p.topic_id, p.post_id, p.forum_id, p.poster_id, p.post_time, pt.post_subject
         FROM ".POSTS_TABLE." AS p, ".POSTS_TEXT_TABLE." as pt
            WHERE p.post_id = pt.post_id
               ORDER BY p.topic_id ASC, p.post_id ASC";
$result = $db->sql_query($sql);

if(!$result)
{
   message_die(GENERAL_ERROR, 'Unable to select posts data', '', __LINE__, __FILE__, $sql);
}

// if there are no valid posts
if($db->sql_numrows($result)==0)
{
   message_die(GENERAL_ERROR, 'No posts exist in the database');
}

$posts = $db->sql_fetchrowset($result);

// We select all poll data
$sql = "SELECT vote_id, topic_id
         FROM ".VOTE_DESC_TABLE."
            ORDER BY topic_id";

$result = $db->sql_query($sql);

if(!$result)
{
   message_die(GENERAL_ERROR, 'Unable to select poll data', '', __LINE__, __FILE__, $sql);
}

$polls = array();

while($row = $db->sql_fetchrow($result))
{
   $polls[$row['topic_id']] = $row['vote_id'];
}

$topics = array();

foreach($posts as $data)
{
   if(!isset($topics[$data['topic_id']]))
   {
      // Topic title is the same as the subject of the first post
      $topics[$data['topic_id']]['topic_title'] = $data['post_subject'];
      // Luckily the forum id is kept in the posts table
      $topics[$data['topic_id']]['forum_id'] = $data['forum_id'];
      // Topic poster is the same as the poster of the first post
      $topics[$data['topic_id']]['topic_poster'] = $data['poster_id'];
      // Topic time from first post time
      $topics[$data['topic_id']]['topic_time'] = $data['post_time'];
      // We lost the view account, so assume 1 atleast
      $topics[$data['topic_id']]['topic_views'] = 1;
      // Replies are every subsequent post, so 0 for now
      $topics[$data['topic_id']]['topic_replies'] = 0;
      // We don't know if the topic was locked/unlocked, so we leave it unlocked
      $topics[$data['topic_id']]['topic_status'] = 0;
      // Check if a poll exists for this topic
      $topics[$data['topic_id']]['topic_vote'] = ( isset($polls[$data['topic_id']]) ) ? $polls[$data['topic_id']] : 0;
      // This is unfortunately another setting we lose, we assume all topics are normal for now
      $topics[$data['topic_id']]['topic_type'] = 0;
      // First post
      $topics[$data['topic_id']]['topic_first_post_id'] = $data['post_id'];
      // We lost all topic moves, so everything is a real topic
      $topics[$data['topic_id']]['topic_moved_id'] = 0;
   }
   else
   {
      // increment replies by 1 for each subsequent post
      $topics[$data['topic_id']]['topic_replies']++;
      // increment views by 1 for the sake of doing it
      $topics[$data['topic_id']]['topic_views']++;
   }
   
   // the last post will keep rolling over until it really is the last post because of the way we
   // sorted the sql query
   $topics[$data['topic_id']]['topic_last_post_id'] = $data['post_id'];   
}

$topics_success = 0;
$topics_failed = 0;

$topics_failed_sql = array();
// we've finished building the topics array, we can go ahead and rebuild
foreach($topics as $topic_id => $array)
{
   extract($array);

   $sql = "INSERT INTO ". TOPICS_TABLE ."
            (topic_id, forum_id, topic_title, topic_poster, topic_time, topic_views, topic_replies, topic_status, topic_vote, topic_type, topic_first_post_id, topic_last_post_id, topic_moved_id)
               VALUES
            ($topic_id, $forum_id, '$topic_title', $topic_poster, $topic_time, $topic_views, $topic_replies, $topic_status, $topic_vote, $topic_type, $topic_first_post_id, $topic_last_post_id, $topic_moved_id)";
   if($db->sql_query($sql))
   {
      $topics_success++;
   }
   else
   {
      $topics_failed++;
      $topics_failed_sql[] = $sql;
   }
}

if($topics_failed == 0)
{
   $plural = ( $topics_success == 1 ) ? '' : 's';
   message_die(GENERAL_MESSAGE, "Successfully rebuilt $topics_success topic$plural");
}
else
{
   $text = '';
   
   $s_plural = ( $topics_success == 1 ) ? '' : 's';
   $f_plural = ( $topics_failed == 1 ) ? '' : 's';
   
   $text .= "Topic$s_plural rebuilt -> $topics_success<br />Topic$f_plural failed -> $topics_failed (See below SQL)";
   
   foreach($topics_failed_sql as $sql)
   {
      $text .= '<br /><br />'.strip_tags(htmlspecialchars($sql));
   }

   message_die(GENERAL_ERROR, $text);
}

die;

?>

_________________
Services gratuits

phpBB-Tutoriaux, tous les tutoriaux pour débuter et utiliser phpBB
Voir le profil de l'utilisateur Envoyer un message privé Visiter le site web du posteur  
 
  Poster un nouveau sujet  Répondre au sujet Forum AideInfo.com Index du Forum » (MOD) Tutoriaux sur les mods et programmes/scripts tiers

Informations
Page 1 sur 1
Permissions: Vous ne pouvez pas poster de nouveaux sujets dans ce forum
Vous ne pouvez pas répondre aux sujets dans ce forum
Vous ne pouvez pas éditer vos messages dans ce forum
Vous ne pouvez pas supprimer vos messages dans ce forum
Vous ne pouvez pas voter dans les sondages de ce forum
Montrer les messages depuis:   
Page 1 sur 1
 
Sauter vers:  


Powered by phpBB v2 © 2001, 2005 phpBB Group ¦ Theme : Creamy White, modifié par Eric FICHOT pour AideInfo.com