Neos\Neos\Service\PublishingService::publishNode PHP Метод

publishNode() публичный Метод

If the given node is a Document or has ContentCollection child nodes, these nodes are published as well.
public publishNode ( Neos\ContentRepository\Domain\Model\NodeInterface $node, Workspace $targetWorkspace = null ) : void
$node Neos\ContentRepository\Domain\Model\NodeInterface
$targetWorkspace Neos\ContentRepository\Domain\Model\Workspace If not set the base workspace is assumed to be the publishing target
Результат void
    public function publishNode(NodeInterface $node, Workspace $targetWorkspace = null)
    {
        if ($targetWorkspace === null) {
            $targetWorkspace = $node->getWorkspace()->getBaseWorkspace();
        }
        if (!$targetWorkspace instanceof Workspace) {
            return;
        }
        $nodes = array($node);
        $nodeType = $node->getNodeType();
        if ($nodeType->isOfType('Neos.Neos:Document') || $nodeType->hasConfiguration('childNodes')) {
            foreach ($node->getChildNodes('Neos.Neos:ContentCollection') as $contentCollectionNode) {
                array_push($nodes, $contentCollectionNode);
            }
        }
        $sourceWorkspace = $node->getWorkspace();
        $sourceWorkspace->publishNodes($nodes, $targetWorkspace);
        $this->emitNodePublished($node, $targetWorkspace);
    }

Usage Example

 /**
  * Publish changes of a workspace
  *
  * This command publishes all modified, created or deleted nodes in the specified workspace to its base workspace.
  * If a target workspace is specified, the content is published to that workspace instead.
  *
  * @param string $workspace Name of the workspace containing the changes to publish, for example "user-john"
  * @param string $targetWorkspace If specified, the content will be published to this workspace instead of the base workspace
  * @param boolean $verbose If enabled, some information about individual nodes will be displayed
  * @param boolean $dryRun If set, only displays which nodes would be published, no real changes are committed
  * @return void
  */
 public function publishCommand($workspace, $targetWorkspace = null, $verbose = false, $dryRun = false)
 {
     $workspaceName = $workspace;
     $workspace = $this->workspaceRepository->findOneByName($workspaceName);
     if (!$workspace instanceof Workspace) {
         $this->outputLine('Workspace "%s" does not exist', [$workspaceName]);
         $this->quit(1);
     }
     if ($targetWorkspace === null) {
         $targetWorkspace = $workspace->getBaseWorkspace();
         $targetWorkspaceName = $targetWorkspace->getName();
     } else {
         $targetWorkspaceName = $targetWorkspace;
         $targetWorkspace = $this->workspaceRepository->findOneByName($targetWorkspaceName);
         if (!$targetWorkspace instanceof Workspace) {
             $this->outputLine('Target workspace "%s" does not exist', [$targetWorkspaceName]);
             $this->quit(2);
         }
         $possibleTargetWorkspaceNames = [];
         $baseWorkspace = $workspace->getBaseWorkspace();
         while ($targetWorkspace !== $baseWorkspace) {
             if ($baseWorkspace === null) {
                 $this->outputLine('The target workspace must be a base workspace of "%s".', [$targetWorkspaceName]);
                 if (count($possibleTargetWorkspaceNames) > 1) {
                     $this->outputLine('For "%s" possible target workspaces currently are: %s', [$workspaceName, implode(', ', $possibleTargetWorkspaceNames)]);
                 } else {
                     $this->outputLine('For "%s" the only possible target workspace currently is "%s".', [$workspaceName, reset($possibleTargetWorkspaceNames)]);
                 }
                 $this->quit(3);
             }
             $possibleTargetWorkspaceNames[] = $baseWorkspace->getName();
             $baseWorkspace = $baseWorkspace->getBaseWorkspace();
         }
     }
     try {
         $nodes = $this->publishingService->getUnpublishedNodes($workspace);
     } catch (\Exception $exception) {
         $this->outputLine('An error occurred while fetching unpublished nodes from workspace %s, publish aborted.', [$workspaceName]);
         $this->quit(1);
     }
     $this->outputLine('The workspace %s contains %u unpublished nodes.', [$workspaceName, count($nodes)]);
     foreach ($nodes as $node) {
         /** @var NodeInterface $node */
         if ($verbose) {
             $this->outputLine('    ' . $node->getPath());
         }
         if (!$dryRun) {
             $this->publishingService->publishNode($node, $targetWorkspace);
         }
     }
     if (!$dryRun) {
         $this->outputLine('Published all nodes in workspace %s to workspace %s', [$workspaceName, $targetWorkspaceName]);
     }
 }
All Usage Examples Of Neos\Neos\Service\PublishingService::publishNode
PublishingService