浏览代码

db_create not create_db

corrected version detection
corrected constant
Matthew Vale 9 年之前
父节点
当前提交
10f35418f7

+ 1 - 1
core/install/resources/classes/detect_switch.php

@@ -125,7 +125,7 @@ require_once "resources/classes/EventSocket.php";
 				throw new Exception('Failed to use event socket');
 			}
 			$FS_Version = $this->event_socket_request('api version');
-			preg_match("/FreeSWITCH Version (\d+)\.(\d+)\.(\d(?:\.\d+)?)$/", $FS_Version, $matches);
+			preg_match("/FreeSWITCH Version (\d+)\.(\d+)\.(\d+(?:\.\d+)?)/", $FS_Version, $matches);
 			$this->_major = $matches[1];
 			$this->_minor = $matches[2];
 			$this->_build = $matches[3];

+ 113 - 114
core/install/resources/classes/install_fusionpbx.php

@@ -232,140 +232,139 @@ include "root.php";
 		}
 
 		protected function create_database_sqlite() {
-			//sqlite database will be created when the config.php is loaded and only if the database file does not exist
-				try {
-					$this->dbh = new PDO('sqlite:'.$this->db_path.'/'.$this->db_name); //sqlite 3
-					//$this->dbh = new PDO('sqlite::memory:'); //sqlite 3
-				}
-				catch (PDOException $error) {
-					throw Exception("Failed to create database: " . $error->getMessage());
-				}
+		//sqlite database will be created when the config.php is loaded and only if the database file does not exist
+			try {
+				$this->dbh = new PDO('sqlite:'.$this->db_path.'/'.$this->db_name); //sqlite 3
+				//$this->dbh = new PDO('sqlite::memory:'); //sqlite 3
+			}
+			catch (PDOException $error) {
+				throw Exception("Failed to create database: " . $error->getMessage());
+			}
 
-			//add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
-				if (!function_exists('php_now')) {
-					function php_now() {
-						if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
-							@date_default_timezone_set(@date_default_timezone_get());
-						}
-						return date("Y-m-d H:i:s");
+		//add additional functions to SQLite - bool PDO::sqliteCreateFunction ( string function_name, callback callback [, int num_args] )
+			if (!function_exists('php_now')) {
+				function php_now() {
+					if(function_exists("date_default_timezone_set") and function_exists("date_default_timezone_get")) {
+						@date_default_timezone_set(@date_default_timezone_get());
 					}
+					return date("Y-m-d H:i:s");
 				}
-				$this->dbh->sqliteCreateFunction('now', 'php_now', 0);
-
-			//add the database structure
-				require_once "resources/classes/schema.php";
-				$schema = new schema;
-				$schema->db = $this->dbh;
-				$schema->db_type = $this->db_type;
-				$schema->sql();
-				$schema->exec();
-
-			//get the contents of the sql file
-				if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){
-					$filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql";
+			}
+			$this->dbh->sqliteCreateFunction('now', 'php_now', 0);
+
+		//add the database structure
+			require_once "resources/classes/schema.php";
+			$schema = new schema;
+			$schema->db = $this->dbh;
+			$schema->db_type = $this->db_type;
+			$schema->sql();
+			$schema->exec();
+
+		//get the contents of the sql file
+			if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql')){
+				$filename = "/usr/share/examples/fusionpbx/resources/install/sql/sqlite.sql";
+			}
+			else {
+				$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
+			}
+			$file_contents = file_get_contents($filename);
+			unset($filename);
+
+		//replace \r\n with \n then explode on \n
+			$file_contents = str_replace("\r\n", "\n", $file_contents);
+
+		//loop line by line through all the lines of sql code
+			$this->dbh->beginTransaction();
+			$string_array = explode("\n", $file_contents);
+			$x = 0;
+			foreach($string_array as $sql) {
+				try {
+					$this->dbh->query($sql);
 				}
-				else {
-					$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/sqlite.sql';
+				catch (PDOException $error) {
+							throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
 				}
-				$file_contents = file_get_contents($filename);
-				unset($filename);
+				$x++;
+			}
+			unset ($file_contents, $sql);
+			$this->dbh->commit();
 
-			//replace \r\n with \n then explode on \n
-				$file_contents = str_replace("\r\n", "\n", $file_contents);
+		//set the file permissions
+			chmod($this->db_path.'/'.$this->db_name, 0777);
+		}
 
-			//loop line by line through all the lines of sql code
-				$this->dbh->beginTransaction();
-				$string_array = explode("\n", $file_contents);
-				$x = 0;
-				foreach($string_array as $sql) {
-					try {
-						$this->dbh->query($sql);
-					}
-					catch (PDOException $error) {
-								throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
+		protected function create_database_pgsql() {
+			if ($this->db_create_option == 'user') {
+			//Attempt to create new PG role and database
+				try {
+					if (strlen($this->db_port) == 0) { $this->db_port = "5432"; }
+					if (strlen($this->db_host) > 0) {
+						$this->dbh = new PDO("pgsql:host={$this->db_host} port={$this->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1");
+					} else {
+						$this->dbh = new PDO("pgsql:host=localhost port={$this->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1");
 					}
-					$x++;
+				} catch (PDOException $error) {
+					throw new Exception("error connecting to database in order to create: " . $error->getMessage());
 				}
-				unset ($file_contents, $sql);
-				$this->dbh->commit();
 
-			//set the file permissions
-				chmod($this->db_path.'/'.$this->db_name, 0777);
-		}
+				//create the database, user, grant perms
+				$this->dbh->exec("CREATE DATABASE {$this->db_name}");
+				$this->dbh->exec("CREATE USER {$this->db_username} WITH PASSWORD '{$this->db_password}'");
+				$this->dbh->exec("GRANT ALL ON {$this->db_name} TO {$this->db_username}");
 
-		protected function create_database_pgsql() {
+				//close database connection_aborted
+				$this->dbh = null;
+			}
 
-					if ($this->db_create_option == 'user') {
-					//Attempt to create new PG role and database
-						try {
-							if (strlen($this->db_port) == 0) { $this->db_port = "5432"; }
-							if (strlen($this->db_host) > 0) {
-								$this->dbh = new PDO("pgsql:host={$this->db_host} port={$this->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1");
-							} else {
-								$this->dbh = new PDO("pgsql:host=localhost port={$this->db_port} user={$this->db_create_username} password={$this->db_create_password} dbname=template1");
-							}
-						} catch (PDOException $error) {
-							throw new Exception("error connecting to database in order to create: " . $error->getMessage());
-						}
+		//open database connection with $this->db_name
+			try {
+				if (strlen($this->db_port) == 0) { $this->db_port = "5432"; }
+				if (strlen($this->db_host) > 0) {
+					$this->dbh = new PDO("pgsql:host={$this->db_host} port={$this->db_port} dbname={$this->db_name} user={$this->db_username} password={$this->db_password}");
+				} else {
+					$this->dbh = new PDO("pgsql:host=localhost port={$this->db_port} user={$this->db_username} password={$this->db_password} dbname={$this->db_name}");
+				}
+			}
+			catch (PDOException $error) {
+				throw new Exception("error connecting to database: " . $error->getMessage());
+			}
 
-						//create the database, user, grant perms
-						$this->dbh->exec("CREATE DATABASE {$this->db_name}");
-						$this->dbh->exec("CREATE USER {$this->db_username} WITH PASSWORD '{$this->db_password}'");
-						$this->dbh->exec("GRANT ALL ON {$this->db_name} TO {$this->db_username}");
+		//add the database structure
+			require_once "resources/classes/schema.php";
+			$schema = new schema;
+			$schema->db = $this->dbh;
+			$schema->db_type = $this->db_type;
+			$schema->sql();
+			$schema->exec();
+
+		//get the contents of the sql file
+			if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql')){
+				$filename = "/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql";
+			}
+			else {
+			$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql';
+			}
+			$file_contents = file_get_contents($filename);
 
-						//close database connection_aborted
-						$this->dbh = null;
-					}
+		//replace \r\n with \n then explode on \n
+			$file_contents = str_replace("\r\n", "\n", $file_contents);
 
-				//open database connection with $this->db_name
+		//loop line by line through all the lines of sql code
+			$string_array = explode("\n", $file_contents);
+			$x = 0;
+			foreach($string_array as $sql) {
+				if (strlen($sql) > 3) {
 					try {
-						if (strlen($this->db_port) == 0) { $this->db_port = "5432"; }
-						if (strlen($this->db_host) > 0) {
-							$this->dbh = new PDO("pgsql:host={$this->db_host} port={$this->db_port} dbname={$this->db_name} user={$this->db_username} password={$this->db_password}");
-						} else {
-							$this->dbh = new PDO("pgsql:host=localhost port={$this->db_port} user={$this->db_username} password={$this->db_password} dbname={$this->db_name}");
-						}
+						$this->dbh->query($sql);
 					}
 					catch (PDOException $error) {
-						throw new Exception("error connecting to database: " . $error->getMessage());
-					}
-
-				//add the database structure
-					require_once "resources/classes/schema.php";
-					$schema = new schema;
-					$schema->db = $this->dbh;
-					$schema->db_type = $this->db_type;
-					$schema->sql();
-					$schema->exec();
-
-				//get the contents of the sql file
-					if (file_exists('/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql')){
-						$filename = "/usr/share/examples/fusionpbx/resources/install/sql/pgsql.sql";
+						throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
 					}
-					else {
-					$filename = $_SERVER["DOCUMENT_ROOT"].PROJECT_PATH.'/resources/install/sql/pgsql.sql';
-					}
-					$file_contents = file_get_contents($filename);
-
-				//replace \r\n with \n then explode on \n
-					$file_contents = str_replace("\r\n", "\n", $file_contents);
-
-				//loop line by line through all the lines of sql code
-					$string_array = explode("\n", $file_contents);
-					$x = 0;
-					foreach($string_array as $sql) {
-						if (strlen($sql) > 3) {
-							try {
-								$this->dbh->query($sql);
-							}
-							catch (PDOException $error) {
-								throw new Exception("error creating database: " . $error->getMessage() . "\n" . $sql );
-							}
-						}
-						$x++;
-					}
-					unset ($file_contents, $sql);
+				}
+				$x++;
 			}
+			unset ($file_contents, $sql);
+		}
 
 		protected function create_database_mysql() {
 				//database connection

+ 3 - 3
core/install/resources/page_parts/install_config_database.php

@@ -242,13 +242,13 @@
 		echo "		Create Database Options\n";
 		echo "</td>\n";
 		echo "<td class='vtable' align='left'>\n";
-		echo "	<label class='radio'><input type='radio' name='create_db_option' value='none'";
+		echo "	<label class='radio'><input type='radio' name='db_create_option' value='none'";
 		if($db_create_option=='none') { echo " checked='checked'"; }
 		echo "/>Do not create database</label>\n";
-		echo "	<label class='radio'><input type='radio' name='create_db_option' value='same'";
+		echo "	<label class='radio'><input type='radio' name='db_create_option' value='same'";
 		if($db_create_option=='same') { echo " checked='checked'"; }
 		echo "/>Create database using above username/password</label>\n";
-		echo "	<label class='radio'><input type='radio' name='create_db_option' value='user'";
+		echo "	<label class='radio'><input type='radio' name='db_create_option' value='user'";
 		if($db_create_option=='user') { echo " checked='checked'"; }
 		echo "/>Create database using below username/password</label>\n";
 		echo "<br />\n";

+ 1 - 1
resources/functions.php

@@ -602,7 +602,7 @@
 
 	if ( !function_exists('normalize_path')) {
 		function normalize_path($path) {
-			return str_replace(DIRECTORY_SEPERATOR, '\\', $path);
+			return str_replace(DIRECTORY_SEPARATOR, '\\', $path);
 		}
 	}