Author: Jonathan.Wage
Date: 2010-01-19 20:07:52 +0100 (Tue, 19 Jan 2010)
New Revision: 26897

Modified:
   plugins/sfSympalPlugin/trunk/lib/cache/sfSympalCache.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSite.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSiteManager.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItem.class.php
   
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItemTable.class.php
Log:
[1.4][sfSympalPlugin][1.0] Fixing issue with menu cache and unpublished items


Modified: plugins/sfSympalPlugin/trunk/lib/cache/sfSympalCache.class.php
===================================================================
--- plugins/sfSympalPlugin/trunk/lib/cache/sfSympalCache.class.php      
2010-01-19 18:35:35 UTC (rev 26896)
+++ plugins/sfSympalPlugin/trunk/lib/cache/sfSympalCache.class.php      
2010-01-19 19:07:52 UTC (rev 26897)
@@ -205,6 +205,11 @@
     $this->set('layouts', $layoutsCache);
   }
 
+  public function remove($key)
+  {
+    return $this->_cacheDriver->remove($key);
+  }
+
   public function set($key, $data, $lifeTime = null)
   {
     return $this->_cacheDriver->set($key, serialize($data), $lifeTime);

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSite.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSite.class.php
     2010-01-19 18:35:35 UTC (rev 26896)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSite.class.php
     2010-01-19 19:07:52 UTC (rev 26897)
@@ -3,8 +3,24 @@
 class sfSympalMenuSite extends sfSympalMenu
 {
   protected 
-    $_menuItem = null;
+    $_menuItem = null,
+    $_cacheKey = null;
 
+  public function setCacheKey($cacheKey)
+  {
+    $this->_cacheKey = $cacheKey;
+  }
+
+  public function getCacheKey()
+  {
+    return $this->_cacheKey;
+  }
+
+  public function clearCache()
+  {
+    return 
sfSympalConfiguration::getActive()->getCache()->remove($this->_cacheKey);
+  }
+
   public function findMenuItem(sfSympalMenuItem $menuItem)
   {
     if ($this->_menuItem['id'] == $menuItem->id)
@@ -88,6 +104,7 @@
       $array['requires_no_auth'] = $menuItem->getRequiresNoAuth();
       $array['all_permissions'] = $menuItem->getAllPermissions();
       $array['level'] = $menuItem->getLevel();
+      $array['date_published'] = $menuItem->getDatePublished();
       unset($array['__children']);
       return $array;
     }
@@ -102,6 +119,13 @@
     $this->requiresNoAuth($this->_menuItem['requires_no_auth']);
     $this->setCredentials($this->_menuItem['all_permissions']);
 
+    // If not published yet then you must have certain credentials
+    $datePublished = strtotime($this->_menuItem['date_published']);
+    if (!$datePublished || $datePublished > time())
+    {
+      $this->setCredentials(array('ManageContent'));
+    }
+
     $currentMenuItem = sfSympalContext::getInstance()->getCurrentMenuItem();
 
     if ($currentMenuItem && $currentMenuItem->exists())

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSiteManager.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSiteManager.class.php
      2010-01-19 18:35:35 UTC (rev 26896)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/menu/sfSympalMenuSiteManager.class.php
      2010-01-19 19:07:52 UTC (rev 26897)
@@ -12,6 +12,14 @@
 
   protected static $_instance;
 
+  public function __construct()
+  {
+    if ($cache = $this->_getCache())
+    {
+      $this->_rootSlugs = $cache->get('SYMPAL_MENU_ROOT_SLUGS');
+    }
+  }
+
   public static function getInstance()
   {
     if (!self::$_instance)
@@ -61,6 +69,12 @@
       return false;
     }
 
+    if ($name instanceof sfSympalMenuItem)
+    {
+      $menuItem = $name;
+      $name = $this->_rootSlugs[$name['root_id']];
+    }
+
     $cacheKey = 'SYMPAL_MENU_'.md5($name.var_export($showChildren, 
true).$class);
     if (isset($this->_menus[$cacheKey]))
     {
@@ -82,9 +96,14 @@
 
     $this->_menus[$cacheKey] = $menu;
 
-    if ($showChildren !== null && $menu)
+    if ($menu)
     {
-      $menu->callRecursively('showChildren', $showChildren);
+      if ($showChildren !== null)
+      {
+        $menu->callRecursively('showChildren', $showChildren);
+      }
+
+      $menu->setCacheKey($cacheKey);
     }
 
     return $menu;
@@ -92,12 +111,6 @@
 
   protected function _buildMenu($name, $class)
   {
-    if ($name instanceof sfSympalMenuItem)
-    {
-      $menuItem = $name;
-      $name = $this->_rootSlugs[$name['root_id']];
-    }
-
     $rootId = array_search($name, $this->_rootSlugs);
 
     if (!$rootId)
@@ -184,6 +197,11 @@
         $this->_hierarchies[$menuItem['root_id']] = $menuItem['__children'];
       }
 
+      if ($cache = $this->_getCache())
+      {
+        $cache->set('SYMPAL_MENU_ROOT_SLUGS', $this->_rootSlugs);
+      }
+
       // Mark the process as done so it is cached
       $this->_initialized = true;
     }

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItem.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItem.class.php
     2010-01-19 18:35:35 UTC (rev 26896)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItem.class.php
     2010-01-19 19:07:52 UTC (rev 26897)
@@ -25,6 +25,11 @@
     return $this->_allPermissions;
   }
 
+  public function postSave($event)
+  {
+    return $this->getMenu()->clearCache();
+  }
+
   public function getParentId()
   {
     $node = $this->getNode();
@@ -110,19 +115,27 @@
     return $route;
   }
 
+  public function getMenu()
+  {
+    return sfSympalMenuSiteManager::getMenu($this);
+  }
+
   public function getBreadcrumbs($subItem = null)
   {
     $breadcrumbs = null;
-    $menu = sfSympalMenuSiteManager::getMenu('primary');
-    if ($menu)
+    // Get the menu this menu item belongs to
+    if ($menu = $this->getMenu())
     {
+      // Find the node for this menu item
       $node = $menu->findMenuItem($this);
 
+      // Get the breadcrumbs
       if ($node)
       {
         $breadcrumbs = $node->getBreadcrumbs($subItem);
       }
     }
+    // If no breadcrumbs generate a blank object
     if (is_null($breadcrumbs))
     {
       $breadcrumbs = sfSympalMenuBreadcrumbs::generate(array());

Modified: 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItemTable.class.php
===================================================================
--- 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItemTable.class.php
        2010-01-19 18:35:35 UTC (rev 26896)
+++ 
plugins/sfSympalPlugin/trunk/lib/plugins/sfSympalMenuPlugin/lib/model/doctrine/PluginsfSympalMenuItemTable.class.php
        2010-01-19 19:07:52 UTC (rev 26897)
@@ -38,13 +38,6 @@
       $q->addSelect('t.*');
     }
 
-    $user = sfContext::getInstance()->getUser();
-    if (!$user->hasCredential('ManageContent'))
-    {
-      $expr = new Doctrine_Expression('NOW()');
-      $q->andWhere('m.date_published <= '.$expr);
-    }
-
     return $q;
   }
 }
\ No newline at end of file

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.


Reply via email to