Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not Solved HTML codes in post when Merging PHPBB3 to MyBB
#1
Not Solved
Hello guys,
im trying to switch to MyBB and im really impressed how simple up to now was.
I just created a new forum, and merged with the merge-software from my previous phpbb3 3.2 forum.
All was going good, a part of this error: basically i have all imported correctly, but the post are formatted with HTML codes (i.e. <br/> and so on). Only few of them are not.

Here is a small pic of the problem, as you can easy understand what im talking about: http://imgur.com/0SKV7Wp

Any ideas to solve it??  Sleepy

Thanks in advance!

No one? Sad
Reply
#2
Not Solved
Is <br/> the only html showing in posts?
> SELECT finger FROM hand WHERE id='3'
Reply
#3
Not Solved
I got the same issue. Moving a phpbb3 board over to myBB. Got more than 220.000 posts so editing them one at the time is not gonna do it. I need to automate it.

I assume the merger will not be modified for this, but does anyone know some kind of an sql code I can execute on the specific table?

thx
Andy
Reply
#4
Not Solved
first take backup of the existing database

sql query for replacing post content can be like below
UPDATE `mybb_posts` SET `message` = REPLACE (`message`, 'current', 'new') WHERE `message` LIKE '%current%'; 

eg. to remove <p> and </p> from the messages

UPDATE `mybb_posts` SET `message` = REPLACE (`message`, '<p>', '') WHERE `message` LIKE '%<p>%';


UPDATE `mybb_posts` SET `message` = REPLACE (`message`, '</p>', '') WHERE `message` LIKE '%</p>%'; 

see also common sql queries guidance
Reply
#5
Not Solved
Hi! I actually came up with an idea Big Grin

Firstly, those are not HTML codes - they are XML. They changed the way of storing data in release from 3.1.x to 3.2.x >>>INFO<<< . I suppose u have newer one Smile I think merger will support it soon, but meanwhile... i wrote some simple php script which might help you and others facing this problem. Of course I wasn't writing any advanced parser to do it, i just used one that is provided in PHPBB3 software, as they have to translate it back to bbcode in case that you hit that "edit" button, am I right?

Soooo... what you need to do:
1. BACKUP YOUR DATABASE BEFORE ANY CHANGES! I WON'T TAKE RESPONSIBILITY IN CASE SOMETHING GOES WRONG!
2. Save script from bottom of this page as something.php and put it in your OLD PHPBB forum root directory as it's only can reach file 'includes/message_parser.php' from this location.
3.  Edit this file to match data that you want to transform. You need to configure those 7 fields:
/**
* PASS INFORMATIONS HERE
*/
$mysql_db_hostname = "localhost";
$mysql_db_user = "user";
$mysql_db_password = "password";
$mysql_db_database = "database";
//Tables to parse

//RUN 1 - POSTS
$table = 'mybb_posts'; //insert table name in which column to parse exists
$id = 'pid'; //insert primary key column name for this table here
$text = 'message'; //insert column name to parse here


database credentials are for already merged MyBB forum database. table,id,text is a choice of column that you want to transform, in your database. In above example we will be fixing posts Smile you will probably also want to fix users signatures, polls, and private messages. You need to make a 'run' for every column

4. Ok, so basicly you are ready to run it. Go to www.oldforum.com/path_to_forum/something.php in your browser, and it's done. If you get printout from this site like this

Quote:  Please wait.........

SUCCESSFULY UPDATED ROWS: 5632


Everything wen't well

Sometimes however u can get something like this:
Quote:[ID 5154] ERROR WHILE EXECUTING QUERY!
Which means that you failed to parse item with this id. Query in the end just didn't execute for that one - you will have to edit it yourselfWink I had only one such post for my forum with over 18k records transformed.  (I think that fault could be combination of backslash ampersand ( \' ) found in this post)

5. Repeat steps 3 and 4 for every column that you want to transform
6. delete this script from server, so nobody can't spam your database

If something is not clear, i will try to explain it better. I know it's not super user friendly solution, but i needed my forum to quickly get back on feet, and as i saw some ppl here having same problem, I decided to share this. 

Good news, are that parser used is literally perfect, as it's the same that phpbb3 use - it will parse your custom bbcodes, attachments, custom smiles etc. You just need to configure them again Smile Let others know if it's work fine for you  

