Ejemplo n.º 1
0
 /**
  * @param string $documentName
  * @param string $idKey
  * @return void
  */
 protected function processChangedRecords($documentName, $idKey)
 {
     $items = $this->source->getChangedRecords($documentName, $idKey);
     if (empty($items)) {
         return;
     }
     if (!$this->eolOnce) {
         $this->eolOnce = true;
         echo PHP_EOL;
     }
     $destinationName = $this->mapReader->getDocumentMap($documentName, MapInterface::TYPE_SOURCE);
     $sourceDocument = $this->source->getDocument($documentName);
     $destDocument = $this->destination->getDocument($destinationName);
     $recordTransformer = $this->getRecordTransformer($sourceDocument, $destDocument);
     do {
         $destinationRecords = $destDocument->getRecords();
         $ids = [];
         foreach ($items as $data) {
             echo '.';
             $ids[] = $data[$idKey];
             $this->transformData($data, $sourceDocument, $destDocument, $recordTransformer, $destinationRecords);
         }
         $this->destination->updateChangedRecords($destinationName, $destinationRecords);
         $documentNameDelta = $this->source->getDeltaLogName($documentName);
         $documentNameDelta = $this->source->addDocumentPrefix($documentNameDelta);
         $this->markRecordsProcessed($documentNameDelta, $idKey, $ids);
     } while (!empty($items = $this->source->getChangedRecords($documentName, $idKey)));
 }
 /**
  * Check if source and destination resources have equal document names and fields
  *
  * @param array $documents
  * @param string $type - allowed values: MapInterface::TYPE_SOURCE, MapInterface::TYPE_DEST
  * @param bool $verifyFields
  * @return $this
  */
 protected function check($documents, $type, $verifyFields = true)
 {
     $documents = $this->filterIgnoredDocuments($documents, $type);
     if (!empty($documents)) {
         $this->hasMappedDocuments = false;
         $source = $type == MapInterface::TYPE_SOURCE ? $this->source : $this->destination;
         $destination = $type == MapInterface::TYPE_SOURCE ? $this->destination : $this->source;
         $destDocuments = array_flip($destination->getDocumentList());
         foreach ($documents as $sourceDocumentName) {
             $this->progress->advance();
             $destinationDocumentName = $this->map->getDocumentMap($sourceDocumentName, $type);
             $sourceDocument = $source->getDocument($sourceDocumentName);
             $destinationDocument = $destination->getDocument($destinationDocumentName);
             if (!isset($destDocuments[$destinationDocumentName]) || !$sourceDocument || !$destinationDocument) {
                 $this->missingDocuments[$type][$sourceDocumentName] = true;
             } else {
                 $this->hasMappedDocuments = true;
                 if ($verifyFields) {
                     $this->verifyFields($sourceDocument, $destinationDocument, $type);
                 }
             }
         }
     }
     return $this;
 }