Ejemplo n.º 1
0
 public function testGetSourceRecordsNoKey()
 {
     $row = ['key' => 'key_value', 'field' => 'field_value'];
     $this->source->expects($this->once())->method('getRecordsCount')->will($this->returnValue(1));
     $this->source->expects($this->once())->method('getRecords')->with('test_source_document', 0, 1)->will($this->returnValue([$row]));
     $this->assertEquals([$row], $this->helper->getSourceRecords('test_source_document'));
 }
 /**
  * Load all attributes from source and destination
  * @return void
  */
 protected function initAttributes()
 {
     if ($this->attributes === null) {
         $sourceDocument = 'eav_attribute';
         foreach ($this->helper->getSourceRecords($sourceDocument, ['attribute_id']) as $id => $record) {
             $this->attributes['source'][$id] = $record;
         }
         $destinationRecords = $this->helper->getDestinationRecords($sourceDocument, ['entity_type_id', 'attribute_code']);
         foreach ($destinationRecords as $id => $record) {
             $this->attributes['dest'][$id] = $record;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * Migrate EAV tables which in result must have all unique records from both source and destination documents
  * @return void
  */
 protected function migrateMappedTables()
 {
     $documents = $this->readerGroups->getGroup('mapped_documents');
     foreach ($documents as $documentName => $mappingFields) {
         $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);
         $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]);
             } 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);
             }
         }
         $this->saveRecords($destinationDocument, $recordsToSave);
     }
 }