/** * Creates a personal workspace for the given user's account if it does not exist already. * * @param User $user The new user to create a workspace for * @param Account $account The user's backend account * @throws IllegalObjectTypeException */ protected function createPersonalWorkspace(User $user, Account $account) { $userWorkspaceName = UserUtility::getPersonalWorkspaceNameForUsername($account->getAccountIdentifier()); $userWorkspace = $this->workspaceRepository->findByIdentifier($userWorkspaceName); if ($userWorkspace === null) { $liveWorkspace = $this->workspaceRepository->findByIdentifier('live'); if (!$liveWorkspace instanceof Workspace) { $liveWorkspace = new Workspace('live'); $liveWorkspace->setTitle('Live'); $this->workspaceRepository->add($liveWorkspace); } $userWorkspace = new Workspace($userWorkspaceName, $liveWorkspace, $user); $userWorkspace->setTitle((string) $user->getName()); $this->workspaceRepository->add($userWorkspace); } }
/** * 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]); } }
/** * Update a workspace * * @param Workspace $workspace A workspace to update * @return void */ public function updateAction(Workspace $workspace) { if ($workspace->getTitle() === '') { $workspace->setTitle($workspace->getName()); } $this->workspaceRepository->update($workspace); $this->addFlashMessage($this->translator->translateById('workspaces.workspaceHasBeenUpdated', [$workspace->getTitle()], null, null, 'Modules', 'Neos.Neos')); $this->redirect('index'); }