/**
  * Discard changes in workspace
  *
  * This command discards all modified, created or deleted nodes in the specified workspace.
  *
  * @param string $workspace Name of the workspace, for example "user-john"
  * @param boolean $verbose If enabled, information about individual nodes will be displayed
  * @param boolean $dryRun 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]);
     }
 }
 /**
  * Discard a a single node
  *
  * @param NodeInterface $node
  * @param Workspace $selectedWorkspace
  * @throws WorkspaceException
  */
 public function discardNodeAction(NodeInterface $node, Workspace $selectedWorkspace)
 {
     // Hint: we cannot use $node->remove() here, as this removes the node recursively (but we just want to *discard changes*)
     $this->publishingService->discardNode($node);
     $this->addFlashMessage($this->translator->translateById('workspaces.selectedChangeHasBeenDiscarded', [], null, null, 'Modules', 'Neos.Neos'));
     $this->redirect('show', null, null, ['workspace' => $selectedWorkspace]);
 }
Example #3
0
 /**
  * Discards the given node
  *
  * @param NodeInterface $node
  * @return void
  */
 public function discardNodeAction(NodeInterface $node)
 {
     $this->publishingService->discardNode($node);
     $this->throwStatus(204, 'Node changes have been discarded', '');
 }