data-migration-tool icon indicating copy to clipboard operation
data-migration-tool copied to clipboard

Delta rewrite URL CE step not using database prefix correctly (with fix)

Open iphigenie opened this issue 6 years ago • 3 comments

Preconditions

  1. Data Migration Completed to or from a site that uses a database prefix
  2. Source prefix is different than destination prefix (or only one has a prefix)

Steps to reproduce

  1. Run Delta step after there have been some changes

Expected result

  1. Should run to completion as it did after migration

Actual result

  1. 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->addDocumentPrefix and it should
  • as the select object is $this->destination I 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->addDocumentPrefix to 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

iphigenie avatar Jan 20 '20 11:01 iphigenie

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

iphigenie avatar Jan 20 '20 11:01 iphigenie

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

victor-v-rad avatar Jan 21 '20 23:01 victor-v-rad

Hi @victor-v-rad

done - obviously I have a sample of one scenario tested only

iphigenie avatar Jan 22 '20 09:01 iphigenie