From aaf28a1f7b7bb7ad94825faf85170a3fc520abfc Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Mon, 11 Jul 2016 19:17:28 +0300 Subject: [PATCH 01/30] MAGETWO-54941: Catalog events do not change its status after migration --- etc/ee-to-ee/1.11.0.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.11.0.1/map.xml.dist | 4 ++ etc/ee-to-ee/1.11.0.2/map.xml.dist | 4 ++ etc/ee-to-ee/1.11.1.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.11.2.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.12.0.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.12.0.1/map.xml.dist | 4 ++ etc/ee-to-ee/1.12.0.2/map.xml.dist | 4 ++ etc/ee-to-ee/1.13.0.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.13.0.1/map.xml.dist | 4 ++ etc/ee-to-ee/1.13.0.2/map.xml.dist | 4 ++ etc/ee-to-ee/1.13.1.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.14.0.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.14.0.1/map.xml.dist | 4 ++ etc/ee-to-ee/1.14.1.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.14.2.0/map.xml.dist | 4 ++ etc/ee-to-ee/1.14.2.1/map.xml.dist | 4 ++ etc/ee-to-ee/1.14.2.2/map.xml.dist | 4 ++ etc/ee-to-ee/1.14.2.3/map.xml.dist | 4 ++ etc/ee-to-ee/1.14.2.4/map.xml.dist | 4 ++ src/Migration/Handler/GetEventStatus.php | 42 +++++++++++ .../Migration/Handler/GetEventStatusTest.php | 70 +++++++++++++++++++ 22 files changed, 192 insertions(+) create mode 100644 src/Migration/Handler/GetEventStatus.php create mode 100644 tests/unit/testsuite/Migration/Handler/GetEventStatusTest.php diff --git a/etc/ee-to-ee/1.11.0.0/map.xml.dist b/etc/ee-to-ee/1.11.0.0/map.xml.dist index 4e0bebefb..a5917986f 100644 --- a/etc/ee-to-ee/1.11.0.0/map.xml.dist +++ b/etc/ee-to-ee/1.11.0.0/map.xml.dist @@ -2368,6 +2368,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.11.0.1/map.xml.dist b/etc/ee-to-ee/1.11.0.1/map.xml.dist index 27fee2650..099c2e938 100644 --- a/etc/ee-to-ee/1.11.0.1/map.xml.dist +++ b/etc/ee-to-ee/1.11.0.1/map.xml.dist @@ -2368,6 +2368,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.11.0.2/map.xml.dist b/etc/ee-to-ee/1.11.0.2/map.xml.dist index 27fee2650..099c2e938 100644 --- a/etc/ee-to-ee/1.11.0.2/map.xml.dist +++ b/etc/ee-to-ee/1.11.0.2/map.xml.dist @@ -2368,6 +2368,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.11.1.0/map.xml.dist b/etc/ee-to-ee/1.11.1.0/map.xml.dist index ec8fef018..d05211cca 100644 --- a/etc/ee-to-ee/1.11.1.0/map.xml.dist +++ b/etc/ee-to-ee/1.11.1.0/map.xml.dist @@ -2356,6 +2356,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.11.2.0/map.xml.dist b/etc/ee-to-ee/1.11.2.0/map.xml.dist index 7fb5e9db5..36493d30f 100644 --- a/etc/ee-to-ee/1.11.2.0/map.xml.dist +++ b/etc/ee-to-ee/1.11.2.0/map.xml.dist @@ -2356,6 +2356,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.12.0.0/map.xml.dist b/etc/ee-to-ee/1.12.0.0/map.xml.dist index 002239665..7c108a156 100644 --- a/etc/ee-to-ee/1.12.0.0/map.xml.dist +++ b/etc/ee-to-ee/1.12.0.0/map.xml.dist @@ -2278,6 +2278,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.12.0.1/map.xml.dist b/etc/ee-to-ee/1.12.0.1/map.xml.dist index a8a4ced04..166e33eec 100644 --- a/etc/ee-to-ee/1.12.0.1/map.xml.dist +++ b/etc/ee-to-ee/1.12.0.1/map.xml.dist @@ -2278,6 +2278,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.12.0.2/map.xml.dist b/etc/ee-to-ee/1.12.0.2/map.xml.dist index a8a4ced04..166e33eec 100644 --- a/etc/ee-to-ee/1.12.0.2/map.xml.dist +++ b/etc/ee-to-ee/1.12.0.2/map.xml.dist @@ -2278,6 +2278,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.13.0.0/map.xml.dist b/etc/ee-to-ee/1.13.0.0/map.xml.dist index 3b4a35ff3..a519498dc 100644 --- a/etc/ee-to-ee/1.13.0.0/map.xml.dist +++ b/etc/ee-to-ee/1.13.0.0/map.xml.dist @@ -2231,6 +2231,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.13.0.1/map.xml.dist b/etc/ee-to-ee/1.13.0.1/map.xml.dist index 8c72607ea..3599e5cc3 100644 --- a/etc/ee-to-ee/1.13.0.1/map.xml.dist +++ b/etc/ee-to-ee/1.13.0.1/map.xml.dist @@ -2231,6 +2231,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.13.0.2/map.xml.dist b/etc/ee-to-ee/1.13.0.2/map.xml.dist index 8c72607ea..3599e5cc3 100644 --- a/etc/ee-to-ee/1.13.0.2/map.xml.dist +++ b/etc/ee-to-ee/1.13.0.2/map.xml.dist @@ -2231,6 +2231,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.13.1.0/map.xml.dist b/etc/ee-to-ee/1.13.1.0/map.xml.dist index 9fc6b5553..4b1dd9471 100644 --- a/etc/ee-to-ee/1.13.1.0/map.xml.dist +++ b/etc/ee-to-ee/1.13.1.0/map.xml.dist @@ -2237,6 +2237,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.14.0.0/map.xml.dist b/etc/ee-to-ee/1.14.0.0/map.xml.dist index 689c78712..0e57e49e1 100644 --- a/etc/ee-to-ee/1.14.0.0/map.xml.dist +++ b/etc/ee-to-ee/1.14.0.0/map.xml.dist @@ -2237,6 +2237,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.14.0.1/map.xml.dist b/etc/ee-to-ee/1.14.0.1/map.xml.dist index 689c78712..0e57e49e1 100644 --- a/etc/ee-to-ee/1.14.0.1/map.xml.dist +++ b/etc/ee-to-ee/1.14.0.1/map.xml.dist @@ -2237,6 +2237,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.14.1.0/map.xml.dist b/etc/ee-to-ee/1.14.1.0/map.xml.dist index 40f2526e3..ef6438233 100644 --- a/etc/ee-to-ee/1.14.1.0/map.xml.dist +++ b/etc/ee-to-ee/1.14.1.0/map.xml.dist @@ -2239,6 +2239,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.14.2.0/map.xml.dist b/etc/ee-to-ee/1.14.2.0/map.xml.dist index 368df7232..1c854697b 100644 --- a/etc/ee-to-ee/1.14.2.0/map.xml.dist +++ b/etc/ee-to-ee/1.14.2.0/map.xml.dist @@ -2276,6 +2276,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.14.2.1/map.xml.dist b/etc/ee-to-ee/1.14.2.1/map.xml.dist index ac7be3ea3..37ce90936 100644 --- a/etc/ee-to-ee/1.14.2.1/map.xml.dist +++ b/etc/ee-to-ee/1.14.2.1/map.xml.dist @@ -2282,6 +2282,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.14.2.2/map.xml.dist b/etc/ee-to-ee/1.14.2.2/map.xml.dist index 671011c74..13e376496 100644 --- a/etc/ee-to-ee/1.14.2.2/map.xml.dist +++ b/etc/ee-to-ee/1.14.2.2/map.xml.dist @@ -2288,6 +2288,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.14.2.3/map.xml.dist b/etc/ee-to-ee/1.14.2.3/map.xml.dist index 93daf160a..957ed70ad 100644 --- a/etc/ee-to-ee/1.14.2.3/map.xml.dist +++ b/etc/ee-to-ee/1.14.2.3/map.xml.dist @@ -2282,6 +2282,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/etc/ee-to-ee/1.14.2.4/map.xml.dist b/etc/ee-to-ee/1.14.2.4/map.xml.dist index 93daf160a..957ed70ad 100644 --- a/etc/ee-to-ee/1.14.2.4/map.xml.dist +++ b/etc/ee-to-ee/1.14.2.4/map.xml.dist @@ -2282,6 +2282,10 @@ + + magento_catalogevent_event.status + + catalog_product_entity_media_gallery_value.entity_id diff --git a/src/Migration/Handler/GetEventStatus.php b/src/Migration/Handler/GetEventStatus.php new file mode 100644 index 000000000..260d896bb --- /dev/null +++ b/src/Migration/Handler/GetEventStatus.php @@ -0,0 +1,42 @@ +validate($recordToHandle); + $dates = [ + 'start' => $recordToHandle->getValue('date_start'), + 'end' =>$recordToHandle->getValue('date_end') + ]; + $currentDate = date('Y-m-d H:i:s'); + if (($dates['start'] <= $currentDate) && ($dates['end'] > $currentDate)) { + $status = self::EVENT_OPEN; + } elseif (($dates['start'] > $currentDate) && ($dates['end'] > $currentDate)) { + $status = self::EVENT_UPCOMING; + } else { + $status = self::EVENT_CLOSED; + } + $recordToHandle->setValue($this->field, $status); + } +} diff --git a/tests/unit/testsuite/Migration/Handler/GetEventStatusTest.php b/tests/unit/testsuite/Migration/Handler/GetEventStatusTest.php new file mode 100644 index 000000000..c5573ff11 --- /dev/null +++ b/tests/unit/testsuite/Migration/Handler/GetEventStatusTest.php @@ -0,0 +1,70 @@ +getMockBuilder('Migration\ResourceModel\Record') + ->setMethods(['setValue', 'getValue', 'getFields']) + ->getMock(); + $record->expects($this->any())->method('getFields')->willReturn(['status']); + $record->expects($this->any())->method('getValue')->willReturnMap( + [ + ['date_start', $dateStart], + ['date_end', $dateEnd] + ] + ); + $record->expects($this->once())->method('setValue')->with('status', $status); + + $record2 = $this->getMockBuilder('Migration\ResourceModel\Record')->disableOriginalConstructor()->getMock(); + + $handler = new GetEventStatus(); + $handler->setField('status'); + $handler->handle($record, $record2); + } + + /** + * @return array + */ + public function eventDatesDataProvider() + { + return [ + 'closed' => [ + 'date_start' => date('Y-m-d H:i:s', strtotime('-5 days')), + 'date_end' => date('Y-m-d H:i:s', strtotime('-2 days')), + 'status' => GetEventStatus::EVENT_CLOSED + ], + 'open' => [ + 'date_start' => date('Y-m-d H:i:s', strtotime('-1 days')), + 'date_end' => date('Y-m-d H:i:s', strtotime('+2 days')), + 'status' => GetEventStatus::EVENT_OPEN + + ], + 'upcoming' => [ + 'date_start' => date('Y-m-d H:i:s', strtotime('+2 days')), + 'date_end' => date('Y-m-d H:i:s', strtotime('+5 days')), + 'status' => GetEventStatus::EVENT_UPCOMING + ] + ]; + + } +} From 9d9051288524953d3a6db9bfcb4ac4375f52b52b Mon Sep 17 00:00:00 2001 From: Yurii Hryhoriev Date: Wed, 13 Jul 2016 14:51:40 +0300 Subject: [PATCH 02/30] MAGETWO-52162: [GitHub] Migration does not run on PHP 7 after DI compilation #64 --- composer.json | 2 +- etc/module.xml | 10 ++++++ registration.php | 11 +++++++ .../App/ProgressBar/LogLevelProcessor.php | 33 ++++++++++--------- src/Migration/App/SetupDeltaLog.php | 20 +++++++++-- src/Migration/Console/MigrateDataCommand.php | 4 +-- src/Migration/Console/MigrateDeltaCommand.php | 4 +-- .../Console/MigrateSettingsCommand.php | 4 +-- src/Migration/Mode/Delta.php | 20 +++++++++-- .../ResourceModel/AbstractResource.php | 20 +++++++---- src/Migration/ResourceModel/Destination.php | 8 ++--- src/Migration/ResourceModel/Source.php | 10 +++--- 12 files changed, 104 insertions(+), 42 deletions(-) create mode 100644 etc/module.xml create mode 100644 registration.php diff --git a/composer.json b/composer.json index 6b664cc54..aca8fa3fa 100644 --- a/composer.json +++ b/composer.json @@ -9,6 +9,6 @@ }, "autoload": { "psr-4": {"Migration\\": ["src/Migration", "tests/unit/testsuite/Migration"]}, - "files" : ["src/Migration/cli_commands.php"] + "files" : ["src/Migration/cli_commands.php", "registration.php"] } } diff --git a/etc/module.xml b/etc/module.xml new file mode 100644 index 000000000..99505a086 --- /dev/null +++ b/etc/module.xml @@ -0,0 +1,10 @@ + + + + + diff --git a/registration.php b/registration.php new file mode 100644 index 000000000..2111dbb29 --- /dev/null +++ b/registration.php @@ -0,0 +1,11 @@ +consoleOutput = $consoleOutput; $this->progressBarFactory = $progressBarFactory; $this->config = $config; - $this->initProgressBar(); - } /** - * @return void + * @return ProgressBar */ - protected function initProgressBar() + protected function getProgressBar() { - $this->progressBar = $this->progressBarFactory->create($this->getOutputInstance()); - $this->progressBar->setFormat($this->config->getOption(self::PROGRESS_BAR_FORMAT_OPTION)); + if (null == $this->progressBar) { + $this->progressBar = $this->progressBarFactory->create($this->getOutputInstance()); + $this->progressBar->setFormat($this->config->getOption(self::PROGRESS_BAR_FORMAT_OPTION)); + } + return $this->progressBar; } /** @@ -102,8 +103,8 @@ public function start($max, $forceLogLevel = false) if ($this->canRun($forceLogLevel)) { echo PHP_EOL; $max = ($max == 0) ? 1: $max; - $this->progressBar->start($max); - $this->progressBar->setOverwrite(true); + $this->getProgressBar()->start($max); + $this->getProgressBar()->setOverwrite(true); } } @@ -114,7 +115,7 @@ public function start($max, $forceLogLevel = false) public function advance($forceLogLevel = false) { if ($this->canRun($forceLogLevel)) { - $this->progressBar->advance(); + $this->getProgressBar()->advance(); } } @@ -125,7 +126,7 @@ public function advance($forceLogLevel = false) public function finish($forceLogLevel = false) { if ($this->canRun($forceLogLevel)) { - $this->progressBar->finish(); + $this->getProgressBar()->finish(); } } diff --git a/src/Migration/App/SetupDeltaLog.php b/src/Migration/App/SetupDeltaLog.php index bdbc0a9f0..fcf670d6e 100644 --- a/src/Migration/App/SetupDeltaLog.php +++ b/src/Migration/App/SetupDeltaLog.php @@ -26,6 +26,11 @@ class SetupDeltaLog implements StageInterface */ protected $progress; + /** + * @var \Migration\Reader\GroupsFactory + */ + private $groupsFactory; + /** * @param Source $source * @param \Migration\Reader\GroupsFactory $groupsFactory @@ -37,7 +42,7 @@ public function __construct( ProgressBar\LogLevelProcessor $progress ) { $this->source = $source; - $this->groupsReader = $groupsFactory->create('delta_document_groups_file'); + $this->groupsFactory = $groupsFactory; $this->progress = $progress; } @@ -46,7 +51,7 @@ public function __construct( */ public function perform() { - $deltaLogs = $this->groupsReader->getGroups(); + $deltaLogs = $this->getGroupsReader()->getGroups(); $this->progress->start(count($deltaLogs, 1) - count($deltaLogs)); foreach ($deltaLogs as $deltaDocuments) { foreach ($deltaDocuments as $documentName => $idKey) { @@ -59,4 +64,15 @@ public function perform() $this->progress->finish(); return true; } + + /** + * @return Groups + */ + private function getGroupsReader() + { + if (null == $this->groupsReader) { + $this->groupsReader = $this->groupsFactory->create('delta_document_groups_file'); + } + return $this->groupsReader; + } } diff --git a/src/Migration/Console/MigrateDataCommand.php b/src/Migration/Console/MigrateDataCommand.php index 7e639e903..557385a81 100644 --- a/src/Migration/Console/MigrateDataCommand.php +++ b/src/Migration/Console/MigrateDataCommand.php @@ -19,13 +19,13 @@ class MigrateDataCommand extends AbstractMigrateCommand * @param \Migration\Config $config * @param \Migration\Logger\Manager $logManager * @param \Migration\App\Progress $progress - * @param \Migration\Mode\Data\Proxy $dataMode + * @param \Migration\Mode\Data $dataMode */ public function __construct( \Migration\Config $config, \Migration\Logger\Manager $logManager, \Migration\App\Progress $progress, - \Migration\Mode\Data\Proxy $dataMode + \Migration\Mode\Data $dataMode ) { $this->dataMode = $dataMode; parent::__construct($config, $logManager, $progress); diff --git a/src/Migration/Console/MigrateDeltaCommand.php b/src/Migration/Console/MigrateDeltaCommand.php index e3512557d..f79913a8f 100644 --- a/src/Migration/Console/MigrateDeltaCommand.php +++ b/src/Migration/Console/MigrateDeltaCommand.php @@ -19,13 +19,13 @@ class MigrateDeltaCommand extends AbstractMigrateCommand * @param \Migration\Config $config * @param \Migration\Logger\Manager $logManager * @param \Migration\App\Progress $progress - * @param \Migration\Mode\Delta\Proxy $deltaMode + * @param \Migration\Mode\Delta $deltaMode */ public function __construct( \Migration\Config $config, \Migration\Logger\Manager $logManager, \Migration\App\Progress $progress, - \Migration\Mode\Delta\Proxy $deltaMode + \Migration\Mode\Delta $deltaMode ) { $this->deltaMode = $deltaMode; parent::__construct($config, $logManager, $progress); diff --git a/src/Migration/Console/MigrateSettingsCommand.php b/src/Migration/Console/MigrateSettingsCommand.php index 1ce5336b1..30cf024b8 100644 --- a/src/Migration/Console/MigrateSettingsCommand.php +++ b/src/Migration/Console/MigrateSettingsCommand.php @@ -19,13 +19,13 @@ class MigrateSettingsCommand extends AbstractMigrateCommand * @param \Migration\Config $config * @param \Migration\Logger\Manager $logManager * @param \Migration\App\Progress $progress - * @param \Migration\Mode\Settings\Proxy $settingsMode + * @param \Migration\Mode\Settings $settingsMode */ public function __construct( \Migration\Config $config, \Migration\Logger\Manager $logManager, \Migration\App\Progress $progress, - \Migration\Mode\Settings\Proxy $settingsMode + \Migration\Mode\Settings $settingsMode ) { $this->settingsMode = $settingsMode; parent::__construct($config, $logManager, $progress); diff --git a/src/Migration/Mode/Delta.php b/src/Migration/Mode/Delta.php index 1522f234a..037e5f7d1 100644 --- a/src/Migration/Mode/Delta.php +++ b/src/Migration/Mode/Delta.php @@ -44,6 +44,11 @@ class Delta extends AbstractMode implements \Migration\App\Mode\ModeInterface */ protected $groupsReader; + /** + * @var \Migration\Reader\GroupsFactory + */ + private $groupsFactory; + /** * @param Progress $progress * @param Logger $logger @@ -62,7 +67,7 @@ public function __construct( ) { $this->source = $source; $this->autoRestart = $autoRestart; - $this->groupsReader = $groupsFactory->create('delta_document_groups_file'); + $this->groupsFactory = $groupsFactory; parent::__construct($progress, $logger, $stepListFactory); } @@ -88,7 +93,7 @@ public function run() } } - $deltaLogs = $this->groupsReader->getGroups(); + $deltaLogs = $this->getGroupsReader()->getGroups(); foreach ($deltaLogs as $deltaDocuments) { foreach (array_keys($deltaDocuments) as $documentName) { /** @var Mysql $adapter */ @@ -135,4 +140,15 @@ private function runVolume(array $step, $stepName) $this->logger->warning('Volume Check failed'); } } + + /** + * @return Groups + */ + private function getGroupsReader() + { + if (null == $this->groupsReader) { + $this->groupsReader = $this->groupsFactory->create('delta_document_groups_file'); + } + return $this->groupsReader; + } } diff --git a/src/Migration/ResourceModel/AbstractResource.php b/src/Migration/ResourceModel/AbstractResource.php index f57e20555..efc80551e 100644 --- a/src/Migration/ResourceModel/AbstractResource.php +++ b/src/Migration/ResourceModel/AbstractResource.php @@ -51,6 +51,11 @@ abstract class AbstractResource */ protected $documentCollection; + /** + * @var AdapterFactory + */ + protected $adapterFactory; + /** * @var array */ @@ -76,7 +81,7 @@ public function __construct( \Migration\ResourceModel\Document\Collection $documentCollection ) { $this->configReader = $configReader; - $this->adapter = $adapterFactory->create(['config' => $this->getResourceConfig()]); + $this->adapterFactory = $adapterFactory; $this->documentFactory = $documentFactory; $this->structureFactory = $structureFactory; $this->documentCollection = $documentCollection; @@ -106,7 +111,7 @@ public function getDocument($documentName) */ public function getStructure($documentName) { - $data = $this->adapter->getDocumentStructure($this->addDocumentPrefix($documentName)); + $data = $this->getAdapter()->getDocumentStructure($this->addDocumentPrefix($documentName)); return $this->structureFactory->create(['documentName' => $documentName, 'data' => $data]); } @@ -117,7 +122,7 @@ public function getStructure($documentName) */ public function getDocumentList() { - $this->documentList = $this->adapter->getDocumentList(); + $this->documentList = $this->getAdapter()->getDocumentList(); foreach ($this->documentList as &$documentName) { $documentName = $this->removeDocumentPrefix($documentName); } @@ -135,7 +140,7 @@ public function getDocumentList() public function getRecordsCount($documentName, $usePrefix = true, $distinctFields = []) { $documentName = $usePrefix ? $this->addDocumentPrefix($documentName) : $documentName; - return $this->adapter->getRecordsCount($documentName, $distinctFields); + return $this->getAdapter()->getRecordsCount($documentName, $distinctFields); } /** @@ -235,7 +240,7 @@ protected function getBytes($memoryLimit) public function getRecords($documentName, $pageNumber, $pageSize = null) { $pageSize = $pageSize ?: $this->getPageSize($documentName) ; - return $this->adapter->loadPage($this->addDocumentPrefix($documentName), $pageNumber, $pageSize); + return $this->getAdapter()->loadPage($this->addDocumentPrefix($documentName), $pageNumber, $pageSize); } /** @@ -248,7 +253,7 @@ public function getRecords($documentName, $pageNumber, $pageSize = null) */ public function deleteRecords($documentName, $idKey, $ids) { - $this->adapter->deleteRecords($documentName, $idKey, $ids); + $this->getAdapter()->deleteRecords($documentName, $idKey, $ids); } /** @@ -258,6 +263,9 @@ public function deleteRecords($documentName, $idKey, $ids) */ public function getAdapter() { + if (null == $this->adapter) { + $this->adapter = $this->adapterFactory->create(['config' => $this->getResourceConfig()]); + } return $this->adapter; } diff --git a/src/Migration/ResourceModel/Destination.php b/src/Migration/ResourceModel/Destination.php index c5442e78f..26ec757ef 100644 --- a/src/Migration/ResourceModel/Destination.php +++ b/src/Migration/ResourceModel/Destination.php @@ -38,13 +38,13 @@ public function saveRecords($documentName, $records, $updateOnDuplicate = false) $data[] = $row; } if ($i == $pageSize) { - $this->adapter->insertRecords($documentName, $data, $updateOnDuplicate); + $this->getAdapter()->insertRecords($documentName, $data, $updateOnDuplicate); $data = []; $i = 0; } } if ($i > 0) { - $this->adapter->insertRecords($documentName, $data, $updateOnDuplicate); + $this->getAdapter()->insertRecords($documentName, $data, $updateOnDuplicate); } return $this; } @@ -75,7 +75,7 @@ protected function getResourceConfig() */ public function clearDocument($documentName) { - $this->adapter->deleteAllRecords($this->addDocumentPrefix($documentName)); + $this->getAdapter()->deleteAllRecords($this->addDocumentPrefix($documentName)); } /** @@ -127,7 +127,7 @@ public function updateChangedRecords($documentName, $records) $data[] = $row->getData(); } if (!empty($data)) { - $this->adapter->updateChangedRecords($this->addDocumentPrefix($documentName), $data); + $this->getAdapter()->updateChangedRecords($this->addDocumentPrefix($documentName), $data); } } } diff --git a/src/Migration/ResourceModel/Source.php b/src/Migration/ResourceModel/Source.php index a3e64aac1..056fb082c 100644 --- a/src/Migration/ResourceModel/Source.php +++ b/src/Migration/ResourceModel/Source.php @@ -62,7 +62,7 @@ protected function getDocumentPrefix() */ public function loadPage($documentName, $pageNumber) { - return $this->adapter->loadPage($documentName, $pageNumber, $this->getPageSize($documentName)); + return $this->getAdapter()->loadPage($documentName, $pageNumber, $this->getPageSize($documentName)); } /** @@ -87,7 +87,7 @@ public function getRecords($documentName, $pageNumber, $pageSize = null) } } - $records = $this->adapter->loadPage( + $records = $this->getAdapter()->loadPage( $this->addDocumentPrefix($documentName), $pageNumber, $pageSize, @@ -141,7 +141,7 @@ protected function getIdentityField($documentName) */ public function createDelta($documentName, $idKey) { - $this->adapter->createDelta( + $this->getAdapter()->createDelta( $this->addDocumentPrefix($documentName), $this->addDocumentPrefix($this->getDeltaLogName($documentName)), $idKey @@ -159,7 +159,7 @@ public function createDelta($documentName, $idKey) */ public function getChangedRecords($documentName, $idKey, $pageNumber = 0, $getProcessed = false) { - return $this->adapter->loadChangedRecords( + return $this->getAdapter()->loadChangedRecords( $this->addDocumentPrefix($documentName), $this->addDocumentPrefix($this->getDeltaLogName($documentName)), $idKey, @@ -179,7 +179,7 @@ public function getChangedRecords($documentName, $idKey, $pageNumber = 0, $getPr */ public function getDeletedRecords($documentName, $idKey, $getProcessed = false) { - return $this->adapter->loadDeletedRecords( + return $this->getAdapter()->loadDeletedRecords( $this->addDocumentPrefix($this->getDeltaLogName($documentName)), $idKey, 0, From 7a6cacaacd0e6fd0158e2cc59c25cee37019684d Mon Sep 17 00:00:00 2001 From: Yurii Hryhoriev Date: Thu, 14 Jul 2016 16:20:12 +0300 Subject: [PATCH 03/30] MAGETWO-52162: [GitHub] Migration does not run on PHP 7 after DI compilation #64 --- src/Migration/App/ConsoleOutputFactory.php | 29 ++++++++++++ .../App/ProgressBar/LogLevelProcessor.php | 26 +++++++---- src/Migration/App/ProgressBarFactory.php | 22 ++------- .../ResourceModel/AbstractResourceTest.php | 45 ++++++++++--------- .../ResourceModel/DestinationTest.php | 41 ++++++++++------- .../Migration/ResourceModel/SourceTest.php | 40 +++++++++-------- 6 files changed, 120 insertions(+), 83 deletions(-) create mode 100644 src/Migration/App/ConsoleOutputFactory.php diff --git a/src/Migration/App/ConsoleOutputFactory.php b/src/Migration/App/ConsoleOutputFactory.php new file mode 100644 index 000000000..b43fa1a27 --- /dev/null +++ b/src/Migration/App/ConsoleOutputFactory.php @@ -0,0 +1,29 @@ +logManager = $logManager; $this->nullOutput = $nullOutput; - $this->consoleOutput = $consoleOutput; + $this->consoleOutputFactory = $consoleOutputFactory; $this->progressBarFactory = $progressBarFactory; $this->config = $config; } @@ -83,12 +89,14 @@ protected function getProgressBar() } /** - * @return ConsoleOutput|NullOutput + * @return OutputInterface */ protected function getOutputInstance() { - if ($this->logManager->getLogLevel() == LogManager::LOG_LEVEL_ERROR) { - return $this->nullOutput; + if (null == $this->consoleOutput) { + $this->consoleOutput = LogManager::LOG_LEVEL_ERROR == $this->logManager->getLogLevel() ? + $this->nullOutput : + $this->consoleOutputFactory->create(); } return $this->consoleOutput; } diff --git a/src/Migration/App/ProgressBarFactory.php b/src/Migration/App/ProgressBarFactory.php index 1cacbfc79..4286b9663 100644 --- a/src/Migration/App/ProgressBarFactory.php +++ b/src/Migration/App/ProgressBarFactory.php @@ -5,7 +5,7 @@ */ namespace Migration\App; -use Magento\Framework\ObjectManagerInterface; +use Symfony\Component\Console\Helper\ProgressBar; use Symfony\Component\Console\Output\OutputInterface; /** @@ -13,28 +13,12 @@ */ class ProgressBarFactory { - /** - * @var ObjectManagerInterface - */ - protected $objectManager; - - /** - * @param ObjectManagerInterface $objectManager - */ - public function __construct(ObjectManagerInterface $objectManager) - { - $this->objectManager = $objectManager; - } - /** * @param OutputInterface $output - * @return \Symfony\Component\Console\Helper\ProgressBar + * @return ProgressBar */ public function create(OutputInterface $output) { - return $this->objectManager->create( - '\\Symfony\\Component\\Console\\Helper\\ProgressBar', - ['output' => $output] - ); + return new ProgressBar($output); } } diff --git a/tests/unit/testsuite/Migration/ResourceModel/AbstractResourceTest.php b/tests/unit/testsuite/Migration/ResourceModel/AbstractResourceTest.php index a85f59b91..a9f595fd6 100644 --- a/tests/unit/testsuite/Migration/ResourceModel/AbstractResourceTest.php +++ b/tests/unit/testsuite/Migration/ResourceModel/AbstractResourceTest.php @@ -76,6 +76,9 @@ protected function setUp() 'dbname' => 'dbname', 'username' => 'uname', 'password' => 'upass', + ], + 'init_select_parts' => [ + 'disable_staging_preview' => true ] ]]; $this->config = $this->getMock( @@ -85,12 +88,12 @@ protected function setUp() '', false ); - $this->config->expects($this->once()) + $this->config->expects($this->any()) ->method('getDestination') - ->will($this->returnValue($destinationConfig)); - $this->config->expects($this->once()) + ->willReturn($destinationConfig); + $this->config->expects($this->any()) ->method('getSource') - ->will($this->returnValue($config)); + ->willReturn($config); $this->adapter = $this->getMock( '\Migration\ResourceModel\Adapter\Mysql', ['insertRecords', 'getRecordsCount', 'getDocumentStructure', 'getDocumentList', 'loadPage'], @@ -154,10 +157,10 @@ public function testGetDocument($prefix, $optionName) $structureData = ['id' => 'int']; $structure = $this->getMock('\Migration\ResourceModel\Structure', [], [], '', false); $document = $this->getMock('\Migration\ResourceModel\Document', [], [], '', false); - $this->config->expects($this->any()) - ->method('getOption') - ->with($optionName) - ->will($this->returnValue($prefix)); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + [$optionName, $prefix] + ]); $this->documentFactory->expects($this->any()) ->method('create') ->with($this->equalTo(['structure' => $structure, 'documentName' => $resourceName])) @@ -194,11 +197,10 @@ public function getDocumentDataSource() */ public function testGetWrongDocument() { - $prefix = 'prefix_'; - $this->config->expects($this->any()) - ->method('getOption') - ->with('dest_prefix') - ->will($this->returnValue($prefix)); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['dest_prefix', 'prefix_'] + ]); $this->adapter->expects($this->any()) ->method('getDocumentList') ->willReturn(['document']); @@ -212,12 +214,11 @@ public function testGetWrongDocument() public function testGetRecordsCount() { $prefix = 'prefix_'; - $this->config->expects($this->any()) - ->method('getOption') - ->with('dest_prefix') - ->will($this->returnValue($prefix)); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['dest_prefix', $prefix] + ]); $resourceName = 'core_config_data'; - $this->adapter->expects($this->any()) ->method('getRecordsCount') ->with($prefix . $resourceName) @@ -233,8 +234,11 @@ public function testGetRecords() { $resourceName = 'core_config_data'; $pageNumber = 2; - $this->config->expects($this->at(0))->method('getOption')->with('bulk_size')->will($this->returnValue(100)); - $this->config->expects($this->at(1))->method('getOption')->with('dest_prefix')->will($this->returnValue(100)); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['bulk_size', 100], + ['dest_prefix', 100], + ]); $this->adapter->expects($this->once())->method('loadPage'); $this->resourceDestination->getRecords($resourceName, $pageNumber); } @@ -244,6 +248,7 @@ public function testGetRecords() */ public function testGetAdapter() { + $this->config->expects($this->once())->method('getOption')->with('edition_migrate')->willReturn('ce-to-ee'); $this->assertSame($this->adapter, $this->resourceDestination->getAdapter()); } } diff --git a/tests/unit/testsuite/Migration/ResourceModel/DestinationTest.php b/tests/unit/testsuite/Migration/ResourceModel/DestinationTest.php index 94ded72b8..3d0e8e3ad 100644 --- a/tests/unit/testsuite/Migration/ResourceModel/DestinationTest.php +++ b/tests/unit/testsuite/Migration/ResourceModel/DestinationTest.php @@ -66,7 +66,10 @@ protected function setUp() 'host' => 'localhost', 'dbname' => 'dbname', 'username' => 'uname', - 'password' => 'upass', + 'password' => 'upass' + ], + 'init_select_parts' => [ + 'disable_staging_preview' => true ] ]]; $this->config = $this->getMock('\Migration\Config', ['getOption', 'getDestination'], [], '', false); @@ -107,13 +110,11 @@ public function testSaveRecords($prefix) { $resourceName = 'core_config_data'; - $this->config->expects($this->any()) - ->method('getOption') - ->willReturnMap([ - ['bulk_size', 3], - ['dest_prefix', $prefix] - ]); - + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['bulk_size', 3], + ['dest_prefix', $prefix] + ]); $this->adapter->expects($this->at(0)) ->method('insertRecords') ->with($prefix . $resourceName, [['data' => 'value1'], ['data' => 'value2'], ['data' => 'value3']]) @@ -167,8 +168,10 @@ public function testClearDocument() { $docName = 'somename'; $this->adapter->expects($this->once())->method('deleteAllRecords')->with('pfx_' . $docName); - $this->config->expects($this->once())->method('getOption')->with('dest_prefix') - ->will($this->returnValue('pfx_')); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['dest_prefix', 'pfx_'] + ]); $this->resourceDestination->clearDocument($docName); } @@ -179,8 +182,10 @@ public function testBackupDocument() { $docName = 'somename'; $this->adapter->expects($this->once())->method('backupDocument')->with('pfx_' . $docName); - $this->config->expects($this->once())->method('getOption')->with('dest_prefix') - ->will($this->returnValue('pfx_')); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['dest_prefix', 'pfx_'] + ]); $this->resourceDestination->backupDocument($docName); } @@ -191,8 +196,10 @@ public function testRollbackDocument() { $docName = 'somename'; $this->adapter->expects($this->once())->method('rollbackDocument')->with('pfx_' . $docName); - $this->config->expects($this->once())->method('getOption')->with('dest_prefix') - ->will($this->returnValue('pfx_')); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['dest_prefix', 'pfx_'] + ]); $this->resourceDestination->rollbackDocument($docName); } @@ -203,8 +210,10 @@ public function testDeleteDocumentBackup() { $docName = 'somename'; $this->adapter->expects($this->once())->method('deleteBackup')->with('pfx_' . $docName); - $this->config->expects($this->once())->method('getOption')->with('dest_prefix') - ->will($this->returnValue('pfx_')); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['dest_prefix', 'pfx_'] + ]); $this->resourceDestination->deleteDocumentBackup($docName); } } diff --git a/tests/unit/testsuite/Migration/ResourceModel/SourceTest.php b/tests/unit/testsuite/Migration/ResourceModel/SourceTest.php index 9ea5adcdc..995bd1f7c 100644 --- a/tests/unit/testsuite/Migration/ResourceModel/SourceTest.php +++ b/tests/unit/testsuite/Migration/ResourceModel/SourceTest.php @@ -62,6 +62,9 @@ protected function setUp() 'password' => 'upass', 'dbname' => 'dbname', 'username' => 'uname' + ], + 'init_select_parts' => [ + 'disable_staging_preview' => true ] ]]; $this->config = $this->getMock('\Migration\Config', ['getOption', 'getSource'], [], '', false); @@ -107,10 +110,10 @@ protected function setUp() */ public function testLoadPage() { - $this->config->expects($this->any()) - ->method('getOption') - ->with('bulk_size') - ->will($this->returnValue($this->bulkSize)); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['bulk_size', $this->bulkSize] + ]); $this->adapter->expects($this->any())->method('loadPage')->with('table', 2)->willReturn(['1', '2']); $this->assertEquals(['1', '2'], $this->resourceSource->loadPage('table', 2)); } @@ -122,9 +125,10 @@ public function testCreateDelta() { $this->adapter->expects($this->once())->method('createDelta') ->with('spfx_document', 'spfx_m2_cl_document', 'key_field'); - $this->config->expects($this->any())->method('getOption') - ->with(Source::CONFIG_DOCUMENT_PREFIX) - ->willReturn('spfx_'); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + [Source::CONFIG_DOCUMENT_PREFIX, 'spfx_'] + ]); $this->resourceSource->createDelta('document', 'key_field'); } @@ -135,12 +139,11 @@ public function testGetChangedRecords() { $this->adapter->expects($this->once())->method('loadChangedRecords') ->with('document', 'm2_cl_document', 'key_field', 0, 100); - $this->config->expects($this->any())->method('getOption')->willReturnMap( - [ - ['source_prefix', ''], - ['bulk_size', 100] - ] - ); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['source_prefix', ''], + ['bulk_size', 100] + ]); $this->resourceSource->getChangedRecords('document', 'key_field'); } @@ -151,12 +154,11 @@ public function testGetDeletedRecords() { $this->adapter->expects($this->once())->method('loadDeletedRecords') ->with('m2_cl_document', 'key_field', 0, 100); - $this->config->expects($this->any())->method('getOption')->willReturnMap( - [ - ['source_prefix', ''], - ['bulk_size', 100] - ] - ); + $this->config->expects($this->any())->method('getOption')->willReturnMap([ + ['edition_migrate', 'ce-to-ee'], + ['source_prefix', ''], + ['bulk_size', 100] + ]); $this->resourceSource->getDeletedRecords('document', 'key_field'); } } From 6949dfe5ec425c78da162ca1003f0d377939c407 Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Thu, 14 Jul 2016 19:46:34 +0300 Subject: [PATCH 04/30] MAGETWO-52582: [GitHub] Data Migration "hung" at "Customer Attributes Step" #75 --- src/Migration/Step/Customer/Data.php | 22 +++++----------------- src/Migration/Step/Customer/Helper.php | 19 ++++++++----------- 2 files changed, 13 insertions(+), 28 deletions(-) diff --git a/src/Migration/Step/Customer/Data.php b/src/Migration/Step/Customer/Data.php index 5b1ba1fd8..54abe58c3 100644 --- a/src/Migration/Step/Customer/Data.php +++ b/src/Migration/Step/Customer/Data.php @@ -110,8 +110,9 @@ public function __construct( */ public function perform() { - $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO); $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents')); + $this->progress->start(count($sourceDocuments), LogManager::LOG_LEVEL_INFO); + foreach ($sourceDocuments as $sourceDocName) { $sourceDocument = $this->source->getDocument($sourceDocName); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); @@ -155,32 +156,19 @@ public function perform() $recordTransformer->transform($record, $destRecord); $destinationRecords->addRecord($destRecord); } - $this->progress->advance(LogManager::LOG_LEVEL_INFO); + $this->progress->advance(LogManager::LOG_LEVEL_DEBUG); $this->helper->updateAttributeData($attributeType, $sourceDocName, $destinationRecords); $this->destination->saveRecords($destinationName, $destinationRecords); } + + $this->progress->advance(LogManager::LOG_LEVEL_INFO); $this->progress->finish(LogManager::LOG_LEVEL_DEBUG); } $this->helper->updateEavAttributes(); $this->progress->finish(LogManager::LOG_LEVEL_INFO); return true; } - - /** - * Get iterations count for step - * - * @return int - */ - protected function getIterationsCount() - { - $iterations = 0; - foreach (array_keys($this->readerGroups->getGroup('source_documents')) as $document) { - $iterations += $this->source->getRecordsCount($document); - } - - return $iterations; - } } diff --git a/src/Migration/Step/Customer/Helper.php b/src/Migration/Step/Customer/Helper.php index 64e5a55b1..35c0910d3 100644 --- a/src/Migration/Step/Customer/Helper.php +++ b/src/Migration/Step/Customer/Helper.php @@ -182,17 +182,15 @@ public function setAttributeData( /** @var Record $record */ foreach ($destinationRecords as $record) { if (isset($recordAttributesData[$record->getValue('entity_id')])) { + $recordEntityData = $recordAttributesData[$record->getValue('entity_id')]; if ($this->configReader->getOption(self::UPGRADE_CUSTOMER_PASSWORD_HASH)) { - $recordAttributesData = $this->upgradeCustomerHash( - $recordAttributesData, - $record->getValue('entity_id') - ); + $recordEntityData = $this->upgradeCustomerHash($recordEntityData); } $data = $record->getData(); $data = array_merge( array_fill_keys($attributeCodes, null), $data, - $recordAttributesData[$record->getValue('entity_id')] + $recordEntityData ); $record->setData($data); } @@ -347,21 +345,20 @@ public function updateEavAttributes() * Upgrade customer hash according M2 algorithm versions * * @param array $recordAttributesData - * @param string $entityId * @return array */ - private function upgradeCustomerHash($recordAttributesData, $entityId) + private function upgradeCustomerHash($recordAttributesData) { - if (isset($recordAttributesData[$entityId]['password_hash'])) { - $hash = $this->explodePasswordHash($recordAttributesData[$entityId]['password_hash']); + if (isset($recordAttributesData['password_hash'])) { + $hash = $this->explodePasswordHash($recordAttributesData['password_hash']); if (strlen($hash[self::PASSWORD_HASH]) == 32) { - $recordAttributesData[$entityId]['password_hash'] = implode( + $recordAttributesData['password_hash'] = implode( ':', [$hash[self::PASSWORD_HASH], $hash[self::PASSWORD_SALT], '0'] ); } elseif (strlen($hash[self::PASSWORD_HASH]) == 64) { - $recordAttributesData[$entityId]['password_hash'] = implode( + $recordAttributesData['password_hash'] = implode( ':', [$hash[self::PASSWORD_HASH], $hash[self::PASSWORD_SALT], '1'] ); From 1b0b2f3b661b4114080275a079e2f7e225681968 Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Fri, 15 Jul 2016 11:01:33 +0300 Subject: [PATCH 05/30] MAGETWO-55436: [GitHub] Installation Issue with Magento 2.1.0 CE #108 --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 20255abb6..ccb78afe4 100644 --- a/README.md +++ b/README.md @@ -81,7 +81,7 @@ To update `composer.json`: 7. Enter the following command to reference Magento packages in `composer.json`: - composer config repositories.magento composer http://repo.magento.com + composer config repositories.magento composer https://repo.magento.com 8. Enter the following command to require the current version of the package: From b60a9008d73effebfe2d0c344c717b3cae7c6b0c Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Fri, 15 Jul 2016 20:25:08 +0300 Subject: [PATCH 06/30] MAGETWO-52582: [GitHub] Data Migration "hung" at "Customer Attributes Step" #75 --- src/Migration/ResourceModel/AbstractResource.php | 3 +++ src/Migration/ResourceModel/Destination.php | 10 +++++++++- src/Migration/ResourceModel/Source.php | 10 +++++++++- src/Migration/Step/Log/Data.php | 8 ++++---- src/Migration/Step/UrlRewrite/Version191to2000.php | 6 +++++- 5 files changed, 30 insertions(+), 7 deletions(-) diff --git a/src/Migration/ResourceModel/AbstractResource.php b/src/Migration/ResourceModel/AbstractResource.php index f57e20555..84ddeee32 100644 --- a/src/Migration/ResourceModel/AbstractResource.php +++ b/src/Migration/ResourceModel/AbstractResource.php @@ -117,6 +117,9 @@ public function getStructure($documentName) */ public function getDocumentList() { + if (null !== $this->documentList) { + return $this->documentList; + } $this->documentList = $this->adapter->getDocumentList(); foreach ($this->documentList as &$documentName) { $documentName = $this->removeDocumentPrefix($documentName); diff --git a/src/Migration/ResourceModel/Destination.php b/src/Migration/ResourceModel/Destination.php index c5442e78f..f671eee2f 100644 --- a/src/Migration/ResourceModel/Destination.php +++ b/src/Migration/ResourceModel/Destination.php @@ -15,6 +15,11 @@ class Destination extends AbstractResource { const CONFIG_DOCUMENT_PREFIX = 'dest_prefix'; + /** + * @var string + */ + protected $documentPrefix; + /** * Save data into destination resource * @@ -83,7 +88,10 @@ public function clearDocument($documentName) */ protected function getDocumentPrefix() { - return $this->configReader->getOption(self::CONFIG_DOCUMENT_PREFIX); + if (null === $this->documentPrefix) { + $this->documentPrefix = $this->configReader->getOption(self::CONFIG_DOCUMENT_PREFIX); + } + return $this->documentPrefix; } /** diff --git a/src/Migration/ResourceModel/Source.php b/src/Migration/ResourceModel/Source.php index a3e64aac1..950f6643f 100644 --- a/src/Migration/ResourceModel/Source.php +++ b/src/Migration/ResourceModel/Source.php @@ -25,6 +25,11 @@ class Source extends AbstractResource */ protected $lastLoadedIdentityId = []; + /** + * @var string + */ + protected $documentPrefix; + /** * {@inheritdoc} */ @@ -50,7 +55,10 @@ protected function getResourceConfig() */ protected function getDocumentPrefix() { - return $this->configReader->getOption(self::CONFIG_DOCUMENT_PREFIX); + if (null === $this->documentPrefix) { + $this->documentPrefix = $this->configReader->getOption(self::CONFIG_DOCUMENT_PREFIX); + } + return $this->documentPrefix; } /** diff --git a/src/Migration/Step/Log/Data.php b/src/Migration/Step/Log/Data.php index 876e09e07..91c1c0f2e 100644 --- a/src/Migration/Step/Log/Data.php +++ b/src/Migration/Step/Log/Data.php @@ -104,7 +104,7 @@ public function __construct( */ public function perform() { - $this->progress->start($this->getIterationsCount(), LogManager::LOG_LEVEL_INFO); + $this->progress->start($this->getBulksCount(), LogManager::LOG_LEVEL_INFO); $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents')); foreach ($sourceDocuments as $sourceDocName) { $sourceDocument = $this->source->getDocument($sourceDocName); @@ -126,7 +126,6 @@ public function perform() $pageNumber++; $destinationRecords = $destDocument->getRecords(); foreach ($bulk as $recordData) { - $this->progress->advance(LogManager::LOG_LEVEL_INFO); $this->progress->advance(LogManager::LOG_LEVEL_DEBUG); /** @var Record $destRecord */ $destRecord = $this->recordFactory->create([ @@ -137,6 +136,7 @@ public function perform() } $this->destination->saveRecords($destinationName, $destinationRecords); } + $this->progress->advance(LogManager::LOG_LEVEL_INFO); $this->progress->finish(LogManager::LOG_LEVEL_DEBUG); } $this->clearLog(array_keys($this->readerGroups->getGroup('destination_documents_to_clear'))); @@ -203,11 +203,11 @@ protected function clearLog($documents) * * @return int */ - protected function getIterationsCount() + protected function getBulksCount() { $iterations = 0; foreach (array_keys($this->readerGroups->getGroup('source_documents')) as $document) { - $iterations += $this->source->getRecordsCount($document); + $iterations += ceil($this->source->getRecordsCount($document) / $this->source->getPageSize($document)); } return count($this->readerGroups->getGroup('destination_documents_to_clear')) diff --git a/src/Migration/Step/UrlRewrite/Version191to2000.php b/src/Migration/Step/UrlRewrite/Version191to2000.php index 5b874bd2f..7fbfbc741 100644 --- a/src/Migration/Step/UrlRewrite/Version191to2000.php +++ b/src/Migration/Step/UrlRewrite/Version191to2000.php @@ -183,7 +183,9 @@ protected function integrity() */ protected function data() { - $this->progress->start($this->source->getRecordsCount(self::SOURCE) + $this->countCmsPageRewrites()); + $this->progress->start( + ceil($this->source->getRecordsCount(self::SOURCE) / $this->source->getPageSize(self::SOURCE)) + ); $sourceDocument = $this->source->getDocument(self::SOURCE); $destDocument = $this->destination->getDocument(self::DESTINATION); @@ -217,6 +219,8 @@ protected function data() $destinationRecords->addRecord($destRecord); } + + $this->progress->advance(); $this->destination->saveRecords(self::DESTINATION, $destinationRecords); $this->destination->saveRecords(self::DESTINATION_PRODUCT_CATEGORY, $destProductCategoryRecords); From 2ce62abc059aa13679da62f74eefee3b1f466afd Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Mon, 18 Jul 2016 13:05:01 +0300 Subject: [PATCH 07/30] MAGETWO-52505: [GitHub] url_rewrite duplicates #81 --- src/Migration/Step/UrlRewrite/Version191to2000.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Migration/Step/UrlRewrite/Version191to2000.php b/src/Migration/Step/UrlRewrite/Version191to2000.php index 5b874bd2f..a36d9440e 100644 --- a/src/Migration/Step/UrlRewrite/Version191to2000.php +++ b/src/Migration/Step/UrlRewrite/Version191to2000.php @@ -207,6 +207,7 @@ protected function data() if ($record->getValue('is_system') && $record->getValue('product_id') && $record->getValue('category_id') + && $record->getValue('request_path') !== null ) { $destProductCategoryRecord = $this->recordFactory->create(['document' => $destProductCategory]); $destProductCategoryRecord->setValue('url_rewrite_id', $record->getValue('url_rewrite_id')); From eb206bcc65cc71827aaffdfc9904cc8c9d221be5 Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Tue, 19 Jul 2016 11:15:24 +0300 Subject: [PATCH 08/30] MAGETWO-52505: [GitHub] url_rewrite duplicates #81 --- .../dest.sql | 0 .../source.sql | 0 .../dest.sql | 0 .../resource/ee.url_rewrite_191/source.sql | 179 ++++++++++++++++++ .../resource/url_rewrite_11410/dest.sql | 128 +++++++++++++ .../source.sql | 0 .../resource/url_rewrite_191/dest.sql | 128 +++++++++++++ .../resource/url_rewrite_191/source.sql | 63 ++++++ .../UrlRewrite/Version11410to2000Test.php | 2 +- .../Step/UrlRewrite/Version191to2000Test.php | 109 +++++++++++ 10 files changed, 608 insertions(+), 1 deletion(-) rename tests/integration/resource/{ee.url_rewrite => ee.url_rewrite_11410}/dest.sql (100%) rename tests/integration/resource/{ee.url_rewrite => ee.url_rewrite_11410}/source.sql (100%) rename tests/integration/resource/{url_rewrite => ee.url_rewrite_191}/dest.sql (100%) create mode 100644 tests/integration/resource/ee.url_rewrite_191/source.sql create mode 100644 tests/integration/resource/url_rewrite_11410/dest.sql rename tests/integration/resource/{url_rewrite => url_rewrite_11410}/source.sql (100%) create mode 100644 tests/integration/resource/url_rewrite_191/dest.sql create mode 100644 tests/integration/resource/url_rewrite_191/source.sql create mode 100644 tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php diff --git a/tests/integration/resource/ee.url_rewrite/dest.sql b/tests/integration/resource/ee.url_rewrite_11410/dest.sql similarity index 100% rename from tests/integration/resource/ee.url_rewrite/dest.sql rename to tests/integration/resource/ee.url_rewrite_11410/dest.sql diff --git a/tests/integration/resource/ee.url_rewrite/source.sql b/tests/integration/resource/ee.url_rewrite_11410/source.sql similarity index 100% rename from tests/integration/resource/ee.url_rewrite/source.sql rename to tests/integration/resource/ee.url_rewrite_11410/source.sql diff --git a/tests/integration/resource/url_rewrite/dest.sql b/tests/integration/resource/ee.url_rewrite_191/dest.sql similarity index 100% rename from tests/integration/resource/url_rewrite/dest.sql rename to tests/integration/resource/ee.url_rewrite_191/dest.sql diff --git a/tests/integration/resource/ee.url_rewrite_191/source.sql b/tests/integration/resource/ee.url_rewrite_191/source.sql new file mode 100644 index 000000000..392984739 --- /dev/null +++ b/tests/integration/resource/ee.url_rewrite_191/source.sql @@ -0,0 +1,179 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +DROP TABLE IF EXISTS `core_store`; +CREATE TABLE `core_store` ( + `store_id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Store Id', + `code` VARCHAR(32) NULL DEFAULT NULL COMMENT 'Code', + `website_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Website Id', + `group_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Group Id', + `name` VARCHAR(255) NOT NULL COMMENT 'Store Name', + `sort_order` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Sort Order', + `is_active` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Activity', + PRIMARY KEY (`store_id`), + UNIQUE INDEX `UNQ_CORE_STORE_CODE` (`code`), + INDEX `IDX_CORE_STORE_WEBSITE_ID` (`website_id`), + INDEX `IDX_CORE_STORE_IS_ACTIVE_SORT_ORDER` (`is_active`, `sort_order`), + INDEX `IDX_CORE_STORE_GROUP_ID` (`group_id`), + CONSTRAINT `FK_CORE_STORE_GROUP_ID_CORE_STORE_GROUP_GROUP_ID` FOREIGN KEY (`group_id`) REFERENCES `core_store_group` (`group_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CORE_STORE_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Stores' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; + +LOCK TABLES `core_store` WRITE; +/*!40000 ALTER TABLE `core_store` DISABLE KEYS */; +INSERT INTO `core_store` VALUES +(0,'admin',0,0,'Admin',0,1), +(1,'default',1,1,'Default Store View',0,1), +(2,'de',1,1,'German',0,1), +(3,'mw_store_02',1,2,'MWStore View02',0,1); +/*!40000 ALTER TABLE `core_store` ENABLE KEYS */; +UNLOCK TABLES; + +DROP TABLE IF EXISTS `cms_page`; +CREATE TABLE `cms_page` ( + `page_id` SMALLINT(6) NOT NULL AUTO_INCREMENT COMMENT 'Page ID', + `title` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Page Title', + `root_template` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Page Template', + `meta_keywords` TEXT NULL COMMENT 'Page Meta Keywords', + `meta_description` TEXT NULL COMMENT 'Page Meta Description', + `identifier` VARCHAR(100) NOT NULL COMMENT 'Page String Identifier', + `content_heading` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Page Content Heading', + `content` MEDIUMTEXT NULL COMMENT 'Page Content', + `creation_time` TIMESTAMP NULL DEFAULT NULL COMMENT 'Page Creation Time', + `update_time` TIMESTAMP NULL DEFAULT NULL COMMENT 'Page Modification Time', + `is_active` SMALLINT(6) NOT NULL DEFAULT '1' COMMENT 'Is Page Active', + `sort_order` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT 'Page Sort Order', + `layout_update_xml` TEXT NULL COMMENT 'Page Layout Update Content', + `custom_theme` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Page Custom Theme', + `custom_root_template` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Page Custom Template', + `custom_layout_update_xml` TEXT NULL COMMENT 'Page Custom Layout Update Content', + `custom_theme_from` DATE NULL DEFAULT NULL COMMENT 'Page Custom Theme Active From Date', + `custom_theme_to` DATE NULL DEFAULT NULL COMMENT 'Page Custom Theme Active To Date', + `published_revision_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Published Revision Id', + `website_root` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'Website Root', + `under_version_control` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Under Version Control Flag', + PRIMARY KEY (`page_id`), + INDEX `IDX_CMS_PAGE_IDENTIFIER` (`identifier`) +) +COMMENT='CMS Page Table' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `cms_page` VALUES +(1, '404 Not Found 1', 'two_columns_right', 'Page keywords', 'Page description', 'no-route', '', '

