public function publishNode(NodeInterface $nodeToPublish, Workspace $targetWorkspace)
    {
        if ($this->publishNodeCanBeSkipped($nodeToPublish, $targetWorkspace)) {
            return;
        }
        $this->emitBeforeNodePublishing($nodeToPublish, $targetWorkspace);

        $correspondingNodeDataInTargetWorkspace = $this->findCorrespondingNodeDataInTargetWorkspace($nodeToPublish, $targetWorkspace);
        $matchingNodeVariantExistsInTargetWorkspace = ($correspondingNodeDataInTargetWorkspace !== null && $correspondingNodeDataInTargetWorkspace->getDimensionValues() === $nodeToPublish->getDimensions());

        // Save the original node workspace because the workspace of $nodeToPublish can be changed by replaceNodeData():
        $originalNodeWorkspace = $nodeToPublish->getWorkspace();

        if ($matchingNodeVariantExistsInTargetWorkspace) {
            $this->replaceNodeData($nodeToPublish, $correspondingNodeDataInTargetWorkspace);
            $this->moveNodeVariantsInOtherWorkspaces($nodeToPublish->getIdentifier(), $nodeToPublish->getPath(), $originalNodeWorkspace, $targetWorkspace);
        } else {
            $this->moveNodeVariantToTargetWorkspace($nodeToPublish, $targetWorkspace);
        }

        $this->emitAfterNodePublishing($nodeToPublish, $targetWorkspace);
    }