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

Fixed vBulletin 4.x Import: prefix_group_id and prefix_id aren't integers

Affected version
2.0.0
#1
Code:
$ php cmd.php xf:import --verbose
Starting import from vBulletin 4.x (Beta)...
 - [...]
 - Step 10 of 19: Moderators - 100.00% (< 1 sec)

                                                                                                        
  [XF\Db\Exception]                                                                                     
  MySQL query error [1366]: Incorrect integer value: 'howto_faq' for column 'prefix_group_id' at row 1 
                                                                                                        

Exception trace:
 () at src/XF/Db/AbstractStatement.php:212
 XF\Db\AbstractStatement->getException() at src/XF/Db/Mysqli/Statement.php:174
 XF\Db\Mysqli\Statement->getException() at src/XF/Db/Mysqli/Statement.php:69
 XF\Db\Mysqli\Statement->execute() at src/XF/Db/AbstractAdapter.php:69
 XF\Db\AbstractAdapter->query() at src/XF/Db/AbstractAdapter.php:145
 XF\Db\AbstractAdapter->insert() at src/XF/Import/Data/EntityEmulator.php:207
 XF\Import\Data\EntityEmulator->insert() at src/XF/Import/Data/AbstractEmulatedData.php:34
 XF\Import\Data\AbstractEmulatedData->write() at src/XF/Import/Data/AbstractData.php:99
 XF\Import\Data\AbstractData->save() at src/XF/Import/Importer/vBulletin.php:2193
 XF\Import\Importer\vBulletin->stepThreadPrefixes() at src/XF/Import/Runner.php:161
 XF\Import\Runner->runStep() at src/XF/Import/Runner.php:75
 XF\Import\Runner->run() at src/XF/Cli/Command/Import.php:64
 XF\Cli\Command\Import->execute() at src/vendor/symfony/console/Command/Command.php:242
 Symfony\Component\Console\Command\Command->run() at src/vendor/symfony/console/Application.php:843
 Symfony\Component\Console\Application->doRunCommand() at src/vendor/symfony/console/Application.php:194
 Symfony\Component\Console\Application->doRun() at src/vendor/symfony/console/Application.php:117
 Symfony\Component\Console\Application->run() at src/XF/Cli/Runner.php:63
 XF\Cli\Runner->run() at cmd.php:15

xf:import

I'm not sure whether the following patch is the correct way to fix this:
Diff:
diff --git a/xenforo/src/XF/Import/Importer/vBulletin.php b/xenforo/src/XF/Import/Importer/vBulletin.php
--- a/xenforo/src/XF/Import/Importer/vBulletin.php
+++ b/xenforo/src/XF/Import/Importer/vBulletin.php
@@ -2190,7 +2190,7 @@ class vBulletin extends AbstractForumImporter
             $importGroup->display_order = $prefixSet['displayorder'];
             $importGroup->setTitle($this->convertToUtf8($prefixSet['title']));
 
-            if ($newGroupId = $importGroup->save($oldGroupId))
+            if ($newGroupId = $importGroup->save(false))
             {
                 $mappedGroupIds[$oldGroupId] = $newGroupId;
             }
@@ -2256,7 +2256,7 @@ class vBulletin extends AbstractForumImporter
                 $importPrefix->setNodes($prefixNodes[$prefixSetId]);
             }
 
-            if ($importPrefix->save($oldPrefixId))
+            if ($importPrefix->save(false))
             {
                 $state->imported++;
             }
 

Kier

XenForo Developer
Staff member
#2
I'm not entirely sure how you've ended up with that error - on my test imports of vB4, i get the original prefix/prefix group ID imported and converted to an integer for XF purposes as expected:

1512048595014.png
 

Kier

XenForo Developer
Staff member
#3
Log for that test import (it's a very fast computer and a very small DB):

Code:
$ php cmd.php xf:import --verbose
Starting import from vBulletin 4.x (Beta)...
 - Step 1 of 19: User groups - 100.00% (< 1 sec)
 - Step 2 of 19: Custom user fields - 100.00% (< 1 sec)
 - Step 3 of 19: Users - 100.00% (< 1 sec)
 - Step 4 of 19: Avatars - 100.00% (< 1 sec)
 - Step 5 of 19: Buddy and ignore lists - 100.00% (< 1 sec)
 - Step 6 of 19: Paid subscriptions - 100.00% (< 1 sec)
 - Step 7 of 19: Private messages - 100.00% (< 1 sec)
 - Step 8 of 19: Profile comments - 100.00% (< 1 sec)
 - Step 9 of 19: Forums - 100.00% (< 1 sec)
 - Step 10 of 19: Moderators - 100.00% (< 1 sec)
 - Step 11 of 19: Thread prefixes - 100.00% (< 1 sec)
 - Step 12 of 19: Threads - 100.00% (< 1 sec)
 - Step 13 of 19: Posts - 100.00% (< 1 sec)
 - Step 14 of 19: Tags - 100.00% (< 1 sec)
 - Step 15 of 19: Edit history - 100.00% (< 1 sec)
 - Step 16 of 19: Polls - 100.00% (< 1 sec)
 - Step 17 of 19: Attachments - 100.00% (< 1 sec)
 - Step 18 of 19: Positive reputation - 100.00% (< 1 sec)
 - Step 19 of 19: Infractions - 100.00% (< 1 sec)
The data has been imported successfully. To finalize this import, you must continue via the control panel.
 

Kier

XenForo Developer
Staff member
#5
I've used the importer option to retain IDs. Did you maybe run the test import without this option?
Ah ha!

Yes, that would do it... let me see what I can sort out, as this is likely to affect several data types with several importers.
 

Kier

XenForo Developer
Staff member
#6
Sorted now:

In AbstractData,
PHP:
protected $allowRetainIds = true;

public function preventRetainIds()
{
	$this->allowRetainIds = false;
}

public function retainIds()
{
	return $this->allowRetainIds && $this->dataManager->getRetainIds();
}
and in vBulletin.php, add $importGroup->preventRetainIds(); and $importPrefix->preventRetainIds(); after those variables have been initialized.
 
#7
Thanks!

I've just stumbled upon a similar issue during the import of polls from vB4. I get a duplicate key error in the xf_poll_response table when using the "retain IDs" option. The problem is that the $i variable in $import->addResponse($i, $importResponse); will be used as primary key but it isn't unique (it starts counting from zero for every poll). Adding $importResponse->preventRetainIds(); solves the duplicate key issue.