/**
  * @return void
  */
 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->resourceDestination->backupDocument($docName);
 }
예제 #2
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);
     }
 }