Delta rewrite URL CE step not using database prefix correctly (with fix)
Preconditions
- Data Migration Completed to or from a site that uses a database prefix
- Source prefix is different than destination prefix (or only one has a prefix)
Steps to reproduce
- Run Delta step after there have been some changes
Expected result
- Should run to completion as it did after migration
Actual result
- Stops at Rewrites step with error
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'catalog_url_rewrite_product_category' doesn't exist, query was: SELECT catalog_url_rewrite_product_category.* FROM catalog_url_re write_product_category WHERE (url_rewrite_id = '9088576') AND (category_id = '27') AND (product_id = '727')
The code complained about does NOT use the prefix as set up in the config
Strangely the delta step had run successfully before so I assume this step is not always run
Solution
My guess is that in the file Migration/Step/UrlRewrite/Version191to2000Delta.php, function saveProductCategoryRecord on line 150 the whole block needs a look
`
$select = $this->destination->getAdapter()->getSelect();
$select->from(Version191to2000::DESTINATION_PRODUCT_CATEGORY)
->where('url_rewrite_id = ?', $record->getValue('url_rewrite_id'))
->where('category_id = ?', $record->getValue('category_id'))
->where('product_id = ?', $record->getValue('product_id'));
if (!$this->destination->getAdapter()->loadDataFromSelect($select)) {
$this->destination->saveRecords(
$this->source->addDocumentPrefix(Version191to2000::DESTINATION_PRODUCT_CATEGORY),
[[
'url_rewrite_id' => $record->getValue('url_rewrite_id'),
'category_id' => $record->getValue('category_id'),
'product_id' => $record->getValue('product_id')
]],
true
);
}
`
- line 151 is not using
$this->source->addDocumentPrefixand it should - as the select object is
$this->destinationI assume it should be$select->from($this->destination->addDocumentPrefix(Version191to2000::DESTINATION_PRODUCT_CATEGORY),'*') - after fixing this the next command then errors again, as it uses
$this->source->addDocumentPrefixto insert into the destination, which fails if they are not the same.
so this is what it should be, I think?
`
$select->from($this->destination->addDocumentPrefix(Version191to2000::DESTINATION_PRODUCT_CATEGORY),'*')
->where('url_rewrite_id = ?', $record->getValue('url_rewrite_id'))
->where('category_id = ?', $record->getValue('category_id'))
->where('product_id = ?', $record->getValue('product_id'));
if (!$this->destination->getAdapter()->loadDataFromSelect($select)) {
$this->destination->saveRecords(
$this->destination->addDocumentPrefix(Version191to2000::DESTINATION_PRODUCT_CATEGORY),
[[
'url_rewrite_id' => $record->getValue('url_rewrite_id'),
'category_id' => $record->getValue('category_id'),
'product_id' => $record->getValue('product_id')
]],
true
);
}
`
THEN you get a similar error for saveCmsPageRewrites
I think
$adapter->delete(Version191to2000::DESTINATION, "entity_type = 'cms-page'");
needs document prefix too
See below for fixes successfully made on my one instance
I put my fixes in a forked repository as I didn't know the process here for pull requests @victor-v-rad
https://github.com/iphigenie/data-migration-tool/pull/1/files
Hi @iphigenie
Thank you for reporting and solving this issue. You can create PR to the repository just like this one https://github.com/magento/data-migration-tool/pull/769 as an example
Hi @victor-v-rad
done - obviously I have a sample of one scenario tested only