2023-11-22, 07:38 AM
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).
sounds good? Any idea?
Thanks!
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
<?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!
(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