Example #1
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;
 }
Example #3
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;
     }
 }
 /**
  * Move temporary file to the permanent directory, which can be overridden
  * @param \ride\library\system\file\File $oldFile
  * @param \ride\library\system\file\File $permanentDirectory
  * @return \ride\library\system\file\File
  */
 public function moveTemporaryToPermanent(File $oldFile, File $permanentDirectory)
 {
     $newFile = $permanentDirectory->getChild($oldFile->getName());
     $this->fileSystem->move($oldFile, $newFile);
     return $newFile;
 }