[Mapbender-commits] r2639 - branches/spsneo_dev/mapbender/update

svn_mapbender at osgeo.org svn_mapbender at osgeo.org
Thu Jul 10 03:38:08 EDT 2008


Author: spsneo
Date: 2008-07-10 03:38:08 -0400 (Thu, 10 Jul 2008)
New Revision: 2639

Added:
   branches/spsneo_dev/mapbender/update/update-utils.inc
Log:
Database Update Routine ready

Added: branches/spsneo_dev/mapbender/update/update-utils.inc
===================================================================
--- branches/spsneo_dev/mapbender/update/update-utils.inc	                        (rev 0)
+++ branches/spsneo_dev/mapbender/update/update-utils.inc	2008-07-10 07:38:08 UTC (rev 2639)
@@ -0,0 +1,128 @@
+<?php
+
+#@author Siddharth Prakash Singh (spsneo)
+#Google SoC 2008 Project
+#
+#This file checks the required version of php and database server
+#
+#
+#Constants defining the minimum Requirements.
+#These Constants to be filled in during the build process
+#
+#Lowest PHP version required to update 
+define("MIN_PHP_VERSION", "5.1.0");
+
+#Lowest Database Server version to upgrade
+#Lowest PostgreSQL server version allowed
+define("MIN_PGSQL_VERSION", "8.1.x");
+#Lowest MySQL Server version allowed
+define("MIN_MYSQL_VERSION", "4.8.x");
+
+
+
+#Function called from update.php
+#Checks the php version
+#Checks the Database version according to database type defined
+#in /conf/mapbender.conf file as SYS_DBTYPE
+function do_version_check() {
+	php_version_check();
+	db_version_check();
+}
+
+
+#This function called from do_version_check()
+#to check and compare the php version installed on user's system
+
+function php_version_check() {
+	# We dare not turn output buffer _off_ since this will break completely
+	# if PHP is globally configured to run through a gzip filter.
+	@ob_implicit_flush( true );
+
+	if( !function_exists( 'version_compare' ) ) {
+		# version_compare was introduced in 4.1.0
+		echo "PHP version installed is too old to upgrade Mapbender. PHP".MIN_PHP_VERSION." or greater is required.";
+		die( -1 );
+	}
+	
+	#comapres the current version with the minimun required
+	if( version_compare( phpversion(), MIN_PHP_VERSION ) < 0 ) {
+		
+		#Error message in case the older version of php is installed
+		echo "PHP version installed is too old to upgrade Mapbender. PHP".MIN_PHP_VERSION." or greater is required.";
+		die( -1 );
+	} else {
+		echo "Correct PHP version installed on your system\n";
+	}
+}
+
+#This function is called from do_version_check
+#to check and compare the database server version installed on user's system
+
+function db_version_check() {
+	
+	#Checks the database type as defined in /conf/mapbender.conf file.
+	#
+	#Database type mysql:
+	if(SYS_DBTYPE=="mysql") {
+		#split the version number by period (".")
+		$required_version = explode(".", MIN_MYSQL_VERSION);
+		#establish a connection to the mysql database server.
+		$conn = db_connect(DBSERVER,OWNER,PW);
+		#fetch the current version of mysql installed on user's system
+		$current_version = explode(".", mysql_get_server_info());
+		
+		#compares the required and current mysql version
+		#Compare the first digit of the version
+		#
+		#current version is smaller than the required version 
+		if ($current_version[0] < $required_version[0]) {
+			#die message
+			echo "MySQL version installed is too old to upgrade Mapbender. MySQL".MIN_MYSQL_VERSION." or greater is required.";
+			die(-1);
+			
+		# first digit of current version is equal to the first digit of required version
+		} else if ($current_version[0] == $required_version[0]) {
+			#check the second digit
+			#second digit : current version is smaller than the required version
+			if($current_version[1] < $required_version[1]) {
+				#die message
+				echo "MySQL version installed is too old to upgrade Mapbender. MySQL".MIN_MYSQL_VERSION." or greater is required.";
+				die(-1);
+			} else {
+				#Correct MySQL version
+				echo "Correct MySQL version installed on your system.\n";
+			} 
+		} else {
+			#Correct MySQL version
+			echo "Correct MySQL version installed on your system.\n";
+		}
+		
+	#Database type : PostgreSQL
+	} else if(SYS_DBTYPE=="pgsql") {
+		#split the version number by period
+		$required_version = explode(".", MIN_PGSQL_VERSION);
+		#establish a connection to the PostgreSQL Server
+		$conn = db_connect(DBSERVER,OWNER,PW);
+		#get the current version
+		$version = pg_version($conn);
+		$current_version = explode(".", $version['client']);
+		if ($current_version[0] < $required_version[0]) {
+			echo "PostGreSQL version installed is too old to upgrade Mapbender. PostGreSQL".MIN_PGSQL_VERSION." or greater is required.";
+			die(-1);
+		} else if ($current_version[0] == $required_version[0]) {
+			if($current_version[1] < $required_version[1]) {
+				echo "PostGreSQL version installed is too old to upgrade Mapbender. PostGreSQL".MIN_PGSQL_VERSION." or greater is required.";
+				die(-1);
+			} else {
+				echo "Correct PostgreSQL version installed on your system.\n";
+			}
+		} else {
+			echo "Correct PostgreSQL version installed on your system.\n";
+		}
+	} else {
+		echo "It seems the SYS_DBTYPE is not properly defined in /conf/mapbender.conf file.\nPlease check out the mapbender.conf file\n";
+		die(-1);
+	}
+}
+
+?>



More information about the Mapbender_commits mailing list