[pLog-svn] r2273 - plog/branches/plog-1.0.2/class/dao
reto at devel.plogworld.net
reto at devel.plogworld.net
Sun Jun 26 13:00:18 GMT 2005
Author: reto
Date: 2005-06-26 13:00:18 +0000 (Sun, 26 Jun 2005)
New Revision: 2273
Modified:
plog/branches/plog-1.0.2/class/dao/blogs.class.php
Log:
fixed http://bugs.plogworld.net/view.php?id=589.
did it in a slightly different way: If the blogname exists, i is added, where i is a integer starting with 1 (blogname1, blogname2 etc).
Modified: plog/branches/plog-1.0.2/class/dao/blogs.class.php
===================================================================
--- plog/branches/plog-1.0.2/class/dao/blogs.class.php 2005-06-26 03:24:28 UTC (rev 2272)
+++ plog/branches/plog-1.0.2/class/dao/blogs.class.php 2005-06-26 13:00:18 UTC (rev 2273)
@@ -287,14 +287,27 @@
*/
function updateBlog( $blogId, &$blogInfo )
{
- // check if there already is a blog wiht the same mangled name
- if( ($blog = $this->getBlogInfoByName( $blogInfo->getMangledBlog()))) {
- // and if so, assign a new one but making sure that we are not actually
+ // ititalize iterator to get unique mangled blog names
+ $i = 0;
+
+ // check if there already is a blog with the same mangled name
+ while( ($blog = $this->getBlogInfoByName( $blogInfo->getMangledBlog() )) )
+ {
+ $i++;
+
+ // and if so, assign a new one but making sure that we are not actually
// seeing ourselves!
- if( $blog->getId() != $blogInfo->getId()) {
- $newMangledName = $blogInfo->getMangledBlog().$blogInfo->getId();
+ if( $blog->getID() != $blogInfo->getID()) {
+
+ // if we already tried with blogname+"i" we have to strip "i" before adding it again!
+ $newMangledName = ( ($i > 1) ? substr( $blogInfo->getMangledBlog(), 0, strlen( $blogInfo->getMangledBlog() )-1 ).$i : $blogInfo->getMangledBlog().$i );
$blogInfo->setMangledBlog( $newMangledName );
+ } else
+ {
+ // break out if we are seeing ourselves, no need to change the mangled name!
+ break;
}
+
}
$query = "UPDATE ".$this->getPrefix()."blogs SET
@@ -318,23 +331,23 @@
* @param blogSettings the BlogSettings object that we would like to update
* @return 'true' if all correct. 'false' otherwise.
*/
- function updateBlogSettings( $blogId, $blogSettings )
- {
+ function updateBlogSettings( $blogId, $blogSettings )
+ {
$query = "UPDATE ".$this->getPrefix()."blogs SET settings = '".serialize($blogSettings)."' WHERE id = ".$blogId;
$result = $this->Execute( $query );
return $result;
- }
+ }
- /**
- * Sends a weblogsUpdate.ping xmlrpc call to notifiy of changes in this blog
- *
- * @param blogInfo The BlogInfo object containing information about the blog
- * @return Returns true if successful or false otherwise.
- */
- function updateNotify( $blogInfo )
- {
+ /**
+ * Sends a weblogsUpdate.ping xmlrpc call to notifiy of changes in this blog
+ *
+ * @param blogInfo The BlogInfo object containing information about the blog
+ * @return Returns true if successful or false otherwise.
+ */
+ function updateNotify( $blogInfo )
+ {
// if this feature is not enabled, we quit
$config =& Config::getConfig();
if( !$config->getValue( "xmlrpc_ping_enabled" ))
@@ -364,18 +377,33 @@
}
return $xmlrpcPingResult;
- }
+ }
- /**
- * Adds a new blog to the database.
- *
- * @param blog A BlogInfo object with the necessary information
- * @see BlogInfo
- * @return False if unsuccessful or true otherwise. It will also set the database id of the
- * parameter passed by reference in case it is successful.
- */
- function addBlog( &$blog )
- {
+ /**
+ * Adds a new blog to the database.
+ *
+ * @param blog A BlogInfo object with the necessary information
+ * @see BlogInfo
+ * @return False if unsuccessful or true otherwise. It will also set the database id of the
+ * parameter passed by reference in case it is successful.
+ */
+ function addBlog( &$blog )
+ {
+ // ititalize iterator to get unique mangled blog names
+ $i = 0;
+
+ // check if there already is a blog with the same mangled name
+ while( $this->getBlogInfoByName( $blog->getMangledBlog() ) )
+ {
+ $i++;
+
+ // and if so, assign a new one (if we already tried with blogname+"i" we have to strip "i" before adding it again!)
+ $newMangledName = ( ($i > 1) ? substr( $blog->getMangledBlog(), 0, strlen( $blog->getMangledBlog() )-1 ).$i : $blog->getMangledBlog().$i );
+ $blog->setMangledBlog( $newMangledName );
+
+ }
+
+
$blogSettings = $blog->getSettings();
if( !$blogSettings )
$blogSettings = new BlogSettings();
@@ -397,16 +425,6 @@
$blogId = $this->_db->Insert_ID();
$blog->setId( $blogId );
-
- // check if there already is a blog wiht the same mangled name
- if( $this->getBlogInfoByName( $blog->getMangledBlog())) {
- // and if so, assign a new one...
- $newMangledName = $blog->getMangledBlog().$blog->getId();
- $blog->setMangledBlog( $newMangledName );
- // if so, let's find a new one based on the blog id (just to make it unique)
- $query = "UPDATE ".$this->getPrefix()."blogs SET mangled_blog = '".Db::qstr($newMangledName)."' WHERE id = '".Db::qstr($blogId)."'";
- $result = $this->Execute( $query );
- }
// create the row for the bayesian filter info
$bayesianFilterInfo = new BayesianFilterInfos();
@@ -414,21 +432,21 @@
// and return the blog identifier
return $blogId;
- }
+ }
- /**
- * Returns all the blogs defined for the site in an array, sorted by its
- * blog identifier.
- *
- * @param page
- * @param itemsPerPage
- *
- * @return Returns an array with all the blogs defined for this site. The array
- * is sorted by the blog identifier, so that $blogs[$blogId] will give us the information
- * of the blog with $blogId as its identifier.
- */
- function getAllBlogs( $status = BLOG_STATUS_ALL, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
- {
+ /**
+ * Returns all the blogs defined for the site in an array, sorted by its
+ * blog identifier.
+ *
+ * @param page
+ * @param itemsPerPage
+ *
+ * @return Returns an array with all the blogs defined for this site. The array
+ * is sorted by the blog identifier, so that $blogs[$blogId] will give us the information
+ * of the blog with $blogId as its identifier.
+ */
+ function getAllBlogs( $status = BLOG_STATUS_ALL, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+ {
if( $status != BLOG_STATUS_ALL )
$where = "WHERE status = '".Db::qstr($status)."'";
@@ -448,15 +466,15 @@
$result->Close();
return $blogs;
- }
+ }
- /**
- * returns only an array with all the blog ids
- *
- * @return an array with blog ids
- */
- function getAllBlogIds()
- {
+ /**
+ * returns only an array with all the blog ids
+ *
+ * @return an array with blog ids
+ */
+ function getAllBlogIds()
+ {
$query = "SELECT id FROM ".$this->getPrefix()."blogs";
$result = $this->Execute( $query );
@@ -471,31 +489,31 @@
$result->Close();
return $blogIds;
- }
+ }
- /**
- * returns the total number of blogs in the site
- *
- * @return The number of blogs
- */
- function getNumBlogs( $status = BLOG_STATUS_ALL )
- {
+ /**
+ * returns the total number of blogs in the site
+ *
+ * @return The number of blogs
+ */
+ function getNumBlogs( $status = BLOG_STATUS_ALL )
+ {
$prefix = $this->getPrefix();
$table = "{$prefix}blogs";
if( $status != BLOG_STATUS_ALL )
$cond = "status = '".Db::qstr($status)."'";
return( $this->getNumItems( $table, $cond ));
- }
+ }
- /**
- * Removes a blog from the database. It also removes all its posts, its posts categories
- * its links, its links categories, its trackbacks and its comments
- *
- * @param blogId the id of the blog we'd like to delete
- */
- function deleteBlog( $blogId )
- {
+ /**
+ * Removes a blog from the database. It also removes all its posts, its posts categories
+ * its links, its links categories, its trackbacks and its comments
+ *
+ * @param blogId the id of the blog we'd like to delete
+ */
+ function deleteBlog( $blogId )
+ {
// first of all, delete the posts
$articles = new Articles();
$articles->deleteBlogPosts( $blogId );
@@ -520,15 +538,15 @@
$result = $this->Execute( $query );
return $result;
- }
+ }
- /**
- * disables a blog
- *
- * @param blogId
- */
- function disableBlog( $blogId )
- {
+ /**
+ * disables a blog
+ *
+ * @param blogId
+ */
+ function disableBlog( $blogId )
+ {
$query = "UPDATE ".$this->getPrefix()."blogs
SET status = '".BLOG_STATUS_DISABLED."'
WHERE id = '".Db::qstr($blogId)."'";
@@ -542,6 +560,6 @@
return false;
return true;
- }
- }
+ }
+ }
?>
\ No newline at end of file
More information about the pLog-svn
mailing list