$versionContext->
addState(self::MERGE_SCOPE
);
$liveContext->
addState(self::MERGE_SCOPE
);
// group all payloads by their action (insert, update, delete) and by their entity name
$writes =
$this->
buildWrites($commits);
// execute writes and get access to the write result to dispatch events later on
$result =
$this->
executeWrites($writes,
$liveContext);
// remove commits which reference the version and create a "merge commit" for the live version with all payloads
$this->
updateVersionData($commits,
$writeContext,
$versionId);
// delete all versioned records
$this->
deleteClones($commits,
$versionContext,
$versionId);
// release lock to ensure no other merge is running
$lock->
release();
// dispatch events to trigger indexer and other subscribts
$writes = EntityWrittenContainerEvent::
createWithWrittenEvents($result->
getWritten(),
$liveContext->
getContext(),
[]);
$deletes = EntityWrittenContainerEvent::
createWithDeletedEvents($result->
getDeleted(),
$liveContext->
getContext(),
[]);