Skip to content

Commit 13728b3

Browse files
committed
MAGETWO-95455: [GitHub] Fields from third-party extensions cause error during migration with -auto option #595
1 parent feca1f2 commit 13728b3

File tree

4 files changed

+61
-2
lines changed

4 files changed

+61
-2
lines changed

src/Migration/RecordTransformer.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,13 +128,16 @@ protected function copy(Record $from, Record $to)
128128
{
129129
$sourceDocumentName = $this->sourceDocument->getName();
130130
$sourceFields = $from->getFields();
131+
$sourceFieldsExtra = array_diff($sourceFields, $to->getFields());
131132
$data = [];
132133
foreach ($sourceFields as $key => $field) {
133134
if ($this->mapReader->isFieldIgnored($sourceDocumentName, $field, MapInterface::TYPE_SOURCE)) {
134-
unset($sourceFields[$key]);
135135
continue;
136136
}
137137
$fieldMap = $this->mapReader->getFieldMap($sourceDocumentName, $field, MapInterface::TYPE_SOURCE);
138+
if ($fieldMap == $field && in_array($field, $sourceFieldsExtra)) {
139+
continue;
140+
}
138141
$data[$fieldMap] = $from->getValue($field);
139142
}
140143
foreach ($data as $key => $value) {

tests/integration/resource/default/dest.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,29 @@ LOCK TABLES `common_table` WRITE;
3838
/*!40000 ALTER TABLE `common_table` ENABLE KEYS */;
3939
UNLOCK TABLES;
4040

41+
--
42+
-- Table structure for table `common_table_extra_field`
43+
--
44+
45+
DROP TABLE IF EXISTS `common_table_extra_field`;
46+
/*!40101 SET @saved_cs_client = @@character_set_client */;
47+
/*!40101 SET character_set_client = utf8 */;
48+
CREATE TABLE `common_table_extra_field` (
49+
`key` int(11) NOT NULL AUTO_INCREMENT,
50+
`common_field` int(11) DEFAULT NULL,
51+
PRIMARY KEY (`key`)
52+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
53+
/*!40101 SET character_set_client = @saved_cs_client */;
54+
55+
--
56+
-- Dumping data for table `common_table_extra_field`
57+
--
58+
59+
LOCK TABLES `common_table_extra_field` WRITE;
60+
/*!40000 ALTER TABLE `common_table_extra_field` DISABLE KEYS */;
61+
/*!40000 ALTER TABLE `common_table_extra_field` ENABLE KEYS */;
62+
UNLOCK TABLES;
63+
4164
--
4265
-- Table structure for table `dest_table_ignored`
4366
--

tests/integration/resource/default/source.sql

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,31 @@ INSERT INTO `common_table` VALUES (1,2,3),(2,3,4),(3,4,5),(4,5,6),(5,5,5),(6,6,7
3939
/*!40000 ALTER TABLE `common_table` ENABLE KEYS */;
4040
UNLOCK TABLES;
4141

42+
--
43+
-- Table structure for table `common_table_extra_field`
44+
--
45+
46+
DROP TABLE IF EXISTS `common_table_extra_field`;
47+
/*!40101 SET @saved_cs_client = @@character_set_client */;
48+
/*!40101 SET character_set_client = utf8 */;
49+
CREATE TABLE `common_table_extra_field` (
50+
`key` int(11) NOT NULL AUTO_INCREMENT,
51+
`common_field` int(11) DEFAULT NULL,
52+
`source_field_extra` int(11) DEFAULT NULL,
53+
PRIMARY KEY (`key`)
54+
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
55+
/*!40101 SET character_set_client = @saved_cs_client */;
56+
57+
--
58+
-- Dumping data for table `common_table_extra_field`
59+
--
60+
61+
LOCK TABLES `common_table_extra_field` WRITE;
62+
/*!40000 ALTER TABLE `common_table_extra_field` DISABLE KEYS */;
63+
INSERT INTO `common_table_extra_field` VALUES (1,2,3),(2,3,4),(3,4,5),(4,5,6),(5,5,5),(6,6,7),(7,7,7);
64+
/*!40000 ALTER TABLE `common_table_extra_field` ENABLE KEYS */;
65+
UNLOCK TABLES;
66+
4267
--
4368
-- Table structure for table `source_table_ignored`
4469
--

tests/integration/testsuite/Migration/Step/Map/IntegrityTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,16 @@ public function testIntegrityWithMap()
4242
ob_start();
4343
$map->perform();
4444
ob_end_clean();
45+
$logOutput = \Migration\Logger\Logger::getMessages();
46+
$this->assertTrue(isset($logOutput[\Monolog\Logger::ERROR]));
4547

48+
$config->setOption(\Migration\Config::OPTION_AUTO_RESOLVE, 1);
49+
\Migration\Logger\Logger::clearMessages();
50+
ob_start();
51+
$map->perform();
52+
ob_end_clean();
4653
$logOutput = \Migration\Logger\Logger::getMessages();
47-
$this->assertFalse(isset($logOutput[\Monolog\Logger::ERROR]));
54+
$this->assertTrue(isset($logOutput[\Monolog\Logger::WARNING]));
4855
}
4956

5057
/**
@@ -59,6 +66,7 @@ public function testIntegrityWithoutMap()
5966
$logger = $objectManager->create(\Migration\Logger\Logger::class);
6067
$logger->pushHandler($objectManager->create(\Migration\Logger\ConsoleHandler::class));
6168
$config = $objectManager->get(\Migration\Config::class);
69+
$config->setOption(\Migration\Config::OPTION_AUTO_RESOLVE, 0);
6270
/** @var \Migration\Logger\Manager $logManager */
6371
$logManager->process(\Migration\Logger\Manager::LOG_LEVEL_ERROR);
6472
\Migration\Logger\Logger::clearMessages();

0 commit comments

Comments
 (0)