Beispiel #1
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;
     }
 }