/**
  * Shows a list of existing workspaces
  *
  * @return string
  */
 public function indexAction()
 {
     $user = $this->userService->getCurrentUser();
     $workspacesArray = [];
     /** @var Workspace $workspace */
     foreach ($this->workspaceRepository->findAll() as $workspace) {
         // FIXME: This check should be implemented through a specialized Workspace Privilege or something similar
         if ($workspace->getOwner() !== null && $workspace->getOwner() !== $user) {
             continue;
         }
         $workspaceArray = ['name' => $workspace->getName(), 'title' => $workspace->getTitle(), 'description' => $workspace->getDescription(), 'baseWorkspace' => $workspace->getBaseWorkspace()];
         if ($user !== null) {
             $workspaceArray['readonly'] = !$this->userService->currentUserCanPublishToWorkspace($workspace);
         }
         $workspacesArray[] = $workspaceArray;
     }
     $this->view->assign('workspaces', $workspacesArray);
 }
 /**
  * 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;
 }
 /**
  * Detect and fix nodes in non-live workspaces whose identifier does not match their corresponding node in the
  * live workspace.
  *
  * @param string $workspaceName This argument will be ignored
  * @param boolean $dryRun Simulate?
  * @return void
  */
 public function fixNodesWithInconsistentIdentifier($workspaceName, $dryRun)
 {
     $this->output->outputLine('Checking for nodes with inconsistent identifier ...');
     $nodesArray = [];
     $liveWorkspaceNames = [];
     $nonLiveWorkspaceNames = [];
     foreach ($this->workspaceRepository->findAll() as $workspace) {
         /** @var Workspace $workspace */
         if ($workspace->getBaseWorkspace() !== null) {
             $nonLiveWorkspaceNames[] = $workspace->getName();
         } else {
             $liveWorkspaceNames[] = $workspace->getName();
         }
     }
     foreach ($nonLiveWorkspaceNames as $workspaceName) {
         /** @var QueryBuilder $queryBuilder */
         $queryBuilder = $this->entityManager->createQueryBuilder();
         $queryBuilder->select('nonlive.Persistence_Object_Identifier, nonlive.identifier, nonlive.path, live.identifier AS liveIdentifier')->from(NodeData::class, 'nonlive')->join(NodeData::class, 'live', 'WITH', 'live.path = nonlive.path AND live.dimensionsHash = nonlive.dimensionsHash AND live.identifier != nonlive.identifier')->where('nonlive.workspace = ?1')->andWhere($queryBuilder->expr()->in('live.workspace', $liveWorkspaceNames))->andWhere('nonlive.path != \'/\'')->setParameter(1, $workspaceName);
         foreach ($queryBuilder->getQuery()->getArrayResult() as $nodeDataArray) {
             $this->output->outputLine('Node %s in workspace %s has identifier %s but live node has identifier %s.', [$nodeDataArray['path'], $workspaceName, $nodeDataArray['identifier'], $nodeDataArray['liveIdentifier']]);
             $nodesArray[] = $nodeDataArray;
         }
     }
     if ($nodesArray === []) {
         return;
     }
     if (!$dryRun) {
         $self = $this;
         $this->output->outputLine();
         $this->output->outputLine('Nodes with inconsistent identifiers found.');
         $this->askBeforeExecutingTask(sprintf('Do you want to fix the identifiers of %s node%s now?', count($nodesArray), count($nodesArray) > 1 ? 's' : ''), function () use($self, $nodesArray) {
             foreach ($nodesArray as $nodeArray) {
                 /** @var QueryBuilder $queryBuilder */
                 $queryBuilder = $this->entityManager->createQueryBuilder();
                 $queryBuilder->update(NodeData::class, 'nonlive')->set('nonlive.identifier', $queryBuilder->expr()->literal($nodeArray['liveIdentifier']))->where('nonlive.Persistence_Object_Identifier = ?1')->setParameter(1, $nodeArray['Persistence_Object_Identifier']);
                 $result = $queryBuilder->getQuery()->getResult();
                 if ($result !== 1) {
                     $self->output->outputLine('<error>Error:</error> The update query returned an unexpected result!');
                     $self->output->outputLine('<b>Query:</b> ' . $queryBuilder->getQuery()->getSQL());
                     $self->output->outputLine('<b>Result:</b> %s', [var_export($result, true)]);
                     exit(1);
                 }
             }
             $self->output->outputLine('Fixed inconsistent identifiers.');
         });
     } else {
         $this->output->outputLine('Found %s node%s with inconsistent identifiers which need to be fixed.', array(count($nodesArray), count($nodesArray) > 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);
 }
 /**
  * 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');
 }