public function testGetStructure() { $this->assertSame($this->structure, $this->recordCollection->getStructure()); }
/** * @param \Migration\Resource\Record\Collection $source * @param \Migration\Resource\Record\Collection $destination * @return void */ protected function migrateRewrites($source, $destination) { /** @var \Migration\Resource\Record $sourceRecord */ foreach ($source as $sourceRecord) { /** @var \Migration\Resource\Record $destinationRecord */ $destinationRecord = $this->recordFactory->create(); $destinationRecord->setStructure($destination->getStructure()); $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'); 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; } } 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); } }