/** * 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()); } }
/** * Repair inconsistent nodes * * This command analyzes and repairs the node tree structure and individual nodes * based on the current node type configuration. * * It is possible to execute only one or more specific checks by providing the <b>--skip</b> * or <b>--only</b> option. See the full description of checks further below for possible check * identifiers. * * The following checks will be performed: * * {pluginDescriptions} * <b>Examples:</b> * * ./flow node:repair * * ./flow node:repair --node-type Neos.NodeTypes:Page * * ./flow node:repair --workspace user-robert --only removeOrphanNodes,removeNodesWithInvalidDimensions * * ./flow node:repair --skip removeUndefinedProperties * * @param string $nodeType Node type name, if empty update all declared node types * @param string $workspace Workspace name, default is 'live' * @param boolean $dryRun Don't do anything, but report actions * @param boolean $cleanup If FALSE, cleanup tasks are skipped * @param string $skip Skip the given check or checks (comma separated) * @param string $only Only execute the given check or checks (comma separated) * @return void */ public function repairCommand($nodeType = null, $workspace = 'live', $dryRun = false, $cleanup = true, $skip = null, $only = null) { $this->pluginConfigurations = self::detectPlugins($this->objectManager); if ($this->workspaceRepository->countByName($workspace) === 0) { $this->outputLine('Workspace "%s" does not exist', array($workspace)); exit(1); } if ($nodeType !== null) { if ($this->nodeTypeManager->hasNodeType($nodeType)) { $nodeType = $this->nodeTypeManager->getNodeType($nodeType); } else { $this->outputLine('Node type "%s" does not exist', array($nodeType)); exit(1); } } if ($dryRun) { $this->outputLine('Dry run, not committing any changes.'); } if (!$cleanup) { $this->outputLine('Omitting cleanup tasks.'); } foreach ($this->pluginConfigurations as $pluginConfiguration) { /** @var NodeCommandControllerPluginInterface $plugin */ $plugin = $pluginConfiguration['object']; $this->outputLine('<b>' . $plugin->getSubCommandShortDescription('repair') . '</b>'); $this->outputLine(); $plugin->invokeSubCommand('repair', $this->output, $nodeType, $workspace, $dryRun, $cleanup, $skip, $only); $this->outputLine(); } $this->outputLine('Node repair finished.'); }
/** * @test */ public function getPersonalWorkspaceReturnsTheUsersWorkspaceIfAUserIsLoggedIn() { $mockUser = $this->getMockBuilder(User::class)->disableOriginalConstructor()->getMock(); $mockUserWorkspace = $this->getMockBuilder(Workspace::class)->disableOriginalConstructor()->getMock(); $this->mockUserDomainService->expects($this->atLeastOnce())->method('getCurrentUser')->will($this->returnValue($mockUser)); $this->mockUserDomainService->expects($this->atLeastOnce())->method('getUserName')->with($mockUser)->will($this->returnValue('TheUserName')); $this->mockWorkspaceRepository->expects($this->atLeastOnce())->method('findOneByName')->with('user-TheUserName')->will($this->returnValue($mockUserWorkspace)); $this->assertSame($mockUserWorkspace, $this->userService->getPersonalWorkspace()); }
/** * @return void */ public function setUp() { parent::setUp(); $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); $this->liveWorkspace = new Workspace('live'); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $this->workspaceRepository->add($this->liveWorkspace); $this->persistenceManager->persistAll(); $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class); $this->context = $this->contextFactory->create(['workspaceName' => 'live']); $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); }
protected function setUpRootNodeAndRepository() { $this->contextFactory = $this->objectManager->get(ContextFactory::class); $personalContext = $this->contextFactory->create(array('workspaceName' => $this->currentTestWorkspaceName)); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); if ($this->liveWorkspace === null) { $this->liveWorkspace = new Workspace('live'); $this->workspaceRepository->add($this->liveWorkspace); $this->workspaceRepository->add(new Workspace($this->currentTestWorkspaceName, $this->liveWorkspace)); $this->persistenceManager->persistAll(); } $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); $this->rootNode = $personalContext->getNode('/'); $this->persistenceManager->persistAll(); }
/** * @param FinisherContext $finisherContext * @return void * @throws Exception */ public function importSite(FinisherContext $finisherContext) { $formValues = $finisherContext->getFormRuntime()->getFormState()->getFormValues(); if (isset($formValues['prune']) && intval($formValues['prune']) === 1) { $this->nodeDataRepository->removeAll(); $this->workspaceRepository->removeAll(); $this->domainRepository->removeAll(); $this->siteRepository->removeAll(); $this->persistenceManager->persistAll(); } if (!empty($formValues['packageKey'])) { if ($this->packageManager->isPackageAvailable($formValues['packageKey'])) { throw new Exception(sprintf('The package key "%s" already exists.', $formValues['packageKey']), 1346759486); } $packageKey = $formValues['packageKey']; $siteName = $formValues['siteName']; $generatorService = $this->objectManager->get(\Neos\SiteKickstarter\Service\GeneratorService::class); $generatorService->generateSitePackage($packageKey, $siteName); } elseif (!empty($formValues['site'])) { $packageKey = $formValues['site']; } $this->deactivateOtherSitePackages($packageKey); $this->packageManager->activatePackage($packageKey); if (!empty($packageKey)) { try { $contentContext = $this->contextFactory->create(array('workspaceName' => 'live')); $this->siteImportService->importFromPackage($packageKey, $contentContext); } catch (\Exception $exception) { $finisherContext->cancel(); $this->systemLogger->logException($exception); throw new SetupException(sprintf('Error: During the import of the "Sites.xml" from the package "%s" an exception occurred: %s', $packageKey, $exception->getMessage()), 1351000864); } } }
/** * Remove dimensions on nodes "/" and "/sites" * * This empties the content dimensions on those nodes, so when traversing via the Node API from the root node, * the nodes below "/sites" are always reachable. * * @param string $workspaceName * @param boolean $dryRun * @return void */ public function removeContentDimensionsFromRootAndSitesNode($workspaceName, $dryRun) { $workspace = $this->workspaceRepository->findByIdentifier($workspaceName); $rootNodes = $this->nodeDataRepository->findByPath('/', $workspace); $sitesNodes = $this->nodeDataRepository->findByPath('/sites', $workspace); $this->output->outputLine('Checking for root and site nodes with content dimensions set ...'); /** @var \Neos\ContentRepository\Domain\Model\NodeData $rootNode */ foreach ($rootNodes as $rootNode) { if ($rootNode->getDimensionValues() !== []) { if ($dryRun === false) { $rootNode->setDimensions([]); $this->nodeDataRepository->update($rootNode); $this->output->outputLine('Removed content dimensions from root node'); } else { $this->output->outputLine('Found root node with content dimensions set.'); } } } /** @var \Neos\ContentRepository\Domain\Model\NodeData $sitesNode */ foreach ($sitesNodes as $sitesNode) { if ($sitesNode->getDimensionValues() !== []) { if ($dryRun === false) { $sitesNode->setDimensions([]); $this->nodeDataRepository->update($sitesNode); $this->output->outputLine('Removed content dimensions from node "/sites"'); } else { $this->output->outputLine('Found node "/sites"'); } } } }
/** * Removes ownership of all workspaces currently owned by the given user * * @param User $user The user currently owning workspaces * @return void */ protected function removeOwnerFromUsersWorkspaces(User $user) { /** @var Workspace $workspace */ foreach ($this->workspaceRepository->findByOwner($user) as $workspace) { $workspace->setOwner(null); $this->workspaceRepository->update($workspace); } }
/** * @return void */ public function setUp() { parent::setUp(); $this->nodeDataRepository = new NodeDataRepository(); if ($this->liveWorkspace === null) { $this->liveWorkspace = new Workspace('live'); $this->objectManager->get(WorkspaceRepository::class); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $this->workspaceRepository->add($this->liveWorkspace); $this->workspaceRepository->add(new Workspace('user-admin', $this->liveWorkspace)); $this->workspaceRepository->add(new Workspace('live2', $this->liveWorkspace)); $this->workspaceRepository->add(new Workspace('test', $this->liveWorkspace)); $this->persistenceManager->persistAll(); } $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class); $this->context = $this->contextFactory->create(['workspaceName' => 'live']); $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); $this->contentDimensionRepository = $this->objectManager->get(ContentDimensionRepository::class); }
/** * @return void */ public function setUp() { parent::setUp(); $contentDimensionRepository = $this->objectManager->get(ContentDimensionRepository::class); $contentDimensionRepository->setDimensionsConfiguration(array('language' => array('default' => 'mul_ZZ'))); $this->currentTestWorkspaceName = uniqid('user-'); $this->contextFactory = $this->objectManager->get(ContextFactory::class); if ($this->liveWorkspace === null) { $this->liveWorkspace = new Workspace('live'); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $this->workspaceRepository->add($this->liveWorkspace); } $this->workspaceRepository->add(new Workspace($this->currentTestWorkspaceName, $this->liveWorkspace)); $this->personalContext = $this->contextFactory->create(array('workspaceName' => $this->currentTestWorkspaceName)); $this->liveContext = $this->contextFactory->create(array('workspaceName' => 'live')); $this->rootNodeInLiveWorkspace = $this->liveContext->getNode('/'); $this->persistenceManager->persistAll(); $this->rootNodeInPersonalWorkspace = $this->personalContext->getNode('/'); }
public function setUp() { parent::setUp(); $this->markSkippedIfNodeTypesPackageIsNotInstalled(); if ($this->liveWorkspace === null) { $this->liveWorkspace = new Workspace('live'); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $this->workspaceRepository->add($this->liveWorkspace); $this->workspaceRepository->add(new Workspace('test', $this->liveWorkspace)); $this->persistenceManager->persistAll(); } $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class); $contentContext = $this->contextFactory->create(array('workspaceName' => 'live')); $siteImportService = $this->objectManager->get(SiteImportService::class); $siteImportService->importFromFile($this->fixtureFileName, $contentContext); $this->persistenceManager->persistAll(); if ($this->nodeContextPath !== null) { $this->node = $this->getNodeWithContextPath($this->nodeContextPath); } }
/** * @test */ public function createNodeFromTemplateUsesWorkspacesOfContext() { $nodeTemplate = $this->generateBasicNodeTemplate(); $userWorkspace = new Workspace('user1', $this->liveWorkspace); $this->workspaceRepository->add($userWorkspace); $this->context = $this->contextFactory->create(array('workspaceName' => 'user1')); $rootNode = $this->context->getNode('/'); $node = $rootNode->createNodeFromTemplate($nodeTemplate, 'just-a-node'); $workspace = $node->getWorkspace(); $this->assertEquals('user1', $workspace->getName(), 'Node should be created in workspace of context'); }
/** * @return void */ protected function setUpRootNodeAndRepository() { $this->contextFactory = $this->objectManager->get(ContextFactory::class); $this->context = $this->contextFactory->create(array('workspaceName' => 'live')); $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); $this->workspaceRepository->add(new Workspace('live')); $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class); $this->rootNode = $this->context->getNode('/'); $this->persistenceManager->persistAll(); }
/** * Creates an array of workspace names and their respective titles which are possible base workspaces for other * workspaces. * * @param Workspace $excludedWorkspace If set, this workspace will be excluded from the list of returned workspaces * @return array */ protected function prepareBaseWorkspaceOptions(Workspace $excludedWorkspace = null) { $baseWorkspaceOptions = []; foreach ($this->workspaceRepository->findAll() as $workspace) { /** @var Workspace $workspace */ if (!$workspace->isPersonalWorkspace() && $workspace !== $excludedWorkspace && ($workspace->isPublicWorkspace() || $workspace->isInternalWorkspace() || $this->userService->currentUserCanManageWorkspace($workspace))) { $baseWorkspaceOptions[$workspace->getName()] = $workspace->getTitle(); } } return $baseWorkspaceOptions; }
/** * 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), ''); }
/** * Repair nodes whose shadow nodes are missing * * This check searches for nodes which have a corresponding node in one of the base workspaces, * have different node paths, but don't have a corresponding shadow node with a "movedto" value. * * @param string $workspaceName Currently ignored * @param boolean $dryRun Simulate? * @param NodeType $nodeType This argument will be ignored * @return void */ protected function repairShadowNodes($workspaceName, $dryRun, NodeType $nodeType = null) { /** @var Workspace $workspace */ $workspace = $this->workspaceRepository->findByIdentifier($workspaceName); if ($workspace->getBaseWorkspace() === null) { $this->output->outputLine('Repairing base workspace "%s", therefore skipping check for shadow nodes.', [$workspaceName]); $this->output->outputLine(); return; } $this->output->outputLine('Checking for nodes with missing shadow nodes ...'); $fixedShadowNodes = $this->fixShadowNodesInWorkspace($workspace, $nodeType); $this->output->outputLine('%s %s node%s with missing shadow nodes.', [$dryRun ? 'Would repair' : 'Repaired', $fixedShadowNodes, $fixedShadowNodes !== 1 ? 's' : '']); $this->output->outputLine(); }
/** * Display a list of existing workspaces * * @return void */ public function listCommand() { $workspaces = $this->workspaceRepository->findAll(); if ($workspaces->count() === 0) { $this->outputLine('No workspaces found.'); $this->quit(0); } $tableRows = []; $headerRow = ['Name', 'Base Workspace', 'Title', 'Owner', 'Description']; foreach ($workspaces as $workspace) { $owner = $workspace->getOwner() ? $workspace->getOwner()->getName() : ''; $tableRows[] = [$workspace->getName(), $workspace->getBaseWorkspace() ? $workspace->getBaseWorkspace()->getName() : '', $workspace->getTitle(), $owner, $workspace->getDescription()]; } $this->output->outputTable($tableRows, $headerRow); }
/** * 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); }
/** * Returns the current workspace. * * @param boolean $createWorkspaceIfNecessary DEPRECATED: If enabled, creates a workspace with the configured name if it doesn't exist already. This option is DEPRECATED, create workspace explicitly instead. * @return Workspace The workspace or NULL * @api */ public function getWorkspace($createWorkspaceIfNecessary = true) { if ($this->workspace !== null) { return $this->workspace; } $this->workspace = $this->workspaceRepository->findByIdentifier($this->workspaceName); if ($this->workspace === null && $createWorkspaceIfNecessary) { $liveWorkspace = $this->workspaceRepository->findByIdentifier('live'); $this->workspace = new Workspace($this->workspaceName, $liveWorkspace); $this->workspaceRepository->add($this->workspace); $this->systemLogger->log(sprintf('Notice: %s::getWorkspace() implicitly created the new workspace "%s". This behaviour is discouraged and will be removed in future versions. Make sure to create workspaces explicitly by adding a new workspace to the Workspace Repository.', __CLASS__, $this->workspaceName), LOG_NOTICE); } if ($this->workspace !== null) { $this->validateWorkspace($this->workspace); } return $this->workspace; }
protected function setUpRootNodeAndRepository() { $this->contextFactory = $this->objectManager->get(ContextFactory::class); $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class); if ($this->liveWorkspace === null) { $this->liveWorkspace = new Workspace('live'); $this->workspaceRepository->add($this->liveWorkspace); $this->groupWorkspace = new Workspace($this->currentGroupWorkspace, $this->liveWorkspace); $this->workspaceRepository->add($this->groupWorkspace); $this->workspaceRepository->add(new Workspace($this->currentUserWorkspace, $this->groupWorkspace)); $this->persistenceManager->persistAll(); } $personalContext = $this->contextFactory->create(['workspaceName' => $this->currentUserWorkspace]); // Make sure the Workspace was created. $this->liveWorkspace = $personalContext->getWorkspace()->getBaseWorkspace()->getBaseWorkspace(); $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class); $this->rootNode = $personalContext->getNode('/'); $this->persistenceManager->persistAll(); }
/** * Update a site * * @param Site $site A site to update * @param string $newSiteNodeName A new site node name * @return void * @Flow\Validate(argumentName="$site", type="UniqueEntity") * @Flow\Validate(argumentName="$newSiteNodeName", type="NotEmpty") * @Flow\Validate(argumentName="$newSiteNodeName", type="StringLength", options={ "minimum"=1, "maximum"=250 }) * @Flow\Validate(argumentName="$newSiteNodeName", type="Neos.Neos:NodeName") */ public function updateSiteAction(Site $site, $newSiteNodeName) { if ($site->getNodeName() !== $newSiteNodeName) { $oldSiteNodePath = NodePaths::addNodePathSegment(SiteService::SITES_ROOT_PATH, $site->getNodeName()); $newSiteNodePath = NodePaths::addNodePathSegment(SiteService::SITES_ROOT_PATH, $newSiteNodeName); /** @var $workspace Workspace */ foreach ($this->workspaceRepository->findAll() as $workspace) { $siteNode = $this->nodeDataRepository->findOneByPath($oldSiteNodePath, $workspace); if ($siteNode !== null) { $siteNode->setPath($newSiteNodePath); } } $site->setNodeName($newSiteNodeName); $this->nodeDataRepository->persistEntities(); } $this->siteRepository->update($site); $this->addFlashMessage('The site "%s" has been updated.', 'Update', null, array(htmlspecialchars($site->getName())), 1412371798); $this->unsetLastVisitedNodeAndRedirect('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; $xmlReader = new \XMLReader(); $xmlReader->open($pathAndFilename, null, LIBXML_PARSEHUGE); if ($this->workspaceRepository->findOneByName('live') === null) { $this->workspaceRepository->add(new Workspace('live')); $this->persistenceManager->persistAll(); } while ($xmlReader->read()) { if ($xmlReader->nodeType != \XMLReader::ELEMENT || $xmlReader->name !== 'site') { continue; } $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(SiteService::SITES_ROOT_PATH); if ($sitesNode === null) { $sitesNode = $rootNode->createNode(NodePaths::getNodeNameFromPath(SiteService::SITES_ROOT_PATH)); } $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; }
/** * Updates a workspace * * @param Workspace $workspace The updated workspace * @return void */ public function updateAction(Workspace $workspace) { $this->workspaceRepository->update($workspace); $this->throwStatus(200, 'Workspace updated', ''); }