Kaynağa Gözat

Upgrade: Added SVN Update, handle Upgrade Data Types differently (still under construction...)

Nate Jones 11 yıl önce
ebeveyn
işleme
577fa823d4
2 değiştirilmiş dosya ile 89 ekleme ve 62 silme
  1. 43 21
      core/upgrade/index.php
  2. 46 41
      resources/schema.php

+ 43 - 21
core/upgrade/index.php

@@ -35,7 +35,6 @@ if (
 	!permission_exists('upgrade_svn') &&
 	!permission_exists('upgrade_schema') &&
 	!permission_exists('upgrade_domains') &&
-	!permission_exists('upgrade_datatypes') &&
 	!permission_exists('menu_restore') &&
 	!permission_exists('group_edit')
 	) {
@@ -49,7 +48,11 @@ if (sizeof($_POST) > 0) {
 
 	// run svn update
 	if ($do["svn"] && permission_exists("upgrade_svn")) {
-
+		$cmd = "svn up /var/www/fusionpbx";
+		exec($cmd, $response_svn_update);
+		if (sizeof($response_svn_update) > 0) {
+			$_SESSION["response_svn_update"] = $response_svn_update;
+		}
 		$response_message = "SVN Updated";
 	}
 
@@ -58,6 +61,7 @@ if (sizeof($_POST) > 0) {
 		$included = true;
 		$response_output = "return";
 		$response_format = "html";
+		$upgrade_data_types = (is_bool($_POST["do_datatypes"])) ? check_str($_POST["do_datatypes"]) : false;
 		require_once "core/upgrade/upgrade_schema.php";
 		if ($response_upgrade_schema != '') {
 			$_SESSION["response_upgrade_schema"] = $response_upgrade_schema;
@@ -76,15 +80,9 @@ if (sizeof($_POST) > 0) {
 		$response_message = "Domain(s) Upgraded";
 	}
 
-	// syncronize data types
-	if ($do["datatypes"] && permission_exists("upgrade_datatypes")) {
-
-		$response_message = "Data Types Syncronized";
-	}
-
 	// restore defaults of the selected menu
 	if ($do["menu"] && permission_exists("menu_restore")) {
-		$sel_menu = explode('|', $_POST["sel_menu"]);
+		$sel_menu = explode('|', check_str($_POST["sel_menu"]));
 		$menu_uuid = $sel_menu[0];
 		$menu_language = $sel_menu[1];
 		$included = true;
@@ -126,9 +124,9 @@ echo "Select the upgrade/update/restore actions below you wish to perform.";
 echo "<br><br><br>";
 
 echo "<form name='frm' method='post' action=''>\n";
-echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
 
 if (permission_exists("upgrade_svn")) {
+	echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
 	echo "<tr>\n";
 	echo "	<td width='30%' class='vncell'>\n";
 	echo "		SVN Update";
@@ -138,45 +136,53 @@ if (permission_exists("upgrade_svn")) {
 	echo "		<br />\n";
 	echo "	</td>\n";
 	echo "</tr>\n";
+	echo "</table>\n";
 }
 
 if (permission_exists("upgrade_schema")) {
+	echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
 	echo "<tr>\n";
 	echo "	<td width='30%' class='vncell'>\n";
 	echo "		Upgrade Schema";
 	echo "	</td>\n";
 	echo "	<td width='70%' class='vtable' style='height: 50px;'>\n";
-	echo "		<input type='checkbox' class='formfld' name='do[schema]' id='do_schema' value='1'>";
+	echo "		<input type='checkbox' class='formfld' name='do[schema]' id='do_schema' value='1' onchange=\"$('#do_datatypes').prop('checked', false); $('#tr_data_types').slideToggle('fast');\">";
 	echo "		<br />\n";
 	echo "	</td>\n";
 	echo "</tr>\n";
-}
+	echo "</table>\n";
 
-if (permission_exists("upgrade_domains")) {
+	echo "<div id='tr_data_types' style='display: none;'>\n";
+	echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
 	echo "<tr>\n";
 	echo "	<td width='30%' class='vncell'>\n";
-	echo "		Upgrade Domain(s)";
+	echo "		Upgrade Data Types";
 	echo "	</td>\n";
 	echo "	<td width='70%' class='vtable' style='height: 50px;'>\n";
-	echo "		<input type='checkbox' class='formfld' name='do[domains]' id='do_domains' value='1'>";
+	echo "		<input type='checkbox' class='formfld' name='do[datatypes]' id='do_datatypes' value='true'>";
 	echo "		<br />\n";
 	echo "	</td>\n";
 	echo "</tr>\n";
+	echo "</table>\n";
+	echo "</div>\n";
 }
 
-if (permission_exists("upgrade_datatypes")) {
+if (permission_exists("upgrade_domains")) {
+	echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
 	echo "<tr>\n";
 	echo "	<td width='30%' class='vncell'>\n";
-	echo "		Syncronize Data Types";
+	echo "		Upgrade Domain(s)";
 	echo "	</td>\n";
 	echo "	<td width='70%' class='vtable' style='height: 50px;'>\n";
-	echo "		<input type='checkbox' class='formfld' name='do[datatypes]' id='do_datatypes' value='1'>";
+	echo "		<input type='checkbox' class='formfld' name='do[domains]' id='do_domains' value='1'>";
 	echo "		<br />\n";
 	echo "	</td>\n";
 	echo "</tr>\n";
+	echo "</table>\n";
 }
 
 if (permission_exists("menu_restore")) {
+	echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
 	echo "<tr>\n";
 	echo "	<td width='30%' class='vncell'>\n";
 	echo "		Restore Menu Defaults";
@@ -184,7 +190,7 @@ if (permission_exists("menu_restore")) {
 	echo "	<td width='70%' class='vtable' style='height: 50px;'>\n";
 	echo "		<table cellpadding='0' cellspacing='0' border='0'>";
 	echo "			<tr><td>";
-	echo "				<input type='checkbox' class='formfld' name='do[menu]' id='do_menu' value='1' onclick=\"$('#sel_menu').fadeToggle('fast');\">";
+	echo "				<input type='checkbox' class='formfld' name='do[menu]' id='do_menu' value='1' onchange=\"$('#sel_menu').fadeToggle('fast');\">";
 	echo "			</td><td>";
 	echo "				<select name='sel_menu' id='sel_menu' class='formfld' style='display: none; margin-left: 15px;'>\n";
 		$sql = "select * from v_menus ";
@@ -200,9 +206,11 @@ if (permission_exists("menu_restore")) {
 	echo "		</table>";
 	echo "	</td>\n";
 	echo "</tr>\n";
+	echo "</table>\n";
 }
 
 if (permission_exists("group_edit")) {
+	echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
 	echo "<tr>\n";
 	echo "	<td width='30%' class='vncell'>\n";
 	echo "		Restore Permission Defaults";
@@ -212,19 +220,33 @@ if (permission_exists("group_edit")) {
 	echo "		<br />\n";
 	echo "	</td>\n";
 	echo "</tr>\n";
+	echo "</table>\n";
 }
 
+echo "<table width='100%'  border='0' cellpadding='6' cellspacing='0'>\n";
 echo "<tr>\n";
 echo "	<td colspan='2' style='text-align: right;'>\n";
 echo "		<input type='submit' class='btn' value='Execute'>\n";
 echo "	</td>\n";
 echo "</tr>\n";
-
-
 echo "</table>\n";
+
 echo "</form>\n";
 
 
+// output result of svn update
+if ($_SESSION["response_svn_update"] != '') {
+	echo "<br /><br /><br />";
+	echo "<b>".$text['header-svn_update_results']."</b>";
+	echo "<br /><br />";
+	echo "<pre>";
+	echo implode("\n", $_SESSION["response_svn_update"]);
+	echo "</pre>";
+	echo "<br /><br />";
+	unset($_SESSION["response_svn_update"]);
+}
+
+
 // output result of upgrade schema
 if ($_SESSION["response_upgrade_schema"] != '') {
 	echo "<br /><br /><br />";

+ 46 - 41
resources/schema.php

@@ -274,6 +274,10 @@ function db_insert_into ($apps, $db_type, $table) {
 function db_upgrade_schema ($db, $db_type, $db_name, $response_output) {
 	global $text; // pulls in language variable array
 	global $response_format;
+	global $upgrade_data_types;
+
+	// set default
+	if (!isset($upgrade_data_types)) { $upgrade_data_types = false; }
 
 	//PHP PDO check if table or column exists
 		//check if table exists
@@ -433,56 +437,57 @@ function db_upgrade_schema ($db, $db_type, $db_name, $response_output) {
 												}
 											}
 										}
-									//change the data type if it has been changed
+//									//change the data type if it has been changed
 										//if the data type in the app db array is different than the type in the database then change the data type
-/*
-										$db_field_type = db_column_data_type ($db, $db_type, $db_name, $table_name, $field_name);
-										$field_type_array = explode("(", $field_type);
-										$field_type = $field_type_array[0];
-										if (trim($db_field_type) != trim($field_type) && strlen($db_field_type) > 0) {
-											if ($db_type == "pgsql") {
-												if (strtolower($field_type) == "uuid") {
-													$sql_update .= "ALTER TABLE ".$table_name." ALTER COLUMN ".$field_name." TYPE uuid USING\n";
-													$sql_update .= "CAST(regexp_replace(".$field_name.", '([A-Z0-9]{4})([A-Z0-9]{12})', E'\\1-\\2')\n";
-													$sql_update .= "AS uuid);\n";
-												}
-												else {
-													if ($db_field_type = "integer" && strtolower($field_type) == "serial") {
-														//field type has not changed
-													} elseif ($db_field_type = "timestamp without time zone" && strtolower($field_type) == "timestamp") {
-														//field type has not changed
-													} elseif ($db_field_type = "timestamp without time zone" && strtolower($field_type) == "datetime") {
-														//field type has not changed
-													} elseif ($db_field_type = "integer" && strtolower($field_type) == "numeric") {
-														//field type has not changed
-													} elseif ($db_field_type = "character" && strtolower($field_type) == "char") {
-														//field type has not changed
+										if ($upgrade_data_types) {
+											$db_field_type = db_column_data_type ($db, $db_type, $db_name, $table_name, $field_name);
+											$field_type_array = explode("(", $field_type);
+											$field_type = $field_type_array[0];
+											if (trim($db_field_type) != trim($field_type) && strlen($db_field_type) > 0) {
+												if ($db_type == "pgsql") {
+													if (strtolower($field_type) == "uuid") {
+														$sql_update .= "ALTER TABLE ".$table_name." ALTER COLUMN ".$field_name." TYPE uuid USING\n";
+														$sql_update .= "CAST(regexp_replace(".$field_name.", '([A-Z0-9]{4})([A-Z0-9]{12})', E'\\1-\\2')\n";
+														$sql_update .= "AS uuid);\n";
 													}
 													else {
-														//$sql_update .= "-- $db_type, $db_name, $table_name, $field_name ".db_column_data_type ($db, $db_type, $db_name, $table_name, $field_name)."<br>";
-														$sql_update .= "ALTER TABLE ".$table_name." ALTER COLUMN ".$field_name." TYPE ".$field_type.";\n";
+														if ($db_field_type = "integer" && strtolower($field_type) == "serial") {
+															//field type has not changed
+														} elseif ($db_field_type = "timestamp without time zone" && strtolower($field_type) == "timestamp") {
+															//field type has not changed
+														} elseif ($db_field_type = "timestamp without time zone" && strtolower($field_type) == "datetime") {
+															//field type has not changed
+														} elseif ($db_field_type = "integer" && strtolower($field_type) == "numeric") {
+															//field type has not changed
+														} elseif ($db_field_type = "character" && strtolower($field_type) == "char") {
+															//field type has not changed
+														}
+														else {
+															//$sql_update .= "-- $db_type, $db_name, $table_name, $field_name ".db_column_data_type ($db, $db_type, $db_name, $table_name, $field_name)."<br>";
+															$sql_update .= "ALTER TABLE ".$table_name." ALTER COLUMN ".$field_name." TYPE ".$field_type.";\n";
+														}
 													}
 												}
-											}
-											if ($db_type == "mysql") {
-												$type = explode("(", $db_field_type);
-												if ($type[0] == $field_type) {
-													//do nothing
-												}
-												elseif ($field_type == "numeric" && $type[0] == "decimal") {
-													//do nothing
+												if ($db_type == "mysql") {
+													$type = explode("(", $db_field_type);
+													if ($type[0] == $field_type) {
+														//do nothing
+													}
+													elseif ($field_type == "numeric" && $type[0] == "decimal") {
+														//do nothing
+													}
+													else {
+														$sql_update .= "ALTER TABLE ".$table_name." modify ".$field_name." ".$field_type.";\n";
+													}
+													unset($type);
 												}
-												else {
-													$sql_update .= "ALTER TABLE ".$table_name." modify ".$field_name." ".$field_type.";\n";
+												if ($db_type == "sqlite") {
+													//a change has been made to the field type
+													$apps[$x]['db'][$y]['rebuild'] = 'true';
 												}
-												unset($type);
-											}
-											if ($db_type == "sqlite") {
-												//a change has been made to the field type
-												$apps[$x]['db'][$y]['rebuild'] = 'true';
 											}
 										}
-*/
+//
 								}
 							}
 							unset($column_array);