[pLog-svn] r2473 - in plog/trunk/class: action/admin dao
dao/userdata database
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Thu Sep 15 20:01:57 GMT 2005
Author: oscar
Date: 2005-09-15 20:01:57 +0000 (Thu, 15 Sep 2005)
New Revision: 2473
Modified:
plog/trunk/class/action/admin/adminaction.class.php
plog/trunk/class/dao/article.class.php
plog/trunk/class/dao/articlecategory.class.php
plog/trunk/class/dao/articles.class.php
plog/trunk/class/dao/bloginfo.class.php
plog/trunk/class/dao/userdata/baseuserdataprovider.class.php
plog/trunk/class/dao/userinfo.class.php
plog/trunk/class/database/dbobject.class.php
Log:
fixed the issue where objects saved to the cache would keep references to other objects whose data could have
changed such as an Article object keeping a copy of an ArticleCategory object that later on changes, but since
the Article object keeps a copy of it, changes in the latter will not be noticed in the former. The only way
around this that I could think of was to implement the __sleep method so that references to other objects are
*never* serialized. This is not an extremely good solution but it will work for the time being...
Modified: plog/trunk/class/action/admin/adminaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaction.class.php 2005-09-15 12:07:33 UTC (rev 2472)
+++ plog/trunk/class/action/admin/adminaction.class.php 2005-09-15 20:01:57 UTC (rev 2473)
@@ -193,4 +193,4 @@
return $this->_pm->notifyEvent( $eventType, $params );
}
}
-?>
+?>
\ No newline at end of file
Modified: plog/trunk/class/dao/article.class.php
===================================================================
--- plog/trunk/class/dao/article.class.php 2005-09-15 12:07:33 UTC (rev 2472)
+++ plog/trunk/class/dao/article.class.php 2005-09-15 20:01:57 UTC (rev 2473)
@@ -46,6 +46,7 @@
var $_slug;
var $_nextArticle;
var $_prevArticle;
+ var $_globalCategory;
/**
* Constructor.
@@ -116,7 +117,7 @@
"num_nonspam_trackbacks" => "getNumTrackbacks",
"num_nonspam_comments" => "getNumComments",
"global_category_id" => "getGlobalCategoryId"
- );
+ );
}
/**
@@ -225,6 +226,7 @@
{
if( $this->_categories == null ) {
include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+ $categories = new ArticleCategories();
foreach( $this->getCategoryIds() as $categoryId ) {
if(( $category = $categories->getCategory( $categoryId )))
$this->_categories[] = $category;
@@ -301,7 +303,8 @@
if( is_null($this->_comments) ) {
include_once( PLOG_CLASS_PATH.'class/dao/articlecomments.class.php' );
$userComments = new ArticleComments();
- $blogSettings = $this->_blogInfo->getSettings();
+ $blogInfo = $this->getBlogInfo();
+ $blogSettings = $blogInfo->getSettings();
$this->setComments( $userComments->getPostComments( $this->getId(), $blogSettings->getValue( 'comments_order' ), COMMENT_STATUS_ALL ));
}
@@ -1023,6 +1026,24 @@
$this->_globalCategory = $category;
$this->_globalCategoryId = $category->getId();
return( true );
- }
+ }
+
+ /**
+ * @private
+ */
+ function __sleep()
+ {
+ // these objects cannot be serialized in the data cache, because otherwise when
+ // we update one of them via the admin interface, we will only be updating that object
+ // and not the copy of it that was serialized along this Article object!
+ $this->_categories = null;
+ $this->_userInfo = null;
+ $this->_blogInfo = null;
+ $this->_nextArticle = null;
+ $this->_prevArticle = null;
+ $this->_globalCategory = null;
+ $this->_fields = null;
+ return( parent::__sleep());
+ }
}
?>
\ No newline at end of file
Modified: plog/trunk/class/dao/articlecategory.class.php
===================================================================
--- plog/trunk/class/dao/articlecategory.class.php 2005-09-15 12:07:33 UTC (rev 2472)
+++ plog/trunk/class/dao/articlecategory.class.php 2005-09-15 20:01:57 UTC (rev 2473)
@@ -22,6 +22,7 @@
var $_parentCategory;
var $_description;
var $_lastModification;
+ var $_blog;
function ArticleCategory( $name, $url, $blogId, $inMainPage, $description = "", $numArticles = 0, $properties = Array(), $id = -1, $lastModification=null, $parentId = null)
{
@@ -42,6 +43,7 @@
$this->_articles = Array();
$this->_numArticles = 0;
$this->_numPublishedArticles = 0;
+ $this->_blog = null;
$this->_pk = "id";
$this->_fields = Array( "name" => "getName",
@@ -303,6 +305,25 @@
{
include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
return( Textfilter::urlize( $this->getName()));
- }
+ }
+
+ function getBlog()
+ {
+ if( $this->_blog == null ) {
+ include_once( PLOG_CLASS_PATH."class/dao/bloginfo.class.php" );
+ $blogs = new Blogs();
+ $this->_blog = $blogs->getBlogInfoById( $this->getBlogId());
+ }
+
+ return( $this->_blog );
+ }
+
+ function __sleep()
+ {
+ $this->_parentCategory = null;
+ $this->_blog = null;
+ $this->_articles = null;
+ return( parent::__sleep());
+ }
}
?>
\ No newline at end of file
Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php 2005-09-15 12:07:33 UTC (rev 2472)
+++ plog/trunk/class/dao/articles.class.php 2005-09-15 20:01:57 UTC (rev 2473)
@@ -135,69 +135,24 @@
$userId = -1,
$status = POST_STATUS_PUBLISHED )
{
- $articleIds = $this->_cache->getData( $articleTitle, CACHE_ARTICLETITLES );
-
- if( !$articleIds || empty($articleIds) ) {
- // ArticleIds are not in the cache, we'll fetch the possible ids
- // from the database.
- // We will fetch all articles with the given title, to store the
- // result in the cache and parse each article later on to find
- // the correct one.
- $whereConditions = array();
- $whereConditions['slug'] = $articleTitle;
-
- $query = Db::buildSelectQuery( ARTICLES_TABLENAME,
- array('id'),
- $whereConditions );
-
- $result = $this->Execute( $query );
-
- if( $result->RecordCount() == 0 ) {
- return false;
- } elseif( $result->RecordCount() == 1 ) {
- $row = $result->FetchRow( $result );
- $articleId = $row['id'];
- $articles = array( $this->getArticle($articleId) );
- $articleIds = array( $articleId );
- } else {
- // we have more than just one id found, we need to
- // check them all.
- $articles = array();
- $articleIds = array();
-
- while( $row = $result->FetchRow($result) ) {
- $articleId = $row['id'];
- $articles[] = $this->getArticle( $articleId );
- $articlesIds[] = $articlesId;
- }
- }
- $this->_cache->setData( $articleTitle, CACHE_ARTICLETITLES, $articlesIds );
- } else {
- foreach( $articleIds as $articleId ) {
- $articles[] = $this->getArticle( $articleId );
- }
- }
-
- foreach( $articles as $article ) {
- if( $blogId != -1 && $blogId != $article->getBlogId() ) {
- // wrong blogId, skip to the next article
- continue;
- }
- if( $categoryId != -1 && !in_array($categoryId, $article->getCategoryIds()) ) {
- // wrong category, skip to the next article
- continue;
- }
- if( $userId != -1 && $userId != $article->getUserId() ) {
- // wrong user, skip to the next article
- continue;
- }
- if( $status != $article->getStatus() ) {
- // wrong status, skip to the next article
- continue;
- }
- return $article;
- }
- return false;
+ // load all the articles with the same title
+ $articles = $this->getMany( "slug",
+ $articleTitle,
+ CACHE_ARTICLES_BYNAME );
+
+ $found = false;
+ foreach( $articles as $article ) {
+ if( $this->check( $article, $date, $categoryId, $status, $userId, $maxDate )) {
+ $found = true;
+ break;
+ }
+ // if not, continue with the next...
+ }
+
+ if( !$found )
+ $article = null;
+
+ return( $article );
}
/**
@@ -778,10 +733,10 @@
// update the article text
$this->updateArticleText( $article );
- if( !$this->updatePostCategoriesLink( $article ) ||
+ /*if( !$this->updatePostCategoriesLink( $article ) ||
!$this->updateArticleCustomFields( $article->getId(), $article->getBlog(),
$article->getFields()) )
- return false;
+ return false;*/
// clean up the cache
$this->_cache->removeData( $article->getBlogId(), CACHE_ARTICLESPERMONTH );
@@ -1006,6 +961,9 @@
return true;
}
+ /**
+ * @private
+ */
function mapRow( $query_result )
{
include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
Modified: plog/trunk/class/dao/bloginfo.class.php
===================================================================
--- plog/trunk/class/dao/bloginfo.class.php 2005-09-15 12:07:33 UTC (rev 2472)
+++ plog/trunk/class/dao/bloginfo.class.php 2005-09-15 20:01:57 UTC (rev 2473)
@@ -595,15 +595,33 @@
return( $this->_category );
}
+ /**
+ @return the mangled name of this blog
+ */
function getMangledBlogName()
{
include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
return( Textfilter::urlize( $this->getBlog()));
}
+ /**
+ * @return whether this blog should be shown in the summary page
+ */
function getShowInSummary()
{
return( $this->_showInSummary );
}
- }
+
+ /**
+ * @private
+ */
+ function __sleep()
+ {
+ $this->_ownerInfo = null;
+ $this->_usersInfo = null;
+ $this->_category = null;
+ //return( get_object_vars( $this ));
+ return( parent::__sleep());
+ }
+ }
?>
\ No newline at end of file
Modified: plog/trunk/class/dao/userdata/baseuserdataprovider.class.php
===================================================================
--- plog/trunk/class/dao/userdata/baseuserdataprovider.class.php 2005-09-15 12:07:33 UTC (rev 2472)
+++ plog/trunk/class/dao/userdata/baseuserdataprovider.class.php 2005-09-15 20:01:57 UTC (rev 2473)
@@ -136,7 +136,7 @@
/**
* @private
*/
- function _mapUserInfoObject( $query_result, $extendedInfo = false )
+ function _mapUserInfoObject( $query_result )
{
include_once( PLOG_CLASS_PATH."class/dao/userinfo.class.php" );
@@ -147,15 +147,7 @@
$query_result["resource_picture_id"],
unserialize($query_result["properties"]),
$query_result["id"]);
-
-
-
- if( $extendedInfo ) {
- // load this data if explicitely required!
- $userBlogs = $this->getUsersBlogs($userInfo->getId());
- $userInfo->setBlogs($userBlogs);
- }
-
+
// set some permissions
//$userInfo->setSiteAdmin($this->perms->isSiteAdmin( $userInfo->getId()));
$userInfo->setSiteAdmin( $query_result["site_admin"] );
Modified: plog/trunk/class/dao/userinfo.class.php
===================================================================
--- plog/trunk/class/dao/userinfo.class.php 2005-09-15 12:07:33 UTC (rev 2472)
+++ plog/trunk/class/dao/userinfo.class.php 2005-09-15 20:01:57 UTC (rev 2473)
@@ -89,7 +89,13 @@
function getBlogs()
{
- return $this->_blogs;
+ if( $this->_blogs == null ) {
+ include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+ $users = new Users();
+ $this->_blogs = $this->getUsersBlogs($userInfo->getId());
+ }
+
+ return( $this->_blogs );
}
function getFullName()
@@ -228,6 +234,17 @@
$this->_status = $status;
return true;
- }
+ }
+
+ /**
+ * @private
+ */
+ /*function __sleep()
+ {
+ $this->_resourcePicture = null;
+ $this->_blogs = null;
+
+ return( get_object_vars( $this ));
+ }*/
}
?>
Modified: plog/trunk/class/database/dbobject.class.php
===================================================================
--- plog/trunk/class/database/dbobject.class.php 2005-09-15 12:07:33 UTC (rev 2472)
+++ plog/trunk/class/database/dbobject.class.php 2005-09-15 20:01:57 UTC (rev 2473)
@@ -16,6 +16,7 @@
var $_class;
var $_fields;
var $_properties;
+ var $unserializable;
function DbObject()
{
@@ -24,6 +25,7 @@
$this->_class = "DbObject";
$this->_fields = Array();
$this->_properties = Array();
+ $this->unserializable = Array();
}
function setValue( $key, $value )
@@ -65,5 +67,24 @@
{
return( $this->_fields );
}
+
+ /**
+ * No null values are serialized to the session. If there any values in your data class
+ * that need not be serialized to the cache, please implement your own version of __sleep,
+ * set those attributes to null and call parent::__sleep() so that those attributes are not
+ * serialized.
+ *
+ * @private
+ */
+ function __sleep()
+ {
+ $vars = (array)$this;
+ foreach ($vars as $key => $val) {
+ if (is_null($val)) {
+ unset($vars[$key]);
+ }
+ }
+ return( array_keys($vars));
+ }
}
?>
\ No newline at end of file
More information about the pLog-svn
mailing list