We’re sorry, the page you’re looking for can not be found.

\n
\n
    \n
  • If you typed the URL directly, please make sure the spelling is correct.
  • \n
  • If you clicked on a link to get here, we must have moved the content.
    Please try our store search box above to search for an item.
  • \n
  • If you are not sure how you got here, go back to the previous page or return to our store homepage.
  • \n
\n
\n\n', '2007-06-20 18:38:32', '2007-08-26 19:11:13', 1, 0, NULL, NULL, '', NULL, NULL, NULL, 1, 1, 0); + +DROP TABLE IF EXISTS `cms_page_store`; +CREATE TABLE `cms_page_store` ( + `page_id` SMALLINT(6) NOT NULL COMMENT 'Page ID', + `store_id` SMALLINT(5) UNSIGNED NOT NULL COMMENT 'Store ID', + PRIMARY KEY (`page_id`, `store_id`), + INDEX `IDX_CMS_PAGE_STORE_STORE_ID` (`store_id`), + CONSTRAINT `FK_CMS_PAGE_STORE_PAGE_ID_CMS_PAGE_PAGE_ID` FOREIGN KEY (`page_id`) REFERENCES `cms_page` (`page_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CMS_PAGE_STORE_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='CMS Page To Store Linkage Table' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `cms_page_store` VALUES (1, 0); + +DROP TABLE IF EXISTS `core_url_rewrite`; +CREATE TABLE `core_url_rewrite` ( + `url_rewrite_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Rewrite Id', + `store_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Id', + `category_id` INT(10) UNSIGNED NULL DEFAULT NULL COMMENT 'Category Id', + `product_id` INT(10) UNSIGNED NULL DEFAULT NULL COMMENT 'Product Id', + `id_path` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Id Path', + `request_path` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Request Path', + `target_path` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Target Path', + `is_system` SMALLINT(5) UNSIGNED NULL DEFAULT '1' COMMENT 'Defines is Rewrite System', + `options` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Options', + `description` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Deascription', + PRIMARY KEY (`url_rewrite_id`), + UNIQUE INDEX `UNQ_CORE_URL_REWRITE_REQUEST_PATH_STORE_ID` (`request_path`, `store_id`), + UNIQUE INDEX `UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID` (`id_path`, `is_system`, `store_id`), + INDEX `IDX_CORE_URL_REWRITE_TARGET_PATH_STORE_ID` (`target_path`, `store_id`), + INDEX `IDX_CORE_URL_REWRITE_ID_PATH` (`id_path`), + INDEX `IDX_CORE_URL_REWRITE_STORE_ID` (`store_id`), + INDEX `FK_CORE_URL_REWRITE_PRODUCT_ID_CATALOG_PRODUCT_ENTITY_ENTITY_ID` (`product_id`), + INDEX `FK_CORE_URL_REWRITE_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` (`category_id`), + CONSTRAINT `FK_CORE_URL_REWRITE_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CORE_URL_REWRITE_PRODUCT_ID_CATALOG_PRODUCT_ENTITY_ENTITY_ID` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CORE_URL_REWRITE_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Url Rewrites' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `core_url_rewrite` VALUES +(1, 0, 1, 1, '1', 'test1.htm', 'contacts', 1, NULL, NULL), +(2, 1, 1, 1, '2', 'test1.htm', 'catalog/category/view/id/6', 1, NULL, NULL), +(3, 0, 2, 2, '3', 'test5.htm', 'contacts', 1, NULL, NULL), +(4, 1, 2, 2, '3', NULL, 'catalog/category/view/id/8', 1, NULL, NULL); + + +DROP TABLE IF EXISTS `catalog_category_entity`; +CREATE TABLE `catalog_category_entity` ( + `entity_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity ID', + `entity_type_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Entity Type ID', + `attribute_set_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Attriute Set ID', + `parent_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Parent Category ID', + `created_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Creation Time', + `updated_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Update Time', + `path` VARCHAR(255) NOT NULL COMMENT 'Tree Path', + `position` INT(11) NOT NULL DEFAULT '0' COMMENT 'Position', + `level` INT(11) NOT NULL DEFAULT '0' COMMENT 'Tree Level', + `children_count` INT(11) NOT NULL DEFAULT '0' COMMENT 'Child Count', + PRIMARY KEY (`entity_id`), + INDEX `IDX_CATALOG_CATEGORY_ENTITY_LEVEL` (`level`), + INDEX `IDX_CATALOG_CATEGORY_ENTITY_PATH_ENTITY_ID` (`path`, `entity_id`) +) +COMMENT='Catalog Category Table' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `catalog_category_entity` VALUES (1, 3, 0, 0, '0000-00-00 00:00:00', '2016-07-13 11:43:28', '1', 0, 0, 2), +(2, 3, 3, 1, '2016-07-13 11:43:28', '2016-07-13 11:43:28', '1/2', 1, 1, 1), +(3, 3, 3, 2, '2016-07-13 12:30:21', '2016-07-13 12:30:21', '1/2/3', 1, 2, 0); + +CREATE TABLE `catalog_product_entity` ( + `entity_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity ID', + `entity_type_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Entity Type ID', + `attribute_set_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Attribute Set ID', + `type_id` VARCHAR(32) NOT NULL DEFAULT 'simple' COMMENT 'Type ID', + `sku` VARCHAR(64) NULL DEFAULT NULL COMMENT 'SKU', + `has_options` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT 'Has Options', + `required_options` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Required Options', + `created_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Creation Time', + `updated_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Update Time', + PRIMARY KEY (`entity_id`), + INDEX `IDX_CATALOG_PRODUCT_ENTITY_ENTITY_TYPE_ID` (`entity_type_id`), + INDEX `IDX_CATALOG_PRODUCT_ENTITY_ATTRIBUTE_SET_ID` (`attribute_set_id`), + INDEX `IDX_CATALOG_PRODUCT_ENTITY_SKU` (`sku`), + CONSTRAINT `FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribute_set_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CAT_PRD_ENTT_ENTT_TYPE_ID_EAV_ENTT_TYPE_ENTT_TYPE_ID` FOREIGN KEY (`entity_type_id`) REFERENCES `eav_entity_type` (`entity_type_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Catalog Product Table' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `catalog_product_entity` VALUES +(1, 4, 4, 'simple', 'SimpleProduct', 1, 1, '2016-07-13 12:31:52', '2016-07-13 12:34:07'), +(2, 4, 4, 'virtual', 'Virtual Product', 0, 0, '2016-07-13 12:34:53', '2016-07-13 12:34:53'); diff --git a/tests/integration/resource/url_rewrite_11410/dest.sql b/tests/integration/resource/url_rewrite_11410/dest.sql new file mode 100644 index 000000000..aee21de32 --- /dev/null +++ b/tests/integration/resource/url_rewrite_11410/dest.sql @@ -0,0 +1,128 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `url_rewrite` +-- + +DROP TABLE IF EXISTS `url_rewrite`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `url_rewrite` ( + `url_rewrite_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Rewrite Id', + `entity_type` varchar(32) NOT NULL COMMENT 'Entity type code', + `entity_id` int(10) unsigned NOT NULL COMMENT 'Entity ID', + `request_path` varchar(255) DEFAULT NULL COMMENT 'Request Path', + `target_path` varchar(255) DEFAULT NULL COMMENT 'Target Path', + `redirect_type` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Redirect Type', + `store_id` smallint(5) unsigned NOT NULL COMMENT 'Store Id', + `description` varchar(255) DEFAULT NULL COMMENT 'Description', + `is_autogenerated` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is rewrite generated automatically flag', + `metadata` varchar(255) DEFAULT NULL COMMENT 'Meta data for url rewrite', + PRIMARY KEY (`url_rewrite_id`), + UNIQUE KEY `UNQ_URL_REWRITE_REQUEST_PATH_STORE_ID` (`request_path`,`store_id`), + KEY `IDX_URL_REWRITE_TARGET_PATH` (`target_path`), + KEY `IDX_URL_REWRITE_STORE_ID_ENTITY_ID` (`store_id`,`entity_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Url Rewrites'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `catalog_category_entity_varchar` +-- + +DROP TABLE IF EXISTS `catalog_category_entity_varchar`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `catalog_category_entity_varchar` ( + `value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID', + `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute ID', + `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store ID', + `entity_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity ID', + `value` varchar(255) DEFAULT NULL COMMENT 'Value', + PRIMARY KEY (`value_id`), + UNIQUE KEY `UNQ_CAT_CTGR_ENTT_VCHR_ENTT_TYPE_ID_ENTT_ID_ATTR_ID_STORE_ID` (`entity_id`,`attribute_id`,`store_id`), + KEY `IDX_CATALOG_CATEGORY_ENTITY_VARCHAR_ENTITY_ID` (`entity_id`), + KEY `IDX_CATALOG_CATEGORY_ENTITY_VARCHAR_ATTRIBUTE_ID` (`attribute_id`), + KEY `IDX_CATALOG_CATEGORY_ENTITY_VARCHAR_STORE_ID` (`store_id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='Catalog Category Varchar Attribute Backend Table'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `catalog_category_entity_varchar` +-- + +LOCK TABLES `catalog_category_entity_varchar` WRITE; +/*!40000 ALTER TABLE `catalog_category_entity_varchar` DISABLE KEYS */; +INSERT INTO `catalog_category_entity_varchar` VALUES +(1,41,0,1,'Root Catalog'), +(2,41,0,2,'Default Category'), +(3,48,0,2,'PRODUCTS'); +/*!40000 ALTER TABLE `catalog_category_entity_varchar` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `catalog_product_entity_varchar` +-- + +DROP TABLE IF EXISTS `catalog_product_entity_varchar`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `catalog_product_entity_varchar` ( + `value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID', + `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute ID', + `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store ID', + `entity_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity ID', + `value` varchar(255) DEFAULT NULL COMMENT 'Value', + PRIMARY KEY (`value_id`), + UNIQUE KEY `UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID` (`entity_id`,`attribute_id`,`store_id`), + KEY `IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ATTRIBUTE_ID` (`attribute_id`), + KEY `IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_STORE_ID` (`store_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Catalog Product Varchar Attribute Backend Table'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `catalog_url_rewrite_product_category` +-- + +DROP TABLE IF EXISTS `catalog_url_rewrite_product_category`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `catalog_url_rewrite_product_category` ( + `url_rewrite_id` int(10) unsigned NOT NULL COMMENT 'url_rewrite_id', + `category_id` int(10) unsigned NOT NULL COMMENT 'category_id', + `product_id` int(10) unsigned NOT NULL COMMENT 'product_id', + KEY `IDX_CATALOG_URL_REWRITE_PRODUCT_CATEGORY_CATEGORY_ID_PRODUCT_ID` (`category_id`,`product_id`), + KEY `FK_CAT_URL_REWRITE_PRD_CTGR_PRD_ID_CAT_PRD_ENTT_ENTT_ID` (`product_id`), + KEY `FK_BB79E64705D7F17FE181F23144528FC8` (`url_rewrite_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='url_rewrite_relation'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `catalog_url_rewrite_product_category` +-- + + +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2015-01-29 19:44:27 diff --git a/tests/integration/resource/url_rewrite/source.sql b/tests/integration/resource/url_rewrite_11410/source.sql similarity index 100% rename from tests/integration/resource/url_rewrite/source.sql rename to tests/integration/resource/url_rewrite_11410/source.sql diff --git a/tests/integration/resource/url_rewrite_191/dest.sql b/tests/integration/resource/url_rewrite_191/dest.sql new file mode 100644 index 000000000..aee21de32 --- /dev/null +++ b/tests/integration/resource/url_rewrite_191/dest.sql @@ -0,0 +1,128 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +-- +-- Table structure for table `url_rewrite` +-- + +DROP TABLE IF EXISTS `url_rewrite`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `url_rewrite` ( + `url_rewrite_id` int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Rewrite Id', + `entity_type` varchar(32) NOT NULL COMMENT 'Entity type code', + `entity_id` int(10) unsigned NOT NULL COMMENT 'Entity ID', + `request_path` varchar(255) DEFAULT NULL COMMENT 'Request Path', + `target_path` varchar(255) DEFAULT NULL COMMENT 'Target Path', + `redirect_type` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Redirect Type', + `store_id` smallint(5) unsigned NOT NULL COMMENT 'Store Id', + `description` varchar(255) DEFAULT NULL COMMENT 'Description', + `is_autogenerated` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Is rewrite generated automatically flag', + `metadata` varchar(255) DEFAULT NULL COMMENT 'Meta data for url rewrite', + PRIMARY KEY (`url_rewrite_id`), + UNIQUE KEY `UNQ_URL_REWRITE_REQUEST_PATH_STORE_ID` (`request_path`,`store_id`), + KEY `IDX_URL_REWRITE_TARGET_PATH` (`target_path`), + KEY `IDX_URL_REWRITE_STORE_ID_ENTITY_ID` (`store_id`,`entity_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Url Rewrites'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `catalog_category_entity_varchar` +-- + +DROP TABLE IF EXISTS `catalog_category_entity_varchar`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `catalog_category_entity_varchar` ( + `value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID', + `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute ID', + `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store ID', + `entity_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity ID', + `value` varchar(255) DEFAULT NULL COMMENT 'Value', + PRIMARY KEY (`value_id`), + UNIQUE KEY `UNQ_CAT_CTGR_ENTT_VCHR_ENTT_TYPE_ID_ENTT_ID_ATTR_ID_STORE_ID` (`entity_id`,`attribute_id`,`store_id`), + KEY `IDX_CATALOG_CATEGORY_ENTITY_VARCHAR_ENTITY_ID` (`entity_id`), + KEY `IDX_CATALOG_CATEGORY_ENTITY_VARCHAR_ATTRIBUTE_ID` (`attribute_id`), + KEY `IDX_CATALOG_CATEGORY_ENTITY_VARCHAR_STORE_ID` (`store_id`) +) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8 COMMENT='Catalog Category Varchar Attribute Backend Table'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `catalog_category_entity_varchar` +-- + +LOCK TABLES `catalog_category_entity_varchar` WRITE; +/*!40000 ALTER TABLE `catalog_category_entity_varchar` DISABLE KEYS */; +INSERT INTO `catalog_category_entity_varchar` VALUES +(1,41,0,1,'Root Catalog'), +(2,41,0,2,'Default Category'), +(3,48,0,2,'PRODUCTS'); +/*!40000 ALTER TABLE `catalog_category_entity_varchar` ENABLE KEYS */; +UNLOCK TABLES; + +-- +-- Table structure for table `catalog_product_entity_varchar` +-- + +DROP TABLE IF EXISTS `catalog_product_entity_varchar`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `catalog_product_entity_varchar` ( + `value_id` int(11) NOT NULL AUTO_INCREMENT COMMENT 'Value ID', + `attribute_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Attribute ID', + `store_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Store ID', + `entity_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity ID', + `value` varchar(255) DEFAULT NULL COMMENT 'Value', + PRIMARY KEY (`value_id`), + UNIQUE KEY `UNQ_CAT_PRD_ENTT_VCHR_ENTT_ID_ATTR_ID_STORE_ID` (`entity_id`,`attribute_id`,`store_id`), + KEY `IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_ATTRIBUTE_ID` (`attribute_id`), + KEY `IDX_CATALOG_PRODUCT_ENTITY_VARCHAR_STORE_ID` (`store_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Catalog Product Varchar Attribute Backend Table'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Table structure for table `catalog_url_rewrite_product_category` +-- + +DROP TABLE IF EXISTS `catalog_url_rewrite_product_category`; +/*!40101 SET @saved_cs_client = @@character_set_client */; +/*!40101 SET character_set_client = utf8 */; +CREATE TABLE `catalog_url_rewrite_product_category` ( + `url_rewrite_id` int(10) unsigned NOT NULL COMMENT 'url_rewrite_id', + `category_id` int(10) unsigned NOT NULL COMMENT 'category_id', + `product_id` int(10) unsigned NOT NULL COMMENT 'product_id', + KEY `IDX_CATALOG_URL_REWRITE_PRODUCT_CATEGORY_CATEGORY_ID_PRODUCT_ID` (`category_id`,`product_id`), + KEY `FK_CAT_URL_REWRITE_PRD_CTGR_PRD_ID_CAT_PRD_ENTT_ENTT_ID` (`product_id`), + KEY `FK_BB79E64705D7F17FE181F23144528FC8` (`url_rewrite_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='url_rewrite_relation'; +/*!40101 SET character_set_client = @saved_cs_client */; + +-- +-- Dumping data for table `catalog_url_rewrite_product_category` +-- + + +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2015-01-29 19:44:27 diff --git a/tests/integration/resource/url_rewrite_191/source.sql b/tests/integration/resource/url_rewrite_191/source.sql new file mode 100644 index 000000000..49b5d9de1 --- /dev/null +++ b/tests/integration/resource/url_rewrite_191/source.sql @@ -0,0 +1,63 @@ +CREATE TABLE `core_url_rewrite` ( + `url_rewrite_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Rewrite Id', + `store_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Id', + `category_id` INT(10) UNSIGNED NULL DEFAULT NULL COMMENT 'Category Id', + `product_id` INT(10) UNSIGNED NULL DEFAULT NULL COMMENT 'Product Id', + `id_path` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Id Path', + `request_path` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Request Path', + `target_path` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Target Path', + `is_system` SMALLINT(5) UNSIGNED NULL DEFAULT '1' COMMENT 'Defines is Rewrite System', + `options` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Options', + `description` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Deascription', + PRIMARY KEY (`url_rewrite_id`), + UNIQUE INDEX `UNQ_CORE_URL_REWRITE_REQUEST_PATH_STORE_ID` (`request_path`, `store_id`), + UNIQUE INDEX `UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID` (`id_path`, `is_system`, `store_id`), + INDEX `IDX_CORE_URL_REWRITE_TARGET_PATH_STORE_ID` (`target_path`, `store_id`), + INDEX `IDX_CORE_URL_REWRITE_ID_PATH` (`id_path`), + INDEX `IDX_CORE_URL_REWRITE_STORE_ID` (`store_id`), + INDEX `FK_CORE_URL_REWRITE_PRODUCT_ID_CATALOG_PRODUCT_ENTITY_ENTITY_ID` (`product_id`), + INDEX `FK_CORE_URL_REWRITE_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` (`category_id`), + CONSTRAINT `FK_CORE_URL_REWRITE_CTGR_ID_CAT_CTGR_ENTT_ENTT_ID` FOREIGN KEY (`category_id`) REFERENCES `catalog_category_entity` (`entity_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CORE_URL_REWRITE_PRODUCT_ID_CATALOG_PRODUCT_ENTITY_ENTITY_ID` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CORE_URL_REWRITE_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Url Rewrites' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (1, 1, 3, 0, 'category/3', 'newcat.html', 'catalog/category/view/id/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (2, 2, 3, 0, 'category/3', 'newcat.html', 'catalog/category/view/id/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (3, 1, 3, 1, 'product/1/3', NULL, 'catalog/product/view/id/1/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (4, 1, 0, 1, 'product/1', NULL, 'catalog/product/view/id/1', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (5, 2, 3, 1, 'product/1/3', NULL, 'catalog/product/view/id/1/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (6, 2, 0, 1, 'product/1', NULL, 'catalog/product/view/id/1', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (7, 1, 3, 2, 'product/2/3', 'newcat/virtual-product.html', 'catalog/product/view/id/2/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (8, 1, 0, 2, 'product/2', 'virtual-product.html', 'catalog/product/view/id/2', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (9, 2, 3, 2, 'product/2/3', 'newcat/virtual-product.html', 'catalog/product/view/id/2/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (10, 2, 0, 2, 'product/2', 'virtual-product.html', 'catalog/product/view/id/2', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (11, 1, 3, 3, 'product/3/3', 'newcat/gift-card.html', 'catalog/product/view/id/3/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (12, 1, 0, 3, 'product/3', 'gift-card.html', 'catalog/product/view/id/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (13, 2, 3, 3, 'product/3/3', 'newcat/gift-card.html', 'catalog/product/view/id/3/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (14, 2, 0, 3, 'product/3', 'gift-card.html', 'catalog/product/view/id/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (15, 1, 3, 4, 'product/4/3', 'newcat/downloadable-product.html', 'catalog/product/view/id/4/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (16, 1, 0, 4, 'product/4', 'downloadable-product.html', 'catalog/product/view/id/4', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (17, 2, 3, 4, 'product/4/3', 'newcat/downloadable-product.html', 'catalog/product/view/id/4/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (18, 2, 0, 4, 'product/4', 'downloadable-product.html', 'catalog/product/view/id/4', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (19, 1, 3, 5, 'product/5/3', 'newcat/grouped-product.html', 'catalog/product/view/id/5/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (20, 1, 0, 5, 'product/5', 'grouped-product.html', 'catalog/product/view/id/5', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (21, 2, 3, 5, 'product/5/3', 'newcat/grouped-product.html', 'catalog/product/view/id/5/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (22, 2, 0, 5, 'product/5', 'grouped-product.html', 'catalog/product/view/id/5', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (23, 1, 3, 6, 'product/6/3', 'newcat/bundle-product.html', 'catalog/product/view/id/6/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (24, 1, 0, 6, 'product/6', 'bundle-product.html', 'catalog/product/view/id/6', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (25, 2, 3, 6, 'product/6/3', 'newcat/bundle-product.html', 'catalog/product/view/id/6/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (26, 2, 0, 6, 'product/6', 'bundle-product.html', 'catalog/product/view/id/6', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (29, 1, 0, 8, 'product/8', 'simple-product-1.html', 'catalog/product/view/id/8', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (30, 2, 0, 8, 'product/8', 'simple-product-1.html', 'catalog/product/view/id/8', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (31, 1, 3, 9, 'product/9/3', 'newcat/simple-product-2.html', 'catalog/product/view/id/9/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (32, 1, 0, 9, 'product/9', 'simple-product-2.html', 'catalog/product/view/id/9', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (33, 2, 3, 9, 'product/9/3', 'newcat/simple-product-2.html', 'catalog/product/view/id/9/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (34, 2, 0, 9, 'product/9', 'simple-product-2.html', 'catalog/product/view/id/9', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (35, 1, 3, 10, 'product/10/3', 'newcat/configurableproduct.html', 'catalog/product/view/id/10/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (36, 1, 0, 10, 'product/10', 'configurableproduct.html', 'catalog/product/view/id/10', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (37, 2, 3, 10, 'product/10/3', 'newcat/configurableproduct.html', 'catalog/product/view/id/10/category/3', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (38, 2, 0, 10, 'product/10', 'configurableproduct.html', 'catalog/product/view/id/10', 1, '', NULL); diff --git a/tests/integration/testsuite/Migration/Step/UrlRewrite/Version11410to2000Test.php b/tests/integration/testsuite/Migration/Step/UrlRewrite/Version11410to2000Test.php index c41cbcf78..9393d74b5 100644 --- a/tests/integration/testsuite/Migration/Step/UrlRewrite/Version11410to2000Test.php +++ b/tests/integration/testsuite/Migration/Step/UrlRewrite/Version11410to2000Test.php @@ -8,7 +8,7 @@ /** * UrlRewrite step test class - * @dbFixture url_rewrite + * @dbFixture url_rewrite_11410 */ class Version11410to2000Test extends \PHPUnit_Framework_TestCase { diff --git a/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php b/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php new file mode 100644 index 000000000..5af4743c2 --- /dev/null +++ b/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php @@ -0,0 +1,109 @@ +objectManager = $helper->getObjectManager(); + $this->objectManager->get('\Migration\Config') + ->init(dirname(__DIR__) . '/../_files/' . $helper->getFixturePrefix() . 'config.xml'); + $this->tableName = 'url_rewrite_m2' . md5('url_rewrite_m2'); + $logManager = $this->objectManager->create('\Migration\Logger\Manager'); + $this->logger = $this->objectManager->create('\Migration\Logger\Logger'); + $this->logger->pushHandler($this->objectManager->create('\Migration\Logger\ConsoleHandler')); + $this->config = $this->objectManager->get('\Migration\Config'); + /** @var \Migration\Logger\Manager $logManager */ + $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR); + \Migration\Logger\Logger::clearMessages(); + } + + /** + * @return void + */ + public function testIntegrity() + { + $urlRewrite = $this->objectManager->create( + '\Migration\Step\UrlRewrite\Version191to2000', + [ + 'logger' => $this->logger, + 'config' => $this->config, + 'stage' => 'integrity' + ] + ); + ob_start(); + $result = $urlRewrite->perform(); + ob_end_clean(); + $this->assertTrue($result); + } + + /** + * @return void + */ + public function testData() + { + $urlRewrite = $this->objectManager->create( + '\Migration\Step\UrlRewrite\Version191to2000', + [ + 'logger' => $this->logger, + 'config' => $this->config, + 'stage' => 'data' + ] + ); + /** @var \Migration\ResourceModel\Destination $destination */ + $destination = $this->objectManager->get('\Migration\ResourceModel\Destination'); + ob_start(); + $urlRewrite->perform(); + ob_end_clean(); + + $logOutput = \Migration\Logger\Logger::getMessages(); + $this->assertTrue(empty($logOutput[\Monolog\Logger::ERROR])); + $this->assertEquals(5, $destination->getRecordsCount('url_rewrite')); + $this->assertEquals(3, $destination->getRecordsCount('catalog_url_rewrite_product_category')); + + $urlRewrite = $this->objectManager->create( + '\Migration\Step\UrlRewrite\Version191to2000', + [ + 'logger' => $this->logger, + 'config' => $this->config, + 'stage' => 'volume' + ] + ); + $result = $urlRewrite->perform(); + $this->assertTrue($result); + } +} From 9cbd537355a92d8d38dc92978123b941f54b8b4b Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Tue, 19 Jul 2016 18:21:23 +0300 Subject: [PATCH 09/30] MAGETWO-52582: [GitHub] Data Migration "hung" at "Customer Attributes Step" #75 --- .../Step/UrlRewrite/Version191to2000Test.php | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/tests/unit/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php b/tests/unit/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php index ca192961e..70fd39c68 100644 --- a/tests/unit/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php +++ b/tests/unit/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php @@ -47,6 +47,16 @@ class Version191to2000Test extends \PHPUnit_Framework_TestCase */ protected $recordFactory; + /** + * @var int + */ + private $recordsAmount = 123; + + /** + * @var int + */ + private $pageSize = 20; + /** * @return void */ @@ -190,13 +200,13 @@ public function testIntegrity() */ public function testData() { - $countCmsPageRewrites = 1; - $recordsAmount = 123; - $progressRecordsAmount = $recordsAmount + $countCmsPageRewrites; - + $progressRecordsAmount = ceil($this->recordsAmount / $this->pageSize); $this->source->expects($this->once()) ->method('getRecordsCount') - ->willReturn($recordsAmount); + ->willReturn($this->recordsAmount); + $this->source->expects($this->once()) + ->method('getPageSize') + ->willReturn($this->pageSize); $this->progress->expects($this->at(0)) ->method('start') ->with($this->equalTo($progressRecordsAmount)); @@ -231,7 +241,7 @@ public function testData() [\Migration\Step\UrlRewrite\Version191to2000::DESTINATION_PRODUCT_CATEGORY] ); - $this->source->expects($this->at(2)) + $this->source->expects($this->at(3)) ->method('getRecords') ->with($this->equalTo(\Migration\Step\UrlRewrite\Version191to2000::SOURCE), $this->equalTo(0)) ->willReturn(['RecordData1']); From ba52cd4daa19f9c1fba016a2267cdebffdcbb113 Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Thu, 21 Jul 2016 11:43:10 +0300 Subject: [PATCH 10/30] MAGETWO-55303: [GitHub] Errors on EAV step #112 --- etc/ce-to-ce/eav-document-groups.xml.dist | 3 +- etc/ce-to-ee/eav-document-groups.xml.dist | 3 +- etc/ee-to-ee/eav-document-groups.xml.dist | 3 +- src/Migration/Step/Eav/Data.php | 398 ++++++++++++---------- src/Migration/Step/Eav/Helper.php | 8 +- src/Migration/Step/Eav/InitialData.php | 17 +- 6 files changed, 238 insertions(+), 194 deletions(-) diff --git a/etc/ce-to-ce/eav-document-groups.xml.dist b/etc/ce-to-ce/eav-document-groups.xml.dist index c4940cbd6..9acd4c8f1 100644 --- a/etc/ce-to-ce/eav-document-groups.xml.dist +++ b/etc/ce-to-ce/eav-document-groups.xml.dist @@ -15,9 +15,8 @@ customer_eav_attribute eav_entity_type - + catalog_eav_attribute customer_eav_attribute - eav_entity_type diff --git a/etc/ce-to-ee/eav-document-groups.xml.dist b/etc/ce-to-ee/eav-document-groups.xml.dist index c4940cbd6..9acd4c8f1 100644 --- a/etc/ce-to-ee/eav-document-groups.xml.dist +++ b/etc/ce-to-ee/eav-document-groups.xml.dist @@ -15,9 +15,8 @@ customer_eav_attribute eav_entity_type - + catalog_eav_attribute customer_eav_attribute - eav_entity_type diff --git a/etc/ee-to-ee/eav-document-groups.xml.dist b/etc/ee-to-ee/eav-document-groups.xml.dist index dbfcc9089..5a59057a5 100644 --- a/etc/ee-to-ee/eav-document-groups.xml.dist +++ b/etc/ee-to-ee/eav-document-groups.xml.dist @@ -16,10 +16,9 @@ eav_entity_type enterprise_rma_item_eav_attribute - + catalog_eav_attribute customer_eav_attribute - eav_entity_type enterprise_rma_item_eav_attribute diff --git a/src/Migration/Step/Eav/Data.php b/src/Migration/Step/Eav/Data.php index 214eab27b..3fecbe559 100644 --- a/src/Migration/Step/Eav/Data.php +++ b/src/Migration/Step/Eav/Data.php @@ -27,37 +27,45 @@ */ class Data implements StageInterface, RollbackInterface { - const ENTITY_TYPE_ID_CATALOG_PRODUCT = 4; + /** + * @var array; + */ + protected $newAttributeSets = []; + + /** + * @var array; + */ + protected $mapAttributeIdsDestOldNew = []; /** * @var array; */ - protected $newAttributes; + protected $mapAttributeIdsSourceDest = []; /** * @var array; */ - protected $newAttributeSets; + protected $mapAttributeSetIdsDestOldNew = []; /** * @var array; */ - protected $newAttributeGroups; + protected $mapAttributeGroupIdsDestOldNew = []; /** * @var array; */ - protected $destAttributeOldNewMap; + protected $mapEntityTypeIdsDestOldNew = []; /** * @var array; */ - protected $destAttributeSetsOldNewMap; + protected $mapEntityTypeIdsSourceDest = []; /** * @var array; */ - protected $destAttributeGroupsOldNewMap; + protected $entityTypesWithOldAttributeSetIds = []; /** * @var Helper @@ -158,16 +166,71 @@ public function perform() { $this->progress->start($this->getIterationsCount()); $this->initialData->init(); + $this->migrateEntityTypes(); $this->migrateAttributeSetsAndGroups(); + $this->changeOldAttributeSetIdsInEntityTypes(); $this->migrateAttributes(); + $this->migrateAttributesExtended(); $this->migrateEntityAttributes(); - $this->migrateMappedTables(); $this->progress->finish(); return true; } + /** + * Migrate Entity Type table + * + * @return void + */ + protected function migrateEntityTypes() + { + $documentName = 'eav_entity_type'; + $mappingField = 'entity_type_code'; + + $this->progress->advance(); + $sourceDocument = $this->source->getDocument($documentName); + $destinationDocument = $this->destination->getDocument( + $this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE) + ); + $this->destination->backupDocument($destinationDocument->getName()); + $destinationRecords = $this->helper->getDestinationRecords($documentName, [$mappingField]); + $recordsToSave = $destinationDocument->getRecords(); + foreach ($this->helper->getSourceRecords($documentName) as $recordData) { + /** @var Record $sourceRecord */ + $sourceRecord = $this->factory->create(['document' => $sourceDocument, 'data' => $recordData]); + /** @var Record $destinationRecord */ + $destinationRecord = $this->factory->create(['document' => $destinationDocument]); + $mappingValue = $sourceRecord->getValue($mappingField); + if (isset($destinationRecords[$mappingValue])) { + $destinationRecordData = $destinationRecords[$mappingValue]; + unset($destinationRecords[$mappingValue]); + } else { + $destinationRecordData = array_fill_keys($destinationRecord->getFields(), null); + } + $destinationRecord->setData($destinationRecordData); + $this->helper->getRecordTransformer($sourceDocument, $destinationDocument) + ->transform($sourceRecord, $destinationRecord); + $recordsToSave->addRecord($destinationRecord); + } + $this->destination->clearDocument($destinationDocument->getName()); + $this->saveRecords($destinationDocument, $recordsToSave); + + $recordsToSave = $destinationDocument->getRecords(); + foreach ($destinationRecords as $record) { + $this->entityTypesWithOldAttributeSetIds[] = $record['entity_type_code']; + $record['entity_type_id'] = null; + $destinationRecord = $this->factory->create([ + 'document' => $destinationDocument, + 'data' => $record + ]); + $recordsToSave->addRecord($destinationRecord); + } + $this->saveRecords($destinationDocument, $recordsToSave); + $this->createMapEntityTypeIds(); + } + /** * Migrate eav_attribute_set and eav_attribute_group + * * @return void */ protected function migrateAttributeSetsAndGroups() @@ -194,6 +257,7 @@ protected function migrateAttributeSetsAndGroups() if ($documentName == 'eav_attribute_set') { foreach ($this->initialData->getAttributeSets('dest') as $record) { $record['attribute_set_id'] = null; + $record['entity_type_id'] = $this->mapEntityTypeIdsDestOldNew[$record['entity_type_id']]; $destinationRecord = $this->factory->create( [ 'document' => $destinationDocument, @@ -207,8 +271,9 @@ protected function migrateAttributeSetsAndGroups() if ($documentName == 'eav_attribute_group') { foreach ($this->initialData->getAttributeGroups('dest') as $record) { $oldAttributeSet = $this->initialData->getAttributeSets('dest')[$record['attribute_set_id']]; + $entityTypeId = $this->mapEntityTypeIdsDestOldNew[$oldAttributeSet['entity_type_id']]; $newAttributeSet = $this->newAttributeSets[ - $oldAttributeSet['entity_type_id'] . '-' . $oldAttributeSet['attribute_set_name'] + $entityTypeId . '-' . $oldAttributeSet['attribute_set_name'] ]; $record['attribute_set_id'] = $newAttributeSet['attribute_set_id']; @@ -227,10 +292,10 @@ protected function migrateAttributeSetsAndGroups() $this->destination->clearDocument($destinationDocument->getName()); $this->saveRecords($destinationDocument, $recordsToSave); if ($documentName == 'eav_attribute_set') { - $this->loadNewAttributeSets(); + $this->createMapAttributeSetIds(); } if ($documentName == 'eav_attribute_group') { - $this->loadNewAttributeGroups(); + $this->createMapAttributeGroupIds(); } } } @@ -245,6 +310,8 @@ protected function migrateAttributeSetsAndGroups() */ protected function addAttributeGroups($recordsToSave, $documentName, array $groupsData) { + $entityTypeIdCatalogProduct = $this->helper->getSourceRecords('eav_entity_type', ['entity_type_code']) + ['catalog_product']['entity_type_id']; /** @var \Magento\Framework\DB\Select $select */ $select = $this->source->getAdapter()->getSelect(); $select->from( @@ -252,7 +319,7 @@ protected function addAttributeGroups($recordsToSave, $documentName, array $grou ['attribute_set_id'] )->where( 'entity_type_id = ?', - self::ENTITY_TYPE_ID_CATALOG_PRODUCT + $entityTypeIdCatalogProduct ); $catalogProductSetIds = $select->getAdapter()->fetchCol($select); $addedGroups = []; @@ -284,8 +351,39 @@ protected function addAttributeGroups($recordsToSave, $documentName, array $grou return $recordsToSave; } + /** + * Change old default attribute set ids in entity types + * + * @return void + */ + protected function changeOldAttributeSetIdsInEntityTypes() + { + $documentName = 'eav_entity_type'; + $destinationDocument = $this->destination->getDocument( + $this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE) + ); + $recordsToSave = $destinationDocument->getRecords(); + $entityTypesMigrated = $this->helper->getDestinationRecords($destinationDocument->getName()); + foreach ($entityTypesMigrated as $record) { + if (in_array($record['entity_type_code'], $this->entityTypesWithOldAttributeSetIds)) { + $record['default_attribute_set_id'] = + $this->mapAttributeSetIdsDestOldNew[$record['default_attribute_set_id']]; + } + $destinationRecord = $this->factory->create( + [ + 'document' => $destinationDocument, + 'data' => $record + ] + ); + $recordsToSave->addRecord($destinationRecord); + } + $this->destination->clearDocument($destinationDocument->getName()); + $this->saveRecords($destinationDocument, $recordsToSave); + } + /** * Migrate eav_attribute + * * @return void */ protected function migrateAttributes() @@ -310,11 +408,14 @@ protected function migrateAttributes() /** @var Record $destinationRecord */ $destinationRecord = $this->factory->create(['document' => $destinationDocument]); - $entityTypeMappedId = $this->getEntityTypeIdMappedByCode($sourceRecord->getValue('entity_type_id'), true); - $mappingValue = $entityTypeMappedId . '-' . $sourceRecord->getValue('attribute_code'); - if (isset($destinationRecords[$mappingValue])) { - $destinationRecordData = $destinationRecords[$mappingValue]; - unset($destinationRecords[$mappingValue]); + if (!isset($this->mapEntityTypeIdsSourceDest[$sourceRecord->getValue('entity_type_id')])) { + continue; + } + $mappedId = $this->mapEntityTypeIdsSourceDest[$sourceRecord->getValue('entity_type_id')]; + $mappedKey = $mappedId . '-' . $sourceRecord->getValue('attribute_code'); + if (isset($destinationRecords[$mappedKey])) { + $destinationRecordData = $destinationRecords[$mappedKey]; + unset($destinationRecords[$mappedKey]); } else { $destinationRecordData = array_fill_keys($destinationRecord->getFields(), null); } @@ -331,13 +432,13 @@ protected function migrateAttributes() $destinationRecord->setValue('attribute_id', null); $destinationRecord->setValue( 'entity_type_id', - $this->getEntityTypeIdMappedByCode($destinationRecord->getValue('entity_type_id'), false) + $this->mapEntityTypeIdsDestOldNew[$destinationRecord->getValue('entity_type_id')] ); $recordsToSave->addRecord($destinationRecord); } $this->destination->clearDocument($destinationDocument->getName()); $this->saveRecords($destinationDocument, $recordsToSave); - $this->loadNewAttributes(); + $this->createMapAttributeIds(); } /** @@ -367,15 +468,17 @@ protected function migrateEntityAttributes() } foreach ($this->helper->getDestinationRecords('eav_entity_attribute') as $record) { - if (!isset($this->destAttributeOldNewMap[$record['attribute_id']]) - || !isset($this->destAttributeSetsOldNewMap[$record['attribute_set_id']]) - || !isset($this->destAttributeGroupsOldNewMap[$record['attribute_group_id']]) + if (!isset($this->mapAttributeIdsDestOldNew[$record['attribute_id']]) + || !isset($this->mapAttributeSetIdsDestOldNew[$record['attribute_set_id']]) + || !isset($this->mapAttributeGroupIdsDestOldNew[$record['attribute_group_id']]) + || !isset($this->mapEntityTypeIdsDestOldNew[$record['entity_type_id']]) ) { continue; } - $record['attribute_id'] = $this->destAttributeOldNewMap[$record['attribute_id']]; - $record['attribute_set_id'] = $this->destAttributeSetsOldNewMap[$record['attribute_set_id']]; - $record['attribute_group_id'] = $this->destAttributeGroupsOldNewMap[$record['attribute_group_id']]; + $record['attribute_id'] = $this->mapAttributeIdsDestOldNew[$record['attribute_id']]; + $record['attribute_set_id'] = $this->mapAttributeSetIdsDestOldNew[$record['attribute_set_id']]; + $record['attribute_group_id'] = $this->mapAttributeGroupIdsDestOldNew[$record['attribute_group_id']]; + $record['entity_type_id'] = $this->mapEntityTypeIdsDestOldNew[$record['entity_type_id']]; $record['entity_attribute_id'] = null; $destinationRecord = $this->factory->create(['document' => $destinationDocument, 'data' => $record]); @@ -383,7 +486,7 @@ protected function migrateEntityAttributes() } $recordsToSave = $this->processDesignEntityAttributes($recordsToSave); - $recordsToSave = $this->moveAttributes($recordsToSave); + $recordsToSave = $this->moveProductAttributes($recordsToSave); $this->destination->clearDocument($destinationDocument->getName()); $this->saveRecords($destinationDocument, $recordsToSave); @@ -395,11 +498,11 @@ protected function migrateEntityAttributes() * @param Record\Collection $recordsToSave * @return Record\Collection */ - private function moveAttributes($recordsToSave) + private function moveProductAttributes($recordsToSave) { - $this->moveAttributeToGroup($recordsToSave, 'price', 'product-details'); - $this->moveAttributeToGroup($recordsToSave, 'shipment_type', 'bundle-items'); - $this->addAttributeToGroup($recordsToSave, 'quantity_and_stock_status', 'product-details'); + $this->moveProductAttributeToGroup($recordsToSave, 'price', 'product-details'); + $this->moveProductAttributeToGroup($recordsToSave, 'shipment_type', 'bundle-items'); + $this->addProductAttributeToGroup($recordsToSave, 'quantity_and_stock_status', 'product-details'); return $recordsToSave; } @@ -411,8 +514,10 @@ private function moveAttributes($recordsToSave) * @param string $attributeGroupCode * @return Record\Collection */ - private function moveAttributeToGroup($recordsToSave, $attributeCode, $attributeGroupCode) + private function moveProductAttributeToGroup($recordsToSave, $attributeCode, $attributeGroupCode) { + $productEntityType + = $this->helper->getSourceRecords('eav_entity_type', ['entity_type_code'])['catalog_product']; $attributes = $this->helper->getDestinationRecords('eav_attribute', ['attribute_id']); $attributeGroups = $this->helper->getDestinationRecords('eav_attribute_group', ['attribute_group_id']); $attributeSetGroups = []; @@ -424,7 +529,10 @@ private function moveAttributeToGroup($recordsToSave, $attributeCode, $attribute } foreach ($recordsToSave as $record) { $attributeId = $record->getValue('attribute_id'); - if (!isset($attributes[$attributeId])) { + $entityTypeId = $record->getValue('entity_type_id'); + if (!isset($attributes[$attributeId]) + || $entityTypeId != $productEntityType['entity_type_id'] + ) { continue; } if ($attributes[$attributeId]['attribute_code'] == $attributeCode) { @@ -445,8 +553,10 @@ private function moveAttributeToGroup($recordsToSave, $attributeCode, $attribute * @param string $attributeGroupCode * @return Record\Collection */ - private function addAttributeToGroup($recordsToSave, $attributeCode, $attributeGroupCode) + private function addProductAttributeToGroup($recordsToSave, $attributeCode, $attributeGroupCode) { + $productEntityType + = $this->helper->getSourceRecords('eav_entity_type', ['entity_type_code'])['catalog_product']; $attributes = $this->helper->getDestinationRecords('eav_attribute', ['attribute_id']); $attributeGroups = $this->helper->getDestinationRecords('eav_attribute_group', ['attribute_group_id']); $attributeSetGroups = []; @@ -459,7 +569,10 @@ private function addAttributeToGroup($recordsToSave, $attributeCode, $attributeG $attribute = null; foreach ($recordsToSave as $record) { $attributeId = $record->getValue('attribute_id'); - if (!isset($attributes[$attributeId])) { + $entityTypeId = $record->getValue('entity_type_id'); + if (!isset($attributes[$attributeId]) + || $entityTypeId != $productEntityType['entity_type_id'] + ) { continue; } if ($attributes[$attributeId]['attribute_code'] == $attributeCode) { @@ -498,19 +611,7 @@ private function addAttributeToGroup($recordsToSave, $attributeCode, $attributeG */ private function processDesignEntityAttributes($recordsToSave) { - $entityTypeIdCatalogProduct = 0; - foreach ($this->helper->getDestinationRecords('eav_entity_type') as $record) { - if ('catalog_product' == $record['entity_type_code']) { - $entityTypeIdCatalogProduct = $record['entity_type_id']; - break; - } - } - $entityTypeIdCatalogProductMapped = $this->getEntityTypeIdMappedByCode($entityTypeIdCatalogProduct, false); - $data = $this->helper->getDesignAttributeAndGroupsData( - $entityTypeIdCatalogProduct, - $entityTypeIdCatalogProductMapped - ); - + $data = $this->helper->getDesignAttributeAndGroupsData(); $entityAttributeDocument = $this->destination->getDocument( $this->map->getDocumentMap('eav_entity_attribute', MapInterface::TYPE_SOURCE) ); @@ -530,7 +631,7 @@ private function processDesignEntityAttributes($recordsToSave) if (isset($data['customDesignAttributeId']) && $data['customDesignAttributeId']) { $dataRecord = [ 'entity_attribute_id' => null, - 'entity_type_id' => $entityTypeIdCatalogProductMapped, + 'entity_type_id' => $data['entityTypeIdCatalogProduct'], 'attribute_set_id' => $group['attribute_set_id'], 'attribute_group_id' => $group['attribute_group_id'], 'attribute_id' => $data['customDesignAttributeId'], @@ -547,7 +648,7 @@ private function processDesignEntityAttributes($recordsToSave) if (isset($data['customLayoutAttributeId']) && $data['customLayoutAttributeId']) { $dataRecord = [ 'entity_attribute_id' => null, - 'entity_type_id' => $entityTypeIdCatalogProductMapped, + 'entity_type_id' => $data['entityTypeIdCatalogProduct'], 'attribute_set_id' => $group['attribute_set_id'], 'attribute_group_id' => $group['attribute_group_id'], 'attribute_id' => $data['customLayoutAttributeId'], @@ -566,75 +667,54 @@ private function processDesignEntityAttributes($recordsToSave) } /** - * Migrate EAV tables which in result must have all unique records from both source and destination documents + * Migrate tables extended from eav_attribute + * * @return void */ - protected function migrateMappedTables() + protected function migrateAttributesExtended() { - $documents = $this->readerGroups->getGroup('mapped_documents'); - - foreach ($documents as $documentName => $mappingFields) { + $documents = $this->readerGroups->getGroup('documents_attribute_extended'); + foreach ($documents as $documentName => $mappingField) { $this->progress->advance(); $sourceDocument = $this->source->getDocument($documentName); $destinationDocument = $this->destination->getDocument( $this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE) ); $this->destination->backupDocument($destinationDocument->getName()); - $mappingFields = explode(',', $mappingFields); - $destinationRecords = $this->helper->getDestinationRecords($documentName, $mappingFields); + $destinationRecords = $this->helper->getDestinationRecords($documentName, [$mappingField]); $recordsToSave = $destinationDocument->getRecords(); foreach ($this->helper->getSourceRecords($documentName) as $recordData) { /** @var Record $sourceRecord */ $sourceRecord = $this->factory->create(['document' => $sourceDocument, 'data' => $recordData]); /** @var Record $destinationRecord */ $destinationRecord = $this->factory->create(['document' => $destinationDocument]); - - $mappingValue = $this->getMappingValue($sourceRecord, $mappingFields); - if (isset($destinationRecords[$mappingValue])) { - $destinationRecordData = $destinationRecords[$mappingValue]; - unset($destinationRecords[$mappingValue]); + if (!isset($this->mapAttributeIdsSourceDest[$sourceRecord->getValue($mappingField)])) { + continue; + } + $mappedId = $this->mapAttributeIdsSourceDest[$sourceRecord->getValue($mappingField)]; + if (isset($destinationRecords[$mappedId])) { + $destinationRecordData = $destinationRecords[$mappedId]; + unset($destinationRecords[$mappedId]); } else { $destinationRecordData = array_fill_keys($destinationRecord->getFields(), null); } $destinationRecord->setData($destinationRecordData); - $this->helper->getRecordTransformer($sourceDocument, $destinationDocument) ->transform($sourceRecord, $destinationRecord); - - if ($documentName == 'eav_entity_type') { - $oldAttributeSetValue = $destinationRecord->getValue('default_attribute_set_id'); - if (isset($this->destAttributeSetsOldNewMap[$oldAttributeSetValue])) { - $destinationRecord->setValue( - 'default_attribute_set_id', - $this->destAttributeSetsOldNewMap[$oldAttributeSetValue] - ); - } - } - $recordsToSave->addRecord($destinationRecord); } $this->destination->clearDocument($destinationDocument->getName()); $this->saveRecords($destinationDocument, $recordsToSave); $recordsToSave = $destinationDocument->getRecords(); - if ($mappingFields) { - foreach ($destinationRecords as $record) { - $destinationRecord = $this->factory->create([ - 'document' => $destinationDocument, - 'data' => $record - ]); - if (isset($record['attribute_id']) - && isset($this->destAttributeOldNewMap[$record['attribute_id']]) - ) { - $destinationRecord->setValue( - 'attribute_id', - $this->destAttributeOldNewMap[$record['attribute_id']] - ); - } - $recordsToSave->addRecord($destinationRecord); - } + foreach ($destinationRecords as $record) { + $record['attribute_id'] = $this->mapAttributeIdsDestOldNew[$record['attribute_id']]; + $destinationRecord = $this->factory->create([ + 'document' => $destinationDocument, + 'data' => $record + ]); + $recordsToSave->addRecord($destinationRecord); } - $this->saveRecords($destinationDocument, $recordsToSave); } } @@ -650,127 +730,103 @@ protected function saveRecords(Document $document, Record\Collection $recordsToS } /** - * @param Record $sourceRecord - * @param array $keyFields - * @return string + * Create mapping for entity type ids + * + * @return void */ - protected function getMappingValue(Record $sourceRecord, $keyFields) + protected function createMapEntityTypeIds() { - $value = []; - foreach ($keyFields as $field) { - switch ($field) { - case 'attribute_id': - $value[] = $this->getDestinationAttributeId($sourceRecord->getValue($field)); - break; - default: - $value[] = $sourceRecord->getValue($field); - break; + $entityTypesMigrated = $this->helper->getDestinationRecords( + 'eav_entity_type', + ['entity_type_code'] + ); + foreach ($this->initialData->getEntityTypes('dest') as $entityTypeIdOld => $recordOld) { + $entityTypeMigrated = $entityTypesMigrated[$recordOld['entity_type_code']]; + $this->mapEntityTypeIdsDestOldNew[$entityTypeIdOld] = $entityTypeMigrated['entity_type_id']; + } + foreach ($this->initialData->getEntityTypes('source') as $entityTypeIdSource => $recordSource) { + $mapFound = false; + foreach ($this->initialData->getEntityTypes('dest') as $entityTypeIdDest => $recordDest) { + if ($recordSource['entity_type_code'] == $recordDest['entity_type_code']) { + $this->mapEntityTypeIdsSourceDest[$entityTypeIdSource] = $entityTypeIdDest; + $mapFound = true; + } + } + if (!$mapFound) { + $this->mapEntityTypeIdsSourceDest[$entityTypeIdSource] = $entityTypeIdSource; } } - return implode('-', $value); } /** - * Load migrated attribute sets data + * Create mapping for attribute set ids + * * @return void */ - protected function loadNewAttributeSets() + protected function createMapAttributeSetIds() { $this->newAttributeSets = $this->helper->getDestinationRecords( 'eav_attribute_set', ['entity_type_id', 'attribute_set_name'] ); foreach ($this->initialData->getAttributeSets('dest') as $attributeSetId => $record) { - $newAttributeSet = $this->newAttributeSets[$record['entity_type_id'] . '-' . $record['attribute_set_name']]; - $this->destAttributeSetsOldNewMap[$attributeSetId] = $newAttributeSet['attribute_set_id']; + $entityTypeId = $this->mapEntityTypeIdsDestOldNew[$record['entity_type_id']]; + $newAttributeSet = $this->newAttributeSets[$entityTypeId . '-' . $record['attribute_set_name']]; + $this->mapAttributeSetIdsDestOldNew[$attributeSetId] = $newAttributeSet['attribute_set_id']; } } /** - * Load migrated attribute groups data + * Create mapping for attribute group ids + * * @return void */ - protected function loadNewAttributeGroups() + protected function createMapAttributeGroupIds() { - $this->newAttributeGroups = $this->helper->getDestinationRecords( + $newAttributeGroups = $this->helper->getDestinationRecords( 'eav_attribute_group', ['attribute_set_id', 'attribute_group_name'] ); foreach ($this->initialData->getAttributeGroups('dest') as $record) { - $newKey = $this->destAttributeSetsOldNewMap[$record['attribute_set_id']] . '-' + $newKey = $this->mapAttributeSetIdsDestOldNew[$record['attribute_set_id']] . '-' . $record['attribute_group_name']; - $newAttributeGroup = $this->newAttributeGroups[$newKey]; - $this->destAttributeGroupsOldNewMap[$record['attribute_group_id']] = + $newAttributeGroup = $newAttributeGroups[$newKey]; + $this->mapAttributeGroupIdsDestOldNew[$record['attribute_group_id']] = $newAttributeGroup['attribute_group_id']; } } /** - * Load migrated attributes data - * @return array + * Create mapping for attribute ids + * + * @return void */ - protected function loadNewAttributes() + protected function createMapAttributeIds() { - $this->newAttributes = $this->helper->getDestinationRecords( + $newAttributes = $this->helper->getDestinationRecords( 'eav_attribute', ['entity_type_id', 'attribute_code'] ); - foreach ($this->initialData->getAttributes('dest') as $key => $attributeData) { - list($entityTypeId, $attributeCode) = explode('-', $key); - $key = $this->getEntityTypeIdMappedByCode($entityTypeId, false) . '-' . $attributeCode; - $this->destAttributeOldNewMap[$attributeData['attribute_id']] = $this->newAttributes[$key]['attribute_id']; + foreach ($this->initialData->getAttributes('dest') as $keyOld => $attributeOld) { + list($entityTypeId, $attributeCodeDest) = explode('-', $keyOld); + $keyMapped = $this->mapEntityTypeIdsDestOldNew[$entityTypeId] . '-' . $attributeCodeDest; + $this->mapAttributeIdsDestOldNew[$attributeOld['attribute_id']] = $newAttributes[$keyMapped]['attribute_id']; } - - return $this->newAttributes; - } - - /** - * Returns destination entity type id for correspondent source entity type id and vise versa - * Linking between two values is performed using entity_type_code - * @param int|string $initialEntityTypeId - * @param bool $returnDestId - * @return mixed - */ - protected function getEntityTypeIdMappedByCode($initialEntityTypeId, $returnDestId = true) - { - $id = $initialEntityTypeId; - $entityTypeIdsFrom = - $this->initialData->getEntityTypesWithKeyField($returnDestId ? 'source' : 'dest', 'entity_type_id'); - $entityTypeCodesTo = - $this->initialData->getEntityTypesWithKeyField($returnDestId ? 'dest' : 'source', 'entity_type_code'); - - if (isset($entityTypeIdsFrom[$initialEntityTypeId])) { - $entityTypeCode = $entityTypeIdsFrom[$initialEntityTypeId]['entity_type_code']; - if (isset($entityTypeCodesTo[$entityTypeCode])) { - $id = $entityTypeCodesTo[$entityTypeCode]['entity_type_id']; + foreach ($this->initialData->getAttributes('source') as $idSource => $attributeSource) { + $mapFound = false; + foreach ($this->initialData->getAttributes('dest') as $keyDest => $attributeDest) { + list($entityTypeIdDest, $attributeCodeDest) = explode('-', $keyDest); + $keyDestMapped = $this->mapEntityTypeIdsDestOldNew[$entityTypeIdDest] . '-' . $attributeCodeDest; + $keySource = $attributeSource['entity_type_id'] . '-' . $attributeSource['attribute_code']; + if ($keySource == $keyDestMapped) { + $this->mapAttributeIdsSourceDest[$idSource] = $attributeDest['attribute_id']; + $mapFound = true; + } + } + if (!$mapFound) { + $this->mapAttributeIdsSourceDest[$idSource] = $idSource; } } - - return $id; - } - - /** - * @param int $sourceAttributeId - * @return mixed - */ - protected function getDestinationAttributeId($sourceAttributeId) - { - $id = null; - $key = null; - if (isset($this->initialData->getAttributes('source')[$sourceAttributeId])) { - $entityTypeId = $this->getEntityTypeIdMappedByCode( - $this->initialData->getAttributes('source')[$sourceAttributeId]['entity_type_id'], - true - ); - $key = $entityTypeId . '-' - . $this->initialData->getAttributes('source')[$sourceAttributeId]['attribute_code']; - } - - if ($key && isset($this->initialData->getAttributes('dest')[$key])) { - $id = $this->initialData->getAttributes('dest')[$key]['attribute_id']; - } - - return $id; } /** diff --git a/src/Migration/Step/Eav/Helper.php b/src/Migration/Step/Eav/Helper.php index 8743b113a..2bb297424 100644 --- a/src/Migration/Step/Eav/Helper.php +++ b/src/Migration/Step/Eav/Helper.php @@ -181,18 +181,18 @@ public function setAddedGroups(array $addedGroups) } /** - * @param int|string $entityTypeIdCatalogProduct - * @param int|string $entityTypeIdCatalogProductMapped * @return array * @SuppressWarnings(PHPMD.CyclomaticComplexity) */ - public function getDesignAttributeAndGroupsData($entityTypeIdCatalogProduct, $entityTypeIdCatalogProductMapped) + public function getDesignAttributeAndGroupsData() { $scheduleGroupsMigrated = []; $catalogProductSetIdsMigrated = []; $catalogProductSetIdDefault = null; $customLayoutAttributeId = null; $customDesignAttributeId = null; + $entityTypeIdCatalogProduct = $this->getDestinationRecords('eav_entity_type', ['entity_type_code']) + ['catalog_product']['entity_type_id']; foreach ($this->getDestinationRecords('eav_attribute_set') as $record) { if ($entityTypeIdCatalogProduct == $record['entity_type_id']) { @@ -211,7 +211,7 @@ public function getDesignAttributeAndGroupsData($entityTypeIdCatalogProduct, $en } } foreach ($this->getDestinationRecords('eav_attribute') as $record) { - if ($record['entity_type_id'] == $entityTypeIdCatalogProductMapped) { + if ($record['entity_type_id'] == $entityTypeIdCatalogProduct) { switch ($record['attribute_code']) { case 'custom_layout': $customLayoutAttributeId = $record['attribute_id']; diff --git a/src/Migration/Step/Eav/InitialData.php b/src/Migration/Step/Eav/InitialData.php index e3e933ccd..c16f8ce72 100644 --- a/src/Migration/Step/Eav/InitialData.php +++ b/src/Migration/Step/Eav/InitialData.php @@ -91,16 +91,8 @@ public function init() protected function initEntityTypes() { if ($this->entityTypes === null) { - $sourceRecords = $this->helper->getSourceRecords('eav_entity_type'); - foreach ($sourceRecords as $record) { - $this->entityTypes['source']['entity_type_id'][$record['entity_type_id']] = $record; - $this->entityTypes['source']['entity_type_code'][$record['entity_type_code']] = $record; - } - $destinationRecords = $this->helper->getDestinationRecords('eav_entity_type'); - foreach ($destinationRecords as $record) { - $this->entityTypes['dest']['entity_type_id'][$record['entity_type_id']] = $record; - $this->entityTypes['dest']['entity_type_code'][$record['entity_type_code']] = $record; - } + $this->entityTypes['source'] = $this->helper->getSourceRecords('eav_entity_type', ['entity_type_id']); + $this->entityTypes['dest'] = $this->helper->getDestinationRecords('eav_entity_type', ['entity_type_id']); } } @@ -156,12 +148,11 @@ protected function initAttributeGroups() /** * @codeCoverageIgnore * @param string $type - * @param string $keyField * @return array */ - public function getEntityTypesWithKeyField($type, $keyField) + public function getEntityTypes($type) { - return $this->entityTypes[$type][$keyField]; + return $this->entityTypes[$type]; } /** From ccbbb2bff87979ea2605c13f9cd460a286154d44 Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Thu, 21 Jul 2016 12:04:10 +0300 Subject: [PATCH 11/30] MAGETWO-55399: Migration delta fails on SalesIncrement Step for EE 1.6 --- src/Migration/Step/SalesIncrement/Helper.php | 34 ++- .../resource/sales_increment/dest.sql | 94 +++++++ .../resource/sales_increment/source.sql | 93 +++++++ .../Step/SalesIncrement/DataTest.php | 232 ++++++++++++++++++ 4 files changed, 448 insertions(+), 5 deletions(-) create mode 100644 tests/integration/resource/sales_increment/dest.sql create mode 100644 tests/integration/resource/sales_increment/source.sql create mode 100644 tests/integration/testsuite/Migration/Step/SalesIncrement/DataTest.php diff --git a/src/Migration/Step/SalesIncrement/Helper.php b/src/Migration/Step/SalesIncrement/Helper.php index 98cb4c01e..87bfbfab9 100644 --- a/src/Migration/Step/SalesIncrement/Helper.php +++ b/src/Migration/Step/SalesIncrement/Helper.php @@ -7,6 +7,7 @@ use Migration\ResourceModel\Source; use Migration\ResourceModel\Destination; +use Migration\ResourceModel\Adapter\Mysql; /** * Class Helper @@ -69,27 +70,22 @@ class Helper */ protected $entityTypeTablesMap = [ [ - 'entity_type_id' => 5, 'entity_type_code' => 'order', 'entity_type_table' => 'sequence_order', 'column' => 'sequence_value' ], [ - 'entity_type_id' => 6, 'entity_type_code' => 'invoice', 'entity_type_table' => 'sequence_invoice', 'column' => 'sequence_value' ], [ - 'entity_type_id' => 7, 'entity_type_code' => 'creditmemo', 'entity_type_table' => 'sequence_creditmemo', 'column' => 'sequence_value' ], [ - 'entity_type_id' => 8, 'entity_type_code' => 'shipment', 'entity_type_table' => 'sequence_shipment', 'column' => 'sequence_value' ], [ - 'entity_type_id' => 9, 'entity_type_code' => 'rma_item', 'entity_type_table' => 'sequence_rma_item', 'column' => 'sequence_value' @@ -146,6 +142,12 @@ public function getStoreIds() */ public function getEntityTypeTablesMap() { + $entityIds = $this->getEntityTypeIdByCode(array_column($this->entityTypeTablesMap, 'entity_type_code')); + foreach ($this->entityTypeTablesMap as &$entityTypeTable) { + $entityTypeTable['entity_type_id'] = $entityIds[$entityTypeTable['entity_type_code']] + ? $entityIds[$entityTypeTable['entity_type_code']] + : null; + } return $this->entityTypeTablesMap; } @@ -193,4 +195,26 @@ public function getTableName($table, $storeId = false) ? $this->destination->addDocumentPrefix($table) . '_' . $storeId : $this->destination->addDocumentPrefix($table); } + + /** + * @param array $entityTypeCodes + * @return array + */ + protected function getEntityTypeIdByCode($entityTypeCodes) + { + /** @var Mysql $adapter */ + $adapter = $this->destination->getAdapter(); + $query = $adapter->getSelect() + ->from( + ['et' => $this->destination->addDocumentPrefix('eav_entity_type')], + ['entity_type_id', 'entity_type_code'] + ) + ->where('et.entity_type_code IN (?)', $entityTypeCodes); + $entityTypeIds = []; + foreach ($query->getAdapter()->fetchAll($query) as $record) { + $entityTypeIds[$record['entity_type_code']] = $record['entity_type_id']; + } + return $entityTypeIds; + + } } diff --git a/tests/integration/resource/sales_increment/dest.sql b/tests/integration/resource/sales_increment/dest.sql new file mode 100644 index 000000000..563e4b790 --- /dev/null +++ b/tests/integration/resource/sales_increment/dest.sql @@ -0,0 +1,94 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +DROP TABLE IF EXISTS `sales_sequence_meta`; +CREATE TABLE `sales_sequence_meta` ( + `meta_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Id', + `entity_type` VARCHAR(32) NOT NULL COMMENT 'Prefix', + `store_id` SMALLINT(5) UNSIGNED NOT NULL COMMENT 'Store Id', + `sequence_table` VARCHAR(32) NOT NULL COMMENT 'table for sequence', + PRIMARY KEY (`meta_id`), + UNIQUE INDEX `SALES_SEQUENCE_META_ENTITY_TYPE_STORE_ID` (`entity_type`, `store_id`) +) +COMMENT='sales_sequence_meta' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +DROP TABLE IF EXISTS `sales_sequence_profile`; +CREATE TABLE `sales_sequence_profile` ( + `profile_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Id', + `meta_id` INT(10) UNSIGNED NOT NULL COMMENT 'Meta_id', + `prefix` VARCHAR(32) NULL DEFAULT NULL COMMENT 'Prefix', + `suffix` VARCHAR(32) NULL DEFAULT NULL COMMENT 'Suffix', + `start_value` INT(10) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'Start value for sequence', + `step` INT(10) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'Step for sequence', + `max_value` INT(10) UNSIGNED NOT NULL COMMENT 'MaxValue for sequence', + `warning_value` INT(10) UNSIGNED NOT NULL COMMENT 'WarningValue for sequence', + `is_active` TINYINT(1) NOT NULL DEFAULT '0' COMMENT 'isActive flag', + PRIMARY KEY (`profile_id`), + UNIQUE INDEX `SALES_SEQUENCE_PROFILE_META_ID_PREFIX_SUFFIX` (`meta_id`, `prefix`, `suffix`), + CONSTRAINT `SALES_SEQUENCE_PROFILE_META_ID_SALES_SEQUENCE_META_META_ID` FOREIGN KEY (`meta_id`) REFERENCES `sales_sequence_meta` (`meta_id`) ON DELETE CASCADE +) +COMMENT='sales_sequence_profile' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; + +DROP TABLE IF EXISTS `eav_entity_type`; +CREATE TABLE `eav_entity_type` ( + `entity_type_id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity Type Id', + `entity_type_code` VARCHAR(50) NOT NULL COMMENT 'Entity Type Code', + `entity_model` VARCHAR(255) NOT NULL COMMENT 'Entity Model', + `attribute_model` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Attribute Model', + `entity_table` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Entity Table', + `value_table_prefix` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Value Table Prefix', + `entity_id_field` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Entity Id Field', + `is_data_sharing` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'Defines Is Data Sharing', + `data_sharing_key` VARCHAR(100) NULL DEFAULT 'default' COMMENT 'Data Sharing Key', + `default_attribute_set_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Default Attribute Set Id', + `increment_model` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Increment Model', + `increment_per_store` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Increment Per Store', + `increment_pad_length` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '8' COMMENT 'Increment Pad Length', + `increment_pad_char` VARCHAR(1) NOT NULL DEFAULT '0' COMMENT 'Increment Pad Char', + `additional_attribute_table` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Additional Attribute Table', + `entity_attribute_collection` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Entity Attribute Collection', + PRIMARY KEY (`entity_type_id`), + INDEX `IDX_EAV_ENTITY_TYPE_ENTITY_TYPE_CODE` (`entity_type_code`) +) +COMMENT='Eav Entity Type' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `eav_entity_type` VALUES +(11, 'order', 'Magento\\Sales\\Model\\ResourceModel\\Order', NULL, 'sales_order', '', '', 1, 'default', 11, 'Magento\\Eav\\Model\\Entity\\Increment\\NumericValue', 1, 8, '0', NULL, NULL), +(16, 'invoice', 'Magento\\Sales\\Model\\ResourceModel\\Order\\Invoice', NULL, 'sales_order_entity', '', '', 1, 'default', 16, 'Magento\\Eav\\Model\\Entity\\Increment\\NumericValue', 1, 8, '0', NULL, NULL), +(19, 'shipment', 'Magento\\Sales\\Model\\ResourceModel\\Order\\Shipment', NULL, 'sales_order_entity', '', '', 1, 'default', 19, 'Magento\\Eav\\Model\\Entity\\Increment\\NumericValue', 1, 8, '0', NULL, NULL), +(23, 'creditmemo', 'Magento\\Sales\\Model\\ResourceModel\\Order\\Creditmemo', NULL, 'sales_order_entity', '', '', 1, 'default', 23, 'Magento\\Eav\\Model\\Entity\\Increment\\NumericValue', 1, 8, '0', NULL, NULL), +(26, 'rma_item', 'Magento\\Rma\\Model\\ResourceModel\\Item', 'Magento\\Rma\\Model\\Item\\Attribute', 'magento_rma_item_entity', NULL, NULL, 1, 'default', 27, 'Magento\\Eav\\Model\\Entity\\Increment\\NumericValue', 1, 8, '0', 'magento_rma_item_eav_attribute', NULL); + + + +/*!40103 SET TIME_ZONE=@OLD_TIME_ZONE */; + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; + +-- Dump completed on 2015-01-29 19:44:27 diff --git a/tests/integration/resource/sales_increment/source.sql b/tests/integration/resource/sales_increment/source.sql new file mode 100644 index 000000000..6a90c6fd5 --- /dev/null +++ b/tests/integration/resource/sales_increment/source.sql @@ -0,0 +1,93 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */; +/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */; +/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */; +/*!40101 SET NAMES utf8 */; +/*!40103 SET @OLD_TIME_ZONE=@@TIME_ZONE */; +/*!40103 SET TIME_ZONE='+00:00' */; +/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */; +/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */; +/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */; +/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */; + +DROP TABLE IF EXISTS `core_store`; +CREATE TABLE `core_store` ( + `store_id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Store Id', + `code` VARCHAR(32) NULL DEFAULT NULL COMMENT 'Code', + `website_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Website Id', + `group_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Group Id', + `name` VARCHAR(255) NOT NULL COMMENT 'Store Name', + `sort_order` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Sort Order', + `is_active` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Activity', + PRIMARY KEY (`store_id`), + UNIQUE INDEX `UNQ_CORE_STORE_CODE` (`code`), + INDEX `IDX_CORE_STORE_WEBSITE_ID` (`website_id`), + INDEX `IDX_CORE_STORE_IS_ACTIVE_SORT_ORDER` (`is_active`, `sort_order`), + INDEX `IDX_CORE_STORE_GROUP_ID` (`group_id`), + CONSTRAINT `FK_CORE_STORE_GROUP_ID_CORE_STORE_GROUP_GROUP_ID` FOREIGN KEY (`group_id`) REFERENCES `core_store_group` (`group_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CORE_STORE_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Stores' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `core_store` VALUES +(0, 'admin', 0, 0, 'Admin', 0, 1), +(1, 'default', 1, 1, 'Default Store View', 0, 1); + +DROP TABLE IF EXISTS `core_store_group`; +CREATE TABLE `core_store_group` ( + `group_id` SMALLINT(5) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Group Id', + `website_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Website Id', + `name` VARCHAR(255) NOT NULL COMMENT 'Store Group Name', + `root_category_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Root Category Id', + `default_store_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Default Store Id', + PRIMARY KEY (`group_id`), + INDEX `IDX_CORE_STORE_GROUP_WEBSITE_ID` (`website_id`), + INDEX `IDX_CORE_STORE_GROUP_DEFAULT_STORE_ID` (`default_store_id`), + CONSTRAINT `FK_CORE_STORE_GROUP_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Store Groups' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `core_store_group` VALUES +(0, 0, 'Default', 0, 0), +(1, 1, 'Main Website Store', 2, 1); + +DROP TABLE IF EXISTS `eav_entity_store`; +CREATE TABLE `eav_entity_store` ( + `entity_store_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity Store Id', + `entity_type_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Entity Type Id', + `store_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Id', + `increment_prefix` VARCHAR(20) NULL DEFAULT NULL COMMENT 'Increment Prefix', + `increment_last_id` VARCHAR(50) NULL DEFAULT NULL COMMENT 'Last Incremented Id', + PRIMARY KEY (`entity_store_id`), + INDEX `IDX_EAV_ENTITY_STORE_ENTITY_TYPE_ID` (`entity_type_id`), + INDEX `IDX_EAV_ENTITY_STORE_STORE_ID` (`store_id`), + CONSTRAINT `FK_EAV_ENTITY_STORE_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_EAV_ENTT_STORE_ENTT_TYPE_ID_EAV_ENTT_TYPE_ENTT_TYPE_ID` FOREIGN KEY (`entity_type_id`) REFERENCES `eav_entity_type` (`entity_type_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Eav Entity Store' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `eav_entity_store` VALUES +(1, 1, 0, '0', '000000001'), +(2, 11, 1, '1', '100000003'), +(3, 16, 1, '1', '100000001'), +(4, 19, 1, '1', '100000001'); + + + +/*!40101 SET SQL_MODE=@OLD_SQL_MODE */; +/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */; +/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */; +/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */; +/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */; +/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */; +/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */; \ No newline at end of file diff --git a/tests/integration/testsuite/Migration/Step/SalesIncrement/DataTest.php b/tests/integration/testsuite/Migration/Step/SalesIncrement/DataTest.php new file mode 100644 index 000000000..f1cd05533 --- /dev/null +++ b/tests/integration/testsuite/Migration/Step/SalesIncrement/DataTest.php @@ -0,0 +1,232 @@ + 1, + 'entity_type' => 'order', + 'store_id' => 0, + 'sequence_table' => 'sequence_order_0', + ], + [ + 'meta_id' => 2, + 'entity_type' => 'order', + 'store_id' => 1, + 'sequence_table' => 'sequence_order_1', + ], + [ + 'meta_id' => 3, + 'entity_type' => 'invoice', + 'store_id' => 0, + 'sequence_table' => 'sequence_invoice_0', + ], + [ + 'meta_id' => 4, + 'entity_type' => 'invoice', + 'store_id' => 1, + 'sequence_table' => 'sequence_invoice_1', + ], + [ + 'meta_id' => 5, + 'entity_type' => 'creditmemo', + 'store_id' => 0, + 'sequence_table' => 'sequence_creditmemo_0', + ], + [ + 'meta_id' => 6, + 'entity_type' => 'creditmemo', + 'store_id' => 1, + 'sequence_table' => 'sequence_creditmemo_1', + ], + [ + 'meta_id' => 7, + 'entity_type' => 'shipment', + 'store_id' => 0, + 'sequence_table' => 'sequence_shipment_0', + ], + [ + 'meta_id' => 8, + 'entity_type' => 'shipment', + 'store_id' => 1, + 'sequence_table' => 'sequence_shipment_1', + ], + [ + 'meta_id' => 9, + 'entity_type' => 'rma_item', + 'store_id' => 0, + 'sequence_table' => 'sequence_rma_item_0', + ], + [ + 'meta_id' => 10, + 'entity_type' => 'rma_item', + 'store_id' => 1, + 'sequence_table' => 'sequence_rma_item_1', + ] + ]; + + /** + * @var array + */ + private $salesSequenceProfile = [ + [ + 'profile_id' => 1, + 'meta_id' => 1, + 'prefix' => '', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 2, + 'meta_id' => 2, + 'prefix' => '1', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 3, + 'meta_id' => 3, + 'prefix' => '', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 4, + 'meta_id' => 4, + 'prefix' => '1', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 5, + 'meta_id' => 5, + 'prefix' => '', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 6, + 'meta_id' => 6, + 'prefix' => '1', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 7, + 'meta_id' => 7, + 'prefix' => '', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 8, + 'meta_id' => 8, + 'prefix' => '1', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 9, + 'meta_id' => 9, + 'prefix' => '', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ], + [ + 'profile_id' => 10, + 'meta_id' => 10, + 'prefix' => '1', + 'suffix' => '', + 'start_value' => 1, + 'step' => 1, + 'max_value' => 4294967295, + 'warning_value' => 4294966295, + 'is_active' => 1, + ] + ]; + + /** + * @throws \Migration\Exception + * @return void + */ + public function testPerform() + { + $helper = \Migration\TestFramework\Helper::getInstance(); + $objectManager = $helper->getObjectManager(); + $objectManager->get('\Migration\Config') + ->init(dirname(__DIR__) . '/../_files/' . $helper->getFixturePrefix() . 'config.xml'); + $logManager = $objectManager->create('\Migration\Logger\Manager'); + $logger = $objectManager->create('\Migration\Logger\Logger'); + $config = $objectManager->get('\Migration\Config'); + $helper = $objectManager->get('\Migration\Step\SalesIncrement\Helper'); + $destination = $objectManager->get('\Migration\ResourceModel\Destination'); + /** @var \Migration\Logger\Manager $logManager */ + $logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR); + \Migration\Logger\Logger::clearMessages(); + /** @var \Migration\Step\SalesIncrement\Data $salesIncrement */ + $salesIncrement = $objectManager->create( + '\Migration\Step\SalesIncrement\Data', + [ + 'logger' => $logger, + 'config' => $config, + 'helper' => $helper + ] + ); + ob_start(); + $salesIncrement->perform(); + ob_end_clean(); + + $this->assertEquals($this->salesSequenceMeta, $destination->getRecords('sales_sequence_meta', 0)); + $this->assertEquals($this->salesSequenceProfile, $destination->getRecords('sales_sequence_profile', 0)); + $logOutput = \Migration\Logger\Logger::getMessages(); + $this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR])); + } +} From 0ada7816d9b888ebe165fc53a214260b51c5ed8b Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Fri, 22 Jul 2016 11:38:32 +0300 Subject: [PATCH 12/30] MAGETWO-55303: [GitHub] Errors on EAV step #112 --- src/Migration/Step/Eav/Data.php | 38 +++++++++------------------------ 1 file changed, 10 insertions(+), 28 deletions(-) diff --git a/src/Migration/Step/Eav/Data.php b/src/Migration/Step/Eav/Data.php index 3fecbe559..d7d44764f 100644 --- a/src/Migration/Step/Eav/Data.php +++ b/src/Migration/Step/Eav/Data.php @@ -62,11 +62,6 @@ class Data implements StageInterface, RollbackInterface */ protected $mapEntityTypeIdsSourceDest = []; - /** - * @var array; - */ - protected $entityTypesWithOldAttributeSetIds = []; - /** * @var Helper */ @@ -216,7 +211,6 @@ protected function migrateEntityTypes() $recordsToSave = $destinationDocument->getRecords(); foreach ($destinationRecords as $record) { - $this->entityTypesWithOldAttributeSetIds[] = $record['entity_type_code']; $record['entity_type_id'] = null; $destinationRecord = $this->factory->create([ 'document' => $destinationDocument, @@ -365,7 +359,7 @@ protected function changeOldAttributeSetIdsInEntityTypes() $recordsToSave = $destinationDocument->getRecords(); $entityTypesMigrated = $this->helper->getDestinationRecords($destinationDocument->getName()); foreach ($entityTypesMigrated as $record) { - if (in_array($record['entity_type_code'], $this->entityTypesWithOldAttributeSetIds)) { + if (isset($this->mapAttributeSetIdsDestOldNew[$record['default_attribute_set_id']])) { $record['default_attribute_set_id'] = $this->mapAttributeSetIdsDestOldNew[$record['default_attribute_set_id']]; } @@ -408,12 +402,11 @@ protected function migrateAttributes() /** @var Record $destinationRecord */ $destinationRecord = $this->factory->create(['document' => $destinationDocument]); - if (!isset($this->mapEntityTypeIdsSourceDest[$sourceRecord->getValue('entity_type_id')])) { - continue; - } - $mappedId = $this->mapEntityTypeIdsSourceDest[$sourceRecord->getValue('entity_type_id')]; - $mappedKey = $mappedId . '-' . $sourceRecord->getValue('attribute_code'); - if (isset($destinationRecords[$mappedKey])) { + $mappedId = isset($this->mapEntityTypeIdsSourceDest[$sourceRecord->getValue('entity_type_id')]) + ? $this->mapEntityTypeIdsSourceDest[$sourceRecord->getValue('entity_type_id')] + : null; + $mappedKey = $mappedId === null ? null : $mappedId . '-' . $sourceRecord->getValue('attribute_code'); + if ($mappedKey !== null && isset($destinationRecords[$mappedKey])) { $destinationRecordData = $destinationRecords[$mappedKey]; unset($destinationRecords[$mappedKey]); } else { @@ -688,11 +681,10 @@ protected function migrateAttributesExtended() $sourceRecord = $this->factory->create(['document' => $sourceDocument, 'data' => $recordData]); /** @var Record $destinationRecord */ $destinationRecord = $this->factory->create(['document' => $destinationDocument]); - if (!isset($this->mapAttributeIdsSourceDest[$sourceRecord->getValue($mappingField)])) { - continue; - } - $mappedId = $this->mapAttributeIdsSourceDest[$sourceRecord->getValue($mappingField)]; - if (isset($destinationRecords[$mappedId])) { + $mappedId = isset($this->mapAttributeIdsSourceDest[$sourceRecord->getValue($mappingField)]) + ? $this->mapAttributeIdsSourceDest[$sourceRecord->getValue($mappingField)] + : null; + if ($mappedId !== null && isset($destinationRecords[$mappedId])) { $destinationRecordData = $destinationRecords[$mappedId]; unset($destinationRecords[$mappedId]); } else { @@ -745,16 +737,11 @@ protected function createMapEntityTypeIds() $this->mapEntityTypeIdsDestOldNew[$entityTypeIdOld] = $entityTypeMigrated['entity_type_id']; } foreach ($this->initialData->getEntityTypes('source') as $entityTypeIdSource => $recordSource) { - $mapFound = false; foreach ($this->initialData->getEntityTypes('dest') as $entityTypeIdDest => $recordDest) { if ($recordSource['entity_type_code'] == $recordDest['entity_type_code']) { $this->mapEntityTypeIdsSourceDest[$entityTypeIdSource] = $entityTypeIdDest; - $mapFound = true; } } - if (!$mapFound) { - $this->mapEntityTypeIdsSourceDest[$entityTypeIdSource] = $entityTypeIdSource; - } } } @@ -813,19 +800,14 @@ protected function createMapAttributeIds() $this->mapAttributeIdsDestOldNew[$attributeOld['attribute_id']] = $newAttributes[$keyMapped]['attribute_id']; } foreach ($this->initialData->getAttributes('source') as $idSource => $attributeSource) { - $mapFound = false; foreach ($this->initialData->getAttributes('dest') as $keyDest => $attributeDest) { list($entityTypeIdDest, $attributeCodeDest) = explode('-', $keyDest); $keyDestMapped = $this->mapEntityTypeIdsDestOldNew[$entityTypeIdDest] . '-' . $attributeCodeDest; $keySource = $attributeSource['entity_type_id'] . '-' . $attributeSource['attribute_code']; if ($keySource == $keyDestMapped) { $this->mapAttributeIdsSourceDest[$idSource] = $attributeDest['attribute_id']; - $mapFound = true; } } - if (!$mapFound) { - $this->mapAttributeIdsSourceDest[$idSource] = $idSource; - } } } From c655bae6d3cfc698dbe1290b1eb7e04e5bf9add6 Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Tue, 26 Jul 2016 17:14:42 +0300 Subject: [PATCH 13/30] MAGETWO-55623: Cover MAGETWO-52582 changes by tests --- tests/integration/framework/Helper.php | 4 +- .../resource/url_rewrite_191/source.sql | 259 +++++++++++++++--- .../Step/UrlRewrite/Version191to2000Test.php | 4 +- .../Migration/Handler/GetEventStatusTest.php | 4 +- 4 files changed, 233 insertions(+), 38 deletions(-) diff --git a/tests/integration/framework/Helper.php b/tests/integration/framework/Helper.php index 17f728565..6b3b508d1 100644 --- a/tests/integration/framework/Helper.php +++ b/tests/integration/framework/Helper.php @@ -112,7 +112,9 @@ public function getObjectManager() ] ] ] - ] + ], + 'Migration\ResourceModel\Source' => ['shared' => false], + 'Migration\ResourceModel\Destination' => ['shared' => false], ]); return $this->objectManager; } diff --git a/tests/integration/resource/url_rewrite_191/source.sql b/tests/integration/resource/url_rewrite_191/source.sql index 49b5d9de1..8cc3ab6c8 100644 --- a/tests/integration/resource/url_rewrite_191/source.sql +++ b/tests/integration/resource/url_rewrite_191/source.sql @@ -1,3 +1,176 @@ +DROP TABLE IF EXISTS `eav_entity_type`; +CREATE TABLE IF NOT EXISTS `eav_entity_type` ( + `entity_type_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Entity Type Id', + `entity_type_code` varchar(50) NOT NULL COMMENT 'Entity Type Code', + `entity_model` varchar(255) NOT NULL COMMENT 'Entity Model', + `attribute_model` varchar(255) DEFAULT NULL COMMENT 'Attribute Model', + `entity_table` varchar(255) DEFAULT NULL COMMENT 'Entity Table', + `value_table_prefix` varchar(255) DEFAULT NULL COMMENT 'Value Table Prefix', + `entity_id_field` varchar(255) DEFAULT NULL COMMENT 'Entity Id Field', + `is_data_sharing` smallint(5) unsigned NOT NULL DEFAULT '1' COMMENT 'Defines Is Data Sharing', + `data_sharing_key` varchar(100) DEFAULT 'default' COMMENT 'Data Sharing Key', + `default_attribute_set_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Default Attribute Set Id', + `increment_model` varchar(255) DEFAULT NULL COMMENT 'Increment Model', + `increment_per_store` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Increment Per Store', + `increment_pad_length` smallint(5) unsigned NOT NULL DEFAULT '8' COMMENT 'Increment Pad Length', + `increment_pad_char` varchar(1) NOT NULL DEFAULT '0' COMMENT 'Increment Pad Char', + `additional_attribute_table` varchar(255) DEFAULT NULL COMMENT 'Additional Attribute Table', + `entity_attribute_collection` varchar(255) DEFAULT NULL COMMENT 'Entity Attribute Collection', + PRIMARY KEY (`entity_type_id`), + KEY `EAV_ENTITY_TYPE_ENTITY_TYPE_CODE` (`entity_type_code`) +) +COMMENT='Eav Entity Type' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; + +INSERT INTO `eav_entity_type` (`entity_type_id`, `entity_type_code`, `entity_model`, `attribute_model`, `entity_table`, `value_table_prefix`, `entity_id_field`, `is_data_sharing`, `data_sharing_key`, `default_attribute_set_id`, `increment_model`, `increment_per_store`, `increment_pad_length`, `increment_pad_char`, `additional_attribute_table`, `entity_attribute_collection`) +VALUES (4, 'catalog_product', 'catalog/product', 'catalog/resource_eav_attribute', 'catalog/product', '', '', 1, 'default', 4, '', 0, 8, '0', 'catalog/eav_attribute', 'catalog/product_attribute_collection'), + (1, 'customer', 'customer/customer', 'customer/attribute', 'customer/entity', '', '', 1, 'default', 1, 'eav/entity_increment_numeric', 0, 8, '0', 'customer/eav_attribute', 'customer/attribute_collection'); + +DROP TABLE IF EXISTS `eav_attribute_set`; +CREATE TABLE IF NOT EXISTS `eav_attribute_set` ( + `attribute_set_id` smallint(5) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Attribute Set Id', + `entity_type_id` smallint(5) unsigned NOT NULL DEFAULT '0' COMMENT 'Entity Type Id', + `attribute_set_name` varchar(255) DEFAULT NULL COMMENT 'Attribute Set Name', + `sort_order` smallint(6) NOT NULL DEFAULT '0' COMMENT 'Sort Order', + PRIMARY KEY (`attribute_set_id`), + UNIQUE KEY `EAV_ATTRIBUTE_SET_ENTITY_TYPE_ID_ATTRIBUTE_SET_NAME` (`entity_type_id`,`attribute_set_name`), + KEY `EAV_ATTRIBUTE_SET_ENTITY_TYPE_ID_SORT_ORDER` (`entity_type_id`,`sort_order`), + CONSTRAINT `EAV_ATTRIBUTE_SET_ENTITY_TYPE_ID_EAV_ENTITY_TYPE_ENTITY_TYPE_ID` FOREIGN KEY (`entity_type_id`) REFERENCES `eav_entity_type` (`entity_type_id`) ON DELETE CASCADE +) +COMMENT='Eav Attribute Set' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `eav_attribute_set` (`attribute_set_id`, `entity_type_id`, `attribute_set_name`, `sort_order`) + VALUES (4, 4, 'Default', 1), (1, 1, 'Default', 1); + +DROP TABLE IF EXISTS `catalog_category_entity`; +CREATE TABLE `catalog_category_entity` ( + `entity_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity ID', + `entity_type_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Entity Type ID', + `attribute_set_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Attriute Set ID', + `parent_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Parent Category ID', + `created_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Creation Time', + `updated_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Update Time', + `path` VARCHAR(255) NOT NULL COMMENT 'Tree Path', + `position` INT(11) NOT NULL DEFAULT '0' COMMENT 'Position', + `level` INT(11) NOT NULL DEFAULT '0' COMMENT 'Tree Level', + `children_count` INT(11) NOT NULL DEFAULT '0' COMMENT 'Child Count', + PRIMARY KEY (`entity_id`), + INDEX `IDX_CATALOG_CATEGORY_ENTITY_LEVEL` (`level`), + INDEX `IDX_CATALOG_CATEGORY_ENTITY_PATH_ENTITY_ID` (`path`, `entity_id`) +) +COMMENT='Catalog Category Table' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `catalog_category_entity` VALUES (1, 3, 0, 0, '0000-00-00 00:00:00', '2016-07-13 11:43:28', '1', 0, 0, 2), +(2, 3, 3, 1, '2016-07-13 11:43:28', '2016-07-13 11:43:28', '1/2', 1, 1, 1), +(3, 3, 3, 2, '2016-07-13 12:30:21', '2016-07-13 12:30:21', '1/2/3', 1, 2, 0); + +DROP TABLE IF EXISTS `catalog_product_entity`; +CREATE TABLE `catalog_product_entity` ( + `entity_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity ID', + `entity_type_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Entity Type ID', + `attribute_set_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Attribute Set ID', + `type_id` VARCHAR(32) NOT NULL DEFAULT 'simple' COMMENT 'Type ID', + `sku` VARCHAR(64) NULL DEFAULT NULL COMMENT 'SKU', + `has_options` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT 'Has Options', + `required_options` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Required Options', + `created_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Creation Time', + `updated_at` TIMESTAMP NULL DEFAULT NULL COMMENT 'Update Time', + PRIMARY KEY (`entity_id`), + INDEX `IDX_CATALOG_PRODUCT_ENTITY_ENTITY_TYPE_ID` (`entity_type_id`), + INDEX `IDX_CATALOG_PRODUCT_ENTITY_ATTRIBUTE_SET_ID` (`attribute_set_id`), + INDEX `IDX_CATALOG_PRODUCT_ENTITY_SKU` (`sku`), + CONSTRAINT `FK_CAT_PRD_ENTT_ATTR_SET_ID_EAV_ATTR_SET_ATTR_SET_ID` FOREIGN KEY (`attribute_set_id`) REFERENCES `eav_attribute_set` (`attribute_set_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Catalog Product Table' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; + +INSERT INTO `catalog_product_entity` VALUES +(1, 4, 4, 'simple', 'SimpleProduct', 1, 1, '2016-07-13 12:31:52', '2016-07-13 12:34:07'), +(2, 4, 4, 'virtual', 'Virtual Product', 0, 0, '2016-07-13 12:34:53', '2016-07-13 12:34:53'); + +CREATE TABLE `core_website` ( + `website_id` SMALLINT(5) UNSIGNED NOT NULL COMMENT 'Website Id', + `code` VARCHAR(32) NULL DEFAULT NULL COMMENT 'Code', + `name` VARCHAR(64) NULL DEFAULT NULL COMMENT 'Website Name', + `sort_order` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Sort Order', + `default_group_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Default Group Id', + `is_default` SMALLINT(5) UNSIGNED NULL DEFAULT '0' COMMENT 'Defines Is Website Default', + `is_staging` TINYINT(1) NOT NULL DEFAULT '0' COMMENT 'Is Staging Flag', + `master_login` VARCHAR(40) NULL DEFAULT NULL COMMENT 'Master Login', + `master_password` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Master Password', + `visibility` VARCHAR(40) NULL DEFAULT NULL COMMENT 'Visibility', + PRIMARY KEY (`website_id`), + UNIQUE INDEX `UNQ_CORE_WEBSITE_CODE` (`code`), + INDEX `IDX_CORE_WEBSITE_SORT_ORDER` (`sort_order`), + INDEX `IDX_CORE_WEBSITE_DEFAULT_GROUP_ID` (`default_group_id`) +) + COMMENT='Websites' + COLLATE='utf8_general_ci' + ENGINE=InnoDB +; +INSERT INTO `core_website` (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`, `is_staging`, `master_login`, `master_password`, `visibility`) VALUES (0, 'admin', 'Admin', 0, 0, 0, 0, '', '', ''); +INSERT INTO `core_website` (`website_id`, `code`, `name`, `sort_order`, `default_group_id`, `is_default`, `is_staging`, `master_login`, `master_password`, `visibility`) VALUES (1, 'base', 'Main Website', 0, 1, 1, 0, '', '', ''); + +CREATE TABLE `core_store_group` ( + `group_id` SMALLINT(5) UNSIGNED NOT NULL COMMENT 'Group Id', + `website_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Website Id', + `name` VARCHAR(255) NOT NULL COMMENT 'Store Group Name', + `root_category_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Root Category Id', + `default_store_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Default Store Id', + PRIMARY KEY (`group_id`), + INDEX `IDX_CORE_STORE_GROUP_WEBSITE_ID` (`website_id`), + INDEX `IDX_CORE_STORE_GROUP_DEFAULT_STORE_ID` (`default_store_id`), + CONSTRAINT `FK_CORE_STORE_GROUP_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON UPDATE CASCADE ON DELETE CASCADE +) + COMMENT='Store Groups' + COLLATE='utf8_general_ci' + ENGINE=InnoDB +; +INSERT INTO `core_store_group` (`group_id`, `website_id`, `name`, `root_category_id`, `default_store_id`) VALUES (0, 0, 'Default', 0, 0); +INSERT INTO `core_store_group` (`group_id`, `website_id`, `name`, `root_category_id`, `default_store_id`) VALUES (1, 1, 'First Main Store', 2, 1); + +DROP TABLE IF EXISTS `core_store`; +CREATE TABLE `core_store` ( + `store_id` SMALLINT(5) UNSIGNED COMMENT 'Store Id', + `code` VARCHAR(32) NULL DEFAULT NULL COMMENT 'Code', + `website_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Website Id', + `group_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Group Id', + `name` VARCHAR(255) NOT NULL COMMENT 'Store Name', + `sort_order` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Sort Order', + `is_active` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Activity', + PRIMARY KEY (`store_id`), + UNIQUE INDEX `UNQ_CORE_STORE_CODE` (`code`), + INDEX `IDX_CORE_STORE_WEBSITE_ID` (`website_id`), + INDEX `IDX_CORE_STORE_IS_ACTIVE_SORT_ORDER` (`is_active`, `sort_order`), + INDEX `IDX_CORE_STORE_GROUP_ID` (`group_id`), + CONSTRAINT `FK_CORE_STORE_GROUP_ID_CORE_STORE_GROUP_GROUP_ID` FOREIGN KEY (`group_id`) REFERENCES `core_store_group` (`group_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CORE_STORE_WEBSITE_ID_CORE_WEBSITE_WEBSITE_ID` FOREIGN KEY (`website_id`) REFERENCES `core_website` (`website_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='Stores' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; + +/*!40000 ALTER TABLE `core_store` DISABLE KEYS */; +LOCK TABLES `core_store` WRITE; +/*!40000 ALTER TABLE `core_store` DISABLE KEYS */; +INSERT INTO `core_store` VALUES +(1,'admin',0,0,'Admin',0,1), +(2,'default',1,1,'Default Store View',0,1); +/*!40000 ALTER TABLE `core_store` ENABLE KEYS */; +UNLOCK TABLES; +/*!40000 ALTER TABLE `core_store` ENABLE KEYS */; + + +DROP TABLE IF EXISTS `core_url_rewrite`; CREATE TABLE `core_url_rewrite` ( `url_rewrite_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Rewrite Id', `store_id` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Store Id', @@ -8,7 +181,7 @@ CREATE TABLE `core_url_rewrite` ( `target_path` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Target Path', `is_system` SMALLINT(5) UNSIGNED NULL DEFAULT '1' COMMENT 'Defines is Rewrite System', `options` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Options', - `description` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Deascription', + `description` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Description', PRIMARY KEY (`url_rewrite_id`), UNIQUE INDEX `UNQ_CORE_URL_REWRITE_REQUEST_PATH_STORE_ID` (`request_path`, `store_id`), UNIQUE INDEX `UNQ_CORE_URL_REWRITE_ID_PATH_IS_SYSTEM_STORE_ID` (`id_path`, `is_system`, `store_id`), @@ -25,39 +198,59 @@ COMMENT='Url Rewrites' COLLATE='utf8_general_ci' ENGINE=InnoDB ; -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (1, 1, 3, 0, 'category/3', 'newcat.html', 'catalog/category/view/id/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (2, 2, 3, 0, 'category/3', 'newcat.html', 'catalog/category/view/id/3', 1, '', NULL); INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (3, 1, 3, 1, 'product/1/3', NULL, 'catalog/product/view/id/1/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (4, 1, 0, 1, 'product/1', NULL, 'catalog/product/view/id/1', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (4, 1, 1, 1, 'product/1', NULL, 'catalog/product/view/id/1', 1, '', NULL); INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (5, 2, 3, 1, 'product/1/3', NULL, 'catalog/product/view/id/1/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (6, 2, 0, 1, 'product/1', NULL, 'catalog/product/view/id/1', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (6, 2, 1, 1, 'product/1', NULL, 'catalog/product/view/id/1', 1, '', NULL); INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (7, 1, 3, 2, 'product/2/3', 'newcat/virtual-product.html', 'catalog/product/view/id/2/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (8, 1, 0, 2, 'product/2', 'virtual-product.html', 'catalog/product/view/id/2', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (8, 1, 1, 2, 'product/2', 'virtual-product.html', 'catalog/product/view/id/2', 1, '', NULL); INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (9, 2, 3, 2, 'product/2/3', 'newcat/virtual-product.html', 'catalog/product/view/id/2/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (10, 2, 0, 2, 'product/2', 'virtual-product.html', 'catalog/product/view/id/2', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (11, 1, 3, 3, 'product/3/3', 'newcat/gift-card.html', 'catalog/product/view/id/3/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (12, 1, 0, 3, 'product/3', 'gift-card.html', 'catalog/product/view/id/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (13, 2, 3, 3, 'product/3/3', 'newcat/gift-card.html', 'catalog/product/view/id/3/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (14, 2, 0, 3, 'product/3', 'gift-card.html', 'catalog/product/view/id/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (15, 1, 3, 4, 'product/4/3', 'newcat/downloadable-product.html', 'catalog/product/view/id/4/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (16, 1, 0, 4, 'product/4', 'downloadable-product.html', 'catalog/product/view/id/4', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (17, 2, 3, 4, 'product/4/3', 'newcat/downloadable-product.html', 'catalog/product/view/id/4/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (18, 2, 0, 4, 'product/4', 'downloadable-product.html', 'catalog/product/view/id/4', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (19, 1, 3, 5, 'product/5/3', 'newcat/grouped-product.html', 'catalog/product/view/id/5/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (20, 1, 0, 5, 'product/5', 'grouped-product.html', 'catalog/product/view/id/5', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (21, 2, 3, 5, 'product/5/3', 'newcat/grouped-product.html', 'catalog/product/view/id/5/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (22, 2, 0, 5, 'product/5', 'grouped-product.html', 'catalog/product/view/id/5', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (23, 1, 3, 6, 'product/6/3', 'newcat/bundle-product.html', 'catalog/product/view/id/6/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (24, 1, 0, 6, 'product/6', 'bundle-product.html', 'catalog/product/view/id/6', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (25, 2, 3, 6, 'product/6/3', 'newcat/bundle-product.html', 'catalog/product/view/id/6/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (26, 2, 0, 6, 'product/6', 'bundle-product.html', 'catalog/product/view/id/6', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (29, 1, 0, 8, 'product/8', 'simple-product-1.html', 'catalog/product/view/id/8', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (30, 2, 0, 8, 'product/8', 'simple-product-1.html', 'catalog/product/view/id/8', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (31, 1, 3, 9, 'product/9/3', 'newcat/simple-product-2.html', 'catalog/product/view/id/9/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (32, 1, 0, 9, 'product/9', 'simple-product-2.html', 'catalog/product/view/id/9', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (33, 2, 3, 9, 'product/9/3', 'newcat/simple-product-2.html', 'catalog/product/view/id/9/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (34, 2, 0, 9, 'product/9', 'simple-product-2.html', 'catalog/product/view/id/9', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (35, 1, 3, 10, 'product/10/3', 'newcat/configurableproduct.html', 'catalog/product/view/id/10/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (36, 1, 0, 10, 'product/10', 'configurableproduct.html', 'catalog/product/view/id/10', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (37, 2, 3, 10, 'product/10/3', 'newcat/configurableproduct.html', 'catalog/product/view/id/10/category/3', 1, '', NULL); -INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (38, 2, 0, 10, 'product/10', 'configurableproduct.html', 'catalog/product/view/id/10', 1, '', NULL); +INSERT INTO `core_url_rewrite` (`url_rewrite_id`, `store_id`, `category_id`, `product_id`, `id_path`, `request_path`, `target_path`, `is_system`, `options`, `description`) VALUES (10, 2, 1, 2, 'product/2', 'virtual-product.html', 'catalog/product/view/id/2', 1, '', NULL); + +DROP TABLE IF EXISTS `cms_page`; +CREATE TABLE `cms_page` ( + `page_id` SMALLINT(6) NOT NULL AUTO_INCREMENT COMMENT 'Page ID', + `title` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Page Title', + `root_template` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Page Template', + `meta_keywords` TEXT NULL COMMENT 'Page Meta Keywords', + `meta_description` TEXT NULL COMMENT 'Page Meta Description', + `identifier` VARCHAR(100) NOT NULL COMMENT 'Page String Identifier', + `content_heading` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Page Content Heading', + `content` MEDIUMTEXT NULL COMMENT 'Page Content', + `creation_time` TIMESTAMP NULL DEFAULT NULL COMMENT 'Page Creation Time', + `update_time` TIMESTAMP NULL DEFAULT NULL COMMENT 'Page Modification Time', + `is_active` SMALLINT(6) NOT NULL DEFAULT '1' COMMENT 'Is Page Active', + `sort_order` SMALLINT(6) NOT NULL DEFAULT '0' COMMENT 'Page Sort Order', + `layout_update_xml` TEXT NULL COMMENT 'Page Layout Update Content', + `custom_theme` VARCHAR(100) NULL DEFAULT NULL COMMENT 'Page Custom Theme', + `custom_root_template` VARCHAR(255) NULL DEFAULT NULL COMMENT 'Page Custom Template', + `custom_layout_update_xml` TEXT NULL COMMENT 'Page Custom Layout Update Content', + `custom_theme_from` DATE NULL DEFAULT NULL COMMENT 'Page Custom Theme Active From Date', + `custom_theme_to` DATE NULL DEFAULT NULL COMMENT 'Page Custom Theme Active To Date', + `published_revision_id` INT(10) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Published Revision Id', + `website_root` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '1' COMMENT 'Website Root', + `under_version_control` SMALLINT(5) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Under Version Control Flag', + PRIMARY KEY (`page_id`), + INDEX `IDX_CMS_PAGE_IDENTIFIER` (`identifier`) +) +COMMENT='CMS Page Table' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `cms_page` VALUES +(1, '404 Not Found 1', 'two_columns_right', 'Page keywords', 'Page description', 'no-route', '', '

We’re sorry, the page you’re looking for can not be found.

\n
\n
    \n
  • If you typed the URL directly, please make sure the spelling is correct.
  • \n
  • If you clicked on a link to get here, we must have moved the content.
    Please try our store search box above to search for an item.
  • \n
  • If you are not sure how you got here, go back to the previous page or return to our store homepage.
  • \n
\n
\n\n', '2007-06-20 18:38:32', '2007-08-26 19:11:13', 1, 0, NULL, NULL, '', NULL, NULL, NULL, 1, 1, 0); + +DROP TABLE IF EXISTS `cms_page_store`; +CREATE TABLE `cms_page_store` ( + `page_id` SMALLINT(6) NOT NULL COMMENT 'Page ID', + `store_id` SMALLINT(5) UNSIGNED NOT NULL COMMENT 'Store ID', + PRIMARY KEY (`page_id`, `store_id`), + INDEX `IDX_CMS_PAGE_STORE_STORE_ID` (`store_id`), + CONSTRAINT `FK_CMS_PAGE_STORE_PAGE_ID_CMS_PAGE_PAGE_ID` FOREIGN KEY (`page_id`) REFERENCES `cms_page` (`page_id`) ON UPDATE CASCADE ON DELETE CASCADE, + CONSTRAINT `FK_CMS_PAGE_STORE_STORE_ID_CORE_STORE_STORE_ID` FOREIGN KEY (`store_id`) REFERENCES `core_store` (`store_id`) ON UPDATE CASCADE ON DELETE CASCADE +) +COMMENT='CMS Page To Store Linkage Table' +COLLATE='utf8_general_ci' +ENGINE=InnoDB +; +INSERT INTO `cms_page_store` VALUES (1, 1); \ No newline at end of file diff --git a/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php b/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php index 5af4743c2..cc4e06861 100644 --- a/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php +++ b/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php @@ -92,8 +92,8 @@ public function testData() $logOutput = \Migration\Logger\Logger::getMessages(); $this->assertTrue(empty($logOutput[\Monolog\Logger::ERROR])); - $this->assertEquals(5, $destination->getRecordsCount('url_rewrite')); - $this->assertEquals(3, $destination->getRecordsCount('catalog_url_rewrite_product_category')); + $this->assertEquals(9, $destination->getRecordsCount('url_rewrite')); + $this->assertEquals(4, $destination->getRecordsCount('catalog_url_rewrite_product_category')); $urlRewrite = $this->objectManager->create( '\Migration\Step\UrlRewrite\Version191to2000', diff --git a/tests/unit/testsuite/Migration/Handler/GetEventStatusTest.php b/tests/unit/testsuite/Migration/Handler/GetEventStatusTest.php index c5573ff11..44a985b1a 100644 --- a/tests/unit/testsuite/Migration/Handler/GetEventStatusTest.php +++ b/tests/unit/testsuite/Migration/Handler/GetEventStatusTest.php @@ -30,7 +30,7 @@ public function testHandle($dateStart, $dateEnd, $status) $record->expects($this->any())->method('getValue')->willReturnMap( [ ['date_start', $dateStart], - ['date_end', $dateEnd] + ['date_end', $dateEnd] ] ); $record->expects($this->once())->method('setValue')->with('status', $status); @@ -64,7 +64,7 @@ public function eventDatesDataProvider() 'date_end' => date('Y-m-d H:i:s', strtotime('+5 days')), 'status' => GetEventStatus::EVENT_UPCOMING ] - ]; + ]; } } From 6e5eb78f2926976e3a869426573daa2603bdc973 Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Thu, 28 Jul 2016 11:35:52 +0300 Subject: [PATCH 14/30] MAGETWO-55303: [GitHub] Errors on EAV step #112 --- src/Migration/App/Step/AbstractIntegrity.php | 51 +++++++++- .../EavAttributeGroup/SetGroupCode.php | 19 ++-- .../Model/Eav/AttributeGroupNameToCodeMap.php | 47 +++++++++ src/Migration/Step/Eav/Data.php | 15 +-- src/Migration/Step/Eav/Integrity.php | 18 ++++ .../Eav/Integrity/AttributeGroupNames.php | 99 +++++++++++++++++++ 6 files changed, 231 insertions(+), 18 deletions(-) create mode 100644 src/Migration/Model/Eav/AttributeGroupNameToCodeMap.php create mode 100644 src/Migration/Step/Eav/Integrity/AttributeGroupNames.php diff --git a/src/Migration/App/Step/AbstractIntegrity.php b/src/Migration/App/Step/AbstractIntegrity.php index 6a4c22646..03180b330 100644 --- a/src/Migration/App/Step/AbstractIntegrity.php +++ b/src/Migration/App/Step/AbstractIntegrity.php @@ -73,6 +73,13 @@ abstract class AbstractIntegrity implements StageInterface */ protected $mismatchDocumentFieldDataTypes; + /** + * Incompatible data in field of document + * + * @var array + */ + protected $incompatibleDocumentFieldsData; + /** * Map reader * @@ -202,13 +209,18 @@ protected function checkForErrors() $checkDocuments = $this->checkDocuments(); $checkDocumentFields = $this->checkDocumentFields(); $checkMismatchDocumentFieldDataTypes = $this->checkMismatchDocumentFieldDataTypes(); - return $checkDocuments && $checkDocumentFields && $checkMismatchDocumentFieldDataTypes; + $checkDocumentFieldsData = $this->checkDocumentFieldsData(); + return + $checkDocuments + && $checkDocumentFields + && $checkMismatchDocumentFieldDataTypes + && $checkDocumentFieldsData; } /** * @return bool */ - public function checkDocuments() + protected function checkDocuments() { $check = function ($errors, $errorMessagePattern, $type) { $isSuccess = true; @@ -251,7 +263,7 @@ public function checkDocuments() /** * @return bool */ - public function checkDocumentFields() + protected function checkDocumentFields() { $check = function ($errors, $errorMessagePattern, $type) { $isSuccess = true; @@ -297,7 +309,7 @@ public function checkDocumentFields() /** * @return bool */ - public function checkMismatchDocumentFieldDataTypes() + protected function checkMismatchDocumentFieldDataTypes() { if (isset($this->mismatchDocumentFieldDataTypes[MapInterface::TYPE_SOURCE])) { foreach ($this->mismatchDocumentFieldDataTypes[MapInterface::TYPE_SOURCE] as $document => $fields) { @@ -319,4 +331,35 @@ public function checkMismatchDocumentFieldDataTypes() } return true; } + + /** + * @return bool + */ + protected function checkDocumentFieldsData() + { + $isSuccess = true; + if (isset($this->incompatibleDocumentFieldsData[MapInterface::TYPE_SOURCE])) { + foreach ($this->incompatibleDocumentFieldsData[MapInterface::TYPE_SOURCE] as $errorDetail) { + $this->logger->error(sprintf( + 'Incompatibility in data. Source document: %s. Field: %s. Error: %s', + $errorDetail['document'], + $errorDetail['field'], + $errorDetail['error'] + )); + } + $isSuccess = false; + } + if (isset($this->incompatibleDocumentFieldsData[MapInterface::TYPE_DEST])) { + foreach ($this->incompatibleDocumentFieldsData[MapInterface::TYPE_DEST] as $errorDetail) { + $this->logger->error(sprintf( + 'Incompatibility in data. Destination document: %s. Field: %s. Error: %s', + $errorDetail['document'], + $errorDetail['field'], + $errorDetail['error'] + )); + } + $isSuccess = false; + } + return $isSuccess; + } } diff --git a/src/Migration/Handler/EavAttributeGroup/SetGroupCode.php b/src/Migration/Handler/EavAttributeGroup/SetGroupCode.php index 4de5add67..74271d1fa 100644 --- a/src/Migration/Handler/EavAttributeGroup/SetGroupCode.php +++ b/src/Migration/Handler/EavAttributeGroup/SetGroupCode.php @@ -11,6 +11,7 @@ use Migration\Config; use Migration\Exception; use Migration\Step\DatabaseStage; +use Migration\Model\Eav\AttributeGroupNameToCodeMap; /** * Class SetGroupCode @@ -34,20 +35,26 @@ class SetGroupCode extends \Migration\Handler\AbstractHandler implements \Migrat */ protected $source; + /** + * @var AttributeGroupNameToCodeMap + */ + protected $groupNameToCodeMap; + /** * @param Config $config * @param Source $source + * @param AttributeGroupNameToCodeMap $groupNameToCodeMap * @throws Exception */ - public function __construct(Config $config, Source $source) + public function __construct(Config $config, Source $source, AttributeGroupNameToCodeMap $groupNameToCodeMap) { + $this->groupNameToCodeMap = $groupNameToCodeMap; $this->canStart = $config->getSource()['type'] == DatabaseStage::SOURCE_TYPE; $this->source = $source; } /** * {@inheritdoc} - * @SuppressWarnings(PHPMD.NPathComplexity) */ public function handle(Record $recordToHandle, Record $oppositeRecord) { @@ -60,12 +67,8 @@ public function handle(Record $recordToHandle, Record $oppositeRecord) $recordToHandle->setValue($this->field, null); return; } - - $newValue = preg_replace('/[^a-z0-9]+/', '-', strtolower($recordToHandle->getValue('attribute_group_name'))); - $newValue = ($newValue == 'migration-general') ? 'product-details' : $newValue; - $newValue = ($newValue == 'migration-prices') ? 'advanced-pricing' : $newValue; - $newValue = ($newValue == 'migration-design') ? 'design' : $newValue; - $recordToHandle->setValue($this->field, $newValue); + $groupCode = $this->groupNameToCodeMap->getGroupCodeMap($recordToHandle->getValue('attribute_group_name')); + $recordToHandle->setValue($this->field, $groupCode); } /** diff --git a/src/Migration/Model/Eav/AttributeGroupNameToCodeMap.php b/src/Migration/Model/Eav/AttributeGroupNameToCodeMap.php new file mode 100644 index 000000000..c8e1075c7 --- /dev/null +++ b/src/Migration/Model/Eav/AttributeGroupNameToCodeMap.php @@ -0,0 +1,47 @@ + 'product-details', + 'Prices' => 'advanced-pricing', + 'Design' => 'design', + ]; + + /** + * @var string + */ + protected $attributeGroupNamePrefix = 'Migration_'; + + /** + * @param string $groupName + * @return array + */ + public function getGroupCodeMap($groupName) + { + $groupNameOriginal = preg_replace('/^' . $this->attributeGroupNamePrefix . '/', '', $groupName); + $groupCodeMap = isset($this->map[$groupNameOriginal]) ? $this->map[$groupNameOriginal] : null; + $groupCodeTransformed = preg_replace('/[^a-z0-9]+/', '-', strtolower($groupName)); + $groupCode = $groupCodeMap ?: $groupCodeTransformed; + return $groupCode; + } + + /** + * @return array + */ + public function getMap() + { + return $this->map; + } +} diff --git a/src/Migration/Step/Eav/Data.php b/src/Migration/Step/Eav/Data.php index d7d44764f..bedaf2f3e 100644 --- a/src/Migration/Step/Eav/Data.php +++ b/src/Migration/Step/Eav/Data.php @@ -402,11 +402,13 @@ protected function migrateAttributes() /** @var Record $destinationRecord */ $destinationRecord = $this->factory->create(['document' => $destinationDocument]); - $mappedId = isset($this->mapEntityTypeIdsSourceDest[$sourceRecord->getValue('entity_type_id')]) - ? $this->mapEntityTypeIdsSourceDest[$sourceRecord->getValue('entity_type_id')] - : null; - $mappedKey = $mappedId === null ? null : $mappedId . '-' . $sourceRecord->getValue('attribute_code'); - if ($mappedKey !== null && isset($destinationRecords[$mappedKey])) { + $mappedKey = null; + $entityTypeId = $sourceRecord->getValue('entity_type_id'); + if (isset($this->mapEntityTypeIdsSourceDest[$entityTypeId])) { + $mappedId = $this->mapEntityTypeIdsSourceDest[$entityTypeId]; + $mappedKey = $mappedId . '-' . $sourceRecord->getValue('attribute_code'); + } + if ($mappedKey && isset($destinationRecords[$mappedKey])) { $destinationRecordData = $destinationRecords[$mappedKey]; unset($destinationRecords[$mappedKey]); } else { @@ -797,7 +799,8 @@ protected function createMapAttributeIds() foreach ($this->initialData->getAttributes('dest') as $keyOld => $attributeOld) { list($entityTypeId, $attributeCodeDest) = explode('-', $keyOld); $keyMapped = $this->mapEntityTypeIdsDestOldNew[$entityTypeId] . '-' . $attributeCodeDest; - $this->mapAttributeIdsDestOldNew[$attributeOld['attribute_id']] = $newAttributes[$keyMapped]['attribute_id']; + $this->mapAttributeIdsDestOldNew[$attributeOld['attribute_id']] + = $newAttributes[$keyMapped]['attribute_id']; } foreach ($this->initialData->getAttributes('source') as $idSource => $attributeSource) { foreach ($this->initialData->getAttributes('dest') as $keyDest => $attributeDest) { diff --git a/src/Migration/Step/Eav/Integrity.php b/src/Migration/Step/Eav/Integrity.php index cce9a6fa0..16afd7eb5 100644 --- a/src/Migration/Step/Eav/Integrity.php +++ b/src/Migration/Step/Eav/Integrity.php @@ -11,6 +11,7 @@ use Migration\Reader\MapFactory; use Migration\App\ProgressBar; use Migration\ResourceModel; +use Migration\Step\Eav\Integrity\AttributeGroupNames as AttributeGroupNamesIntegrity; /** * Class Integrity @@ -22,6 +23,11 @@ class Integrity extends \Migration\App\Step\AbstractIntegrity */ protected $groups; + /** + * @var AttributeGroupNamesIntegrity + */ + protected $attributeGroupNamesIntegrity; + /** * @param ProgressBar\LogLevelProcessor $progress * @param Logger $logger @@ -29,6 +35,7 @@ class Integrity extends \Migration\App\Step\AbstractIntegrity * @param ResourceModel\Destination $destination * @param MapFactory $mapFactory * @param GroupsFactory $groupsFactory + * @param AttributeGroupNamesIntegrity $attributeGroupNamesIntegrity * @param string $mapConfigOption */ public function __construct( @@ -38,9 +45,11 @@ public function __construct( ResourceModel\Destination $destination, MapFactory $mapFactory, GroupsFactory $groupsFactory, + AttributeGroupNamesIntegrity $attributeGroupNamesIntegrity, $mapConfigOption = 'eav_map_file' ) { $this->groups = $groupsFactory->create('eav_document_groups_file'); + $this->attributeGroupNamesIntegrity = $attributeGroupNamesIntegrity; parent::__construct($progress, $logger, $source, $destination, $mapFactory, $mapConfigOption); } @@ -62,6 +71,15 @@ public function perform() return $this->checkForErrors(); } + /** + * @return bool + */ + protected function checkDocumentFieldsData() + { + $this->incompatibleDocumentFieldsData = $this->attributeGroupNamesIntegrity->checkAttributeGroupNames(); + return parent::checkDocumentFieldsData(); + } + /** * Returns number of iterations for integrity check * @return mixed diff --git a/src/Migration/Step/Eav/Integrity/AttributeGroupNames.php b/src/Migration/Step/Eav/Integrity/AttributeGroupNames.php new file mode 100644 index 000000000..df85b3ede --- /dev/null +++ b/src/Migration/Step/Eav/Integrity/AttributeGroupNames.php @@ -0,0 +1,99 @@ +helper = $helper; + $this->groupNameToCodeMap = $groupNameToCodeMap; + } + + /** + * @return bool + */ + public function checkAttributeGroupNames() + { + $attributeGroups = $this->helper->getSourceRecords($this->attributeGroupDocument, ['attribute_group_id']); + $entityTypeIdCatalogProduct = $this->helper->getSourceRecords('eav_entity_type', ['entity_type_code']) + ['catalog_product']['entity_type_id']; + $attributeSetsOfCatalogProduct = []; + $attributeSets = $this->helper->getSourceRecords('eav_attribute_set', ['attribute_set_id']); + foreach ($attributeSets as $attributeSet) { + if ($attributeSet['entity_type_id'] == $entityTypeIdCatalogProduct) { + $attributeSetsOfCatalogProduct[$attributeSet['attribute_set_id']] = + $attributeSet['attribute_set_name']; + } + } + $attributeGroupsOfCatalogProduct = []; + foreach ($attributeGroups as $group) { + if (in_array($group['attribute_set_id'], array_keys($attributeSetsOfCatalogProduct))) { + $attributeGroupsOfCatalogProduct[$group['attribute_set_id']][] = $group[$this->attributeGroupFieldName]; + } + } + return $this->checkForErrors($attributeGroupsOfCatalogProduct, $attributeSetsOfCatalogProduct); + } + + /** + * @param array $attributeGroupsOfCatalogProduct + * @param array $attributeSetsOfCatalogProduct + * @return array + */ + protected function checkForErrors(array $attributeGroupsOfCatalogProduct, array $attributeSetsOfCatalogProduct) + { + $incompatibleDocumentFieldsData = []; + $groupNamesToValidate = array_keys($this->groupNameToCodeMap->getMap()); + foreach ($attributeGroupsOfCatalogProduct as $attributeSetId => $groupNames) { + if (!empty(array_diff($groupNamesToValidate, $groupNames))) { + $error = 'The product attribute set "%s" does not contain all required attribute group names "%s"'; + $error = sprintf( + $error, + $attributeSetsOfCatalogProduct[$attributeSetId], + implode(', ', $groupNamesToValidate) + ); + $errorDetails['document'] = $this->attributeGroupDocument; + $errorDetails['field'] = $this->attributeGroupFieldName; + $errorDetails['error'] = $error; + $incompatibleDocumentFieldsData[MapInterface::TYPE_SOURCE][] = $errorDetails; + } + } + return $incompatibleDocumentFieldsData; + } +} From 7537b509fe87cb38fe342664cebde6402cafcf09 Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Fri, 29 Jul 2016 15:26:28 +0300 Subject: [PATCH 15/30] MAGETWO-55846: Migrate DB from RedBox and analyze founded issues --- src/Migration/Step/Map/Data.php | 2 +- src/Migration/Step/SalesIncrement/Helper.php | 2 +- src/Migration/Step/UrlRewrite/Version191to2000.php | 1 - 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/Migration/Step/Map/Data.php b/src/Migration/Step/Map/Data.php index 91b7810ba..45de41826 100644 --- a/src/Migration/Step/Map/Data.php +++ b/src/Migration/Step/Map/Data.php @@ -249,7 +249,7 @@ protected function isCopiedDirectly(Document $sourceDocument, Document $destinat ); } catch (\Exception $e) { $this->copyDirectly = false; - $this->logger->error( + $this->logger->warning( 'Document ' . $sourceDocument->getName() . ' can not be copied directly because of error: ' . $e->getMessage() ); diff --git a/src/Migration/Step/SalesIncrement/Helper.php b/src/Migration/Step/SalesIncrement/Helper.php index 87bfbfab9..4054058a0 100644 --- a/src/Migration/Step/SalesIncrement/Helper.php +++ b/src/Migration/Step/SalesIncrement/Helper.php @@ -144,7 +144,7 @@ public function getEntityTypeTablesMap() { $entityIds = $this->getEntityTypeIdByCode(array_column($this->entityTypeTablesMap, 'entity_type_code')); foreach ($this->entityTypeTablesMap as &$entityTypeTable) { - $entityTypeTable['entity_type_id'] = $entityIds[$entityTypeTable['entity_type_code']] + $entityTypeTable['entity_type_id'] = isset($entityIds[$entityTypeTable['entity_type_code']]) ? $entityIds[$entityTypeTable['entity_type_code']] : null; } diff --git a/src/Migration/Step/UrlRewrite/Version191to2000.php b/src/Migration/Step/UrlRewrite/Version191to2000.php index 73a1cc5df..d11c28421 100644 --- a/src/Migration/Step/UrlRewrite/Version191to2000.php +++ b/src/Migration/Step/UrlRewrite/Version191to2000.php @@ -200,7 +200,6 @@ protected function data() $destinationRecords = $destDocument->getRecords(); $destProductCategoryRecords = $destProductCategory->getRecords(); foreach ($bulk as $recordData) { - $this->progress->advance(); /** @var Record $record */ $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $recordData]); /** @var Record $destRecord */ From 4622adb815a0a8ad21649fd2049653909dd1aea2 Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Fri, 29 Jul 2016 15:42:42 +0300 Subject: [PATCH 16/30] MAGETWO-55303: [GitHub] Errors on EAV step #112 --- src/Migration/App/Step/AbstractIntegrity.php | 8 ++++++++ .../Handler/EavAttributeGroup/SetGroupCode.php | 2 +- src/Migration/Step/Eav/Data.php | 4 ++-- src/Migration/Step/Eav/Integrity.php | 15 +++------------ .../Step/Eav/Integrity/AttributeGroupNames.php | 10 ++++++---- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/src/Migration/App/Step/AbstractIntegrity.php b/src/Migration/App/Step/AbstractIntegrity.php index 03180b330..16e1cfe56 100644 --- a/src/Migration/App/Step/AbstractIntegrity.php +++ b/src/Migration/App/Step/AbstractIntegrity.php @@ -218,6 +218,8 @@ protected function checkForErrors() } /** + * Check documents + * * @return bool */ protected function checkDocuments() @@ -261,6 +263,8 @@ protected function checkDocuments() } /** + * Check fields of document + * * @return bool */ protected function checkDocumentFields() @@ -307,6 +311,8 @@ protected function checkDocumentFields() } /** + * Check mismatch in data types of document field + * * @return bool */ protected function checkMismatchDocumentFieldDataTypes() @@ -333,6 +339,8 @@ protected function checkMismatchDocumentFieldDataTypes() } /** + * Check data in document fields + * * @return bool */ protected function checkDocumentFieldsData() diff --git a/src/Migration/Handler/EavAttributeGroup/SetGroupCode.php b/src/Migration/Handler/EavAttributeGroup/SetGroupCode.php index 74271d1fa..dcd36b1db 100644 --- a/src/Migration/Handler/EavAttributeGroup/SetGroupCode.php +++ b/src/Migration/Handler/EavAttributeGroup/SetGroupCode.php @@ -38,7 +38,7 @@ class SetGroupCode extends \Migration\Handler\AbstractHandler implements \Migrat /** * @var AttributeGroupNameToCodeMap */ - protected $groupNameToCodeMap; + private $groupNameToCodeMap; /** * @param Config $config diff --git a/src/Migration/Step/Eav/Data.php b/src/Migration/Step/Eav/Data.php index bedaf2f3e..be955f737 100644 --- a/src/Migration/Step/Eav/Data.php +++ b/src/Migration/Step/Eav/Data.php @@ -799,8 +799,8 @@ protected function createMapAttributeIds() foreach ($this->initialData->getAttributes('dest') as $keyOld => $attributeOld) { list($entityTypeId, $attributeCodeDest) = explode('-', $keyOld); $keyMapped = $this->mapEntityTypeIdsDestOldNew[$entityTypeId] . '-' . $attributeCodeDest; - $this->mapAttributeIdsDestOldNew[$attributeOld['attribute_id']] - = $newAttributes[$keyMapped]['attribute_id']; + $this->mapAttributeIdsDestOldNew[$attributeOld['attribute_id']] = + $newAttributes[$keyMapped]['attribute_id']; } foreach ($this->initialData->getAttributes('source') as $idSource => $attributeSource) { foreach ($this->initialData->getAttributes('dest') as $keyDest => $attributeDest) { diff --git a/src/Migration/Step/Eav/Integrity.php b/src/Migration/Step/Eav/Integrity.php index 16afd7eb5..f04b74961 100644 --- a/src/Migration/Step/Eav/Integrity.php +++ b/src/Migration/Step/Eav/Integrity.php @@ -21,12 +21,12 @@ class Integrity extends \Migration\App\Step\AbstractIntegrity /** * @var \Migration\Reader\Groups */ - protected $groups; + private $groups; /** * @var AttributeGroupNamesIntegrity */ - protected $attributeGroupNamesIntegrity; + private $attributeGroupNamesIntegrity; /** * @param ProgressBar\LogLevelProcessor $progress @@ -66,20 +66,11 @@ public function perform() $destinationDocumentName = $this->map->getDocumentMap($sourceDocumentName, MapInterface::TYPE_SOURCE); $this->check([$destinationDocumentName], MapInterface::TYPE_DEST); } - + $this->incompatibleDocumentFieldsData = $this->attributeGroupNamesIntegrity->checkAttributeGroupNames(); $this->progress->finish(); return $this->checkForErrors(); } - /** - * @return bool - */ - protected function checkDocumentFieldsData() - { - $this->incompatibleDocumentFieldsData = $this->attributeGroupNamesIntegrity->checkAttributeGroupNames(); - return parent::checkDocumentFieldsData(); - } - /** * Returns number of iterations for integrity check * @return mixed diff --git a/src/Migration/Step/Eav/Integrity/AttributeGroupNames.php b/src/Migration/Step/Eav/Integrity/AttributeGroupNames.php index df85b3ede..2ac6ffab6 100644 --- a/src/Migration/Step/Eav/Integrity/AttributeGroupNames.php +++ b/src/Migration/Step/Eav/Integrity/AttributeGroupNames.php @@ -17,22 +17,22 @@ class AttributeGroupNames /** * @var Helper */ - protected $helper; + private $helper; /** * @var AttributeGroupNameToCodeMap */ - protected $groupNameToCodeMap; + private $groupNameToCodeMap; /** * @var string */ - protected $attributeGroupDocument = 'eav_attribute_group'; + private $attributeGroupDocument = 'eav_attribute_group'; /** * @var string */ - protected $attributeGroupFieldName = 'attribute_group_name'; + private $attributeGroupFieldName = 'attribute_group_name'; /** * @param Helper $helper @@ -47,6 +47,8 @@ public function __construct( } /** + * Check product attribute sets contain all required attribute group names + * * @return bool */ public function checkAttributeGroupNames() From e9ca1072cb0662cb3758da7295bb3f074732d022 Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Mon, 1 Aug 2016 12:23:25 +0300 Subject: [PATCH 17/30] MAGETWO-55303: [GitHub] Errors on EAV step #112 --- .../EavAttributeGroup/SetGroupCodeTest.php | 20 ++++++++++++++++--- .../Migration/Step/Eav/IntegrityTest.php | 12 ++++++++++- 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/tests/unit/testsuite/Migration/Handler/EavAttributeGroup/SetGroupCodeTest.php b/tests/unit/testsuite/Migration/Handler/EavAttributeGroup/SetGroupCodeTest.php index 56c38d4f8..5d16f3077 100644 --- a/tests/unit/testsuite/Migration/Handler/EavAttributeGroup/SetGroupCodeTest.php +++ b/tests/unit/testsuite/Migration/Handler/EavAttributeGroup/SetGroupCodeTest.php @@ -7,6 +7,7 @@ use Migration\ResourceModel\Record; use Migration\Step\DatabaseStage; +use Migration\Model\Eav\AttributeGroupNameToCodeMap; /** * Class SetGroupCodeTest @@ -18,6 +19,8 @@ class SetGroupCodeTest extends \PHPUnit_Framework_TestCase */ public function testHandle() { + $groupName = 'Migration General'; + $groupCode = 'migration-general'; /** @var \Migration\ResourceModel\Record|\PHPUnit_Framework_MockObject_MockObject $recordToHandle */ $recordToHandle = $this->getMockBuilder('Migration\ResourceModel\Record') ->setMethods(['getValue', 'setValue', 'getFields']) @@ -28,12 +31,23 @@ public function testHandle() ->disableOriginalConstructor() ->getMock(); + /** @var AttributeGroupNameToCodeMap $attributeGroupNameToCodeMap|\PHPUnit_Framework_MockObject_MockObject */ + $attributeGroupNameToCodeMap = $this->getMockBuilder('Migration\Model\Eav\AttributeGroupNameToCodeMap') + ->setMethods(['getGroupCodeMap']) + ->disableOriginalConstructor() + ->getMock(); + + $attributeGroupNameToCodeMap->expects($this->once()) + ->method('getGroupCodeMap') + ->with($groupName) + ->willReturn($groupCode); + $fieldName = 'fieldname'; $recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName])); $recordToHandle->expects($this->at(1))->method('getValue')->with('attribute_set_id')->willReturn(1); $recordToHandle->expects($this->at(2))->method('getValue')->with('attribute_group_name') - ->willReturn('Migration General'); - $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, 'product-details'); + ->willReturn($groupName); + $recordToHandle->expects($this->once())->method('setValue')->with($fieldName, $groupCode); $config = $this->getMockBuilder('Migration\Config') ->disableOriginalConstructor()->setMethods(['getSource'])->getMock(); @@ -57,7 +71,7 @@ public function testHandle() $adapter->expects($this->once())->method('getSelect')->willReturn($select); $adapter->expects($this->once())->method('fetchCol')->willReturn([1=>0, 2=>1]); - $handler = new SetGroupCode($config, $source); + $handler = new SetGroupCode($config, $source, $attributeGroupNameToCodeMap); $handler->setField($fieldName); $handler->handle($recordToHandle, $oppositeRecord); } diff --git a/tests/unit/testsuite/Migration/Step/Eav/IntegrityTest.php b/tests/unit/testsuite/Migration/Step/Eav/IntegrityTest.php index 1a1020c5d..e2139dd70 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/IntegrityTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/IntegrityTest.php @@ -47,6 +47,11 @@ class IntegrityTest extends \PHPUnit_Framework_TestCase */ protected $map; + /** + * @var \Migration\Model\Eav\AttributeGroupNameToCodeMap|\PHPUnit_Framework_MockObject_MockObject + */ + protected $attributeGroupNameToCodeMap; + /** * @return void */ @@ -68,6 +73,10 @@ public function setUp() $this->map = $this->getMockBuilder('\Migration\Reader\Map')->disableOriginalConstructor() ->setMethods(['getDocumentMap', 'getDocumentList', 'getFieldMap', 'isDocumentIgnored']) ->getMock(); + $this->attributeGroupNameToCodeMap = $this->getMockBuilder('Migration\Model\Eav\AttributeGroupNameToCodeMap') + ->setMethods(['checkAttributeGroupNames']) + ->disableOriginalConstructor() + ->getMock(); /** @var \Migration\Reader\MapFactory|\PHPUnit_Framework_MockObject_MockObject $mapFactory */ $mapFactory = $this->getMock('\Migration\Reader\MapFactory', [], [], '', false); @@ -92,7 +101,8 @@ public function setUp() $this->source, $this->destination, $mapFactory, - $groupsFactory + $groupsFactory, + $this->attributeGroupNameToCodeMap ); } From 33d2490304fc88ca36640cd366ea2beaa617fd54 Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Mon, 1 Aug 2016 16:25:35 +0300 Subject: [PATCH 18/30] MAGETWO-56087: Duplicate entry for key 'URL_REWRITE_REQUEST_PATH_STORE_ID' revert --- .../Step/UrlRewrite/Version191to2000.php | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Migration/Step/UrlRewrite/Version191to2000.php b/src/Migration/Step/UrlRewrite/Version191to2000.php index 73a1cc5df..37cdb9b01 100644 --- a/src/Migration/Step/UrlRewrite/Version191to2000.php +++ b/src/Migration/Step/UrlRewrite/Version191to2000.php @@ -253,7 +253,7 @@ protected function volume() $result = true; $this->progress->start(1); $result &= $this->source->getRecordsCount(self::SOURCE) + $this->countCmsPageRewrites(true) == - $this->destination->getRecordsCount(self::DESTINATION); + ($this->destination->getRecordsCount(self::DESTINATION) + $this->getCmsPageUrlRewriteMatchedRecordsCount()); if (!$result) { $this->logger->error('Mismatch of entities in the document: url_rewrite'); } @@ -262,6 +262,26 @@ protected function volume() return (bool)$result; } + /** + * Get amount of records of cms_page that matches the same request paths into core_url_rewrite + * + * @return int + */ + protected function getCmsPageUrlRewriteMatchedRecordsCount() + { + $select = $this->source->getAdapter()->getSelect(); + $select->distinct()->from( + ['cur' => $this->source->addDocumentPrefix(self::SOURCE)], + new \Zend_Db_Expr('COUNT(cur.url_rewrite_id)') + )->join( + ['cp' => $this->source->addDocumentPrefix($this->cmsPageTableName)], + 'cur.request_path = cp.identifier', + [] + ); + + return $this->source->getAdapter()->fetchOne($select); + } + /** * @inheritdoc */ @@ -357,7 +377,7 @@ protected function collectCmsPageRewrites() { $select = $this->selectCmsPageRewrites(); $urlRewrites = $this->source->getAdapter()->loadDataFromSelect($select); - $this->destination->saveRecords(self::DESTINATION, $urlRewrites); + $this->destination->saveRecords(self::DESTINATION, $urlRewrites, ['request_path' => 'request_path']); } /** From 62f3a01a0c45fc7194646601ec946d5519a97d3e Mon Sep 17 00:00:00 2001 From: Yurii Hryhoriev Date: Tue, 2 Aug 2016 10:35:40 +0300 Subject: [PATCH 19/30] MAGETWO-55303: [GitHub] Errors on EAV step #112 - tests are added --- .../Eav/AttributeGroupNameToCodeMapTest.php | 53 +++++++ .../Eav/Integrity/AttributeGroupNamesTest.php | 136 ++++++++++++++++++ .../Migration/Step/Eav/IntegrityTest.php | 2 +- 3 files changed, 190 insertions(+), 1 deletion(-) create mode 100644 tests/unit/testsuite/Migration/Model/Eav/AttributeGroupNameToCodeMapTest.php create mode 100644 tests/unit/testsuite/Migration/Step/Eav/Integrity/AttributeGroupNamesTest.php diff --git a/tests/unit/testsuite/Migration/Model/Eav/AttributeGroupNameToCodeMapTest.php b/tests/unit/testsuite/Migration/Model/Eav/AttributeGroupNameToCodeMapTest.php new file mode 100644 index 000000000..55111b51c --- /dev/null +++ b/tests/unit/testsuite/Migration/Model/Eav/AttributeGroupNameToCodeMapTest.php @@ -0,0 +1,53 @@ +model = $objectHelper->getObject('\Migration\Model\Eav\AttributeGroupNameToCodeMap'); + } + + /** + * @dataProvider getGroupsData() + * @param string $groupName + * @param string $groupCode + * @return void + */ + public function testGetGroupCodeMap($groupName, $groupCode) + { + $result = $this->model->getGroupCodeMap($groupName); + $this->assertEquals($result, $groupCode); + } + + /** + * @return array + */ + public function getGroupsData() + { + return [ + ['Migration_General', 'product-details'], + ['Migration_Prices', 'advanced-pricing'], + ['Migration_Design', 'design'], + ['Migration_Something', 'migration-something'], + ]; + } +} diff --git a/tests/unit/testsuite/Migration/Step/Eav/Integrity/AttributeGroupNamesTest.php b/tests/unit/testsuite/Migration/Step/Eav/Integrity/AttributeGroupNamesTest.php new file mode 100644 index 000000000..a46934cef --- /dev/null +++ b/tests/unit/testsuite/Migration/Step/Eav/Integrity/AttributeGroupNamesTest.php @@ -0,0 +1,136 @@ +helper = $this->getMockBuilder('\Migration\Step\Eav\Helper') + ->disableOriginalConstructor() + ->setMethods(['getSourceRecords']) + ->getMock(); + + $objectHelper = new ObjectManager($this); + $groupNameToCodeMap = $objectHelper->getObject('\Migration\Model\Eav\AttributeGroupNameToCodeMap'); + + $this->model = $objectHelper->getObject('\Migration\Step\Eav\Integrity\AttributeGroupNames', [ + 'helper' => $this->helper, + 'groupNameToCodeMap' => $groupNameToCodeMap + ]); + } + + /** + * @dataProvider getFixtureData() + * @param array $sourceData + * @param int $errorsCount + * @return void + */ + public function testCheckAttributeGroupNames($sourceData, $errorsCount) + { + $this->helper->expects($this->any())->method('getSourceRecords')->willReturnMap([ + ['eav_attribute_group', ['attribute_group_id'], $sourceData['eav_attribute_group']], + ['eav_entity_type', ['entity_type_code'], $sourceData['eav_entity_type']], + ['eav_attribute_set', ['attribute_set_id'], $sourceData['eav_attribute_set']] + ]); + + $result = $this->model->checkAttributeGroupNames(); + if (array_key_exists(MapInterface::TYPE_SOURCE, $result)) { + $result = $result[MapInterface::TYPE_SOURCE]; + } + + $this->assertCount($errorsCount, $result); + } + + /** + * @return array + */ + public function getFixtureData() + { + return [ + [ + [ + 'eav_attribute_group' => [ + 7 => ['attribute_set_id' => 4, 'attribute_group_name' => 'General'], + 8 => ['attribute_set_id' => 4, 'attribute_group_name' => 'Prices'], + 11 => ['attribute_set_id' => 4, 'attribute_group_name' => 'Design'] + ], + 'eav_entity_type' => [ + 'catalog_product' => ['entity_type_id' => 4] + ], + 'eav_attribute_set' => [ + 3 => ['attribute_set_id' => 3, 'entity_type_id' => 3, 'attribute_set_name' => 'Default'], + 4 => ['attribute_set_id' => 4, 'entity_type_id' => 4, 'attribute_set_name' => 'Default'] + ] + ], + 0 + ], [ + [ + 'eav_attribute_group' => [ + 5 => ['attribute_set_id' => 2, 'attribute_group_name' => 'Prices'], + 7 => ['attribute_set_id' => 3, 'attribute_group_name' => 'General'], + 8 => ['attribute_set_id' => 3, 'attribute_group_name' => 'Prices'], + 11 => ['attribute_set_id' => 3, 'attribute_group_name' => 'Design'], + 12 => ['attribute_set_id' => 4, 'attribute_group_name' => 'General'] + ], + 'eav_entity_type' => [ + 'catalog_product' => ['entity_type_id' => 4] + ], + 'eav_attribute_set' => [ + 1 => ['attribute_set_id' => 1, 'entity_type_id' => 3, 'attribute_set_name' => 'Default'], + 2 => ['attribute_set_id' => 2, 'entity_type_id' => 4, 'attribute_set_name' => 'Default'], + 3 => ['attribute_set_id' => 3, 'entity_type_id' => 4, 'attribute_set_name' => 'Default_2'], + 4 => ['attribute_set_id' => 4, 'entity_type_id' => 4, 'attribute_set_name' => 'Default_3'] + ] + ], + 2 + ], [ + [ + 'eav_attribute_group' => [ + 2 => ['attribute_set_id' => 2, 'attribute_group_name' => 'General'], + 7 => ['attribute_set_id' => 3, 'attribute_group_name' => 'General'], + 8 => ['attribute_set_id' => 3, 'attribute_group_name' => 'Prices'], + 11 => ['attribute_set_id' => 3, 'attribute_group_name' => 'Design'], + 12 => ['attribute_set_id' => 4, 'attribute_group_name' => 'General'] + ], + 'eav_entity_type' => [ + 'customer' => ['entity_type_id' => 1], + 'catalog_product' => ['entity_type_id' => 4], + 'order' => ['entity_type_id' => 5] + ], + 'eav_attribute_set' => [ + 1 => ['attribute_set_id' => 1, 'entity_type_id' => 2, 'attribute_set_name' => 'Custom'], + 2 => ['attribute_set_id' => 2, 'entity_type_id' => 3, 'attribute_set_name' => 'Default'], + 3 => ['attribute_set_id' => 3, 'entity_type_id' => 4, 'attribute_set_name' => 'Default_2'], + 4 => ['attribute_set_id' => 4, 'entity_type_id' => 4, 'attribute_set_name' => 'Default_3'] + ] + ], + 1 + ], + ]; + } +} diff --git a/tests/unit/testsuite/Migration/Step/Eav/IntegrityTest.php b/tests/unit/testsuite/Migration/Step/Eav/IntegrityTest.php index e2139dd70..1417c0db5 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/IntegrityTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/IntegrityTest.php @@ -73,7 +73,7 @@ public function setUp() $this->map = $this->getMockBuilder('\Migration\Reader\Map')->disableOriginalConstructor() ->setMethods(['getDocumentMap', 'getDocumentList', 'getFieldMap', 'isDocumentIgnored']) ->getMock(); - $this->attributeGroupNameToCodeMap = $this->getMockBuilder('Migration\Model\Eav\AttributeGroupNameToCodeMap') + $this->attributeGroupNameToCodeMap = $this->getMockBuilder('Migration\Step\Eav\Integrity\AttributeGroupNames') ->setMethods(['checkAttributeGroupNames']) ->disableOriginalConstructor() ->getMock(); From 2fb00765fcef0f9c579f555d599ac6c89508f4bc Mon Sep 17 00:00:00 2001 From: Ruslan Kostiv Date: Thu, 4 Aug 2016 19:00:36 +0300 Subject: [PATCH 20/30] MAGETWO-56087: Duplicate entry for key 'URL_REWRITE_REQUEST_PATH_STORE_ID' --- .../Step/UrlRewrite/Version191to2000.php | 31 +++++++++---------- .../Step/UrlRewrite/Version191to2000Test.php | 2 +- 2 files changed, 16 insertions(+), 17 deletions(-) diff --git a/src/Migration/Step/UrlRewrite/Version191to2000.php b/src/Migration/Step/UrlRewrite/Version191to2000.php index 81ef56911..d553d3fe9 100644 --- a/src/Migration/Step/UrlRewrite/Version191to2000.php +++ b/src/Migration/Step/UrlRewrite/Version191to2000.php @@ -225,7 +225,7 @@ protected function data() $this->destination->saveRecords(self::DESTINATION_PRODUCT_CATEGORY, $destProductCategoryRecords); } - $this->collectCmsPageRewrites(); + $this->saveCmsPageRewrites(); $this->progress->finish(); return true; } @@ -251,8 +251,8 @@ protected function volume() { $result = true; $this->progress->start(1); - $result &= $this->source->getRecordsCount(self::SOURCE) + $this->countCmsPageRewrites(true) == - ($this->destination->getRecordsCount(self::DESTINATION) + $this->getCmsPageUrlRewriteMatchedRecordsCount()); + $result &= $this->source->getRecordsCount(self::SOURCE) + $this->countCmsPageRewrites() == + ($this->destination->getRecordsCount(self::DESTINATION)); if (!$result) { $this->logger->error('Mismatch of entities in the document: url_rewrite'); } @@ -262,23 +262,23 @@ protected function volume() } /** - * Get amount of records of cms_page that matches the same request paths into core_url_rewrite + * Get request_paths from core_url_rewrite that matches cms_page.identifier * - * @return int + * @return \Magento\Framework\Db\Select */ - protected function getCmsPageUrlRewriteMatchedRecordsCount() + protected function getUrlRewriteRequestPathsSelect() { $select = $this->source->getAdapter()->getSelect(); - $select->distinct()->from( + $select->from( ['cur' => $this->source->addDocumentPrefix(self::SOURCE)], - new \Zend_Db_Expr('COUNT(cur.url_rewrite_id)') - )->join( + ['cur.request_path'] + )->joinLeft( ['cp' => $this->source->addDocumentPrefix($this->cmsPageTableName)], 'cur.request_path = cp.identifier', [] ); - return $this->source->getAdapter()->fetchOne($select); + return $select; } /** @@ -364,6 +364,9 @@ protected function selectCmsPageRewrites() [] )->where( 'cp.is_active = 1' + )->where( + 'cp.identifier NOT IN(?)', + $this->getUrlRewriteRequestPathsSelect() )->group(['request_path', 'cps.store_id']); return $select; @@ -372,7 +375,7 @@ protected function selectCmsPageRewrites() /** * @return void */ - protected function collectCmsPageRewrites() + protected function saveCmsPageRewrites() { $select = $this->selectCmsPageRewrites(); $urlRewrites = $this->source->getAdapter()->loadDataFromSelect($select); @@ -380,14 +383,10 @@ protected function collectCmsPageRewrites() } /** - * @param bool $countVolume * @return int */ - protected function countCmsPageRewrites($countVolume = false) + protected function countCmsPageRewrites() { - if (!$countVolume) { - return 1; - } $select = $this->selectCmsPageRewrites(); $urlRewrites = $this->source->getAdapter()->loadDataFromSelect($select); return count($urlRewrites); diff --git a/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php b/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php index cc4e06861..5ae4dae7f 100644 --- a/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php +++ b/tests/integration/testsuite/Migration/Step/UrlRewrite/Version191to2000Test.php @@ -92,7 +92,7 @@ public function testData() $logOutput = \Migration\Logger\Logger::getMessages(); $this->assertTrue(empty($logOutput[\Monolog\Logger::ERROR])); - $this->assertEquals(9, $destination->getRecordsCount('url_rewrite')); + $this->assertEquals(8, $destination->getRecordsCount('url_rewrite')); $this->assertEquals(4, $destination->getRecordsCount('catalog_url_rewrite_product_category')); $urlRewrite = $this->objectManager->create( From 767467c4c3ccf7e5c4f3ae7ce51050db129dad68 Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Wed, 10 Aug 2016 13:07:51 +0300 Subject: [PATCH 21/30] MAGETWO-55890: Make pull request to github and package to repo.magento.com --- src/Migration/ResourceModel/AbstractResource.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Migration/ResourceModel/AbstractResource.php b/src/Migration/ResourceModel/AbstractResource.php index 7610feb90..3043161ed 100644 --- a/src/Migration/ResourceModel/AbstractResource.php +++ b/src/Migration/ResourceModel/AbstractResource.php @@ -95,11 +95,11 @@ public function __construct( */ public function getDocument($documentName) { - $documentList = $this->getDocumentList(); - if (!in_array($documentName, $documentList)) { + try { + $structure = $this->getStructure($documentName); + } catch (\Exception $e) { return false; } - $structure = $this->getStructure($documentName); return $this->documentFactory->create(['structure' => $structure, 'documentName' => $documentName]); } From 0cd9e4db1d89e7e0f1307a47cd48e00cc96e5687 Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Wed, 10 Aug 2016 14:39:56 +0300 Subject: [PATCH 22/30] MAGETWO-55890: Make pull request to github and package to repo.magento.com --- src/Migration/ResourceModel/AbstractResource.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Migration/ResourceModel/AbstractResource.php b/src/Migration/ResourceModel/AbstractResource.php index 3043161ed..1833e3abd 100644 --- a/src/Migration/ResourceModel/AbstractResource.php +++ b/src/Migration/ResourceModel/AbstractResource.php @@ -95,12 +95,13 @@ public function __construct( */ public function getDocument($documentName) { + $document = false; try { $structure = $this->getStructure($documentName); - } catch (\Exception $e) { - return false; - } - return $this->documentFactory->create(['structure' => $structure, 'documentName' => $documentName]); + $document = $this->documentFactory->create(['structure' => $structure, 'documentName' => $documentName]); + } catch (\Exception $e) {} + + return $document; } /** From 6cf9da54533e558410822c2c5b5a3efd41b0b135 Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Wed, 10 Aug 2016 14:57:09 +0300 Subject: [PATCH 23/30] MAGETWO-55890: Make pull request to github and package to repo.magento.com --- src/Migration/ResourceModel/AbstractResource.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/Migration/ResourceModel/AbstractResource.php b/src/Migration/ResourceModel/AbstractResource.php index 1833e3abd..5596ea693 100644 --- a/src/Migration/ResourceModel/AbstractResource.php +++ b/src/Migration/ResourceModel/AbstractResource.php @@ -98,7 +98,11 @@ public function getDocument($documentName) $document = false; try { $structure = $this->getStructure($documentName); - $document = $this->documentFactory->create(['structure' => $structure, 'documentName' => $documentName]); + if ($structure instanceof \Migration\ResourceModel\Structure) { + $document = $this->documentFactory->create( + ['structure' => $structure, 'documentName' => $documentName] + ); + } } catch (\Exception $e) {} return $document; From 9cfb2884e59d49e17fb6b4da579391835cd3f8ac Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Wed, 10 Aug 2016 16:51:25 +0300 Subject: [PATCH 24/30] MAGETWO-55890: Make pull request to github and package to repo.magento.com --- src/Migration/ResourceModel/AbstractResource.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/Migration/ResourceModel/AbstractResource.php b/src/Migration/ResourceModel/AbstractResource.php index 5596ea693..e9894673e 100644 --- a/src/Migration/ResourceModel/AbstractResource.php +++ b/src/Migration/ResourceModel/AbstractResource.php @@ -103,7 +103,9 @@ public function getDocument($documentName) ['structure' => $structure, 'documentName' => $documentName] ); } - } catch (\Exception $e) {} + } catch (\Exception $e) { + + } return $document; } From fbb9e3cf88be0e7167736055b1be9427feab9abf Mon Sep 17 00:00:00 2001 From: Victor Rad Date: Thu, 11 Aug 2016 13:09:41 +0300 Subject: [PATCH 25/30] MAGETWO-56461: DMT 2.1.1 release S39 --- CHANGELOG.md | 15 +++++++++++++++ composer.json | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fae66b8f..b0498f1e4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,18 @@ +2.1.1 +============= +* Improvements in migration of Magento 1 CE stores upgraded to 1.6 and later versions from versions earlier than 1.6 version +* Performance improvements in migration process +* Added support for migration for the following versions: + + * Magento CE version 2.1.1 + * Magento EE version 2.1.1 + +* Fixed bugs: + * Fixed an issue with URL Rewrite duplication in CMS Pages and Catalog + * [Issue#112](https://github.com/magento/data-migration-tool/issues/112) Errors on EAV step + * [Issue#75](https://github.com/magento/data-migration-tool/issues/75) Data Migration hung at Customer Attributes Step + * [Issue#64](https://github.com/magento/data-migration-tool/issues/64) Migration does not run on PHP 7 after DI compilation + 2.1.0 ============= * Added support for migration of Magento 1 CE stores upgraded to 1.6 and later versions from versions earlier than 1.6 version diff --git a/composer.json b/composer.json index aca8fa3fa..90b7287c1 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "magento/data-migration-tool", "description": "Migration Tool", - "version": "2.1.0", + "version": "2.1.1", "require": { "symfony/console": "~2.3", "magento/framework": "~100.1", From c98fcdf4427abe5da70dc27dfda650afb4a0537f Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Fri, 19 Aug 2016 19:19:12 +0300 Subject: [PATCH 26/30] MAGETWO-52161: [GitHub] Bug in EAV with group_price attribute #69 --- src/Migration/Step/Eav/Data.php | 29 +------------- src/Migration/Step/Eav/Helper.php | 39 ++++++++++++++++++- src/Migration/Step/Eav/InitialData.php | 6 ++- tests/integration/resource/eav/dest.sql | 1 + tests/integration/resource/eav/source.sql | 2 + tests/integration/resource/ee.eav/dest.sql | 1 + tests/integration/resource/ee.eav/source.sql | 2 + .../Migration/Step/Eav/HelperTest.php | 18 +++++++-- .../Migration/Step/Eav/InitialDataTest.php | 6 ++- 9 files changed, 70 insertions(+), 34 deletions(-) diff --git a/src/Migration/Step/Eav/Data.php b/src/Migration/Step/Eav/Data.php index be955f737..a0fbcf1ed 100644 --- a/src/Migration/Step/Eav/Data.php +++ b/src/Migration/Step/Eav/Data.php @@ -102,11 +102,6 @@ class Data implements StageInterface, RollbackInterface */ protected $readerGroups; - /** - * @var \Migration\Reader\Groups - */ - protected $readerAttributes; - /** * @var array */ @@ -146,7 +141,6 @@ public function __construct( $this->destination = $destination; $this->map = $mapFactory->create('eav_map_file'); $this->readerGroups = $groupsFactory->create('eav_document_groups_file'); - $this->readerAttributes = $groupsFactory->create('eav_attribute_groups_file'); $this->helper = $helper; $this->factory = $factory; $this->initialData = $initialData; @@ -389,10 +383,7 @@ protected function migrateAttributes() $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE) ); $this->destination->backupDocument($destinationDocument->getName()); - $sourceRecords = $this->source->getRecords($sourceDocName, 0, $this->source->getRecordsCount($sourceDocName)); - foreach (array_keys($this->readerAttributes->getGroup('ignore')) as $attributeToClear) { - $sourceRecords = $this->clearIgnoredAttributes($sourceRecords, $attributeToClear); - } + $sourceRecords = $this->initialData->getAttributes('source');; $destinationRecords = $this->initialData->getAttributes('dest'); $recordsToSave = $destinationDocument->getRecords(); @@ -837,22 +828,4 @@ public function rollback() } } } - - /** - * Remove ignored attributes from source records - * - * @param array $sourceRecords - * @param array $attributeToClear - * @return array - */ - protected function clearIgnoredAttributes($sourceRecords, $attributeToClear) - { - foreach ($sourceRecords as $attrNum => $sourceAttribute) { - if ($sourceAttribute['attribute_code'] == $attributeToClear) { - unset($sourceRecords[$attrNum]); - } - } - return $sourceRecords; - } - // @codeCoverageIgnoreEnd } diff --git a/src/Migration/Step/Eav/Helper.php b/src/Migration/Step/Eav/Helper.php index 2bb297424..886e15bbe 100644 --- a/src/Migration/Step/Eav/Helper.php +++ b/src/Migration/Step/Eav/Helper.php @@ -40,10 +40,15 @@ class Helper */ protected $readerGroups; + /** + * @var \Migration\Reader\Groups + */ + protected $readerAttributes; + /** * @var \Migration\ResourceModel\Record[] */ - protected $addedGroups ; + protected $addedGroups; /** * @param MapFactory $mapFactory @@ -64,6 +69,7 @@ public function __construct( $this->destination = $destination; $this->factory = $factory; $this->readerGroups = $groupsFactory->create('eav_document_groups_file'); + $this->readerAttributes = $groupsFactory->create('eav_attribute_groups_file'); } /** @@ -231,4 +237,35 @@ public function getDesignAttributeAndGroupsData() 'entityTypeIdCatalogProduct' => $entityTypeIdCatalogProduct ]; } + + /** + * @param array $sourceRecords + * @return array + */ + public function clearIgnored($sourceRecords) + { + foreach (array_keys($this->readerAttributes->getGroup('ignore')) as $attributeToClear) { + $sourceRecords = $this->clearIgnoredAttributes($sourceRecords, $attributeToClear); + } + return $sourceRecords; + } + + /** + * Remove ignored attributes from source records + * + * @param array $sourceRecords + * @param array $attributeToClear + * @return array + */ + protected function clearIgnoredAttributes($sourceRecords, $attributeToClear) + { + foreach ($sourceRecords as $attrNum => $sourceAttribute) { + if ( + isset($sourceAttribute['attribute_code']) && ($sourceAttribute['attribute_code'] == $attributeToClear) + ) { + unset($sourceRecords[$attrNum]); + } + } + return $sourceRecords; + } } diff --git a/src/Migration/Step/Eav/InitialData.php b/src/Migration/Step/Eav/InitialData.php index c16f8ce72..280740f5d 100644 --- a/src/Migration/Step/Eav/InitialData.php +++ b/src/Migration/Step/Eav/InitialData.php @@ -106,7 +106,11 @@ protected function initAttributes() if ($this->attributes === null) { $sourceDocument = 'eav_attribute'; - foreach ($this->helper->getSourceRecords($sourceDocument, ['attribute_id']) as $id => $record) { + foreach ( + $this->helper->clearIgnored( + $this->helper->getSourceRecords($sourceDocument, ['attribute_id']) + ) as $id => $record + ) { $this->attributes['source'][$id] = $record; } diff --git a/tests/integration/resource/eav/dest.sql b/tests/integration/resource/eav/dest.sql index 9908dd785..94d20610c 100644 --- a/tests/integration/resource/eav/dest.sql +++ b/tests/integration/resource/eav/dest.sql @@ -133,6 +133,7 @@ ENGINE=InnoDB ; INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`, `attribute_group_code`, `tab_group_code`) VALUES (7, 4, 'Product Details', 10, 1, 'product-details', 'basic'); INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`, `attribute_group_code`, `tab_group_code`) VALUES (1, 1, 'General', 1, 1, NULL, NULL); +INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`, `attribute_group_code`, `tab_group_code`) VALUES (8, 4, 'Design', 11, 1, 'design', 'advanced'); CREATE TABLE `eav_entity_attribute` ( `entity_attribute_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity Attribute Id', diff --git a/tests/integration/resource/eav/source.sql b/tests/integration/resource/eav/source.sql index 2eed9730b..1893966f4 100644 --- a/tests/integration/resource/eav/source.sql +++ b/tests/integration/resource/eav/source.sql @@ -127,6 +127,8 @@ ENGINE=InnoDB ; INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`) VALUES (4, 4, 'General', 1, 1); INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`) VALUES (1, 1, 'General', 1, 1); +INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`) VALUES (5, 4, 'Prices', 2, 0); +INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`) VALUES (6, 4, 'Design', 3, 0); CREATE TABLE `eav_entity_attribute` ( `entity_attribute_id` INT(10) UNSIGNED NOT NULL COMMENT 'Entity Attribute Id', diff --git a/tests/integration/resource/ee.eav/dest.sql b/tests/integration/resource/ee.eav/dest.sql index 61e4d8844..145944215 100644 --- a/tests/integration/resource/ee.eav/dest.sql +++ b/tests/integration/resource/ee.eav/dest.sql @@ -133,6 +133,7 @@ ENGINE=InnoDB ; INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`, `attribute_group_code`, `tab_group_code`) VALUES (7, 4, 'Product Details', 10, 1, 'product-details', 'basic'); INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`, `attribute_group_code`, `tab_group_code`) VALUES (1, 1, 'General', 1, 1, NULL, NULL); +INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`, `attribute_group_code`, `tab_group_code`) VALUES (8, 4, 'Design', 11, 1, 'design', 'advanced'); CREATE TABLE `eav_entity_attribute` ( `entity_attribute_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT COMMENT 'Entity Attribute Id', diff --git a/tests/integration/resource/ee.eav/source.sql b/tests/integration/resource/ee.eav/source.sql index 45e77d3e3..2cddcf89f 100644 --- a/tests/integration/resource/ee.eav/source.sql +++ b/tests/integration/resource/ee.eav/source.sql @@ -127,6 +127,8 @@ ENGINE=InnoDB ; INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`) VALUES (4, 4, 'General', 1, 1); INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`) VALUES (1, 1, 'General', 1, 1); +INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`) VALUES (5, 4, 'Prices', 2, 0); +INSERT INTO `eav_attribute_group` (`attribute_group_id`, `attribute_set_id`, `attribute_group_name`, `sort_order`, `default_id`) VALUES (6, 4, 'Design', 3, 0); CREATE TABLE `eav_entity_attribute` ( `entity_attribute_id` INT(10) UNSIGNED NOT NULL COMMENT 'Entity Attribute Id', diff --git a/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php b/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php index 7fd32bd97..ea17933e3 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php @@ -46,6 +46,11 @@ class HelperTest extends \PHPUnit_Framework_TestCase */ protected $readerGroups; + /** + * @var \Migration\Reader\Groups|\PHPUnit_Framework_MockObject_MockObject + */ + protected $readerAttributes; + /** * @return void */ @@ -72,6 +77,10 @@ public function setUp() ->disableOriginalConstructor() ->setMethods([]) ->getMock(); + $this->readerAttributes = $this->getMockBuilder('\Migration\Reader\Groups') + ->disableOriginalConstructor() + ->setMethods([]) + ->getMock(); /** @var \Migration\Reader\GroupsFactory|\PHPUnit_Framework_MockObject_MockObject $groupsFactory */ $groupsFactory = $this->getMockBuilder('\Migration\Reader\GroupsFactory') ->disableOriginalConstructor() @@ -79,9 +88,12 @@ public function setUp() ->getMock(); $groupsFactory->expects($this->any()) ->method('create') - ->with('eav_document_groups_file') - ->willReturn($this->readerGroups); - + ->willReturnMap( + [ + ['eav_document_groups_file', $this->readerGroups], + ['eav_attribute_groups_file', $this->readerAttributes] + ] + ); $this->helper = new Helper($mapFactory, $this->source, $this->destination, $this->factory, $groupsFactory); } diff --git a/tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php b/tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php index 0431baec9..921bc1c2d 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php @@ -55,7 +55,7 @@ public function setUp() ->setMethods([]) ->getMock(); $this->helper = $this->getMockBuilder('\Migration\Step\Eav\Helper')->disableOriginalConstructor() - ->setMethods(['getSourceRecords', 'getDestinationRecords']) + ->setMethods(['getSourceRecords', 'getDestinationRecords', 'clearIgnored']) ->getMock(); $this->initialData = new InitialData($mapFactory, $this->source, $this->destination, $this->helper); } @@ -101,6 +101,10 @@ public function testInit() ['eav_attribute', ['attribute_id'], $dataAttributes['source']], ['eav_entity_type', [], $eavEntityTypes['source']] ]); + $this->helper->expects($this->any())->method('clearIgnored')->willReturnMap([ + [$dataAttributes['source'], $dataAttributes['source']], + [$eavEntityTypes['source'], $eavEntityTypes['source']] + ]); $this->helper->expects($this->any())->method('getDestinationRecords')->willReturnMap( [ ['eav_attribute', ['entity_type_id', 'attribute_code'], $dataAttributes['dest']], From 60a16473e291ab96be827a8a324538aeaae54be4 Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Mon, 22 Aug 2016 13:30:05 +0300 Subject: [PATCH 27/30] MAGETWO-52161: [GitHub] Bug in EAV with group_price attribute #69 --- src/Migration/Step/Eav/Data.php | 2 +- src/Migration/Step/Eav/InitialData.php | 6 +----- src/Migration/Step/Eav/Volume.php | 2 +- tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php | 2 +- tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php | 4 +++- 5 files changed, 7 insertions(+), 9 deletions(-) diff --git a/src/Migration/Step/Eav/Data.php b/src/Migration/Step/Eav/Data.php index a0fbcf1ed..65576e98e 100644 --- a/src/Migration/Step/Eav/Data.php +++ b/src/Migration/Step/Eav/Data.php @@ -383,7 +383,7 @@ protected function migrateAttributes() $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE) ); $this->destination->backupDocument($destinationDocument->getName()); - $sourceRecords = $this->initialData->getAttributes('source');; + $sourceRecords = $this->helper->clearIgnored($this->initialData->getAttributes('source')); $destinationRecords = $this->initialData->getAttributes('dest'); $recordsToSave = $destinationDocument->getRecords(); diff --git a/src/Migration/Step/Eav/InitialData.php b/src/Migration/Step/Eav/InitialData.php index 280740f5d..c16f8ce72 100644 --- a/src/Migration/Step/Eav/InitialData.php +++ b/src/Migration/Step/Eav/InitialData.php @@ -106,11 +106,7 @@ protected function initAttributes() if ($this->attributes === null) { $sourceDocument = 'eav_attribute'; - foreach ( - $this->helper->clearIgnored( - $this->helper->getSourceRecords($sourceDocument, ['attribute_id']) - ) as $id => $record - ) { + foreach ($this->helper->getSourceRecords($sourceDocument, ['attribute_id']) as $id => $record) { $this->attributes['source'][$id] = $record; } diff --git a/src/Migration/Step/Eav/Volume.php b/src/Migration/Step/Eav/Volume.php index ba1ba5a0f..2a35d2c21 100644 --- a/src/Migration/Step/Eav/Volume.php +++ b/src/Migration/Step/Eav/Volume.php @@ -178,7 +178,7 @@ protected function validateCustomConditions(array $attribute, array $conditions) */ protected function checkAttributesMismatch($attribute) { - $sourceAttributes = $this->initialData->getAttributes('source'); + $sourceAttributes = $this->helper->clearIgnored($this->initialData->getAttributes('source')); if (isset($sourceAttributes[$attribute['attribute_id']]) && ($sourceAttributes[$attribute['attribute_id']]['attribute_code'] != $attribute['attribute_code']) diff --git a/tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php b/tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php index 921bc1c2d..bb3bfc99c 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/InitialDataTest.php @@ -55,7 +55,7 @@ public function setUp() ->setMethods([]) ->getMock(); $this->helper = $this->getMockBuilder('\Migration\Step\Eav\Helper')->disableOriginalConstructor() - ->setMethods(['getSourceRecords', 'getDestinationRecords', 'clearIgnored']) + ->setMethods(['getSourceRecords', 'getDestinationRecords']) ->getMock(); $this->initialData = new InitialData($mapFactory, $this->source, $this->destination, $this->helper); } diff --git a/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php b/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php index 1abe64ea4..d899a7e5b 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php @@ -59,7 +59,8 @@ public function setUp() 'getDestinationRecords', 'getSourceRecordsCount', 'getDestinationRecordsCount', - 'deleteBackups' + 'deleteBackups', + 'clearIgnored' ] )->getMock(); $this->logger = $this->getMockBuilder('\Migration\Logger\Logger')->disableOriginalConstructor() @@ -153,6 +154,7 @@ public function testPerform() $this->initialData->expects($this->once())->method('getAttributeGroups')->willReturn(1); $this->helper->expects($this->any())->method('getDestinationRecordsCount')->willReturn(2); $this->helper->expects($this->once())->method('deleteBackups'); + $this->helper->expects($this->any())->method('clearIgnored')->with($eavAttributes)->willReturn($eavAttributes); $this->logger->expects($this->never())->method('addRecord'); $documentsMap = $this->getDocumentsMap(); From b7a821df893b7e5f17525e729908b54ef28d28d0 Mon Sep 17 00:00:00 2001 From: Leonid Poluyanov Date: Mon, 22 Aug 2016 14:44:19 +0300 Subject: [PATCH 28/30] MAGETWO-52161: [GitHub] Bug in EAV with group_price attribute #69 --- src/Migration/Step/Eav/Data.php | 2 +- src/Migration/Step/Eav/Helper.php | 19 +++--------- src/Migration/Step/Eav/Volume.php | 2 +- .../Migration/Step/Eav/HelperTest.php | 29 +++++++++++++++++++ .../Migration/Step/Eav/VolumeTest.php | 5 ++-- 5 files changed, 38 insertions(+), 19 deletions(-) diff --git a/src/Migration/Step/Eav/Data.php b/src/Migration/Step/Eav/Data.php index 65576e98e..6f81e5203 100644 --- a/src/Migration/Step/Eav/Data.php +++ b/src/Migration/Step/Eav/Data.php @@ -383,7 +383,7 @@ protected function migrateAttributes() $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE) ); $this->destination->backupDocument($destinationDocument->getName()); - $sourceRecords = $this->helper->clearIgnored($this->initialData->getAttributes('source')); + $sourceRecords = $this->helper->clearIgnoredAttributes($this->initialData->getAttributes('source')); $destinationRecords = $this->initialData->getAttributes('dest'); $recordsToSave = $destinationDocument->getRecords(); diff --git a/src/Migration/Step/Eav/Helper.php b/src/Migration/Step/Eav/Helper.php index 886e15bbe..81c83bb34 100644 --- a/src/Migration/Step/Eav/Helper.php +++ b/src/Migration/Step/Eav/Helper.php @@ -238,30 +238,19 @@ public function getDesignAttributeAndGroupsData() ]; } - /** - * @param array $sourceRecords - * @return array - */ - public function clearIgnored($sourceRecords) - { - foreach (array_keys($this->readerAttributes->getGroup('ignore')) as $attributeToClear) { - $sourceRecords = $this->clearIgnoredAttributes($sourceRecords, $attributeToClear); - } - return $sourceRecords; - } - /** * Remove ignored attributes from source records * * @param array $sourceRecords - * @param array $attributeToClear * @return array */ - protected function clearIgnoredAttributes($sourceRecords, $attributeToClear) + public function clearIgnoredAttributes($sourceRecords) { + $ignoredAttributes = array_keys($this->readerAttributes->getGroup('ignore')); foreach ($sourceRecords as $attrNum => $sourceAttribute) { if ( - isset($sourceAttribute['attribute_code']) && ($sourceAttribute['attribute_code'] == $attributeToClear) + isset($sourceAttribute['attribute_code']) + && (in_array($sourceAttribute['attribute_code'], $ignoredAttributes)) ) { unset($sourceRecords[$attrNum]); } diff --git a/src/Migration/Step/Eav/Volume.php b/src/Migration/Step/Eav/Volume.php index 2a35d2c21..d77edadd0 100644 --- a/src/Migration/Step/Eav/Volume.php +++ b/src/Migration/Step/Eav/Volume.php @@ -178,7 +178,7 @@ protected function validateCustomConditions(array $attribute, array $conditions) */ protected function checkAttributesMismatch($attribute) { - $sourceAttributes = $this->helper->clearIgnored($this->initialData->getAttributes('source')); + $sourceAttributes = $this->helper->clearIgnoredAttributes($this->initialData->getAttributes('source')); if (isset($sourceAttributes[$attribute['attribute_id']]) && ($sourceAttributes[$attribute['attribute_id']]['attribute_code'] != $attribute['attribute_code']) diff --git a/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php b/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php index ea17933e3..3e6c3040e 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/HelperTest.php @@ -226,4 +226,33 @@ public function testDeleteBackups() $this->destination->expects($this->once())->method('deleteDocumentBackup')->with('some_dest_document'); $this->helper->deleteBackups(); } + + /** + * @return void + */ + public function testClearIgnoredAttributes() + { + $allSourceRecords = [ + 0 => [ + 'attribute_code' => 'ignored_attribute' + ], + 1 => [ + 'attribute_code' => 'attribute_1' + ], + 2 => [ + 'attribute_code' => 'attribute_2' + ] + ]; + $clearedSourceRecords = [ + 1 => [ + 'attribute_code' => 'attribute_1' + ], + 2 => [ + 'attribute_code' => 'attribute_2' + ] + ]; + $this->readerAttributes->expects($this->once())->method('getGroup')->with('ignore') + ->willReturn(['ignored_attribute' => 0]); + $this->assertEquals($clearedSourceRecords, $this->helper->clearIgnoredAttributes($allSourceRecords)); + } } diff --git a/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php b/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php index d899a7e5b..17550c95b 100644 --- a/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php +++ b/tests/unit/testsuite/Migration/Step/Eav/VolumeTest.php @@ -60,7 +60,7 @@ public function setUp() 'getSourceRecordsCount', 'getDestinationRecordsCount', 'deleteBackups', - 'clearIgnored' + 'clearIgnoredAttributes' ] )->getMock(); $this->logger = $this->getMockBuilder('\Migration\Logger\Logger')->disableOriginalConstructor() @@ -154,7 +154,8 @@ public function testPerform() $this->initialData->expects($this->once())->method('getAttributeGroups')->willReturn(1); $this->helper->expects($this->any())->method('getDestinationRecordsCount')->willReturn(2); $this->helper->expects($this->once())->method('deleteBackups'); - $this->helper->expects($this->any())->method('clearIgnored')->with($eavAttributes)->willReturn($eavAttributes); + $this->helper->expects($this->any())->method('clearIgnoredAttributes')->with($eavAttributes) + ->willReturn($eavAttributes); $this->logger->expects($this->never())->method('addRecord'); $documentsMap = $this->getDocumentsMap(); From bcc54763ce22417feb789c4126e77681d689679b Mon Sep 17 00:00:00 2001 From: Yurii Hryhoriev Date: Mon, 29 Aug 2016 15:22:07 +0300 Subject: [PATCH 29/30] MAGETWO-56234: [DB-HA] Magento 2 frontend does not work after migration --- etc/ce-to-ce/settings.xml.dist | 14 ++++++-------- etc/ce-to-ee/settings.xml.dist | 14 ++++++-------- etc/ee-to-ee/settings.xml.dist | 14 ++++++-------- 3 files changed, 18 insertions(+), 24 deletions(-) diff --git a/etc/ce-to-ce/settings.xml.dist b/etc/ce-to-ce/settings.xml.dist index 8313b9bce..b9e0ff059 100644 --- a/etc/ce-to-ce/settings.xml.dist +++ b/etc/ce-to-ce/settings.xml.dist @@ -1039,6 +1039,12 @@ system/page_cache/debug + + design/theme/template + + + design/theme/template_ua_regexp + admin/security/session_cookie_lifetime admin/security/session_lifetime @@ -1179,14 +1185,6 @@ design/header/logo_src_small design/header/logo_src - - design/theme/template - design/theme/theme_id - - - design/theme/template_ua_regexp - design/theme/ua_regexp - general/store_information/merchant_country general/store_information/country_id diff --git a/etc/ce-to-ee/settings.xml.dist b/etc/ce-to-ee/settings.xml.dist index 8313b9bce..b9e0ff059 100644 --- a/etc/ce-to-ee/settings.xml.dist +++ b/etc/ce-to-ee/settings.xml.dist @@ -1039,6 +1039,12 @@ system/page_cache/debug + + design/theme/template + + + design/theme/template_ua_regexp + admin/security/session_cookie_lifetime admin/security/session_lifetime @@ -1179,14 +1185,6 @@ design/header/logo_src_small design/header/logo_src - - design/theme/template - design/theme/theme_id - - - design/theme/template_ua_regexp - design/theme/ua_regexp - general/store_information/merchant_country general/store_information/country_id diff --git a/etc/ee-to-ee/settings.xml.dist b/etc/ee-to-ee/settings.xml.dist index 8bf008364..68b95d130 100644 --- a/etc/ee-to-ee/settings.xml.dist +++ b/etc/ee-to-ee/settings.xml.dist @@ -1084,6 +1084,12 @@ system/page_cache/debug + + design/theme/template + + + design/theme/template_ua_regexp + admin/security/session_cookie_lifetime admin/security/session_lifetime @@ -1340,14 +1346,6 @@ design/header/logo_src_small design/header/logo_src - - design/theme/template - design/theme/theme_id - - - design/theme/template_ua_regexp - design/theme/ua_regexp - enterprise_giftregistry/general/enabled magento_giftregistry/general/enabled From af8d414659e929721a4d1d3a812db1f1dffae1f5 Mon Sep 17 00:00:00 2001 From: Yurii Hryhoriev Date: Tue, 30 Aug 2016 12:44:58 +0300 Subject: [PATCH 30/30] MAGETWO-57477: [DB-HA] Cannot login as admin after migration --- etc/ce-to-ce/settings.xml.dist | 5 ++--- etc/ce-to-ee/settings.xml.dist | 5 ++--- etc/ee-to-ee/settings.xml.dist | 5 ++--- 3 files changed, 6 insertions(+), 9 deletions(-) diff --git a/etc/ce-to-ce/settings.xml.dist b/etc/ce-to-ce/settings.xml.dist index 8313b9bce..ddeefe7cc 100644 --- a/etc/ce-to-ce/settings.xml.dist +++ b/etc/ce-to-ce/settings.xml.dist @@ -1039,10 +1039,9 @@ system/page_cache/debug - + admin/security/session_cookie_lifetime - admin/security/session_lifetime - + api/config/charset webapi/soap/charset diff --git a/etc/ce-to-ee/settings.xml.dist b/etc/ce-to-ee/settings.xml.dist index 8313b9bce..ddeefe7cc 100644 --- a/etc/ce-to-ee/settings.xml.dist +++ b/etc/ce-to-ee/settings.xml.dist @@ -1039,10 +1039,9 @@ system/page_cache/debug - + admin/security/session_cookie_lifetime - admin/security/session_lifetime - + api/config/charset webapi/soap/charset diff --git a/etc/ee-to-ee/settings.xml.dist b/etc/ee-to-ee/settings.xml.dist index 8bf008364..f62081269 100644 --- a/etc/ee-to-ee/settings.xml.dist +++ b/etc/ee-to-ee/settings.xml.dist @@ -1084,10 +1084,9 @@ system/page_cache/debug - + admin/security/session_cookie_lifetime - admin/security/session_lifetime - + api/config/charset webapi/soap/charset