public function changeBaseWorkspaceAction(string $targetWorkspaceName, NodeInterface $documentNode)
    {
        try {
            $targetWorkspace = $this->workspaceRepository->findOneByName($targetWorkspaceName);
            $userWorkspace = $this->userService->getPersonalWorkspace();

            if (count($this->workspaceService->getPublishableNodeInfo($userWorkspace)) > 0) {
                // TODO: proper error dialog
                throw new \Exception('Your personal workspace currently contains unpublished changes. In order to switch to a different target workspace you need to either publish or discard pending changes first.');
            }

            $userWorkspace->setBaseWorkspace($targetWorkspace);
            $this->workspaceRepository->update($userWorkspace);

            $success = new Success();
            $success->setMessage(sprintf('Switched base workspace to %s.', $targetWorkspaceName));
            $this->feedbackCollection->add($success);

            $updateWorkspaceInfo = new UpdateWorkspaceInfo();
            $updateWorkspaceInfo->setWorkspace($userWorkspace);
            $this->feedbackCollection->add($updateWorkspaceInfo);

            // Construct base workspace context
            $originalContext = $documentNode->getContext();
            $contextProperties = $documentNode->getContext()->getProperties();
            $contextProperties['workspaceName'] = $targetWorkspaceName;
            $contentContext = $this->contextFactory->create($contextProperties);

            // If current document node doesn't exist in the base workspace, traverse its parents to find the one that exists
            $redirectNode = $documentNode;
            while (true) {
                $redirectNodeInBaseWorkspace = $contentContext->getNodeByIdentifier($redirectNode->getIdentifier());
                if ($redirectNodeInBaseWorkspace) {
                    break;
                } else {
                    $redirectNode = $redirectNode->getParent();
                    if (!$redirectNode) {
                        throw new \Exception(sprintf('Wasn\'t able to locate any valid node in rootline of node %s in the workspace %s.', $documentNode->getContextPath(), $targetWorkspaceName), 1458814469);
                    }
                }
            }

            // If current document node exists in the base workspace, then reload, else redirect
            if ($redirectNode === $documentNode) {
                $reloadDocument = new ReloadDocument();
                $reloadDocument->setNode($documentNode);
                $this->feedbackCollection->add($reloadDocument);
            } else {
                $redirect = new Redirect();
                $redirect->setNode($redirectNode);
                $this->feedbackCollection->add($redirect);
            }

            $this->persistenceManager->persistAll();
        } catch (\Exception $e) {
            $error = new Error();
            $error->setMessage($e->getMessage());

            $this->feedbackCollection->add($error);
        }

        $this->view->assign('value', $this->feedbackCollection);
    }
public function changeBaseWorkspaceAction(string $targetWorkspaceName, NodeInterface $documentNode)
    {
        try {
            $targetWorkspace = $this->workspaceRepository->findOneByName($targetWorkspaceName);
            $userWorkspace = $this->userService->getPersonalWorkspace();

            if (count($this->workspaceService->getPublishableNodeInfo($userWorkspace)) > 0) {
                // TODO: proper error dialog
                throw new \Exception('Your personal workspace currently contains unpublished changes. In order to switch to a different target workspace you need to either publish or discard pending changes first.');
            }

            $userWorkspace->setBaseWorkspace($targetWorkspace);
            $this->workspaceRepository->update($userWorkspace);

            $success = new Success();
            $success->setMessage(sprintf('Switched base workspace to %s.', $targetWorkspaceName));
            $this->feedbackCollection->add($success);

            $updateWorkspaceInfo = new UpdateWorkspaceInfo();
            $updateWorkspaceInfo->setWorkspace($userWorkspace);
            $this->feedbackCollection->add($updateWorkspaceInfo);

            // Construct base workspace context
            $originalContext = $documentNode->getContext();
            $contextProperties = $documentNode->getContext()->getProperties();
            $contextProperties['workspaceName'] = $targetWorkspaceName;
            $contentContext = $this->contextFactory->create($contextProperties);

            // If current document node doesn't exist in the base workspace, traverse its parents to find the one that exists
            $redirectNode = $documentNode;
            while (true) {
                $redirectNodeInBaseWorkspace = $contentContext->getNodeByIdentifier($redirectNode->getIdentifier());
                if ($redirectNodeInBaseWorkspace) {
                    break;
                } else {
                    $redirectNode = $redirectNode->getParent();
                    if (!$redirectNode) {
                        throw new \Exception(sprintf('Wasn\'t able to locate any valid node in rootline of node %s in the workspace %s.', $documentNode->getContextPath(), $targetWorkspaceName), 1458814469);
                    }
                }
            }

            // If current document node exists in the base workspace, then reload, else redirect
            if ($redirectNode === $documentNode) {
                $reloadDocument = new ReloadDocument();
                $reloadDocument->setNode($documentNode);
                $this->feedbackCollection->add($reloadDocument);
            } else {
                $redirect = new Redirect();
                $redirect->setNode($redirectNode);
                $this->feedbackCollection->add($redirect);
            }

            $this->persistenceManager->persistAll();
        } catch (\Exception $e) {
            $error = new Error();
            $error->setMessage($e->getMessage());

            $this->feedbackCollection->add($error);
        }

        $this->view->assign('value', $this->feedbackCollection);
    }
