Neos\Neos\Command\WorkspaceCommandController::createCommand PHP Method

createCommand() public method

This command creates a new workspace.
public createCommand ( string $workspace, string $baseWorkspace = 'live', string $title = null, string $description = null, string $owner = '' ) : void
$workspace string Name of the workspace, for example "christmas-campaign"
$baseWorkspace string Name of the base workspace. If none is specified, "live" is assumed.
$title string Human friendly title of the workspace, for example "Christmas Campaign"
$description string A description explaining the purpose of the new workspace
$owner string 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]);
        }
    }