[pLog-svn] r5551 - in plog/branches/lifetype-1.2: . class/action/admin class/controller class/misc class/test/tests/misc locale/admin templates/admin

oscar at devel.lifetype.net oscar at devel.lifetype.net
Sat Jun 16 04:32:38 EDT 2007


Author: oscar
Date: 2007-06-16 04:32:38 -0400 (Sat, 16 Jun 2007)
New Revision: 5551

Added:
   plog/branches/lifetype-1.2/class/test/tests/misc/version_test.class.php
Modified:
   plog/branches/lifetype-1.2/class/action/admin/adminplugincenteraction.class.php
   plog/branches/lifetype-1.2/class/action/admin/adminversioncheckaction.class.php
   plog/branches/lifetype-1.2/class/controller/admincontrollermap.properties.php
   plog/branches/lifetype-1.2/class/misc/version.class.php
   plog/branches/lifetype-1.2/locale/admin/locale_en_UK.php
   plog/branches/lifetype-1.2/templates/admin/versions.template
   plog/branches/lifetype-1.2/version.php
Log:
Added support for Lifetype version checking in the admin interface in the "Versions" tab within the "Administration" group. This feature is built on another RSS 2.0 feed at http://www.lifetype.net/feeds/1.2/lifetype.xml that contains some basic information about the most recent Lifetype release.

