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]);
}
}