Exemplo n.º 1
0
 protected function readSiteRevision(File $revisionFile)
 {
     $nodes = array();
     $json = $revisionFile->read();
     $nodesArray = $this->jsonParser->parseToPhp($json);
     foreach ($nodesArray as $nodeId => $nodeArray) {
         $nodes[$nodeId] = $this->getNodeFromArray($nodeArray);
     }
     return $nodes;
 }
Exemplo n.º 2
0
 /**
  * Clears the cache of this node IO
  * @return null
  */
 public function clearCache()
 {
     $this->nodes = null;
     if ($this->file->exists()) {
         $this->file->delete();
     }
     if (isset($this->needsClear)) {
         unset($this->needsClear);
     }
     $this->needsWrite = true;
 }
Exemplo n.º 3
0
 /**
  * Removes a theme from the configuration
  * @param GenericTheme $theme
  * @return null
  */
 public function removeTheme(GenericTheme $theme)
 {
     $engines = $theme->getEngines();
     $theme = $theme->getName();
     $this->config->set('theme.' . $theme, null);
     foreach ($engines as $engine) {
         $directory = $this->directory->getChild('view/' . $engine . '/' . $theme);
         if ($directory->exists()) {
             $directory->delete();
         }
     }
 }
 /**
  * Gets the expired routes from the data source
  * @param string $site Id of the site
  * @return array Array with ExpiredRoute objects
  */
 public function getExpiredRoutes($site)
 {
     $routes = array();
     $file = $this->directory->getChild($site . '/' . self::FILE);
     if (!$file->exists()) {
         return $routes;
     }
     $dom = new DOMDocument();
     $dom->load($file);
     foreach ($dom->documentElement->childNodes as $element) {
         if ($element->nodeName != self::TAG_ROUTE) {
             continue;
         }
         $node = $element->getAttribute(self::ATTRIBUTE_NODE);
         $locale = $element->getAttribute(self::ATTRIBUTE_LOCALE);
         $path = $element->getAttribute(self::ATTRIBUTE_PATH);
         $baseUrl = $element->getAttribute(self::ATTRIBUTE_BASE_URL);
         $routes[] = new ExpiredRoute($node, $locale, $path, $baseUrl);
     }
     return $routes;
 }
