[pLog-svn] r3453 - in plog/trunk/class: action/admin template/templatesets

mark at devel.lifetype.net mark at devel.lifetype.net
Wed May 24 04:38:42 GMT 2006


Author: mark
Date: 2006-05-24 04:38:40 +0000 (Wed, 24 May 2006)
New Revision: 3453

Modified:
   plog/trunk/class/action/admin/adminaddtemplateaction.class.php
   plog/trunk/class/action/admin/admindeletetemplatesaction.class.php
   plog/trunk/class/action/admin/adminupdateblogsettingsaction.class.php
   plog/trunk/class/template/templatesets/templatesetstorage.class.php
Log:
Fixed the bug: http://forums.lifetype.net/viewtopic.php?t=4631&start=0&postdays=0&postorder=asc&highlight=

This bug is quite complex. It is because the  blogInfo in session is different from the blogInfo in Database.

We should very take care of this. When we update the blogInfo in DB, we should also remember update the blogInfo in session.

Or we will get the data dirty.

Mark

Modified: plog/trunk/class/action/admin/adminaddtemplateaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminaddtemplateaction.class.php	2006-05-23 20:52:38 UTC (rev 3452)
+++ plog/trunk/class/action/admin/adminaddtemplateaction.class.php	2006-05-24 04:38:40 UTC (rev 3453)
@@ -8,7 +8,7 @@
     include_once( PLOG_CLASS_PATH.'class/template/templatesandbox.class.php' );
     include_once( PLOG_CLASS_PATH.'class/file/fileuploads.class.php' );
 	include_once( PLOG_CLASS_PATH.'class/template/templatesets/templatesetstorage.class.php' );
