/**
* Create a new workspace
*
* This command creates a new workspace.
*
* @param string $workspace Name of the workspace, for example "christmas-campaign"
* @param string $baseWorkspace Name of the base workspace. If none is specified, "live" is assumed.
* @param string $title Human friendly title of the workspace, for example "Christmas Campaign"
* @param string $description A description explaining the purpose of the new workspace
* @param string $owner The identifier of a User to own the workspace
* @return void
*/
public function createCommand($workspace, $baseWorkspace = 'live', $title = null, $description = null, $owner = '')
{
$workspaceName = $workspace;
$workspace = $this->workspaceRepository->findOneByName($workspaceName);
if ($workspace instanceof Workspace) {
$this->outputLine('Workspace "%s" already exists', [$workspaceName]);
$this->quit(1);
}
$baseWorkspaceName = $baseWorkspace;
$baseWorkspace = $this->workspaceRepository->findOneByName($baseWorkspaceName);
if (!$baseWorkspace instanceof Workspace) {
$this->outputLine('The base workspace "%s" does not exist', [$baseWorkspaceName]);
$this->quit(2);
}
if ($owner === '') {
$owningUser = null;
} else {
$owningUser = $this->userService->getUser($owner);
if ($owningUser === null) {
$this->outputLine('The user "%s" specified as owner does not exist', [$owner]);
$this->quit(3);
}
}
if ($title === null) {
$title = $workspaceName;
}
$workspace = new Workspace($workspaceName, $baseWorkspace, $owningUser);
$workspace->setTitle($title);
$workspace->setDescription($description);
$this->workspaceRepository->add($workspace);
if ($owningUser instanceof User) {
$this->outputLine('Created a new workspace "%s", based on workspace "%s", owned by "%s".', [$workspaceName, $baseWorkspaceName, $owner]);
} else {
$this->outputLine('Created a new workspace "%s", based on workspace "%s".', [$workspaceName, $baseWorkspaceName]);
}
}