Exemplo n.º 5
0
 /**
  * Perform the actual publishing of a single node
  * @param \ride\library\cms\node\SiteNode $site
  * @param \ride\library\cms\node\Node $node
  * @param string $revision
  * @param \ride\library\system\file\File $publishDirectory
  * @param boolean $isRecursive Flag to see if this publishing is part of a
  * recursive publish action
  * @return null
  */
 protected function publishNode(SiteNode $site, Node $node, $revision, File $publishDirectory, $isRecursive)
 {
     // initialize needed variables
     $siteId = $site->getId();
     $nodeId = $node->getId();
     $changedNodes = array();
     try {
         $publishSite = $this->getSite($siteId, $revision);
     } catch (NodeNotFoundException $exception) {
         $publishSite = null;
     }
     // process and merge the necessairy nodes
     try {
         $oldNode = $this->getNode($siteId, $revision, $nodeId);
         // check for expired routes
         $oldRoutes = $oldNode->getRoutes();
         $newRoutes = $node->getRoutes();
         if ($oldRoutes && $oldRoutes !== $newRoutes) {
             foreach ($oldRoutes as $locale => $route) {
                 if (isset($newRoutes[$locale]) && $route === $newRoutes[$locale]) {
                     continue;
                 }
                 $this->expiredRouteModel->addExpiredRoute($siteId, $nodeId, $locale, $route, $site->getBaseUrl($locale));
             }
         }
         // check for order conflicts
         $nodeOrderIndex = $node->getOrderIndex();
         $nodeParent = $node->getParent();
         if (!$isRecursive && ($nodeOrderIndex != $oldNode->getOrderIndex() || $nodeParent != $oldNode->getParent())) {
             $orderIndex = 0;
             $parentNodes = $this->getChildren($siteId, $revision, $nodeParent, 0);
             foreach ($parentNodes as $parentNodeId => $parentNode) {
                 $orderIndex++;
                 $parentOrderIndex = $parentNode->getOrderIndex();
                 $isBefore = $parentOrderIndex < $nodeOrderIndex;
                 if ($isBefore && $parentOrderIndex == $orderIndex) {
                     continue;
                 } elseif ($nodeOrderIndex == $parentOrderIndex && $nodeId != $parentNodeId) {
                     $orderIndex++;
                     $parentNode->setOrderIndex($orderIndex);
                     $changedNodes[] = $parentNode;
                 } elseif ($nodeId == $parentNodeId) {
                     $orderIndex--;
                     continue;
                 } else {
                     $parentNode->setOrderIndex($orderIndex);
                     $changedNodes[] = $parentNode;
                 }
             }
         }
     } catch (NodeNotFoundException $exception) {
         // new node in the revision
     }
     // check for new widgets
     if ($publishSite) {
         $isPublishSiteChanged = false;
         $usedWidgets = $node->getUsedWidgets();
         $availableWidgetsSite = $site->getAvailableWidgets();
         $availableWidgetsPublishSite = $publishSite->getAvailableWidgets();
         foreach ($usedWidgets as $widgetId) {
             if (!$widgetId || isset($availableWidgetsPublishSite[$widgetId]) || !isset($availableWidgetsSite[$widgetId])) {
                 continue;
             }
             $publishSite->set(Node::PROPERTY_WIDGET . '.' . $widgetId, $availableWidgetsSite[$widgetId], true);
             $isPublishSiteChanged = true;
         }
         if ($isPublishSiteChanged) {
             $changedNodes[] = $publishSite;
         }
     }
     // write the changed nodes
     foreach ($changedNodes as $changedNode) {
         $this->writeNode($changedNode);
     }
     // write the node file to the publish directory
     $nodeFile = $this->getNodeFile($node);
     $publishFile = $publishDirectory->getChild($nodeFile->getName());
     if ($nodeFile->exists()) {
         // node has been created or updated
         $nodeFile->copy($publishFile);
         return null;
     } elseif ($publishFile->exists()) {
         // node has been deleted
         $publishFile->delete();
         return $node;
     }
 }
Exemplo n.º 6
0
 /**
  * Get the relative path of a file
  * @param \ride\library\system\file\File $file
  * @return string
  */
 public function getRelativePath(File $file)
 {
     $relativePath = $file->getAbsolutePath();
     foreach ($this->absolutePaths as $absolutePath) {
         if (strpos($relativePath, $absolutePath) === 0) {
             $relativePath = str_replace($absolutePath . '/', '', $relativePath);
             break;
         }
     }
     return $relativePath;
 }
 /**
  * Reads the site revisions from the provided site directory
  * @param \ride\library\system\file\File $siteDirectory Directory of the site
  * @param string $defaultRevision Default revision for the site
  * @param string $revision Revision to load
  * @return array Array with the name of the revision as key and value
  * @throws \ride\library\cms\exception\CmsException when the site directory
  * could not be read
  */
 protected function readSiteRevisions(File $siteDirectory, $defaultRevision, &$revision = null)
 {
     $revisions = array();
     $files = $siteDirectory->read();
     foreach ($files as $file) {
         $revision = $file->getName(true);
         if ($revision === $this->archiveName || $revision === $this->trashName || !$file->isDirectory()) {
             continue;
         }
         $revisions[$revision] = $revision;
     }
     if (!$revisions) {
         throw new CmsException('No valid site in ' . $siteDirectory->getAbsolutePath());
     }
     if (isset($revisions[$defaultRevision])) {
         $revision = $defaultRevision;
     } else {
         $revision = reset($revisions);
     }
     return $revisions;
 }