/**
  * @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();
 }
Ejemplo n.º 3
0
 /**
  * @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();
 }
 /**
  * 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);
 }
 /**
  * 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);
     }
 }
Ejemplo n.º 10
0
 /**
  * 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;
 }
 /**
  * Create a workspace
  *
  * @param string $workspaceName
  * @param Workspace $baseWorkspace
  * @param string $ownerAccountIdentifier
  * @return string
  */
 public function createAction($workspaceName, Workspace $baseWorkspace, $ownerAccountIdentifier = null)
 {
     $existingWorkspace = $this->workspaceRepository->findByIdentifier($workspaceName);
     if ($existingWorkspace !== null) {
         $this->throwStatus(409, 'Workspace already exists', '');
     }
     if ($ownerAccountIdentifier !== null) {
         $owner = $this->userService->getUser($ownerAccountIdentifier);
         if ($owner === null) {
             $this->throwStatus(422, 'Requested owner account does not exist', '');
         }
     } else {
         $owner = null;
     }
     $workspace = new Workspace($workspaceName, $baseWorkspace, $owner);
     $this->workspaceRepository->add($workspace);
     $this->throwStatus(201, 'Workspace created', '');
 }
 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();
 }
 /**
  * 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;
 }
 /**
  * Create a workspace
  *
  * @Flow\Validate(argumentName="title", type="\Neos\Flow\Validation\Validator\NotEmptyValidator")
  * @param string $title Human friendly title of the workspace, for example "Christmas Campaign"
  * @param Workspace $baseWorkspace Workspace the new workspace should be based on
  * @param string $visibility Visibility of the new workspace, must be either "internal" or "shared"
  * @param string $description A description explaining the purpose of the new workspace
  * @return void
  */
 public function createAction($title, Workspace $baseWorkspace, $visibility, $description = '')
 {
     $workspace = $this->workspaceRepository->findOneByTitle($title);
     if ($workspace instanceof Workspace) {
         $this->addFlashMessage($this->translator->translateById('workspaces.workspaceWithThisTitleAlreadyExists', [], null, null, 'Modules', 'Neos.Neos'), '', Message::SEVERITY_WARNING);
         $this->redirect('new');
     }
     $workspaceName = Utility::renderValidNodeName($title) . '-' . substr(base_convert(microtime(false), 10, 36), -5, 5);
     while ($this->workspaceRepository->findOneByName($workspaceName) instanceof Workspace) {
         $workspaceName = Utility::renderValidNodeName($title) . '-' . substr(base_convert(microtime(false), 10, 36), -5, 5);
     }
     if ($visibility === 'private') {
         $owner = $this->userService->getCurrentUser();
     } else {
         $owner = null;
     }
     $workspace = new Workspace($workspaceName, $baseWorkspace, $owner);
     $workspace->setTitle($title);
     $workspace->setDescription($description);
     $this->workspaceRepository->add($workspace);
     $this->redirect('index');
 }
 /**
  * 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]);
     }
 }