Neos\ContentRepository\Domain\Model\Workspace::publishNode PHP Method

publishNode() public method

The specified workspace must be a base workspace of this workspace.
public publishNode ( Neos\ContentRepository\Domain\Model\NodeInterface $node, Workspace $targetWorkspace ) : void
$node Neos\ContentRepository\Domain\Model\NodeInterface The node to publish
$targetWorkspace Workspace 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);
    }

Usage Example

 /**
  * @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);
 }