MyBB Community Forums

Full Version: Private messages FluxBB -> myBB1.8
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
I managed to write this code. Do you think it's appropriate? What I cannot understand is where to get the "toid" for MyBB (which is a single ID) while in FluxBB there is only the "Receiver ID" which is list with two elements (like: 353, 2).

<?php
// Database connection credentials
////// HERE MY CREDENTIAL

// Load user mapping array from file (used to align the IDs for those users who underwent an ID change during the conversion from FluxBB to MyBB)
$file_content = file_get_contents('userarray.txt');
$user_mapping = json_decode($file_content, true);

// Connect to the database
$mysqli = new mysqli($db_host, $db_username, $db_password, $db_name);
// Check the database connection
if ($mysqli->connect_error) {
    die("Database connection failed: " . $mysqli->connect_error);
}
// Set encoding to utf8 to handle special characters
$mysqli->set_charset('utf8');

// Retrieve data from flux_messages
$query_flux_data = "SELECT * FROM " . $db_fluxprefix . "messages";
$result_flux_data = $mysqli->query($query_flux_data);

// Prepare the data insertion into mybb_privatemessages
$query_insert_data = "INSERT INTO " . $db_mybbprefix . "privatemessages 
                      (uid, toid, fromid, recipients, folder, subject, icon, message, dateline, deletetime, status, statustime, includesig, smilieoff, receipt, readtime, ipaddress) 
                      VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

// Prepare the statement
$stmt = $mysqli->prepare($query_insert_data);

// Bind parameters
$stmt->bind_param("iiisissssiiiiiiis", $uid, $toid, $fromid, $recipients, $folder, $subject, $icon, $message, $dateline, $deletetime, $status, $statustime, $includesig, $smilieoff, $receipt, $readtime, $ipaddress);

// Fetch data from flux_messages and insert into mybb_privatemessages
while ($row_flux_data = $result_flux_data->fetch_assoc()) {
    
// Define values to insert
    $sender_id_flux = $row_flux_data['sender_id'];
    $receiver_id_flux = $row_flux_data['receiver_id'];
    $owner_flux = $row_flux_data['owner'];
    
// Get user mapping from $user_mapping
    $sender_id_mybb = $user_mapping[$sender_id_flux]['mybb_id'];
    $receiver_id_mybb = $user_mapping[$receiver_id_flux]['mybb_id'];
    $owner_mybb = $user_mapping[$owner_flux]['mybb_id'];
    $uid = $owner_mybb;
    $toid = $receiver_id_mybb;
    $fromid = $sender_id_mybb;
    
// Define additional values
    $additional_recipients = [$owner_mybb, $sender_id_mybb];  // Array of additional recipients
    $recipients = serialize($additional_recipients);  // Serialize data for MyBB
    $folder = 1;  // Unsure how to manage this......
    $subject = $row_flux_data['subject'];
    $icon = 0;
    $message = $row_flux_data['message'];
    $dateline = $row_flux_data['posted'];
    $deletetime = 0;
    $status = 0;  // Not totally sure...
    $statustime = 0;  // Not totally sure...
    $includesig = 1;  
    $smilieoff = 0; 
    $receipt = 0; 
    $readtime = $row_flux_data['showed'];
    $ipaddress = $row_flux_data['sender_ip'];
    
    // Execute the insertion
    $stmt->execute();
}

// Close the statement
$stmt->close();

// Close the database connection
$mysqli->close();
?>

sounds good? Any idea?

Thanks! Wink

(2023-11-22, 06:47 AM)ArouG Wrote: [ -> ]Hello ! My old code : https://github.com/ArouG/PHP-Mess-FluxBB--MyBB

Cool! I was writing my previous reply and did not notice your reply! I'll give it a close look!

Thank you very much ArouG.
J
Would be nice to read the final (successful) result for this !
(2023-11-26, 12:10 AM)Omar G. Wrote: [ -> ]Would be nice to read the final (successful) result for this !

Hi Omar! Nice to meet you here! Smile 

I'm working on it! I'm facing some challenges, but not giving up. :-) The main issues are:
My database, which is running on "MySQL version 10.2.44-MariaDB-log-cll-lve", consequently I need to convert the code. Which I did (let's say so Smile ). Additionally, I'm encountering difficulties in importing messages so that they are grouped within their respective conversations rather than being treated as separate entities (this is probably the main problem)... Some of the toid also result NULL, which is quite strange... In my Fluxbb_messages table, I'm also grappling with how to handle "last_post_id" and "last_poster", which seem to be missing in the code provided by Aroug...

To sum up: life is hard, but I won't give it up  Big Grin
Pages: 1 2