-	include_once( PLOG_CLASS_PATH.'class/template/templatesets/templatefinder.class.php' );	
+	include_once( PLOG_CLASS_PATH.'class/template/templatesets/templatefinder.class.php' );
 	include_once( PLOG_CLASS_PATH.'class/data/validator/uploadvalidator.class.php' );
 
     /**
@@ -68,14 +68,14 @@
             // handle the uploaded file
             $files    = HttpVars::getFiles();
             $uploads  = new FileUploads( $files );
-            
+
             if( count($files) == 0 || $files["templateFile"]["name"] == "") {
 				$this->_view = new AdminTemplatedView( $this->_blogInfo, "newglobaltemplate" );
 				$this->_view->setValue( "templateFolder", TemplateSetStorage::getBaseTemplateFolder());
                 $this->_view->setErrorMessage( $this->_locale->tr("error_must_upload_file"));
                 $this->setCommonData();
                 return false;
-			}            
+			}
 
             $config =& Config::getConfig();
 
@@ -143,7 +143,7 @@
             $templateSandbox = new TemplateSandbox();
             $valid = $templateSandbox->checkTemplateFolder( $templateName, $ts->getBaseTemplateFolder());
             if( $valid < 0 ) {
-				$this->_errorMessage = $this->_locale->pr( 'error_installing_template', $templateName ).': '.$this->_checkTemplateSandboxResult( $valid ).'<br/>';				
+				$this->_errorMessage = $this->_locale->pr( 'error_installing_template', $templateName ).': '.$this->_checkTemplateSandboxResult( $valid ).'<br/>';
 				$result = false;
 			}
             else {
@@ -156,7 +156,7 @@
             $this->setCommonData();
             return $result;
         }
-		
+
 		/**
 		 * scans the templates folder looking for new files
 		 *
@@ -165,15 +165,15 @@
 		function _performScanTemplateFolder()
 		{
 			// set up the view
-            $this->_view = new AdminSiteTemplatesListView( $this->_blogInfo );		
-		
+            $this->_view = new AdminSiteTemplatesListView( $this->_blogInfo );
+
 			// and tell the template finder to find any new template file...
 			$tf = new TemplateFinder();
 			$newTemplates = $tf->find();
-			
+
 			$this->_errorMessage = "";
 			$this->_successMessage = "";
-			
+
 			if( count($newTemplates) == 0 ) {
 				// no new templates found
 				$this->_errorMessage = $this->_locale->tr( 'error_no_new_templates_found' );
@@ -184,11 +184,11 @@
 					$this->_addTemplateCode( $newTemplate );
 				}
 			}
-			
+
 			// set the success and error messages, if any
 			if( $this->_errorMessage != '' ) $this->_view->setErrorMessage( $this->_errorMessage );
 			if( $this->_successMessage != '' ) $this->_view->setSuccessMessage( $this->_successMessage );
-			
+
 			return true;
 		}
 
@@ -208,6 +208,13 @@
 
             $this->setCommonData();
 
+            // We should update the session too, or we will get data dirty
+            include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+            $blog = new Blogs();
+            $blogInfo = $blogs->getBlogInfo( $this->_blogInfo->getId() );
+            $this->_session->setValue( "blogInfo", $blogInfo );
+            $this->saveSession();
+
             return $result;
         }
     }

Modified: plog/trunk/class/action/admin/admindeletetemplatesaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admindeletetemplatesaction.class.php	2006-05-23 20:52:38 UTC (rev 3452)
+++ plog/trunk/class/action/admin/admindeletetemplatesaction.class.php	2006-05-24 04:38:40 UTC (rev 3453)
@@ -82,6 +82,13 @@
 			if( $successMessage != "" ) $this->_view->setSuccessMessage( $successMessage );
             $this->setCommonData();
 
+            // We should update the session too, or we will get data dirty
+            include_once( PLOG_CLASS_PATH."class/dao/blogs.class.php" );
+            $blog = new Blogs();
+            $blogInfo = $blogs->getBlogInfo( $this->_blogInfo->getId() );
+            $this->_session->setValue( "blogInfo", $blogInfo );
+            $this->saveSession();
+
             return true;
         }
     }

Modified: plog/trunk/class/action/admin/adminupdateblogsettingsaction.class.php
===================================================================
--- plog/trunk/class/action/admin/adminupdateblogsettingsaction.class.php	2006-05-23 20:52:38 UTC (rev 3452)
+++ plog/trunk/class/action/admin/adminupdateblogsettingsaction.class.php	2006-05-24 04:38:40 UTC (rev 3453)
@@ -6,15 +6,15 @@
     include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );
 	include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
 	include_once( PLOG_CLASS_PATH."class/view/admin/adminblogsettingsview.class.php" );
-	
 
+
     /**
      * \ingroup Action
      * @private
      *
      * Action that shows a form to change the settings of the current blog.
      */
