• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

Fixed Xenforo 1.2 Beta to Xenforo Importer Error (Attached Files)

DRE

Well-known member
#1
Got this error when importing attachments. Everything else had ran fine up to that point.

Admin Control Panel - XenForo
Server Error
Mysqli prepare error: 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 3

  1. Zend_Db_Statement_Mysqli->_prepare() in Zend/Db/Statement.php at line 115
  2. Zend_Db_Statement->__construct() in Zend/Db/Adapter/Mysqli.php at line 381
  3. Zend_Db_Adapter_Mysqli->prepare() in Zend/Db/Adapter/Abstract.php at line 478
  4. Zend_Db_Adapter_Abstract->query() in Zend/Db/Adapter/Abstract.php at line 808
  5. Zend_Db_Adapter_Abstract->fetchPairs() in XenForo/Importer/XenForo.php at line 2232
  6. XenForo_Importer_XenForo->stepAttachments() in XenForo/Importer/Abstract.php at line 77
  7. XenForo_Importer_Abstract->runStep() in XenForo/ControllerAdmin/Import.php at line 195
  8. XenForo_ControllerAdmin_Import->_runStep() in XenForo/ControllerAdmin/Import.php at line 143
  9. XenForo_ControllerAdmin_Import->actionImport() in XenForo/FrontController.php at line 337
  10. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
  11. XenForo_FrontController->run() in /home/me/public_html/admin.php at line 13
 

xfrocks

Well-known member
#5
Line 2232 of xenforo/library/XenForo/Importer/XenForo.php

PHP:
$contentItems = $db->fetchPairs("
SELECT $sqlIdName, message
FROM $sqlTableName
WHERE $sqlIdName IN (". $db->quote($contentIdMap) .")
");
I guess the array `$contentIdMap` is empty (result of XenForo_Model_Import::getImportContentMap) and caused the SQL error. A simple empty check should help you go through with the import. Replace the above block of code with these and try again:

PHP:
if (!empty($contentIdMap))
{
$contentItems = $db->fetchPairs("
SELECT $sqlIdName, message
FROM $sqlTableName
WHERE $sqlIdName IN (". $db->quote($contentIdMap) .")
");
}
else
{
$contentItems = array();
}
TL;DR: It's a bug in the importer (not an add-on problem).
 

Mick West

Well-known member
#6
Is there a reason though that $contentIdMap would be empty normally? It seems possible that I'm doing something wrong with the way I create attachments in MetaMirror. (or BD AttachmentStore).
 

xfrocks

Well-known member
#7
Is there a reason though that $contentIdMap would be empty normally? It seems possible that I'm doing something wrong with the way I create attachments in MetaMirror. (or BD AttachmentStore).
I don't know really. I find it a bit strange because `$attachments` was not queried with any kind of keys so array_keys will simply array indeces. I could be wrong though...

Btw, @DRE, you installed [bd] Attachment Store on the source forum or on the target forum? If you have it installed in source forum, you need to rebuild attachment with default mode to move all files back into their original location. Or your import will fail ;)
 

DRE

Well-known member
#8
I don't know really. I find it a bit strange because `$attachments` was not queried with any kind of keys so array_keys will simply array indeces. I could be wrong though...

Btw, @DRE, you installed [bd] Attachment Store on the source forum or on the target forum? If you have it installed in source forum, you need to rebuild attachment with default mode to move all files back into their original location. Or your import will fail ;)
Source forum and no I didn't do that when I ran the import. I'll try again. Do I still use your code edit?
 

xfrocks

Well-known member
#9
Source forum and no I didn't do that when I ran the import. I'll try again. Do I still use your code edit?
If you didn't rebuild it, the importer will fail without any error. It will just ignore the attachments in external data/Amazon S3/FTP (it will import attachments in default just fine). You still need to figure out what caused the current error.
 

DRE

Well-known member
#10
Alright so I did all the steps listed in this thread EXCEPT the code edit @xfrocks posted and this is the error.