<?php


	/**
	* PASS INFORMATIONS HERE
	*/
        $mysql_db_hostname = "localhost";
        $mysql_db_user = "user";
        $mysql_db_password = "password";
        $mysql_db_database = "database";
	//Tables to parse
	
	//RUN 1 - POSTS
	$table = 'mybb_posts'; //insert table name in which column to parse exists
	$id = 'pid'; //insert primary key column name for this table here
	$text = 'message'; //insert column name to parse here
	
	//RUN 2 USER SIGNATURES;
	//$table = 'mybb_users'; 
	//$id = 'uid'; 
	//$text = 'signature'; 
	
	//RUN 3 USERS PRIVATE MESSAGES
	//$table = 'mybb_privatemessages'; 
	//$id = 'pmid'; 
	//$text = 'message'; 
	
	//RUN 4 POOLS QUESTIONS
	//$table = 'mybb_polls'; 
	//$id = 'pid'; 
	//$text = 'question'; 
	
	//RUN 5 POOLS OPTIONS
	//$table = 'mybb_polls'; 
	//$id = 'pid'; 
	//$text = 'options';
	
	/**
	* END OF PASS INFORMATIONS HERE
	*/
	
	
	
    /**
	* CONNECTING TO DATABASE
	*/
    $con = @mysqli_connect($mysql_db_hostname, $mysql_db_user, $mysql_db_password,$mysql_db_database);   
    
    if (!$con) {
		echo 'shieeeeet somting went wrung - database not connected';
        trigger_error('Could not connect to MySQL: ' . mysqli_connect_error());
		exit();
    }

	/* change character set to utf8 */
	if (!$con->set_charset("utf8")) {
		printf("Error loading character set utf8: %s\n", $con->error);
		$con->close();
		exit();
	}
	/**
	* END OF CONNECTING TO DATABASE
	*/
	
	
	
	/**
	* REQUIRED INCLUDE FROM phpbb3
	*/
	define('IN_PHPBB', true);
	$phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : './';
	$phpEx = substr(strrchr(__FILE__, '.'), 1);
	include($phpbb_root_path . 'common.' . $phpEx);
	include($phpbb_root_path . 'includes/functions_display.' . $phpEx);
	
	if (!defined('IN_PHPBB'))
	{
		$con->close();
		exit;
	}

	if (!class_exists('message_parser'))
	{
		// The following lines are for extensions which include message_parser.php
		// while $phpbb_root_path and $phpEx are out of the script scope
		// which may lead to the 'Undefined variable' and 'failed to open stream' errors
		if (!isset($phpbb_root_path))
		{
			global $phpbb_root_path;
		}
    
		if (!isset($phpEx))
		{
			global $phpEx;
		}
    
		include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
	}
	/**
	* END OF REQUIRED INCLUDE FROM PHPBB3
	*/

	//DEBUG MODE COMMANDS
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);


	
	
	
	$sql = "SELECT " . $id . "," . $text . " FROM " . $table ;
    
	$var = array();
	$result = mysqli_query($con, $sql);
	while($obj = mysqli_fetch_object($result)) {
        $var[] = $obj;
    }
	
	$updated_rows_count = 0;
	
	echo "Please wait...";
	for ($i = 0; $i < count($var); $i++)
	{
	   
	   $parse = new parse_message($var[$i]->$text);
	   $parse->decode_message();
	   $parse->message = str_replace("'", "''", $parse->message);
	   //echo $parse->message;
	   
	   $update_query = "UPDATE `" . $table . "` SET `" . $text . "` = '" . $parse->message . "' WHERE `" . $id . "` = " . $var[$i]->$id;
	   //echo $update_query;
	   
	   $update = mysqli_query($con, $update_query);
	   
	   if ( mysqli_affected_rows($con) == -1 ) echo '<br />[ID ' . $var[$i]->$id . '] ERROR WHILE EXECUTING QUERY!<br />';
	   else $updated_rows_count += mysqli_affected_rows($con);
	   
	   if($i%1000 == 0) echo '.';
	}
	
	echo "<br /><br />SUCCESSFULY UPDATED ROWS: " . $updated_rows_count;
	
	$con->close();
?>
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)