[pLog-svn] r6497 - plog/branches/lifetype-1.2/class/dao
jondaley at devel.lifetype.net
jondaley at devel.lifetype.net
Fri May 30 08:53:11 EDT 2008
Author: jondaley
Date: 2008-05-30 08:53:11 -0400 (Fri, 30 May 2008)
New Revision: 6497
Modified:
plog/branches/lifetype-1.2/class/dao/articlecategories.class.php
Log:
don't allow categories to have the same mangled name. Fixes http://bugs.lifetype.net/view.php?id=1463
Modified: plog/branches/lifetype-1.2/class/dao/articlecategories.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/dao/articlecategories.class.php 2008-05-30 12:15:34 UTC (rev 6496)
+++ plog/branches/lifetype-1.2/class/dao/articlecategories.class.php 2008-05-30 12:53:11 UTC (rev 6497)
@@ -226,7 +226,22 @@
*/
function addArticleCategory( &$articleCategory )
{
- if(( $result = $this->add( $articleCategory, Array( CACHE_ARTICLE_CATEGORIES => "getId" )))) {
+ $mangledName = $articleCategory->getMangledName();
+ $i = 1;
+ // check if there already is a category with the same mangled name
+ while($this->getCategoryByName($mangledName,
+ $articleCategory->getBlogId()))
+ {
+ $i++;
+ // and if so, assign a new one
+ // if we already tried with blogname+"i" we have
+ // to strip "i" before adding it again!
+ $mangledName = substr($mangledName, 0,
+ ($i > 2) ? strlen($mangledName)-strlen($i-1) : strlen($mangledName)).$i;
+ }
+ $articleCategory->setMangledName($mangledName);
+
+ if(( $result = $this->add( $articleCategory, Array( CACHE_ARTICLE_CATEGORIES => "getId" )))) {
$this->_cache->removeData( $articleCategory->getBlogId(), CACHE_ARTICLE_CATEGORIES_BLOG );
$this->_cache->removeData( $articleCategory->getMangledName(), CACHE_ARTICLE_CATEGORIES_BYNAME );
}
@@ -303,7 +318,27 @@
"acl.category_id = '".Db::qstr($category->getId())."' and acl.article_id = a.id and a.status = ".POST_STATUS_PUBLISHED,
"acl.category_id"
));
- if( $result = $this->update( $category )) {
+
+ $mangledName = $category->getMangledName();
+ $i = 1;
+ // check if there already is a category with the same mangled name
+ while($existingCategory = $this->getCategoryByName($mangledName,
+ $category->getBlogId()))
+ {
+ // if we found ourselves, it is okay to keep using this name
+ if($existingCategory->getId() == $category->getId())
+ break;
+
+ $i++;
+ // and if so, assign a new one
+ // if we already tried with blogname+"i" we have
+ // to strip "i" before adding it again!
+ $mangledName = substr($mangledName, 0,
+ ($i > 2) ? strlen($mangledName)-strlen($i-1) : strlen($mangledName)).$i;
+ }
+ $category->setMangledName($mangledName);
+
+ if( $result = $this->update( $category )) {
$this->_cache->removeData( $category->getBlogId(), CACHE_ARTICLE_CATEGORIES_BLOG );
$this->_cache->setData( $category->getId(), CACHE_ARTICLE_CATEGORIES, $category );
}
More information about the pLog-svn
mailing list