/** * Returns the current user's personal workspace or null if no user is logged in * * @return Workspace * @api */ public function getPersonalWorkspace() { $workspaceName = $this->getPersonalWorkspaceName(); if ($workspaceName !== null) { return $this->workspaceRepository->findOneByName($this->getPersonalWorkspaceName()); } }
/** * Publishes the whole workspace * * @param Workspace $workspace * @return void */ public function publishWorkspaceAction(Workspace $workspace) { $liveWorkspace = $this->workspaceRepository->findOneByName('live'); $workspace->publish($liveWorkspace); $this->addFlashMessage('Changes in workspace "%s" have been published', 'Changes published', Message::SEVERITY_OK, array($workspace->getName()), 1412420808); $this->redirect('index'); }
/** * @return \TYPO3\TYPO3CR\Domain\Service\Context */ protected function createContext() { $workspace = $this->workspaceRepository->findOneByName('live'); if ($workspace === null) { $this->workspaceRepository->add(new Workspace('live')); } $this->persistenceManager->persistAll(); return $this->contextFactory->create(array('workspaceName' => 'live', 'invisibleContentShown' => true, 'inaccessibleContentShown' => true)); }
/** * Publishes the whole workspace * * @param Workspace $workspace * @return void */ public function publishWorkspaceAction(Workspace $workspace) { if (($targetWorkspace = $workspace->getBaseWorkspace()) === null) { $targetWorkspace = $this->workspaceRepository->findOneByName('live'); } $workspace->publish($targetWorkspace); $this->addFlashMessage($this->translator->translateById('workspaces.allChangesInWorkspaceHaveBeenPublished', [htmlspecialchars($workspace->getTitle()), htmlspecialchars($targetWorkspace->getTitle())], null, null, 'Modules', 'TYPO3.Neos')); $this->redirect('index'); }
/** * Imports one or multiple sites from the XML file at $pathAndFilename * * @param string $pathAndFilename * @return Site The imported site * @throws UnknownPackageException|InvalidPackageStateException|NeosException */ public function importFromFile($pathAndFilename) { /** @var Site $importedSite */ $site = NULL; $this->eventEmittingService->withoutEventLog(function () use($pathAndFilename, &$site) { $xmlReader = new \XMLReader(); $xmlReader->open($pathAndFilename, NULL, LIBXML_PARSEHUGE); if ($this->workspaceRepository->findOneByName('live') === NULL) { $this->workspaceRepository->add(new Workspace('live')); } $rootNode = $this->contextFactory->create()->getRootNode(); $this->persistenceManager->persistAll(); $sitesNode = $rootNode->getNode('/sites'); if ($sitesNode === NULL) { $sitesNode = $rootNode->createSingleNode('sites'); } while ($xmlReader->read()) { if ($xmlReader->nodeType != \XMLReader::ELEMENT || $xmlReader->name !== 'site') { continue; } $isLegacyFormat = $xmlReader->getAttribute('nodeName') !== NULL && $xmlReader->getAttribute('state') === NULL && $xmlReader->getAttribute('siteResourcesPackageKey') === NULL; if ($isLegacyFormat) { $site = $this->legacySiteImportService->importSitesFromFile($pathAndFilename); return; } $site = $this->getSiteByNodeName($xmlReader->getAttribute('siteNodeName')); $site->setName($xmlReader->getAttribute('name')); $site->setState((int) $xmlReader->getAttribute('state')); $siteResourcesPackageKey = $xmlReader->getAttribute('siteResourcesPackageKey'); if (!$this->packageManager->isPackageAvailable($siteResourcesPackageKey)) { throw new UnknownPackageException(sprintf('Package "%s" specified in the XML as site resources package does not exist.', $siteResourcesPackageKey), 1303891443); } if (!$this->packageManager->isPackageActive($siteResourcesPackageKey)) { throw new InvalidPackageStateException(sprintf('Package "%s" specified in the XML as site resources package is not active.', $siteResourcesPackageKey), 1303898135); } $site->setSiteResourcesPackageKey($siteResourcesPackageKey); $rootNode = $this->contextFactory->create()->getRootNode(); // We fetch the workspace to be sure it's known to the persistence manager and persist all // so the workspace and site node are persisted before we import any nodes to it. $rootNode->getContext()->getWorkspace(); $this->persistenceManager->persistAll(); $sitesNode = $rootNode->getNode('/sites'); if ($sitesNode === NULL) { $sitesNode = $rootNode->createNode('sites'); } $this->nodeImportService->import($xmlReader, $sitesNode->getPath(), dirname($pathAndFilename) . '/Resources'); } }); if ($site === NULL) { throw new NeosException(sprintf('The XML file did not contain a valid site node.'), 1418999522); } $this->emitSiteImported($site); return $site; }
/** * Publish everything in the workspace with the given workspace name * * @param string $sourceWorkspaceName Name of the source workspace containing the content to publish * @param string $targetWorkspaceName Name of the target workspace the content should be published to * @return void */ public function publishAllAction($sourceWorkspaceName, $targetWorkspaceName) { $sourceWorkspace = $this->workspaceRepository->findOneByName($sourceWorkspaceName); $targetWorkspace = $this->workspaceRepository->findOneByName($targetWorkspaceName); if ($sourceWorkspace === null) { $this->throwStatus(400, 'Invalid source workspace'); } if ($targetWorkspace === null) { $this->throwStatus(400, 'Invalid target workspace'); } $this->publishingService->publishNodes($this->publishingService->getUnpublishedNodes($sourceWorkspace), $targetWorkspace); $this->throwStatus(204, sprintf('All changes in workspace %s have been published to %s', $sourceWorkspaceName, $targetWorkspaceName), ''); }
/** * If the specified workspace or its root node does not exist yet, the workspace and root node will be created. * * This method is basically a safeguard for legacy and potentially broken websites where users might not have * their own workspace yet. In a normal setup, the Domain User Service is responsible for creating and deleting * user workspaces. * * @param string $workspaceName Name of the workspace * @return void */ protected function createWorkspaceAndRootNodeIfNecessary($workspaceName) { $workspace = $this->workspaceRepository->findOneByName($workspaceName); if ($workspace === NULL) { $liveWorkspace = $this->workspaceRepository->findOneByName('live'); $workspace = new Workspace($workspaceName, $liveWorkspace); $this->workspaceRepository->add($workspace); $this->persistenceManager->whitelistObject($workspace); } $contentContext = $this->createContext($workspaceName); $rootNode = $contentContext->getRootNode(); $this->persistenceManager->whitelistObject($rootNode); $this->persistenceManager->whitelistObject($rootNode->getNodeData()); $this->persistenceManager->persistAll(TRUE); }
/** * If the specified workspace or its root node does not exist yet, the workspace and root node will be created. * * This method is basically a safeguard for legacy and potentially broken websites where users might not have * their own workspace yet. In a normal setup, the Domain User Service is responsible for creating and deleting * user workspaces. * * @param string $workspaceName Name of the workspace * @return void */ protected function createWorkspaceAndRootNodeIfNecessary($workspaceName) { $workspace = $this->workspaceRepository->findOneByName($workspaceName); if ($workspace === null) { $liveWorkspace = $this->workspaceRepository->findOneByName('live'); $owner = $this->userService->getBackendUser(); $workspace = new Workspace($workspaceName, $liveWorkspace, $owner); $this->workspaceRepository->add($workspace); $this->persistenceManager->whitelistObject($workspace); } $contentContext = $this->createContext($workspaceName); $rootNode = $contentContext->getRootNode(); $this->persistenceManager->whitelistObject($rootNode); $this->persistenceManager->whitelistObject($rootNode->getNodeData()); $this->persistenceManager->persistAll(true); }
/** * Rebase a workspace * * This command sets a new base workspace for the specified workspace. Note that doing so will put the possible * changes contained in the workspace to be rebased into a different context and thus might lead to unintended * results when being published. * * @param string $workspace Name of the workspace to rebase, for example "user-john" * @param string $baseWorkspace Name of the new base workspace * @return void */ public function rebaseCommand($workspace, $baseWorkspace) { $workspaceName = $workspace; $workspace = $this->workspaceRepository->findOneByName($workspaceName); if (!$workspace instanceof Workspace) { $this->outputLine('Workspace "%s" does not exist', array($workspaceName)); $this->quit(1); } $baseWorkspaceName = $baseWorkspace; $baseWorkspace = $this->workspaceRepository->findOneByName($baseWorkspaceName); if (!$baseWorkspace instanceof Workspace) { $this->outputLine('The base workspace "%s" does not exist', array($baseWorkspaceName)); $this->quit(2); } $workspace->setBaseWorkspace($baseWorkspace); $this->workspaceRepository->update($workspace); $this->outputLine('Set "%s" as the new base workspace for "%s".', array($baseWorkspaceName, $workspaceName)); }
/** * @test */ public function changedNodeCanBePublishedFromPersonalToLiveWorkspace() { $liveContext = $this->contextFactory->create(array('workspaceName' => 'live')); $liveContext->getRootNode()->createNode('homepage')->createNode('teaser')->createNode('node52697bdfee199'); $teaserNode = $this->rootNode->getNode('/homepage/teaser/node52697bdfee199'); $teaserNode->setProperty('text', 'Updated text!'); $this->saveNodesAndTearDownRootNodeAndRepository(); $this->setUpRootNodeAndRepository(); $this->liveWorkspace = $this->workspaceRepository->findOneByName('live'); $teaserNode = $this->rootNode->getNode('/homepage/teaser/node52697bdfee199'); $this->rootNode->getWorkspace()->publishNode($teaserNode, $this->liveWorkspace); $this->saveNodesAndTearDownRootNodeAndRepository(); $this->setUpRootNodeAndRepository(); $liveContext = $this->contextFactory->create(array('workspaceName' => 'live')); $liveRootNode = $liveContext->getRootNode(); $teaserNode = $liveRootNode->getNode('/homepage/teaser/node52697bdfee199'); $this->assertInstanceOf('TYPO3\\TYPO3CR\\Domain\\Model\\NodeInterface', $teaserNode); }
/** * Publish nodes * * @param array $nodeContextPaths * @param string $targetWorkspaceName * @return void */ public function publishAction(array $nodeContextPaths, $targetWorkspaceName) { try { $targetWorkspace = $this->workspaceRepository->findOneByName($targetWorkspaceName); foreach ($nodeContextPaths as $contextPath) { $node = $this->nodeService->getNodeFromContextPath($contextPath); $this->publishingService->publishNode($node, $targetWorkspace); } $success = new Success(); $success->setMessage(sprintf('Published %d change(s) to %s.', count($nodeContextPaths), $targetWorkspaceName)); $this->updateWorkspaceInfo($nodeContextPaths[0]); $this->feedbackCollection->add($success); $this->persistenceManager->persistAll(); } catch (\Exception $e) { $error = new Error(); $error->setMessage($e->getMessage()); $this->feedbackCollection->add($error); } $this->view->assign('value', $this->feedbackCollection); }
/** * Returns the current workspace. * * @param boolean $createWorkspaceIfNecessary If enabled, creates a workspace with the configured name if it doesn't exist already * @return \TYPO3\TYPO3CR\Domain\Model\Workspace The workspace or NULL * @api */ public function getWorkspace($createWorkspaceIfNecessary = TRUE) { if ($this->workspace === NULL) { $this->workspace = $this->workspaceRepository->findOneByName($this->workspaceName); if (!$this->workspace) { if ($createWorkspaceIfNecessary === FALSE) { return NULL; } $liveWorkspace = $this->workspaceRepository->findOneByName('live'); if (!$liveWorkspace) { $liveWorkspace = new \TYPO3\TYPO3CR\Domain\Model\Workspace('live'); $this->workspaceRepository->add($liveWorkspace); } if ($this->workspaceName === 'live') { $this->workspace = $liveWorkspace; } else { $this->workspace = new \TYPO3\TYPO3CR\Domain\Model\Workspace($this->workspaceName, $liveWorkspace); $this->workspaceRepository->add($this->workspace); } } } return $this->workspace; }
/** * Returns the Workspace of the currently logged in user or NULL if no matching workspace was found. * If no user is logged in this returns the live workspace * * @return Workspace */ public function getUserWorkspace() { return $this->workspaceRepository->findOneByName($this->getUserWorkspaceName()); }
/** * @param string $workspaceName * @param string $targetWorkspaceName * @return void */ public function publishWorkspace($workspaceName, $targetWorkspaceName = 'live') { $this->workspaceRepository->findOneByName($workspaceName)->publish($targetWorkspaceName); }