public function deleteCommand($workspace, $force = false)
{
$workspaceName = $workspace;
$workspace = $this->workspaceRepository->findOneByName($workspaceName);
if (!$workspace instanceof Workspace) {
$this->outputLine('Workspace "%s" does not exist', [$workspaceName]);
$this->quit(1);
}
if ($workspace->isPersonalWorkspace()) {
$this->outputLine('Did not delete workspace "%s" because it is a personal workspace. Personal workspaces cannot be deleted manually.', [$workspaceName]);
$this->quit(2);
}
$dependentWorkspaces = $this->workspaceRepository->findByBaseWorkspace($workspace);
if (count($dependentWorkspaces) > 0) {
$this->outputLine('Workspace "%s" cannot be deleted because the following workspaces are based on it:', [$workspaceName]);
$this->outputLine();
$tableRows = [];
$headerRow = ['Name', 'Title', 'Description'];
/** @var Workspace $workspace */
foreach ($dependentWorkspaces as $workspace) {
$tableRows[] = [$workspace->getName(), $workspace->getTitle(), $workspace->getDescription()];
}
$this->output->outputTable($tableRows, $headerRow);
$this->quit(3);
}
try {
$nodesCount = $this->publishingService->getUnpublishedNodesCount($workspace);
} catch (\Exception $exception) {
$this->outputLine('An error occurred while fetching unpublished nodes from workspace %s, nothing was deleted.', [$workspaceName]);
$this->quit(4);
}
if ($nodesCount > 0) {
if ($force === false) {
$this->outputLine('Did not delete workspace "%s" because it contains %s unpublished node(s). Use --force to delete it nevertheless.', [$workspaceName, $nodesCount]);
$this->quit(5);
}
$this->discardCommand($workspaceName);
}
$this->workspaceRepository->remove($workspace);
$this->outputLine('Deleted workspace "%s"', [$workspaceName]);
}