The format of the version.php file has also changed a bit, now it should always be "lifetype-x.y.z" for major releases and "lifetype-x.y.z-dev" when talking about development releases or when working with an svn branch. The Version class has been improved to support these new format as well as improved methods for comparing versions (based on PHP's version_compare)


Modified: plog/branches/lifetype-1.2/class/action/admin/adminplugincenteraction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminplugincenteraction.class.php	2007-06-16 05:12:39 UTC (rev 5550)
+++ plog/branches/lifetype-1.2/class/action/admin/adminplugincenteraction.class.php	2007-06-16 08:32:38 UTC (rev 5551)
@@ -6,12 +6,6 @@
     lt_include( PLOG_CLASS_PATH."class/plugin/pluginmanager.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/xml/rssparser/rssparser.class.php" );
 
-	/**
-	 * This needs to be udpated after every major release, so that the plugin feed
-	 * is fetched from the right place
-	 */
-	define( "LIFETYPE_DEFAULT_PLUGIN_VERSION_FEED", "http://www.lifetype.net/feeds/1.2/plugins.xml" );
-
     /**
      * \ingroup Action
      * @private
@@ -73,7 +67,7 @@
 			// load the feed with plugin versions and display an error if there was a problem
 			if( $doVersionCheck ) {
 				$rss = new RssParser();
-				if( $rss->parse( LIFETYPE_DEFAULT_PLUGIN_VERSION_FEED )) {
+				if( $rss->parse( Version::getPluginVersionFeed())) {
 					$items = $rss->getItems();
 
 					// process the parsed rss feed

Modified: plog/branches/lifetype-1.2/class/action/admin/adminversioncheckaction.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/action/admin/adminversioncheckaction.class.php	2007-06-16 05:12:39 UTC (rev 5550)
+++ plog/branches/lifetype-1.2/class/action/admin/adminversioncheckaction.class.php	2007-06-16 08:32:38 UTC (rev 5551)
@@ -3,7 +3,8 @@
 	lt_include( PLOG_CLASS_PATH."class/action/admin/adminaction.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/view/admin/admintemplatedview.class.php" );
 	lt_include( PLOG_CLASS_PATH."class/misc/integritychecker.class.php" );
-
+	lt_include( PLOG_CLASS_PATH."class/xml/rssparser/rssparser.class.php" );	
+	
     /**
      * \ingroup Action
      * @private
@@ -26,8 +27,7 @@
 			$this->_view = new AdminTemplatedView( $this->_blogInfo, "versions" );
 			
 			// decide what we're going to do...
-			$this->_op = $this->_request->getValue( "op" );
-			if( $this->_op == "doFileVersionCheck" ) {
+			if( $this->_request->getValue( "doFileVersionCheck" ) != "" ) {
 				// here we have to check the files and display the result
 				
 				// load the file with the reference checksums, as generated by the development
@@ -48,6 +48,27 @@
 					$this->_view->setErrorMessage( $message );
 				}
 			}
+			elseif( $this->_request->getValue( "doLTVersionCheck" ) != "" ) {
+				$rss = new RssParser();
+				if( $rss->parse( Version::getLifetypeVersionFeed() )) {					
+					$items = $rss->getItems();
+					
+					// there is only one item tag in the feed, the one containing the latest stable
+					// version only
+					if( isset( $items[0] )) {
+						$version = $items[0]->getTitle();
+						if( Version::isNewer( $version )) {
+							$message = $this->_locale->tr( "lt_version_error" )."<b>$version</b>";
+							$message .= "<br/><a href=\"".$items[0]->getLink()."\">".$this->_locale->tr("download")."</a>";
+							$message .= "<br/><a href=\"".$items[0]->_item["lt"]["relnotes"]."\">".$this->_locale->tr("release_notes")."</a>";							
+							$this->_view->setErrorMessage( $message );
+						}
+						else  {
+							$this->_view->setSuccessMessage( $this->_locale->tr( "lt_version_ok" ));
+						}
+					}
+				}
+			}
 
 			lt_include( PLOG_CLASS_PATH."class/misc/version.class.php" );
 			$this->_view->setValue( "version", Version::getVersion());

Modified: plog/branches/lifetype-1.2/class/controller/admincontrollermap.properties.php
===================================================================
--- plog/branches/lifetype-1.2/class/controller/admincontrollermap.properties.php	2007-06-16 05:12:39 UTC (rev 5550)
+++ plog/branches/lifetype-1.2/class/controller/admincontrollermap.properties.php	2007-06-16 08:32:38 UTC (rev 5551)
@@ -322,5 +322,4 @@
 	$actions["changeUserStatus"] = "AdminChangeUserStatusAction";
 	// perform an md5 check of some core files	
 	$actions["Versions"] = "AdminVersionCheckAction";
-	$actions["doFileVersionCheck"] = "AdminVersionCheckAction";
 ?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/class/misc/version.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/misc/version.class.php	2007-06-16 05:12:39 UTC (rev 5550)
+++ plog/branches/lifetype-1.2/class/misc/version.class.php	2007-06-16 08:32:38 UTC (rev 5551)
@@ -1,7 +1,25 @@
 <?php
 
-    define( "PLOG_PROJECT_PAGE", "http://www.lifetype.net" );
+	/**
+	 * URL pointing to the project page
+	 */
+    define( "LIFETYPE_PROJECT_PAGE", "http://www.lifetype.net" );
+
+	/**
+	 * This needs to be udpated after every major release, so that the version feed
+	 * is fetched from the right place
+	 */	
+	define( "LIFETYPE_DEFAULT_VERSION_FEED", "http://www.lifetype.net/feeds/1.2/lifetype.xml" );	
+	
+	/**
+	 * This needs to be udpated after every major release, so that the plugin feed
+	 * is fetched from the right place
+	 */
+	define( "LIFETYPE_DEFAULT_PLUGIN_VERSION_FEED", "http://www.lifetype.net/feeds/1.2/plugins.xml" );	
     
+	/**
+	 * File where the version string is stored
+	 */
     if ( !defined("DEFAULT_VERSION_FILE") )
       define( "DEFAULT_VERSION_FILE", PLOG_CLASS_PATH . "version.php" );
 
@@ -43,10 +61,43 @@
          */
         function getProjectPage()
         {
-            return PLOG_PROJECT_PAGE;
+            return LIFETYPE_PROJECT_PAGE;
         }
+
+		/**
+		 * Returns the link to the current Lifetype version feed
+		 *
+		 * @static
+		 */
+		function getLifetypeVersionFeed()
+		{
+			return( LIFETYPE_DEFAULT_VERSION_FEED );
+		}
 		
 		/**
+		 * Returns the link to the current Lifetype version feed
+		 *
+		 * @static
+		 */		
+		function getPluginVersionFeed()
+		{
+			return( LIFETYPE_DEFAULT_PLUGIN_VERSION_FEED );
+		}
+		
+		/**
+		 * Returns true if the current version is a development version
+		 * 
+		 * @static
+		 */
+		function isDevelopment( $version = "" )
+		{
+			if( $version == "" )
+				$version = Version::getVersion();
+				
+			return( substr( $version, -3, 3 ) == "dev" );
+		}		
+		
+		/**
 		 * Compares two LT versions
 		 *
 		 * @param v1
@@ -57,7 +108,28 @@
 		 */
 		function compare( $v1, $v2 )
 		{
+			// remove the "lifetype-" string from both versions in case if it's there
+			// as it will make it easier for version_compare to work
+			$v1 = str_replace( "lifetype-", "", $v1 );
+			$v2 = str_replace( "lifetype-", "", $v2 );
+			
 			return( version_compare( $v1, $v2 ));
 		}
+		
+		/**
+		 * Returns true if the given version is newer than the current one
+		 *
+		 * @param v1 The version that we'd like to compare to
+		 * @param v1 If specified, the version that we should check whether it's older than v1 or not.
+		 * If not specified, the current version will be used.
+		 * @return True if the given version is newer than the current one or false otherwise
+		 */
+		function isNewer( $v1, $v2 = "" )
+		{
+			if( $v2 == "" )
+				$v2 = Version::getVersion();
+				
+			return( Version::compare( $v2, $v1 ) == -1 );
+		}
     }
 ?>

