[pLog-svn] r763 - in plog/trunk: . class/action class/dao templates/admin

oscar at devel.plogworld.net oscar at devel.plogworld.net
Wed Jan 19 18:34:46 GMT 2005


Author: oscar
Date: 2005-01-19 18:34:46 +0000 (Wed, 19 Jan 2005)
New Revision: 763

Modified:
   plog/trunk/class/action/viewarticleaction.class.php
   plog/trunk/class/dao/articles.class.php
   plog/trunk/templates/admin/globalsettings_general.template
   plog/trunk/wizard.php
Log:
added one new option, 'update_cached_article_reads' that will update the count with the number of times that an article has been read *even* if caching is enabled (so far, when caching was on nothing was being updated to the db) See issue http://bugs.plogworld.net/view.php?id=128 for more information.

Modified: plog/trunk/class/action/viewarticleaction.class.php
===================================================================
--- plog/trunk/class/action/viewarticleaction.class.php	2005-01-19 18:21:42 UTC (rev 762)
+++ plog/trunk/class/action/viewarticleaction.class.php	2005-01-19 18:34:46 UTC (rev 763)
@@ -23,7 +23,7 @@
 
     	var $_config;
         var $_articleId;
-	var $_articleName;
+		var $_articleName;
 		var $_date;
 		var $_userId;
 		var $_userName;
@@ -39,7 +39,7 @@
         function validate()
         {
         	$this->_articleId = $this->_request->getValue( "articleId" );
-		$this->_articleName = $this->_request->getValue( "articleName" );
+			$this->_articleName = $this->_request->getValue( "articleName" );
 			
 			// find some other additional parameters and use some 'null' values
 			// in casuse they're empty
@@ -59,6 +59,20 @@
 			$this->_view->setValue( "message", "error_fetching_article" );
 			$this->setCommonData();		
 		}
+		
+		/**
+		 * @private
+		 * updates the number of times that an article has been read in the db
+		 * 
+		 * @param articleId
+		 * @return always true
+		 */
+		function updateNumArticleReads( $articleId )
+		{
+			$this->articles->updateArticleNumReads( $articleId );
+			
+			return( true );
+		}
 
         function perform()
         {
@@ -73,7 +87,11 @@
                                                           "date" => $this->_date )); 
 
 			if( $this->_view->isCached()) {
-				// if the view is cached, there is nothing to do!
+				// if the view is cached, only update the number of times that the article has been
+				// read (if configured to do so) and quit
+				if( $config->getValue( 'update_cached_article_reads', false )) {
+					$this->updateNumArticleReads( $this->_articleId );
+				}
 				return true;
 			}
 
@@ -129,9 +147,7 @@
 
             // check if we have to update how many times an article has been read
             if( $this->_config->getValue( "update_article_reads" )) {
-            	$curReads = $article->getNumReads();
-            	$article->setNumReads( $curReads + 1 );
-                $this->articles->updateArticleNumReads( $article->getId(), $curReads + 1 );
+				$this->updateNumArticleReads( $article->getId());
             }
 						
             // if everything's fine, we set up the article object for the view

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2005-01-19 18:21:42 UTC (rev 762)
+++ plog/trunk/class/dao/articles.class.php	2005-01-19 18:34:46 UTC (rev 763)
@@ -832,11 +832,11 @@
          * @param numReads A value, meaning how many times the post has been read.
          * @return Returns true if successful or false otherwise.
          */
-        function updateArticleNumReads( $articleId, $numReads )
+        function updateArticleNumReads( $articleId )
         {
             // we have to build up the query, which will be pretty long...
             $query = "UPDATE ".$this->getPrefix()."articles SET ".
-                     " num_reads = $numReads ".
+                     " num_reads = num_reads+1 ".
                      ", date = date ".
                      " WHERE id = $articleId;";
 

Modified: plog/trunk/templates/admin/globalsettings_general.template
===================================================================
--- plog/trunk/templates/admin/globalsettings_general.template	2005-01-19 18:21:42 UTC (rev 762)
+++ plog/trunk/templates/admin/globalsettings_general.template	2005-01-19 18:34:46 UTC (rev 763)
@@ -175,6 +175,13 @@
     <input class="radio" type="radio" name="config[update_article_reads]" value="1" {if $update_article_reads == 1 } checked="checked" {/if} />{$locale->tr("yes")}
     <input class="radio" type="radio" name="config[update_article_reads]" value="0" {if $update_article_reads == 0 } checked="checked" {/if} />{$locale->tr("no")}
    </div>
+   <!-- update_cached_article_reads -->
+   <div class="field">
+    <label for="config[update_cached_article_reads]">update_cached_article_reads</label>
+    <div class="formHelp">{$locale->tr("help_update_cached_article_reads")}</div>
+    <input class="radio" type="radio" name="config[update_cached_article_reads]" value="1" {if $update_cached_article_reads == 1 } checked="checked" {/if} />{$locale->tr("yes")}
+    <input class="radio" type="radio" name="config[update_cached_article_reads]" value="0" {if $update_cached_article_reads == 0 } checked="checked" {/if} />{$locale->tr("no")}
+   </div>
    <!-- xmlrpc_ping_enabled -->
    <div class="field">
     <label for="config[xmlrpc_ping_enabled]">xmlrpc_ping_enabled</label>

Modified: plog/trunk/wizard.php
===================================================================
--- plog/trunk/wizard.php	2005-01-19 18:21:42 UTC (rev 762)
+++ plog/trunk/wizard.php	2005-01-19 18:34:46 UTC (rev 763)
@@ -624,7 +624,9 @@
 $Inserts[106] = "INSERT INTO {dbprefix}config (config_key, config_value, value_type) VALUES('template_http_cache_enabled', '0', 1);";
 $Inserts[107] = "INSERT INTO {dbprefix}config (config_key, config_value, value_type) VALUES('template_http_cache_enabled', '0', 1);";
 $Inserts[108] = "INSERT INTO {dbprefix}config (config_key, config_value, value_type) VALUES('template_compile_check', '1', 1);";
+$Inserts[109] = "INSERT INTO {dbprefix}config (config_key, config_value, value_type) VALUES('update_cached_article_reads', '1', 1);";
 
+
 	/**
 	 * Open a connection to the database
 	 */
@@ -1397,7 +1399,7 @@
             // ---
             // add the new configuration settings that were added for 1.0
             // ---
-            $newSettings = range( 71, 108 );
+            $newSettings = range( 71, 109 );
             foreach( $newSettings as $settingId ) {
                 $setting = $Inserts[$settingId];
                 $query = str_replace( "{dbprefix}", $this->_dbPrefix, $setting );




More information about the pLog-svn mailing list