FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum » FUDforum Installation Issues » Script for moving data from file to database for 2.7.4  () 1 Vote
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Script for moving data from file to database for 2.7.4 [message #30391] Wed, 22 February 2006 12:41
melink is currently offline  melink   Hong Kong
Messages: 6
Registered: January 2006
Karma: 0
Junior Member
Here is my script to move my forum data from file to database.

*** IMPORTANT NOTE ***
You MUST get latest version of private.inc.t from this URL: http://cvs.prohost.org/c/index.cgi/FUDforum/rlog?f=install/forum_data/src/p rivate.inc.t
(I tested with version 1.52)
Please backup (and test your backup) before running this script.
Use at your own risk. I am NOT resiponsible to any data lost.
*** IMPORTANT NOTE ***

<?php

require("./GLOBALS.php");

fud_use("db.inc");
fud_use("fileio.inc");
fud_use("private.inc");

echo "Processing messages...<br/>";
$msg_res = q("SELECT id, foff, length, file_id, thread_id FROM ".$GLOBALS["DBHOST_TBL_PREFIX"]."msg");
while($msg = db_rowobj($msg_res)) {
        $body = read_msg_body($msg->foff, $msg->length, $msg->file_id);

        $file_id_preview = $length_preview = 0;
        $offset = $offset_preview = -1;
        $length = strlen($body);

        // copy msg to db
        $file_id = db_qid("INSERT INTO ".$GLOBALS["DBHOST_TBL_PREFIX"]."msg_store (data) VALUES ("._esc($body).")");

        $message_threshold = q_singleval("SELECT f.message_threshold FROM ".$GLOBALS["DBHOST_TBL_PREFIX"]."forum f, ".$GLOBALS["DBHOST_TBL_PREFIX"]."thread t WHERE f.id = t.forum_id AND t.id = ".$msg->thread_id);
        if ($message_threshold && $length > $message_threshold) {
                $file_id_preview = db_qid("INSERT INTO ".$GLOBALS["DBHOST_TBL_PREFIX"]."msg_store (data) VALUES ("._esc(trim_html($body, $message_threshold)).")");
        }

        q("UPDATE ".$GLOBALS["DBHOST_TBL_PREFIX"]."msg SET file_id = ".$file_id.", foff = ".$offset.", length = ".$length.", file_id_preview = ".$file_id_preview.", offset_preview = ".$offset_preview.", length_preview = ".$length_preview." WHERE id = ".$msg->id);
}

echo "Processing private messages...<br/>";
$pmsg_res = q("SELECT id, foff, length FROM ".$GLOBALS["DBHOST_TBL_PREFIX"]."pmsg");
while($pmsg = db_rowobj($pmsg_res)) {
        $pbody = read_pmsg_body($pmsg->foff, $pmsg->length);
        $fid = db_qid("INSERT INTO ".$GLOBALS["DBHOST_TBL_PREFIX"]."msg_store (data) VALUES ("._esc($pbody).")");
        q("UPDATE ".$GLOBALS["DBHOST_TBL_PREFIX"]."pmsg SET foff = -1, length = ".$fid." WHERE id = ".$pmsg->id);
}

echo "Done...<br/>";

?>
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Mailing list integration problem
Next Topic: Synching Forum with Mail List
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Dec 01 06:08:41 GMT 2024

Total time taken to generate the page: 0.02480 seconds