Added: plog/branches/lifetype-1.2/class/test/tests/misc/version_test.class.php
===================================================================
--- plog/branches/lifetype-1.2/class/test/tests/misc/version_test.class.php	                        (rev 0)
+++ plog/branches/lifetype-1.2/class/test/tests/misc/version_test.class.php	2007-06-16 08:32:38 UTC (rev 5551)
@@ -0,0 +1,49 @@
+<?php
+
+	lt_include( PLOG_CLASS_PATH."class/test/helpers/lifetypetestcase.class.php" );
+	lt_include( PLOG_CLASS_PATH."class/misc/version.class.php" );	
+
+	/**
+	 * \ingroup Test
+	 *
+	 * Test cases for the Version class.
+	 */
+	class Version_Test extends LifeTypeTestCase
+	{
+		var $_data;
+		
+		function setUp()
+		{
+			$this->_data = Array(
+				Array( "lifetype-1.2.3", "1.2.4", -1 ),
+				Array( "lifetype-1.2.3", "1.3", -1 ),
+				Array( "1.2", "1.1.2", 1 ),
+				Array( "1.2.3", "lifetype-1.2.3", 0 ),		// they are the same
+				Array( "1.2.3-dev", "lifetype-1.2.3", -1 ),		// a stable release is always newer than the same number in "dev" mode
+				Array( "lifetype-1.2.3-dev", "lifetype-1.2.3", -1 ),
+				Array( "1.2.3-dev", "1.2.3", -1 ),
+				Array( "1.2.3", "1.2.3-dev", 1 ),
+				Array( "1.3-dev", "1.2.3-dev", 1 ),		// dev in 1.3 is newer than dev in 1.2.3
+				Array( "1.3-dev", "1.2.4", 1 )
+			);			
+		}
+		
+		function testVersionCompare()
+		{
+			foreach( $this->_data as $version ) {
+				$this->assertEquals( Version::compare( $version[0], $version[1] ), $version[2],
+				                     "Error comparing <b>$version[0]</b> with <b>$version[1]</b>" ); 
+			}
+		}
+		
+		function testIsNewer()
+		{
+			foreach( $this->_data as $version ) {
+				if( $version[2] == -1 ) 
+					$this->assertTrue( Version::isNewer( $version[1], $version[0] ));
+				else
+					$this->assertFalse( Version::isNewer( $version[1], $version[0] ));
+			}			
+		}
+	}
+?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/locale/admin/locale_en_UK.php
===================================================================
--- plog/branches/lifetype-1.2/locale/admin/locale_en_UK.php	2007-06-16 05:12:39 UTC (rev 5550)
+++ plog/branches/lifetype-1.2/locale/admin/locale_en_UK.php	2007-06-16 08:32:38 UTC (rev 5551)
@@ -1187,4 +1187,7 @@
 /// new strings for LT 1.2.4 ///
 $messages['plugin_latest_version'] = 'Most recent version available: ';
 $messages['check_versions'] = 'Check versions';
+$messages['lt_version_ok'] = 'The current version of Lifetype is up to date.';
+$messages['lt_version_error'] = 'The most recent version of Lifetype is: ';
+$messages['release_notes'] = 'Release notes';
 ?>
\ No newline at end of file

Modified: plog/branches/lifetype-1.2/templates/admin/versions.template
===================================================================
--- plog/branches/lifetype-1.2/templates/admin/versions.template	2007-06-16 05:12:39 UTC (rev 5550)
+++ plog/branches/lifetype-1.2/templates/admin/versions.template	2007-06-16 08:32:38 UTC (rev 5551)
@@ -11,6 +11,8 @@
    <span class="required"></span>
    <div class="formHelp">{$locale->tr("lifetype_version_help")}</div>
    <span style="font-weight:bold">{$version}</span>
+   <br/>	
+   <input type="submit" class="button" name="doLTVersionCheck" value="{$locale->tr("check")}" />
   </div>
 
   <div class="field">
@@ -19,7 +21,7 @@
    <div class="formHelp">{$locale->tr("file_version_check_help")}</div>
    <input type="submit" class="button" name="doFileVersionCheck" value="{$locale->tr("check")}" />
   </div>  
-  <input type="hidden" name="op" value="doFileVersionCheck" />
+  <input type="hidden" name="op" value="Versions" />
  </fieldset>
 </form>
 {include file="$admintemplatepath/footernavigation.template"}

Modified: plog/branches/lifetype-1.2/version.php
===================================================================
--- plog/branches/lifetype-1.2/version.php	2007-06-16 05:12:39 UTC (rev 5550)
+++ plog/branches/lifetype-1.2/version.php	2007-06-16 08:32:38 UTC (rev 5551)
@@ -1,3 +1,3 @@
 <?php
-$version = 'LIFETYPE_1_2_3_DEV';
+$version = 'lifetype-1.2.4-dev';
 ?>



More information about the pLog-svn mailing list