/**
  * @test
  */
 public function setDateTimeAllowsForMockingTheCurrentTime()
 {
     $simulatedCurrentTime = new \DateTime();
     date_add($simulatedCurrentTime, new \DateInterval('P1D'));
     $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live');
     $contentContext->setCurrentDateTime($simulatedCurrentTime);
     $this->assertEquals($simulatedCurrentTime, $contentContext->getCurrentDateTime());
 }
 /**
  * @param string $workspaceName
  * @return void
  * @todo Pagination
  * @todo Tree filtering + level limit
  * @todo Search field
  * @todo Difference mechanism
  */
 public function indexAction($workspaceName = NULL)
 {
     if (is_null($workspaceName)) {
         $workspaceName = $this->securityContext->getParty()->getPreferences()->get('context.workspace');
     }
     $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext($workspaceName);
     $contentContext->setInvisibleContentShown(TRUE);
     $contentContext->setRemovedContentShown(TRUE);
     $contentContext->setInaccessibleContentShown(TRUE);
     $this->nodeRepository->setContext($contentContext);
     $sites = array();
     foreach ($this->workspacesService->getUnpublishedNodes($workspaceName) as $node) {
         if (!$node->getContentType()->isOfType('TYPO3.Phoenix.ContentTypes:Section')) {
             $pathParts = explode('/', $node->getPath());
             if (count($pathParts) > 2) {
                 $siteNodeName = $pathParts[2];
                 $folder = $this->findFolderNode($node);
                 $folderPath = implode('/', array_slice(explode('/', $folder->getPath()), 3));
                 $relativePath = str_replace(sprintf('/sites/%s/%s', $siteNodeName, $folderPath), '', $node->getPath());
                 if (!isset($sites[$siteNodeName]['siteNode'])) {
                     $sites[$siteNodeName]['siteNode'] = $this->siteRepository->findOneByNodeName($siteNodeName);
                 }
                 $sites[$siteNodeName]['folders'][$folderPath]['folderNode'] = $folder;
                 $change = array('node' => $node);
                 if ($node->getContentType()->isOfType('TYPO3.Phoenix.ContentTypes:AbstractNode')) {
                     $change['configuration'] = $node->getContentType()->getConfiguration();
                 }
                 $sites[$siteNodeName]['folders'][$folderPath]['changes'][$relativePath] = $change;
             }
         }
     }
     $liveWorkspace = $this->workspacesService->getWorkspace('live');
     ksort($sites);
     foreach ($sites as $siteKey => $site) {
         foreach ($site['folders'] as $folderKey => $folder) {
             foreach ($folder['changes'] as $changeKey => $change) {
                 $liveNode = $this->nodeRepository->findOneByIdentifier($change['node']->getIdentifier(), $liveWorkspace);
                 $sites[$siteKey]['folders'][$folderKey]['changes'][$changeKey]['isNew'] = is_null($liveNode);
                 $sites[$siteKey]['folders'][$folderKey]['changes'][$changeKey]['isMoved'] = $liveNode && $change['node']->getPath() !== $liveNode->getPath();
             }
         }
         ksort($sites[$siteKey]['folders']);
     }
     $workspaces = array();
     foreach ($this->workspacesService->getWorkspaces() as $workspace) {
         array_push($workspaces, array('workspaceNode' => $workspace, 'unpublishedNodesCount' => $this->workspacesService->getUnpublishedNodesCount($workspace->getName())));
     }
     $this->view->assignMultiple(array('workspaceName' => $workspaceName, 'workspaces' => $workspaces, 'sites' => $sites));
 }
 /**
  * Default action of the backend controller.
  *
  * @return void
  * @FLOW3\SkipCsrfProtection
  */
 public function indexAction()
 {
     $workspaceName = $this->securityContext->getParty()->getPreferences()->get('context.workspace');
     // Hack: Create the workspace if it does not exist yet.
     $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext($workspaceName);
     $contentContext->getWorkspace();
     if (isset($_COOKIE['TYPO3_lastVisitedUri'])) {
         $redirectUri = $_COOKIE['TYPO3_lastVisitedUri'];
         $appendHtml = !strpos($redirectUri, '.html') ? FALSE : TRUE;
         if (!strpos($redirectUri, '@')) {
             $redirectUri = str_replace('.html', '', $redirectUri);
         } else {
             $redirectUri = substr($redirectUri, 0, strpos($redirectUri, '@'));
         }
         $redirectUri .= '@' . $workspaceName . ($appendHtml === TRUE ? '.html' : '');
         $this->redirectToUri($redirectUri);
     } else {
         $this->redirectToUri('/@' . $workspaceName . '.html');
     }
 }
