/** * @return void */ public function testPerform() { $data = new Data($this->progress, $this->source, $this->destination, $this->recordFactory, $this->helper); $this->assertTrue($data->perform()); foreach ($this->destinationDocuments as $documentName => $recordsCount) { $this->assertEquals($recordsCount, count($this->destination->getRecords($documentName, 0))); } }
/** * {@inheritdoc} */ public function perform() { $destinationDocument = $this->destination->getDocument(self::CONFIG_TABLE_NAME_DESTINATION); $recordsCountSource = $this->source->getRecordsCount(self::CONFIG_TABLE_NAME_SOURCE); $recordsCountDestination = $this->destination->getRecordsCount(self::CONFIG_TABLE_NAME_DESTINATION); $this->progress->start($recordsCountSource); $sourceRecords = $this->source->getRecords(self::CONFIG_TABLE_NAME_SOURCE, 0, $recordsCountSource); $destinationRecords = $this->destination->getRecords(self::CONFIG_TABLE_NAME_DESTINATION, 0, $recordsCountDestination); foreach ($sourceRecords as $sourceRecord) { $this->progress->advance(); if (!$this->readerSettings->isNodeIgnored($sourceRecord[self::CONFIG_FIELD_PATH])) { $sourceRecordPathMapped = $this->readerSettings->getNodeMap($sourceRecord[self::CONFIG_FIELD_PATH]); foreach ($destinationRecords as &$destinationRecord) { if ($destinationRecord[self::CONFIG_FIELD_SCOPE] == $sourceRecord[self::CONFIG_FIELD_SCOPE] && $destinationRecord[self::CONFIG_FIELD_SCOPE_ID] == $sourceRecord[self::CONFIG_FIELD_SCOPE_ID] && $destinationRecord[self::CONFIG_FIELD_PATH] == $sourceRecordPathMapped) { $record = $this->applyHandler($destinationDocument, $sourceRecord, $destinationRecord); $destinationRecord[self::CONFIG_FIELD_VALUE] = $record->getValue(self::CONFIG_FIELD_VALUE); continue 2; } } $record = $this->applyHandler($destinationDocument, $sourceRecord, []); $record->setValue(self::CONFIG_FIELD_PATH, $sourceRecordPathMapped); $destinationRecords[] = $record->getData(); } } foreach ($destinationRecords as &$destinationRecord) { unset($destinationRecord[self::CONFIG_FIELD_CONFIG_ID]); } $this->destination->clearDocument(self::CONFIG_TABLE_NAME_DESTINATION); $this->destination->saveRecords(self::CONFIG_TABLE_NAME_DESTINATION, $destinationRecords); $this->progress->finish(); return true; }
/** * @param string $sourceDocName * @param array $keyFields * @return array */ public function getDestinationRecords($sourceDocName, $keyFields = []) { $destinationDocumentName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); $data = []; $count = $this->destination->getRecordsCount($destinationDocumentName); foreach ($this->destination->getRecords($destinationDocumentName, 0, $count) as $row) { if ($keyFields) { $key = []; foreach ($keyFields as $keyField) { $key[] = $row[$keyField]; } $data[implode('-', $key)] = $row; } else { $data[] = $row; } } return $data; }
/** * @return void */ public function testGetRecords() { $resourceName = 'core_config_data'; $pageNumber = 2; $this->config->expects($this->at(0))->method('getOption')->with('bulk_size')->will($this->returnValue(100)); $this->config->expects($this->at(1))->method('getOption')->with('dest_prefix')->will($this->returnValue(100)); $this->adapter->expects($this->once())->method('loadPage'); $this->resourceDestination->getRecords($resourceName, $pageNumber); }
/** * @param string $eavAttributeCode * @return array|null */ protected function getAttributeData($eavAttributeCode) { $attributeData = null; $pageNumber = 0; while (!empty($bulk = $this->destination->getRecords('eav_attribute', $pageNumber))) { $pageNumber++; foreach ($bulk as $eavData) { if ($eavData['attribute_code'] == $eavAttributeCode) { $attributeData = $eavData; break; } } } return $attributeData; }