public publishNode ( Neos\ContentRepository\Domain\Model\NodeInterface $node, |
||
$node | Neos\ContentRepository\Domain\Model\NodeInterface | The node to publish |
$targetWorkspace | The workspace to publish to | |
return | void |
public function publishNode(NodeInterface $node, Workspace $targetWorkspace)
{
if ($this->baseWorkspace === null) {
return;
}
if ($node->getWorkspace() !== $this) {
return;
}
// Might happen if a node which has been published during an earlier call of publishNode() is attempted to
// be published again:
if ($node->getWorkspace() === $targetWorkspace) {
return;
}
$this->verifyPublishingTargetWorkspace($targetWorkspace);
$this->emitBeforeNodePublishing($node, $targetWorkspace);
if ($node->getPath() === '/') {
return;
}
$targetNodeData = $this->findNodeDataInTargetWorkspace($node, $targetWorkspace);
$matchingNodeVariantExistsInTargetWorkspace = $targetNodeData !== null && $targetNodeData->getDimensionValues() === $node->getDimensions();
if ($matchingNodeVariantExistsInTargetWorkspace) {
$this->replaceNodeData($node, $targetNodeData);
} else {
$this->moveNodeVariantToTargetWorkspace($node, $targetWorkspace);
}
$this->emitAfterNodePublishing($node, $targetWorkspace);
}
/** * @test */ public function publishNodeWithANodeInTheTargetWorkspaceShouldDoNothing() { $liveWorkspace = new Workspace('live'); $personalWorkspace = new Workspace('user-admin', $liveWorkspace); $nodeDataRepository = $this->getMockBuilder(NodeDataRepository::class)->disableOriginalConstructor()->getMock(); $this->inject($liveWorkspace, 'nodeDataRepository', $nodeDataRepository); $node = $this->createMock(NodeInterface::class); $node->expects($this->any())->method('getWorkspace')->will($this->returnValue($liveWorkspace)); $nodeDataRepository->expects($this->never())->method('findOneByIdentifier'); $personalWorkspace->publishNode($node, $liveWorkspace); }