// load all commits of the provided version
$commits =
$this->
getCommits($versionId,
$writeContext);
// create context for live and version
$versionContext =
$writeContext->
createWithVersionId($versionId);
$liveContext =
$writeContext->
createWithVersionId(Defaults::LIVE_VERSION
);
$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