/** * @expectedException \Exception * @expectedExceptionMessage Record structure does not equal Collection structure * @return void */ public function testAddRecordWithException() { $this->assertEquals(3, count($this->recordCollection)); $record = $this->getMock('\\Migration\\ResourceModel\\Record', [], [], '', false); $this->recordCollection->addRecord($record); $this->assertEquals(4, count($this->recordCollection)); }
/** * @param \Migration\ResourceModel\Record\Collection $source * @param \Migration\ResourceModel\Record\Collection $destination * @return void */ protected function migrateRewrites($source, $destination) { /** @var \Migration\ResourceModel\Record $sourceRecord */ foreach ($source as $sourceRecord) { /** @var \Migration\ResourceModel\Record $destinationRecord */ $destinationRecord = $this->recordFactory->create(); $destinationRecord->setStructure($destination->getStructure()); $destinationRecord->setValue('url_rewrite_id', null); $destinationRecord->setValue('store_id', $sourceRecord->getValue('store_id')); $destinationRecord->setValue('description', $sourceRecord->getValue('description')); $destinationRecord->setValue('redirect_type', 0); $destinationRecord->setValue('is_autogenerated', $sourceRecord->getValue('is_system')); $destinationRecord->setValue('metadata', ''); $destinationRecord->setValue('redirect_type', $sourceRecord->getValue('redirect_type')); $destinationRecord->setValue('entity_type', $sourceRecord->getValue('entity_type')); $destinationRecord->setValue('request_path', $sourceRecord->getValue('request_path')); $targetPath = $sourceRecord->getValue('target_path'); $productId = $sourceRecord->getValue('product_id'); $categoryId = $sourceRecord->getValue('category_id'); $cmsPageId = $sourceRecord->getValue('cms_page_id'); if (!empty($productId) && !empty($categoryId)) { $length = strlen($categoryId); $metadata = sprintf('a:1:{s:11:"category_id";s:%s:"%s";}', $length, $categoryId); $destinationRecord->setValue('metadata', $metadata); $destinationRecord->setValue('entity_type', 'product'); $destinationRecord->setValue('entity_id', $productId); $targetPath = "catalog/product/view/id/{$productId}/category/{$categoryId}"; } elseif (!empty($productId) && empty($categoryId)) { $destinationRecord->setValue('entity_type', 'product'); $destinationRecord->setValue('entity_id', $productId); $targetPath = 'catalog/product/view/id/' . $productId; } elseif (empty($productId) && !empty($categoryId)) { $destinationRecord->setValue('entity_type', 'category'); $destinationRecord->setValue('entity_id', $categoryId); if ($sourceRecord->getValue('entity_type') != 'custom') { $targetPath = 'catalog/category/view/id/' . $categoryId; } } elseif (!empty($cmsPageId)) { $destinationRecord->setValue('entity_id', $cmsPageId); } else { $destinationRecord->setValue('entity_id', 0); } if (!empty($this->duplicateIndex[$sourceRecord->getValue('request_path')])) { $shouldResolve = false; foreach ($this->duplicateIndex[$sourceRecord->getValue('request_path')] as &$duplicate) { $onStore = $duplicate['store_id'] == $sourceRecord->getValue('store_id'); if ($onStore && empty($duplicate['used'])) { $duplicate['used'] = true; break; } if ($onStore) { $shouldResolve = true; } } if ($shouldResolve) { $hash = md5(mt_rand()); $requestPath = preg_replace('/^(.*)\\.([^\\.]+)$/i', '$1-' . $hash . '.$2', $sourceRecord->getValue('request_path')); $this->resolvedDuplicates[$destinationRecord->getValue('entity_type')][$destinationRecord->getValue('entity_id')][$sourceRecord->getValue('store_id')] = $hash; $destinationRecord->setValue('request_path', $requestPath); $message = 'Duplicate resolved. ' . sprintf('Request path was: %s Target path was: %s Store ID: %s New request path: %s', $sourceRecord->getValue('request_path'), $sourceRecord->getValue('target_path'), $sourceRecord->getValue('store_id'), $destinationRecord->getValue('request_path')); $this->logger->addInfo($message); } } $destinationRecord->setValue('target_path', $targetPath); $destination->addRecord($destinationRecord); } }
/** * @param array $data * @param ResourceModel\Document $sourceDocument * @param ResourceModel\Document $destDocument * @param \Migration\RecordTransformer $recordTransformer * @param ResourceModel\Record\Collection $destinationRecords * @return void */ protected function transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords) { if ($recordTransformer) { $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $data]); $destRecord = $this->recordFactory->create(['document' => $destDocument]); $recordTransformer->transform($record, $destRecord); } else { $destRecord = $this->recordFactory->create(['document' => $destDocument, 'data' => $data]); } $destinationRecords->addRecord($destRecord); }
/** * @param array $data * @param ResourceModel\Document $sourceDocument * @param Record\Collection $destEavCollection * @return void */ public function migrateAdditionalOrderData($data, $sourceDocument, $destEavCollection) { foreach ($this->helper->getEavAttributes() as $orderEavAttribute) { $eavAttributeData = $this->prepareEavEntityData($orderEavAttribute, $data); if ($eavAttributeData) { $attributeRecord = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $eavAttributeData]); $destEavCollection->addRecord($attributeRecord); } } }