MyBB Community Forums

Full Version: phpBB 3.x import: can't handle orphaned attachments
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, when importing a rather large database from a phpBB3 instance, I get the following error:

Quote:MyBB has experienced an internal SQL error and cannot continue.
SQL Error:1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Query:SELECT tid FROM mybb_posts WHERE pid=
Looking at the attachment it's choking on, the problem is that there's no post ID that matches, and the attachment itself is orphaned (in fact its "is_orphan" value is 1). I don't know how reliable the is_orphan value is, but checking that is certainly better than nothing, although of course the importer should also ensure that it has a pid to attach to.

Anyway, this simple change seems to have gotten things working for me for now:
--- merge/boards/phpbb3/attachments.php	2015-07-06 09:30:50.000000000 -0700
+++ merge-new/boards/phpbb3/attachments.php	2015-11-15 09:57:58.803000987 -0800
@@ -48,7 +48,7 @@
 	{
 		global $import_session;
 
-		$query = $this->old_db->simple_select("attachments", "*", "", array('limit_start' => $this->trackers['start_attachments'], 'limit' => $import_session['attachments_per_screen']));
+		$query = $this->old_db->simple_select("attachments", "*", "is_orphan != 1", array('limit_start' => $this->trackers['start_attachments'], 'limit' => $import_session['attachments_per_screen']));
 		while($attachment = $this->old_db->fetch_array($query))
 		{
 			$this->insert($attachment);

although a better fix would be to change the merge system to ignore attachments which don't have a matching import_pid, or to orphan them appropriately (I don't know if myBB supports orphaned attachments).
(2015-11-15, 06:02 PM)fluffy.critter Wrote: [ -> ]Hi, when importing a rather large database from a phpBB3 instance, I get the following error:

Quote:MyBB has experienced an internal SQL error and cannot continue.
SQL Error:1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
Query:SELECT tid FROM mybb_posts WHERE pid=
Looking at the attachment it's choking on, the problem is that there's no post ID that matches, and the attachment itself is orphaned (in fact its "is_orphan" value is 1). I don't know how reliable the is_orphan value is, but checking that is certainly better than nothing, although of course the importer should also ensure that it has a pid to attach to.

Anyway, this simple change seems to have gotten things working for me for now:
--- merge/boards/phpbb3/attachments.php	2015-07-06 09:30:50.000000000 -0700
+++ merge-new/boards/phpbb3/attachments.php	2015-11-15 09:57:58.803000987 -0800
@@ -48,7 +48,7 @@
 	{
 		global $import_session;
 
-		$query = $this->old_db->simple_select("attachments", "*", "", array('limit_start' => $this->trackers['start_attachments'], 'limit' => $import_session['attachments_per_screen']));
+		$query = $this->old_db->simple_select("attachments", "*", "is_orphan != 1", array('limit_start' => $this->trackers['start_attachments'], 'limit' => $import_session['attachments_per_screen']));
 		while($attachment = $this->old_db->fetch_array($query))
 		{
 			$this->insert($attachment);

although a better fix would be to change the merge system to ignore attachments which don't have a matching import_pid, or to orphan them appropriately (I don't know if myBB supports orphaned attachments).

i have the same error where i will replace this code