Esempio n. 4
0
 /**
  * Get the page by the node path, needed for internal links.
  *
  * @param string $nodePath
  * @return void
  * @ExtDirect
  */
 public function getPageByNodePathAction($nodePath)
 {
     $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live');
     $node = $contentContext->getNode($nodePath);
     $this->view->assign('value', array('node' => $this->processNodeForEditorPlugins($node), 'success' => TRUE));
 }
 /**
  * Imports the specified bundle into the configured "importRootNodePath".
  *
  * @param string $bundle
  * @return void
  */
 protected function importBundle($bundle)
 {
     $this->outputLine('Importing bundle "%s"', array($bundle));
     $renderedDocumentationRootPath = rtrim($this->bundleConfiguration['renderedDocumentationRootPath'], '/');
     $contentContext = new \TYPO3\TYPO3\Domain\Service\ContentContext('live');
     $contentContext->setInvisibleContentShown(TRUE);
     $siteNode = $contentContext->getCurrentSiteNode();
     $importRootNode = $siteNode->getNode($this->bundleConfiguration['importRootNodePath']);
     if ($importRootNode === NULL) {
         $this->output('ImportRootNode "%s" does not exist!', array($this->bundleConfiguration['importRootNodePath']));
         $this->quit(1);
     }
     if (!is_dir($renderedDocumentationRootPath)) {
         $this->outputLine('The folder "%s" does not exist. Did you render the documentation?', array($renderedDocumentationRootPath));
         $this->quit(1);
     }
     $unorderedJsonFileNames = \TYPO3\FLOW3\Utility\Files::readDirectoryRecursively($renderedDocumentationRootPath, '.fjson');
     if ($unorderedJsonFileNames === array()) {
         $this->outputLine('The folder "%s" contains no fjson files. Did you render the documentation?', array($renderedDocumentationRootPath));
         $this->quit(1);
     }
     $orderedNodePaths = array();
     foreach ($unorderedJsonFileNames as $jsonPathAndFileName) {
         if (basename($jsonPathAndFileName) === 'Index.fjson') {
             $chapterRelativeNodePath = substr($jsonPathAndFileName, strlen($renderedDocumentationRootPath), -12) . '/';
             #				$orderedNodePaths[] = $this->normalizeNodePath(substr($chapterRelativeNodePath, 0, -1));
             $indexArray = json_decode(file_get_contents($jsonPathAndFileName), TRUE);
             foreach (explode(chr(10), $indexArray['body']) as $tocHtmlLine) {
                 preg_match('!^\\<li class="toctree-l1"\\>\\<a class="reference internal" href="\\.\\./([a-zA-Z0-9]+)/.*$!', $tocHtmlLine, $matches);
                 if ($matches !== array()) {
                     $orderedNodePaths[] = $this->normalizeNodePath($chapterRelativeNodePath . $matches[1]);
                 }
             }
         }
     }
     foreach ($unorderedJsonFileNames as $jsonPathAndFileName) {
         $data = json_decode(file_get_contents($jsonPathAndFileName));
         if (!isset($data->body)) {
             continue;
         }
         $relativeNodePath = substr($jsonPathAndFileName, strlen($renderedDocumentationRootPath) + 1, -6);
         $relativeNodePath = $this->normalizeNodePath($relativeNodePath);
         $segments = explode('/', $relativeNodePath);
         $pageNode = $importRootNode;
         while ($segment = array_shift($segments)) {
             $nodeName = preg_replace('/[^a-z0-9\\-]/', '', $segment);
             $subPageNode = $pageNode->getNode($nodeName);
             if ($subPageNode === NULL) {
                 $this->outputLine('Creating page node "%s"', array($relativeNodePath));
                 $subPageNode = $pageNode->createNode($nodeName, 'TYPO3.TYPO3:Page');
                 if (!$subPageNode->hasProperty('title')) {
                     $subPageNode->setProperty('title', $nodeName);
                 }
             }
             $pageNode = $subPageNode;
         }
         $sectionNode = $pageNode->getNode('main');
         if ($sectionNode === NULL) {
             $this->outputLine('Creating section node "%s"', array($relativeNodePath . '/main'));
             $sectionNode = $pageNode->createNode('main', 'TYPO3.TYPO3:Section');
         }
         $textNode = $sectionNode->getNode('text1');
         if ($textNode === NULL) {
             $this->outputLine('Creating text node "%s"', array($relativeNodePath . '/main/text1'));
             $textNode = $sectionNode->createNode('text1', 'TYPO3.TYPO3:Text');
         }
         $pageNode->setProperty('title', $data->title);
         $this->outputLine('Setting page title of page "%s" to "%s"', array($relativeNodePath, $data->title));
         $bodyText = $this->prepareBodyText($data->body, $relativeNodePath);
         $textNode->setProperty('text', $bodyText);
     }
     $importRootNodePath = $importRootNode->getPath();
     $currentParentNodePath = '';
     foreach ($orderedNodePaths as $nodePath) {
         $node = $importRootNode->getNode($importRootNodePath . $nodePath);
         if ($node !== NULL) {
             if ($node->getParent()->getPath() !== $currentParentNodePath) {
                 $currentParentNodePath = $node->getParent()->getPath();
                 $previousNode = NULL;
             }
             if ($previousNode !== NULL) {
                 $this->outputLine('Moved node %s', array($node->getPath()));
                 $this->outputLine('after node %s', array($previousNode->getPath()));
                 $node->moveAfter($previousNode);
             } else {
                 // FIXME: Node->isFirst() or Node->moveFirst() would be needed here
             }
             $previousNode = $node;
         } else {
             $this->outputLine('Node %s does not exist.', array($importRootNodePath . $nodePath));
         }
     }
     $this->siteRepository->update($contentContext->getCurrentSite());
 }