public function changeBaseWorkspaceAction ( string $ targetWorkspaceName , NodeInterface $ documentNode ) { try { $ targetWorkspace = $ this -> workspaceRepository -> findOneByName ( $ targetWorkspaceName ) ; $ userWorkspace = $ this -> userService -> getPersonalWorkspace ( ) ; if ( count ( $ this -> workspaceService -> getPublishableNodeInfo ( $ userWorkspace ) ) > 0 ) { // TODO: proper error dialog throw new \ Exception ( 'Your personal workspace currently contains unpublished changes. In order to switch to a different target workspace you need to either publish or discard pending changes first.' ) ; } $ userWorkspace -> setBaseWorkspace ( $ targetWorkspace ) ; $ this -> workspaceRepository -> update ( $ userWorkspace ) ; $ success = new Success ( ) ; $ success -> setMessage ( sprintf ( 'Switched base workspace to %s.' , $ targetWorkspaceName ) ) ; $ this -> feedbackCollection -> add ( $ success ) ; $ updateWorkspaceInfo = new UpdateWorkspaceInfo ( ) ; $ updateWorkspaceInfo -> setWorkspace ( $ userWorkspace ) ; $ this -> feedbackCollection -> add ( $ updateWorkspaceInfo ) ; // Construct base workspace context $ originalContext = $ documentNode -> getContext ( ) ; $ contextProperties = $ documentNode -> getContext ( ) -> getProperties ( ) ; $ contextProperties [ 'workspaceName' ] = $ targetWorkspaceName ; $ contentContext = $ this -> contextFactory -> create ( $ contextProperties ) ; // If current document node doesn't exist in the base workspace, traverse its parents to find the one that exists $ redirectNode = $ documentNode ; while ( true ) { $ redirectNodeInBaseWorkspace = $ contentContext -> getNodeByIdentifier ( $ redirectNode -> getIdentifier ( ) ) ; if ( $ redirectNodeInBaseWorkspace ) { break ; } else { $ redirectNode = $ redirectNode -> getParent ( ) ; if ( ! $ redirectNode ) { throw new \ Exception ( sprintf ( 'Wasn\'t able to locate any valid node in rootline of node %s in the workspace %s.' , $ documentNode -> getContextPath ( ) , $ targetWorkspaceName ) , 1458814469 ) ; } } } // If current document node exists in the base workspace, then reload, else redirect if ( $ redirectNode === $ documentNode ) { $ reloadDocument = new ReloadDocument ( ) ; $ reloadDocument -> setNode ( $ documentNode ) ; $ this -> feedbackCollection -> add ( $ reloadDocument ) ; } else { $ redirect = new Redirect ( ) ; $ redirect -> setNode ( $ redirectNode ) ; $ this -> feedbackCollection -> add ( $ redirect ) ; } $ this -> persistenceManager -> persistAll ( ) ; } catch ( \ Exception $ e ) { $ error = new Error ( ) ; $ error -> setMessage ( $ e -> getMessage ( ) ) ; $ this -> feedbackCollection -> add ( $ error ) ; } $ this -> view -> assign ( 'value' , $ this -> feedbackCollection ) ; }
Change base workspace of current user workspace

@param string $targetWorkspaceName ,
@param NodeInterface $documentNode
@return void
@throws \Exception
Change base workspace of current user workspace