Skip to content

Commit

Permalink
check if document exists before mappin
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaidas Bagdonas committed Feb 19, 2020
1 parent ad7beca commit 8946497
Showing 1 changed file with 11 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,8 @@ public function process($sObject)
$mappedDocument = $this->mapper->mapToDomainObject($sObject, $this->documentClassName);
$existingDocument = $this->documentManager->find($this->documentClassName, $mappedDocument->getId());

$this->mapInitialDocumentValues($mappedDocument, $existingDocument);

if ($this->isForceCompared
&& $existingDocument
&& $this->objectComparator->equals(
Expand All @@ -131,8 +133,7 @@ public function process($sObject)
return;
}

$allowedProperties = $this->getAllowedProperties($this->documentClassName);
$this->documentUpdater->updateWithDocument($mappedDocument, $existingDocument, null, $allowedProperties);
$this->mapInitialDocumentValues();

$beforeFlushEvent = $this->outboundMessageBeforeFlushEventBuilder->build($mappedDocument, $existingDocument);
$this->eventDispatcher->dispatch(OutboundMessageBeforeFlushEvent::NAME, $beforeFlushEvent);
Expand All @@ -157,6 +158,14 @@ public function process($sObject)
$this->eventDispatcher->dispatch(OutboundMessageAfterFlushEvent::NAME, $afterFlushEvent);
}

public function mapInitialDocumentValues($mappedDocument, $existingDocument): void
{
if($existingDocument) {
$allowedProperties = $this->getAllowedProperties($this->documentClassName);
$this->documentUpdater->updateWithDocument($mappedDocument, $existingDocument, null, $allowedProperties);
}
}

public function getAllowedProperties(string $documentClass): array
{
/** @var Field[]|ArrayCollection|null $salesforceFields */
Expand Down

0 comments on commit 8946497

Please sign in to comment.