Admin Control Panel - XenForo
Server Error
Mysqli prepare error: 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 3

  1. Zend_Db_Statement_Mysqli->_prepare() in Zend/Db/Statement.php at line 115
  2. Zend_Db_Statement->__construct() in Zend/Db/Adapter/Mysqli.php at line 381
  3. Zend_Db_Adapter_Mysqli->prepare() in Zend/Db/Adapter/Abstract.php at line 478
  4. Zend_Db_Adapter_Abstract->query() in Zend/Db/Adapter/Abstract.php at line 808
  5. Zend_Db_Adapter_Abstract->fetchPairs() in XenForo/Importer/XenForo.php at line 2232
  6. XenForo_Importer_XenForo->stepAttachments() in XenForo/Importer/Abstract.php at line 77
  7. XenForo_Importer_Abstract->runStep() in XenForo/ControllerAdmin/Import.php at line 195
  8. XenForo_ControllerAdmin_Import->_runStep() in XenForo/ControllerAdmin/Import.php at line 143
  9. XenForo_ControllerAdmin_Import->actionImport() in XenForo/FrontController.php at line 337
  10. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
  11. XenForo_FrontController->run() in /home/me/public_html/test/admin.php at line 13

Gonna do that code edit now.
 
Last edited:

DRE

Well-known member
#11
Only posting that to let you know that I got further with the import after following the other directions.
 

DRE

Well-known member
#12
I did your code edit and it did not work. I did everything posted in this thread including close my main board and disabled every addon, no dice.

Server Error
Mysqli prepare error: 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 3

  1. Zend_Db_Statement_Mysqli->_prepare() in Zend/Db/Statement.php at line 115
  2. Zend_Db_Statement->__construct() in Zend/Db/Adapter/Mysqli.php at line 381
  3. Zend_Db_Adapter_Mysqli->prepare() in Zend/Db/Adapter/Abstract.php at line 478
  4. Zend_Db_Adapter_Abstract->query() in Zend/Db/Adapter/Abstract.php at line 808
  5. Zend_Db_Adapter_Abstract->fetchPairs() in XenForo/Importer/XenForo.php at line 2232
  6. XenForo_Importer_XenForo->stepAttachments() in XenForo/Importer/Abstract.php at line 77
  7. XenForo_Importer_Abstract->runStep() in XenForo/ControllerAdmin/Import.php at line 195
  8. XenForo_ControllerAdmin_Import->_runStep() in XenForo/ControllerAdmin/Import.php at line 143
  9. XenForo_ControllerAdmin_Import->actionImport() in XenForo/FrontController.php at line 337
  10. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
  11. XenForo_FrontController->run() in /home/me/public_html/test/admin.php at line 13
 

xfrocks

Well-known member
#13
I did your code edit and it did not work. I did everything posted in this thread including close my main board and disabled every addon, no dice.

Server Error
Mysqli prepare error: 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 3

  1. Zend_Db_Statement_Mysqli->_prepare() in Zend/Db/Statement.php at line 115
  2. Zend_Db_Statement->__construct() in Zend/Db/Adapter/Mysqli.php at line 381
  3. Zend_Db_Adapter_Mysqli->prepare() in Zend/Db/Adapter/Abstract.php at line 478
  4. Zend_Db_Adapter_Abstract->query() in Zend/Db/Adapter/Abstract.php at line 808
  5. Zend_Db_Adapter_Abstract->fetchPairs() in XenForo/Importer/XenForo.php at line 2232
  6. XenForo_Importer_XenForo->stepAttachments() in XenForo/Importer/Abstract.php at line 77
  7. XenForo_Importer_Abstract->runStep() in XenForo/ControllerAdmin/Import.php at line 195
  8. XenForo_ControllerAdmin_Import->_runStep() in XenForo/ControllerAdmin/Import.php at line 143
  9. XenForo_ControllerAdmin_Import->actionImport() in XenForo/FrontController.php at line 337
  10. XenForo_FrontController->dispatch() in XenForo/FrontController.php at line 134
  11. XenForo_FrontController->run() in /home/me/public_html/test/admin.php at line 13
The error is still at 2232, if you did the edit, it should be line 2234. Are you sure you made the edit correctly? You probably want to upload the contents to some gist.github.com or similar and send the link to me. Should open a conversation for that to avoid copyright issue.
 

Mike

XenForo developer
Staff member
#15
I've added a similar check to prevent this error.

If I'm reading this code right, this error should only happen if the found attachments are all orphaned from their content. I'm not sure why that would happen, as attachments should generally be cleaned up if data is hard deleted, though I suppose it could be a throwback to 1.1 if a forum were deleted.