/** * @return bool */ public function perform() { $this->progress->start(count($this->groups->getGroup('documents'))); $this->validateAttributes(); $this->validateAttributeSetsAndGroups(); $this->progress->finish(); return $this->checkForErrors(); }
/** * @return bool */ public function perform() { $this->progress->start(count($this->groups->getGroup('documents'))); $this->validateAttributes(); $this->validateAttributeSetsAndGroups(); $this->progress->finish(); $result = $this->checkForErrors(Logger::ERROR); if ($result) { $this->helper->deleteBackups(); } return $result; }
/** * @throws \Zend_Db_Adapter_Exception * @return void */ public function updateEavAttributes() { /** @var Mysql $adapter */ $adapter = $this->destination->getAdapter(); $query = $adapter->getSelect()->from($this->destination->addDocumentPrefix('eav_entity_type'), ['entity_type_id', 'entity_type_code']); $entityTypes = $query->getAdapter()->fetchAll($query); $entityTypesByCode = []; foreach ($entityTypes as $entityType) { $entityTypesByCode[$entityType['entity_type_code']] = $entityType['entity_type_id']; } $where = []; $entities = array_keys($this->readerGroups->getGroup('eav_entities')); foreach ($entities as $entity) { $documents = $this->readerGroups->getGroup($entity); $codes = []; foreach ($documents as $document => $key) { if ($key != 'entity_id') { continue; } $codes = implode("','", array_keys($this->readerAttributes->getGroup($document))); } $where += [sprintf("attribute_code IN ('%s')", $codes), sprintf("entity_type_id = '%s'", $entityTypesByCode[$entity])]; } $adapter->getSelect()->getAdapter()->update($this->destination->addDocumentPrefix('eav_attribute'), ['backend_type' => 'static'], $where); }
/** * Get iterations count for step * * @return int */ protected function getIterationsCount() { $iterations = 0; foreach (array_keys($this->readerGroups->getGroup('source_documents')) as $document) { $iterations += $this->source->getRecordsCount($document); } return $iterations; }
/** * Rollback backed up documents * @return void */ public function rollback() { foreach (array_keys($this->readerGroups->getGroup('documents')) as $documentName) { $destinationDocument = $this->destination->getDocument($this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE)); if ($destinationDocument !== false) { $this->destination->rollbackDocument($destinationDocument->getName()); } } }
/** * Delete backed up documents * @return void */ public function deleteBackups() { foreach (array_keys($this->readerGroups->getGroup('documents')) as $documentName) { $documentName = $this->map->getDocumentMap($documentName, MapInterface::TYPE_SOURCE); if ($documentName) { $this->destination->deleteDocumentBackup($documentName); } } }
/** * Volume check * * @return bool */ public function perform() { $sourceDocuments = array_keys($this->groups->getGroup('source_documents')); $this->progress->start(count($sourceDocuments)); foreach ($sourceDocuments as $sourceName) { $this->progress->advance(); $destinationName = $this->map->getDocumentMap($sourceName, MapInterface::TYPE_SOURCE); $sourceFields = $this->source->getDocument($sourceName)->getStructure()->getFields(); $destinationFields = $this->destination->getDocument($destinationName)->getStructure()->getFields(); if (!empty(array_diff_key($sourceFields, $destinationFields))) { $this->errors[] = 'Mismatch of fields in the document: ' . $destinationName; } if ($this->source->getRecordsCount($sourceName) != $this->destination->getRecordsCount($destinationName)) { $this->errors[] = 'Mismatch of entities in the document: ' . $destinationName; } } $this->progress->finish(); return $this->checkForErrors(); }
/** * {@inheritdoc} */ public function perform() { $updateData = $this->helper->getUpdateData(); $selectData = $this->helper->getSelectData(); $sourceDocuments = $this->readerGroups->getGroup('source_documents'); foreach ($sourceDocuments as $sourceDocName => $idKey) { if ($this->source->getRecordsCount($this->source->getDeltaLogName($sourceDocName)) == 0) { continue; } $items = $this->source->getChangedRecords($sourceDocName, $idKey, 0, true); if (empty($items)) { continue; } $this->logger->debug(sprintf('%s has changes', $sourceDocName)); if (!$this->eolOnce) { $this->eolOnce = true; echo PHP_EOL; } $gridIdKey = $updateData[$sourceDocName]['idKey']; $page = 1; do { $ids = []; foreach ($items as $data) { echo '.'; $ids[] = $data[$gridIdKey]; } foreach ($updateData[$sourceDocName]['methods'] as $method) { echo '.'; $destinationDocumentName = $selectData[$method]['destination']; $select = call_user_func_array([$this->data, $method], [$selectData[$method]['columns'], $ids]); $this->destination->getAdapter()->insertFromSelect($select, $this->destination->addDocumentPrefix($destinationDocumentName), [], \Magento\Framework\Db\Adapter\AdapterInterface::INSERT_ON_DUPLICATE); } $documentNameDelta = $this->source->getDeltaLogName($sourceDocName); $documentNameDelta = $this->source->addDocumentPrefix($documentNameDelta); $this->markRecordsProcessed($documentNameDelta, $idKey, $ids); } while (!empty($items = $this->source->getChangedRecords($sourceDocName, $idKey, $page++))); } return true; }
/** * {@inheritdoc} */ public function perform() { $sourceDocuments = array_keys($this->readerGroups->getGroup('source_documents')); $this->progress->start(count($sourceDocuments), LogManager::LOG_LEVEL_INFO); $this->helper->initEavEntityCollection('catalog_category_entity_varchar'); foreach ($sourceDocuments as $sourceDocName) { $this->progress->advance(LogManager::LOG_LEVEL_INFO); $sourceDocument = $this->source->getDocument($sourceDocName); $destinationName = $this->map->getDocumentMap($sourceDocName, MapInterface::TYPE_SOURCE); if (!$destinationName) { continue; } $destDocument = $this->destination->getDocument($destinationName); $this->destination->clearDocument($destinationName); $this->logger->debug('migrating', ['table' => $sourceDocName]); $recordTransformer = $this->recordTransformerFactory->create(['sourceDocument' => $sourceDocument, 'destDocument' => $destDocument, 'mapReader' => $this->map]); $recordTransformer->init(); $this->progress->start(ceil($this->source->getRecordsCount($sourceDocName) / $this->source->getPageSize($sourceDocName)), LogManager::LOG_LEVEL_DEBUG); $pageNumber = 0; while (!empty($items = $this->source->getRecords($sourceDocName, $pageNumber))) { $pageNumber++; $destinationRecords = $destDocument->getRecords(); foreach ($items as $data) { /** @var Record $record */ $record = $this->recordFactory->create(['document' => $sourceDocument, 'data' => $data]); /** @var Record $destRecord */ $destRecord = $this->recordFactory->create(['document' => $destDocument]); $recordTransformer->transform($record, $destRecord); $destinationRecords->addRecord($destRecord); $this->helper->updateAttributeData($data); } $this->source->setLastLoadedRecord($sourceDocName, end($items)); $this->progress->advance(LogManager::LOG_LEVEL_DEBUG); $this->destination->saveRecords($destinationName, $destinationRecords); } $this->progress->finish(LogManager::LOG_LEVEL_DEBUG); } $this->helper->saveRecords(); $this->helper->updateEavAttributes(); $this->progress->finish(LogManager::LOG_LEVEL_INFO); return true; }
/** * Get iterations count for step * * @return int */ protected function getIterationsCount() { return count($this->readerGroups->getGroup('source_documents')); }
/** * {@inheritdoc} */ protected function getIterationsCount() { return count($this->readerGroups->getGroup('destination_documents_to_clear')) + count($this->readerGroups->getGroup('source_documents')) * 2; }
/** * Returns number of iterations for integrity check * @return mixed */ protected function getIterationsCount() { return count($this->groups->getGroup('documents')) * 2; }
/** * @param GroupsFactory $groupsFactory */ public function __construct(GroupsFactory $groupsFactory) { $this->readerGroups = $groupsFactory->create('map_document_groups'); $this->documentsDuplicateOnUpdate = $this->readerGroups->getGroup('destination_documents_update_on_duplicate'); }