Fixed src/XF/Db/AbstractStatement.php error during import

Azonaco

Member
Affected version
2.0.1
When someone gets a chance, please update me on what I can do to sidestep this.
This error happened during importation of a VBulletin 4 forum. Step 25 of 32, notices.

XF\Db\DuplicateKeyException: MySQL query error [1062]: Duplicate entry '4' for key 'PRIMARY' in src/XF/Db/AbstractStatement.php at line 212
  1. XF\Db\AbstractStatement->getException() insrc/XF/Db/Mysqli/Statement.php at line 174
  2. XF\Db\Mysqli\Statement->getException() insrc/XF/Db/Mysqli/Statement.php at line 70
  3. XF\Db\Mysqli\Statement->execute() in src/XF/Db/AbstractAdapter.phpat line 74
  4. XF\Db\AbstractAdapter->query() in src/XF/Db/AbstractAdapter.php at line 151
  5. XF\Db\AbstractAdapter->insert() insrc/XF/Import/Data/EntityEmulator.php at line 207
  6. XF\Import\Data\EntityEmulator->insert() insrc/XF/Import/Data/AbstractEmulatedData.php at line 34
  7. XF\Import\Data\AbstractEmulatedData->write() insrc/XF/Import/Data/AbstractData.php at line 126
  8. XF\Import\Data\AbstractData->save() insrc/XF/Import/Importer/vBulletinBlogTrait.php at line 173
  9. XF\Import\Importer\vBulletin4WithBlog->stepBlogUsers() insrc/XF/Import/Runner.php at line 160
  10. XF\Import\Runner->runStep() in src/XF/Import/Runner.php at line 74
  11. XF\Import\Runner->run() in src/XF/Admin/Controller/Import.php at line231
  12. XF\Admin\Controller\Import->actionRun() insrc/XF/Mvc/Dispatcher.php at line 249
  13. XF\Mvc\Dispatcher->dispatchClass() in src/XF/Mvc/Dispatcher.php at line89
  14. XF\Mvc\Dispatcher->dispatchLoop() in src/XF/Mvc/Dispatcher.php at line41
  15. XF\Mvc\Dispatcher->run() in src/XF/App.php at line 1880
  16. XF\App->run() in src/XF.php at line 328
  17. XF::runApp() in admin.php at line 13
 
Last edited:
Full output:

  • XF\Db\DuplicateKeyException: MySQL query error [1062]: Duplicate entry '4' for key 'PRIMARY'
  • src/XF/Db/AbstractStatement.php:212
  • Generated by:
  • Dec 27, 2017 at 4:57 PM
Stack trace
INSERT INTO `xf_node` (`node_id`, `title`, `node_name`, `description`, `node_type_id`, `parent_node_id`, `display_order`, `style_id`, `effective_style_id`, `display_in_list`, `breadcrumb_data`, `navigation_id`, `effective_navigation_id`) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
------------

#0 src/XF/Db/Mysqli/Statement.php(174): XF\Db\AbstractStatement->getException('MySQL query err...', 1062, '23000')
#1 src/XF/Db/Mysqli/Statement.php(70): XF\Db\Mysqli\Statement->getException('MySQL query err...', 1062, '23000')
#2 src/XF/Db/AbstractAdapter.php(74): XF\Db\Mysqli\Statement->execute()
#3 src/XF/Db/AbstractAdapter.php(151): XF\Db\AbstractAdapter->query('INSERT INTO `x...', Array)
#4 src/XF/Import/Data/EntityEmulator.php(207): XF\Db\AbstractAdapter->insert('xf_node', Array)
#5 src/XF/Import/Data/AbstractEmulatedData.php(34): XF\Import\Data\EntityEmulator->insert(4, Object(XF\Db\Mysqli\Adapter))
#6 src/XF/Import/Data/AbstractData.php(126): XF\Import\Data\AbstractEmulatedData->write(4)
#7 src/XF/Import/Importer/vBulletinBlogTrait.php(173): XF\Import\Data\AbstractData->save(4)
#8 src/XF/Import/Runner.php(160): XF\Import\Importer\vBulletin4WithBlog->stepBlogUsers(Object(XF\Import\StepState), Array, 8)
#9 src/XF/Import/Runner.php(74): XF\Import\Runner->runStep('blogUsers', Object(XF\Import\StepState), 8)
#10 src/XF/Admin/Controller/Import.php(231): XF\Import\Runner->run()
#11 src/XF/Mvc/Dispatcher.php(249): XF\Admin\Controller\Import->actionRun(Object(XF\Mvc\ParameterBag))
#12 src/XF/Mvc/Dispatcher.php(89): XF\Mvc\Dispatcher->dispatchClass('XF:Import', 'run', 'html', Object(XF\Mvc\ParameterBag), 'importData', Object(XF\Admin\Controller\Import), NULL)
#13 src/XF/Mvc/Dispatcher.php(41): XF\Mvc\Dispatcher->dispatchLoop(Object(XF\Mvc\RouteMatch))
#14 src/XF/App.php(1880): XF\Mvc\Dispatcher->run()
#15 src/XF.php(328): XF\App->run()
#16 admin.php(13): XF::runApp('XF\\Admin\\App')
#17 {main}

Request state
array(4) {
["url"] => string(28) "/forum2/admin.php?import/run"
["referrer"] => string(54) "admin.php?import/run"
["_GET"] => array(1) {
["import/run"] => string(0) ""
}
["_POST"] => array(1) {
["_xfToken"] => string(8) "********"
}
}
 
As of right now, we don't have a direct fix. The only recommendations would be to do the import on 1.5 and upgrade or to not do the import with any blog-related data. (This would require restoring to a pre-import state or a doing a fresh install.)

Choosing to not retain IDs may be an option as well, though that may not be 100% viable.
 
I've looked into this, and the problem is related to the fact that the XF2 importers dual-purpose forums, threads and posts as blog containers. The importers as you have them right now will attempt to retain IDs for blog users, blog entries and blog comments, but this isn't possible because you will already have genuine forums, threads and posts that may occupy the IDs the blog content attempts to use.

The solution here is to use the 'preventRetainIds' switch for the various blog content items, as shown in the following diff:

Screen Shot 2018-01-05 at 09.44.18.webp
 
Back
Top Bottom