-    class AdminUpdateBlogSettingsAction extends BlogOwnerAdminAction 
+    class AdminUpdateBlogSettingsAction extends BlogOwnerAdminAction
 	{
     	/**
          * Constructor. If nothing else, it also has to call the constructor of the parent
@@ -23,7 +23,7 @@
         function AdminUpdateBlogSettingsAction( $actionInfo, $request )
         {
         	$this->BlogOwnerAdminAction( $actionInfo, $request );
-			
+
 			// lots of stuff to register here...
 			$this->registerFieldValidator( "blogMaxRecentItems", new IntegerValidator());
 			$this->registerFieldValidator( "blogMaxMainPageItems", new IntegerValidator());
@@ -31,14 +31,14 @@
 			$this->registerFieldValidator( "blogLocale", new StringValidator());
 			$this->registerFieldValidator( "blogTemplate", new StringValidator());
 			$this->registerFieldValidator( "blogCategory", new IntegerValidator());
-			$this->registerField( "blogAbout" );			
+			$this->registerField( "blogAbout" );
 			$this->registerField( "blogShowMoreEnabled" );
 			$this->registerField( "blogEnableHtmlarea" );
 			$this->registerField( "blogEnablePullDownMenu" );
 			$this->registerField( "blogCommentsEnabled" );
 			$this->registerField( "blogCommentsOrder" );
 			$this->registerField( "blogShowFuturePosts" );
-			//$this->registerFieldValidator( "blogTimeOffset", new IntegerValidator());
+			$this->registerField( "blogTimeOffset" );
 			$this->registerField( "properties" );
 			$this->registerField( "blogCategoriesOrder" );
 			$this->registerField( "blogLinkCategoriesOrder" );
@@ -62,10 +62,9 @@
             $blogSettings->setValue( "locale", $this->_request->getValue( "blogLocale" ));
             $blogSettings->setValue( "show_posts_max", $this->_request->getValue( "blogMaxMainPageItems" ));
             $blogSettings->setValue( "recent_posts_max", $this->_request->getValue( "blogMaxRecentItems" ));
-            $blogSettings->setValue( "template", $this->_request->getValue( "blogTemplate" ));
             $blogSettings->setValue( "time_offset", $this->_request->getValue( "blogTimeOffset" ));
 			$blogSettings->setValue( "categories_order", $this->_request->getValue( "blogCategoriesOrder" ));
-			$blogSettings->setValue( "link_categories_order", $this->_request->getValue( "blogLinkCategoriesOrder" ));			
+			$blogSettings->setValue( "link_categories_order", $this->_request->getValue( "blogLinkCategoriesOrder" ));
            	$blogSettings->setValue( "show_more_enabled",  Textfilter::checkboxToBoolean($this->_request->getValue( "blogShowMoreEnabled" )));
            	$blogSettings->setValue( "htmlarea_enabled", Textfilter::checkboxToBoolean($this->_request->getValue( "blogEnableHtmlarea" )));
            	$blogSettings->setValue( "pull_down_menu_enabled", Textfilter::checkboxToBoolean($this->_request->getValue( "blogEnablePullDownMenu" )));
@@ -77,16 +76,17 @@
             $this->_blogInfo->setAbout( Textfilter::filterAllHTML($this->_request->getValue( "blogAbout" )));
             $this->_blogInfo->setBlog( Textfilter::filterAllHTML($this->_request->getValue( "blogName" )));
             $this->_blogInfo->setSettings( $blogSettings );
+            $this->_blogInfo->setTemplate( $this->_request->getValue( "blogTemplate" ));
 			$this->_blogInfo->setProperties( $this->_request->getValue( "properties" ));
 			$this->_blogInfo->setBlogCategoryId( $this->_request->getValue( "blogCategory" ));
 			$this->_blogInfo->setMangledBlogName( Textfilter::urlize( $this->_blogInfo->getBlog()));
-			$this->_blogInfo->setShowInSummary( Textfilter::checkboxToBoolean( $this->_request->getValue( "blogShowInSummary" )));			
+			$this->_blogInfo->setShowInSummary( Textfilter::checkboxToBoolean( $this->_request->getValue( "blogShowInSummary" )));
 
             // and now update the settings in the database
             $blogs = new Blogs();
-                        
+
             // and now we can proceed...
-			$this->notifyEvent( EVENT_PRE_BLOG_UPDATE, Array( "blog" => &$this->_blogInfo ));						
+			$this->notifyEvent( EVENT_PRE_BLOG_UPDATE, Array( "blog" => &$this->_blogInfo ));
 			$blogs = new Blogs();
             if( !$blogs->updateBlog( $this->_blogInfo )) {
             	$this->_view = new AdminBlogSettingsView( $this->_blogInfo );
@@ -96,11 +96,6 @@
                 return false;
             }
 
-            // do it again, baby :)))
-            $this->_blogInfo->setAbout( Textfilter::filterAllHTML(stripslashes($this->_request->getValue( "blogAbout" ))));
-            $this->_blogInfo->setBlog( Textfilter::filterAllHTML(stripslashes($this->_request->getValue( "blogName" ))));
-            $this->_blogInfo->setSettings( $blogSettings );
-			$this->_blogInfo->setProperties( Array());
             $this->_session->setValue( "blogInfo", $this->_blogInfo );
             $this->saveSession();
 
@@ -109,9 +104,9 @@
             $this->_locale =& Locales::getLocale( $blogSettings->getValue( "locale" ));
             $this->_view->setSuccessMessage( $this->_locale->pr("blog_settings_updated_ok", $this->_blogInfo->getBlog()));
             $this->setCommonData();
-			
+
 			// clear the cache
-			CacheControl::resetBlogCache( $this->_blogInfo->getId());			
+			CacheControl::resetBlogCache( $this->_blogInfo->getId());
 
             // better to return true if everything fine
             return true;

Modified: plog/trunk/class/template/templatesets/templatesetstorage.class.php
===================================================================
--- plog/trunk/class/template/templatesets/templatesetstorage.class.php	2006-05-23 20:52:38 UTC (rev 3452)
+++ plog/trunk/class/template/templatesets/templatesetstorage.class.php	2006-05-24 04:38:40 UTC (rev 3453)
@@ -1,6 +1,6 @@
 <?php
 
-	
+
     include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
     include_once( PLOG_CLASS_PATH."class/misc/glob.class.php" );
     include_once( PLOG_CLASS_PATH."class/file/file.class.php" );
@@ -20,7 +20,7 @@
 	 *
 	 * Class and API users should not need to use this class directly.
 	 */
-	class TemplateSetStorage 
+	class TemplateSetStorage
 	{
 
 		/**
@@ -28,7 +28,7 @@
 		 */
 		function TemplateSetStorage()
 		{
-			
+
 		}
 
         /**
@@ -84,7 +84,7 @@
             if( $baseFolder[strlen($baseFolder)-1] != "/" )
             	$baseFolder = $baseFolder."/";
 
-            $templateFolder = $baseFolder.BLOG_BASE_TEMPLATE_FOLDER."$blogId/".$templateName."/";
+            $templateFolder = $baseFolder.BLOG_BASE_TEMPLATE_FOLDER."$blogId/";
 
             return $templateFolder;
         }
@@ -98,11 +98,11 @@
         {
 		// if the folder does not even exist, let's not even bother trying... It
 		// could be that it was manually removed by the user or something!
-		if( File::exists( $folderName )) 
+		if( File::exists( $folderName ))
 			$result = File::deleteDir( $folderName, true );
 		else
 			$result = true;
-		
+
 		return( $result );
         }
 
@@ -166,7 +166,7 @@
             $blogSettings = $blog->getSettings();
 
             // looks like the blog doesn't exist, so let's not bother...
-            if( $blogSettings == false || $blogSettings == "" )
+            if( empty($blogSettings) )
             	return false;
 
 			// check if the template really exists
@@ -186,7 +186,7 @@
             // finally, save the settings
             $blogSettings->setValue( "blog_templates", $newTemplateList );
             $blog->setSettings( $blogSettings );
-            $blogs->updateBlog( $blog );            
+            $blogs->updateBlog( $blog );
 
             return true;
         }
@@ -284,7 +284,7 @@
         	$blogs = new Blogs();
             $blog = $blogs->getBlogInfo( $blogId );
             $blogSettings = $blog->getSettings();
-            if( $blogSettings == "" || $blogSettings == false )
+            if( empty($blogSettings) )
             	return false;
 
             // get the array with the templates
@@ -427,7 +427,7 @@
 
 			return $url;
 		}
-		
+
 		/**
 		 * returns the path to the 'templates/misc/' folder
 		 *
@@ -437,7 +437,7 @@
 		function getMiscTemplateFolder()
 		{
 			$templatePath = TemplateSetStorage::getBaseTemplateFolder()."/misc";
-			return $templatePath;		
+			return $templatePath;
 		}
 	}
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list