Neos\Neos\Command\WorkspaceCommandController::discardCommand PHP Method

discardCommand() public method

This command discards all modified, created or deleted nodes in the specified workspace.
public discardCommand ( string $workspace, boolean $verbose = false, boolean $dryRun = false ) : void
$workspace string Name of the workspace, for example "user-john"
$verbose boolean If enabled, information about individual nodes will be displayed
$dryRun boolean If set, only displays which nodes would be discarded, no real changes are committed
return void
    public function discardCommand($workspace, $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);
        }
        try {
            $nodes = $this->publishingService->getUnpublishedNodes($workspace);
        } catch (\Exception $exception) {
            $this->outputLine('An error occurred while fetching unpublished nodes from workspace %s, discard 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 ($node->getPath() !== '/') {
                if ($verbose) {
                    $this->outputLine('    ' . $node->getPath());
                }
                if (!$dryRun) {
                    $this->publishingService->discardNode($node);
                }
            }
        }
        if (!$dryRun) {
            $this->outputLine('Discarded all nodes in workspace %s', [$workspaceName]);
        }
    }