/**
  * Shows details of the given workspace
  *
  * @param string $workspaceName
  * @param Workspace $baseWorkspace
  * @return string
  */
 public function createAction($workspaceName, Workspace $baseWorkspace)
 {
     $existingWorkspace = $this->workspaceRepository->findByIdentifier($workspaceName);
     if ($existingWorkspace !== NULL) {
         $this->throwStatus(409, 'Workspace already exists', '');
     }
     $workspace = new Workspace($workspaceName, $baseWorkspace);
     $this->workspaceRepository->add($workspace);
     $this->throwStatus(201, 'Workspace created', '');
 }
 /**
  * @test
  */
 public function nodePathAvailableForNodeWillReturnFalseIfNodeWithGivenPathExistsAlready()
 {
     $this->workspaceRepository->add(new \TYPO3\TYPO3CR\Domain\Model\Workspace('live'));
     $rootNode = $this->context->getRootNode();
     $fooNode = $rootNode->createNode('foo');
     $fooNode->createNode('bar');
     $bazNode = $rootNode->createNode('baz');
     $this->persistenceManager->persistAll();
     $actualResult = $this->nodeService->nodePathAvailableForNode('/foo/bar', $bazNode);
     $this->assertFalse($actualResult);
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->nodeTypeManager = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Service\NodeTypeManager::class);
     $this->liveWorkspace = new Workspace('live');
     $this->workspaceRepository = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Repository\WorkspaceRepository::class);
     $this->workspaceRepository->add($this->liveWorkspace);
     $this->persistenceManager->persistAll();
     $this->contextFactory = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Service\ContextFactoryInterface::class);
     $this->context = $this->contextFactory->create(['workspaceName' => 'live']);
     $this->nodeDataRepository = $this->objectManager->get(\TYPO3\TYPO3CR\Domain\Repository\NodeDataRepository::class);
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $this->liveWorkspace = new Workspace('live');
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     $this->workspaceRepository->add($this->liveWorkspace);
     $this->persistenceManager->persistAll();
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $this->context = $this->contextFactory->create(array('workspaceName' => 'live'));
     $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
 }
 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();
 }
 protected function setUpRootNodeAndRepository()
 {
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactory');
     $personalContext = $this->contextFactory->create(array('workspaceName' => $this->currentTestWorkspaceName));
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     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('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
     $this->rootNode = $personalContext->getNode('/');
     $this->persistenceManager->persistAll();
 }
 public function setUp()
 {
     parent::setUp();
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     $liveWorkspace = new Workspace('live');
     $this->workspaceRepository->add($liveWorkspace);
     $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $this->context = $this->contextFactory->create(['workspaceName' => 'live', 'dimensions' => ['language' => ['en_US']], 'targetDimensions' => ['language' => 'en_US']]);
     $rootNode = $this->context->getRootNode();
     $this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page'));
     $this->siteNode->setProperty('title', 'welcome');
     $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
     $this->nodeIndexCommandController = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Command\\NodeIndexCommandController');
     $this->createNodesForNodeSearchTest();
 }
 public function setUp()
 {
     parent::setUp();
     $this->workspaceRepository = $this->objectManager->get(WorkspaceRepository::class);
     $liveWorkspace = new Workspace('live');
     $this->workspaceRepository->add($liveWorkspace);
     $this->nodeTypeManager = $this->objectManager->get(NodeTypeManager::class);
     $this->contextFactory = $this->objectManager->get(ContextFactoryInterface::class);
     $this->context = $this->contextFactory->create(['workspaceName' => 'live', 'dimensions' => ['language' => ['en_US']], 'targetDimensions' => ['language' => 'en_US']]);
     $rootNode = $this->context->getRootNode();
     $this->siteNode = $rootNode->createNode('welcome', $this->nodeTypeManager->getNodeType('TYPO3.Neos.NodeTypes:Page'));
     $this->siteNode->setProperty('title', 'welcome');
     $this->nodeDataRepository = $this->objectManager->get(NodeDataRepository::class);
     $this->nodeIndexCommandController = $this->objectManager->get(NodeIndexCommandController::class);
     $this->createNodesForNodeSearchTest();
 }
 public function setUp()
 {
     parent::setUp();
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     $liveWorkspace = new Workspace("live");
     $this->workspaceRepository->add($liveWorkspace);
     $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $this->context = $this->contextFactory->create(array('workspaceName' => 'live', 'dimensions' => array('language' => array('en_US'))));
     $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
     $this->queryBuilder = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Eel\\ElasticSearchQueryBuilder');
     $this->nodeIndexCommandController = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Command\\NodeIndexCommandController');
     $this->queryBuilder->log();
     $this->initializeIndex();
     $this->createNodesForNodeSearchTest();
 }
 /**
  * @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));
 }
 public function setUp()
 {
     parent::setUp();
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     $liveWorkspace = new \TYPO3\TYPO3CR\Domain\Model\Workspace("live");
     $this->workspaceRepository->add($liveWorkspace);
     $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $this->context = $this->contextFactory->create(array('workspaceName' => 'live', 'dimensions' => array('language' => array('de'))));
     $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
     $this->queryBuilder = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Eel\\ElasticSearchQueryBuilder');
     $this->queryBuilder->log();
     // we need to make sure that the index will be prefixed with an unique name. so we add a sleet as it is not
     // possible right now to set the index name
     sleep(4);
     $this->nodeIndexCommandController = $this->objectManager->get('Flowpack\\ElasticSearch\\ContentRepositoryAdaptor\\Command\\NodeIndexCommandController');
     $this->nodeIndexCommandController->buildCommand();
     $this->createNodesForNodeSearchTest();
 }
 /**
  * @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('/');
 }
 /**
  * @return void
  */
 public function setUp()
 {
     parent::setUp();
     $this->nodeDataRepository = new NodeDataRepository();
     if ($this->liveWorkspace === null) {
         $this->liveWorkspace = new Workspace('live');
         $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
         $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
         $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('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $this->context = $this->contextFactory->create(['workspaceName' => 'live']);
     $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $this->contentDimensionRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\ContentDimensionRepository');
 }
 /**
  * @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);
 }
 /**
  * @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');
 }
 public function setUp()
 {
     parent::setUp();
     $this->markSkippedIfNodeTypesPackageIsNotInstalled();
     if ($this->liveWorkspace === null) {
         $this->liveWorkspace = new Workspace('live');
         $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
         $this->workspaceRepository->add($this->liveWorkspace);
         $this->workspaceRepository->add(new Workspace('test', $this->liveWorkspace));
         $this->persistenceManager->persistAll();
     }
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface');
     $contentContext = $this->contextFactory->create(array('workspaceName' => 'live'));
     $siteImportService = $this->objectManager->get('TYPO3\\Neos\\Domain\\Service\\SiteImportService');
     $siteImportService->importFromFile($this->fixtureFileName, $contentContext);
     $this->persistenceManager->persistAll();
     if ($this->nodeContextPath !== null) {
         $this->node = $this->getNodeWithContextPath($this->nodeContextPath);
     }
 }
 /**
  * @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();
 }
 /**
  * @return void
  */
 protected function setUpRootNodeAndRepository()
 {
     $this->contextFactory = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactory');
     $this->context = $this->contextFactory->create(array('workspaceName' => 'live'));
     $this->nodeDataRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     $this->workspaceRepository->add(new Workspace('live'));
     $this->nodeTypeManager = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Service\\NodeTypeManager');
     $this->rootNode = $this->context->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;
     $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;
 }
 /**
  * Creates a user workspace for the given user's account if it does not exist already.
  *
  * @param string $accountIdentifier Identifier of the user's account to create workspaces for
  * @return void
  */
 protected function createUserWorkspace($accountIdentifier)
 {
     $userWorkspace = $this->workspaceRepository->findByIdentifier('user-' . $accountIdentifier);
     if ($userWorkspace === null) {
         $liveWorkspace = $this->workspaceRepository->findByIdentifier('live');
         if (!$liveWorkspace instanceof Workspace) {
             $liveWorkspace = new Workspace('live');
             $this->workspaceRepository->add($liveWorkspace);
         }
         $userWorkspace = new Workspace('user-' . $accountIdentifier, $liveWorkspace);
         $this->workspaceRepository->add($userWorkspace);
     }
 }
 /**
  * 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);
 }
 /**
  * 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) {
         return $this->workspace;
     }
     if ($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);
     }
 }
 /**
  * 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 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('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactory');
     $this->workspaceRepository = $this->objectManager->get('TYPO3\\TYPO3CR\\Domain\\Repository\\WorkspaceRepository');
     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('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository');
     $this->rootNode = $personalContext->getNode('/');
     $this->persistenceManager->persistAll();
 }
 /**
  * Create a workspace
  *
  * @Flow\Validate(argumentName="title", type="\TYPO3\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', 'TYPO3.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');
 }
示例#28
0
 /**
  * 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;
 }
 /**
  * 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
  * @return void
  */
 public function createCommand($workspace, $baseWorkspace = 'live', $title = NULL, $description = NULL)
 {
     $workspaceName = $workspace;
     $workspace = $this->workspaceRepository->findOneByName($workspaceName);
     if ($workspace instanceof Workspace) {
         $this->outputLine('Workspace "%s" already exists', 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);
     }
     if ($title === NULL) {
         $title = $workspaceName;
     }
     $workspace = new Workspace($workspaceName, $baseWorkspace);
     $workspace->setTitle($title);
     $workspace->setDescription($description);
     $this->workspaceRepository->add($workspace);
     $this->outputLine('Created a new workspace "%s", based on workspace "%s".', array($workspaceName, $baseWorkspaceName));
 }
 /**
  * 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]);
     }
 }