[pLog-svn] r1720 - in plog/branches/plog-1.1-ben/class: action
action/admin cache
Oscar Renalias
phunkphorce at gmail.com
Tue Apr 5 06:20:44 GMT 2005
I don't quite see the point of the BlogInfoManager class. Why can't it
be merged with the current Blogs class?
For example the job of BlogInfoManager::getBlogInfo() could be done by
Blogs::getBlogInfo() which would take into account the cache and so
on.
Any comments?
On Apr 5, 2005 2:57 AM, ork at devel.plogworld.net <ork at devel.plogworld.net> wrote:
> Author: ork
> Date: 2005-04-04 23:57:20 +0000 (Mon, 04 Apr 2005)
> New Revision: 1720
>
> Added:
> plog/branches/plog-1.1-ben/class/cache/bloginfomanager.class.php
> Modified:
> plog/branches/plog-1.1-ben/class/action/admin/adminaction.class.php
> plog/branches/plog-1.1-ben/class/action/admin/adminmainaction.class.php
> plog/branches/plog-1.1-ben/class/action/admin/adminupdateblogsettingsaction.class.php
> plog/branches/plog-1.1-ben/class/action/blogaction.class.php
> Log:
> implemented a BlogInfoManager to handle all request for blogInfos.. just a singleton accessing the cache and returning the cached object.
> changed adminupdateblogsettingsaction to use BlogInfoManager as well.. so a changed bloginfo gets removed from the cache.
>
> i'm not sure if class/cache is the right place for this.. didn't want to place it in dao/ either.. i'm welcome to any opinion :)
>
> Modified: plog/branches/plog-1.1-ben/class/action/admin/adminaction.class.php
> ===================================================================
> --- plog/branches/plog-1.1-ben/class/action/admin/adminaction.class.php 2005-04-04 23:52:07 UTC (rev 1719)
> +++ plog/branches/plog-1.1-ben/class/action/admin/adminaction.class.php 2005-04-04 23:57:20 UTC (rev 1720)
> @@ -81,10 +81,15 @@
> */
> function _getBlogInfo()
> {
> + // TBD: this is not good yet..
> + require_once( PLOG_CLASS_PATH . "class/cache/bloginfomanager.class.php" );
> +
> $session = HttpVars::getSession();
> $sessionInfo = $session["SessionInfo"];
> + $blogInfoManager = BlogInfoManager::getBlogInfoManager();
>
> - $this->_blogInfo = $sessionInfo->getValue( "blogInfo" );
> + $blogId = $sessionInfo->getValue( "blogId" );
> + $this->_blogInfo = $blogInfoManager->getBlogInfo( $blogId );
> }
>
> /**
> @@ -147,7 +152,7 @@
> */
> function saveSession()
> {
> - $this->_session->setValue( "blogInfo", $this->_blogInfo );
> + $this->_session->setValue( "blogId", $this->_blogInfo->getId() );
> $this->_session->setValue( "userInfo", $this->_userInfo );
> //$_SESSION["SessionInfo"] = $this->_session;
> $session = HttpVars::getSession();
>
> Modified: plog/branches/plog-1.1-ben/class/action/admin/adminmainaction.class.php
> ===================================================================
> --- plog/branches/plog-1.1-ben/class/action/admin/adminmainaction.class.php 2005-04-04 23:52:07 UTC (rev 1719)
> +++ plog/branches/plog-1.1-ben/class/action/admin/adminmainaction.class.php 2005-04-04 23:57:20 UTC (rev 1720)
> @@ -51,8 +51,9 @@
> }
>
> // load the blog
> - $blogs = new Blogs();
> - $this->_blogInfo = $blogs->getBlogInfo( $this->_blogId );
> + require_once( PLOG_CLASS_PATH . "class/cache/bloginfomanager.class.php" );
> + $blogInfoManager = BlogInfoManager::getBlogInfoManager();
> + $this->_blogInfo = $blogInfoManager->getBlogInfo( $this->_blogId );
>
> // check if the blog really exists
> if( !$this->_blogInfo ) {
> @@ -77,7 +78,7 @@
> // if all correct, we can now set the blogInfo object in the session for later
> // use
> $session = HttpVars::getSession();
> - $session["SessionInfo"]->setValue( "blogInfo", $this->_blogInfo );
> + $session["SessionInfo"]->setValue( "blogId", $this->_blogInfo->getId() );
> HttpVars::setSession( $session );
>
> return true;
>
> Modified: plog/branches/plog-1.1-ben/class/action/admin/adminupdateblogsettingsaction.class.php
> ===================================================================
> --- plog/branches/plog-1.1-ben/class/action/admin/adminupdateblogsettingsaction.class.php 2005-04-04 23:52:07 UTC (rev 1719)
> +++ plog/branches/plog-1.1-ben/class/action/admin/adminupdateblogsettingsaction.class.php 2005-04-04 23:57:20 UTC (rev 1720)
> @@ -52,6 +52,8 @@
> */
> function perform()
> {
> + require_once( PLOG_CLASS_PATH . "class/cache/bloginfomanager.class.php" );
> +
> // fetch the settings from the db and update them accordingly
> $blogs = new Blogs();
> $blogSettings = $blogs->getBlogSettings( $this->_blogInfo->getId());
> @@ -77,7 +79,8 @@
> // and now update the settings in the database
> $blogs = new Blogs();
> $this->notifyEvent( EVENT_PRE_BLOG_UPDATE, Array( "blog" => &$this->_blogInfo ));
> - if( !$blogs->updateBlog( $this->_blogInfo->getId(), $this->_blogInfo )) {
> + $blogInfoManager = BlogInfoManager::getBlogInfoManager();
> + if( !$blogInfoManager->updateBlogInfo( $this->_blogInfo->getId(), $this->_blogInfo )) {
> $this->_view = new AdminBlogSettingsView( $this->_blogInfo );
> $this->_view->setErrorMessage( $this->_locale->tr("error_updating_settings"));
> $this->setCommonData();
>
> Modified: plog/branches/plog-1.1-ben/class/action/blogaction.class.php
> ===================================================================
> --- plog/branches/plog-1.1-ben/class/action/blogaction.class.php 2005-04-04 23:52:07 UTC (rev 1719)
> +++ plog/branches/plog-1.1-ben/class/action/blogaction.class.php 2005-04-04 23:57:20 UTC (rev 1720)
> @@ -175,11 +175,17 @@
> }
>
> // fetch the BlogInfo object
> - $blogs = new Blogs();
> - if( $blogId )
> - $this->_blogInfo = $blogs->getBlogInfo( $blogId );
> - else
> + if( $blogId ) {
> + require_once( PLOG_CLASS_PATH . "class/cache/bloginfomanager.class.php" );
> +
> + $blogInfoManager =& BlogInfoManager::getBlogInfoManager();
> + $this->_blogInfo = $blogInfoManager->getBlogInfo( $blogId );
> +
> + // $this->_blogInfo = $blogs->getBlogInfo( $blogId );
> + } else {
> + $blogs = new Blogs();
> $this->_blogInfo = $blogs->getBlogInfoByName( $blogName );
> + }
>
> // security checks...
> if( $this->_blogInfo == false ) {
>
> Added: plog/branches/plog-1.1-ben/class/cache/bloginfomanager.class.php
> ===================================================================
> --- plog/branches/plog-1.1-ben/class/cache/bloginfomanager.class.php 2005-04-04 23:52:07 UTC (rev 1719)
> +++ plog/branches/plog-1.1-ben/class/cache/bloginfomanager.class.php 2005-04-04 23:57:20 UTC (rev 1720)
> @@ -0,0 +1,55 @@
> +<?php
> +
> + class BlogInfoManager extends Object
> + {
> +
> + var $_knownBlogs = array();
> +
> + function getBlogInfo( $blogId )
> + {
> + if( array_key_exists( $blogId, $this->_knownBlogs) )
> + return $this->_knownBlogs[$blogId];
> +
> + require_once( PLOG_CLASS_PATH . "class/cache/cachemanager.class.php" );
> + require_once( PLOG_CLASS_PATH . "class/dao/blogsettings.class.php" );
> +
> + $cache =& CacheManager::getCache();
> + $blogInfo = $cache->getData( $blogId, CACHE_BLOGINFOS );
> +
> + if( !$blogInfo ) {
> + require_once( PLOG_CLASS_PATH . "class/dao/blogs.class.php" );
> + $blogs = new Blogs();
> + $blogInfo = $blogs->getBlogInfo( $blogId );
> + $cache->setData( $blogId, CACHE_BLOGINFOS, $blogInfo );
> + }
> +
> + $this->_knownBlogs[ $blogId ] = $blogInfo;
> + return $blogInfo;
> + }
> +
> + function updateBlogInfo( $blogId, $blogInfo )
> + {
> + require_once( PLOG_CLASS_PATH . "class/dao/blogs.class.php" );
> +
> + // remove all cached info
> + $cache =& CacheManager::getCache();
> + $cache->removeData( $blogId, CACHE_BLOGINFOS );
> +
> + // save the new blogInfo
> + // this is slow right now, but we don't care at this point
> + $blogs = new Blogs();
> + return $blogs->updateBlog( $blogId, $blogInfo );
> + }
> +
> + function &getBlogInfoManager()
> + {
> + static $manager;
> +
> + if( !is_object($manager) ) {
> + $manager = new BlogInfoManager();
> + }
> +
> + return $manager;
> + }
> + }
> +?>
>
> Property changes on: plog/branches/plog-1.1-ben/class/cache/bloginfomanager.class.php
> ___________________________________________________________________
> Name: svn:executable
> + *
>
> _______________________________________________
> pLog-svn mailing list
> pLog-svn at devel.plogworld.net
> http://devel.plogworld.net/mailman/listinfo/plog-svn
>
More information about the pLog-svn
mailing list