From a72e124ce0358ad802df83aa3c73359e85e60feb Mon Sep 17 00:00:00 2001 From: Nate Jones Date: Thu, 10 Jul 2014 07:15:51 +0000 Subject: [PATCH] Upgrade: Added SVN Update, handle Upgrade Data Types differently (still under construction...) --- core/upgrade/index.php | 74 ++++++++++++++++++++++------------- resources/schema.php | 87 ++++++++++++++++++++++-------------------- 2 files changed, 94 insertions(+), 67 deletions(-) diff --git a/core/upgrade/index.php b/core/upgrade/index.php index 01f218202a..3823040f42 100644 --- a/core/upgrade/index.php +++ b/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 "


"; echo "
\n"; -echo "\n"; if (permission_exists("upgrade_svn")) { + echo "
\n"; echo "\n"; echo " \n"; echo "\n"; + echo "
\n"; echo " SVN Update"; @@ -138,21 +136,39 @@ if (permission_exists("upgrade_svn")) { echo "
\n"; echo "
\n"; } if (permission_exists("upgrade_schema")) { + echo "\n"; echo "\n"; echo " \n"; echo " \n"; echo "\n"; + echo "
\n"; echo " Upgrade Schema"; echo " \n"; - echo " "; + echo " "; echo "
\n"; echo "
\n"; + + echo "\n"; } if (permission_exists("upgrade_domains")) { + echo "\n"; echo "\n"; echo " \n"; echo "\n"; -} - -if (permission_exists("upgrade_datatypes")) { - echo "\n"; - echo " \n"; - echo " \n"; - echo "\n"; + echo "
\n"; echo " Upgrade Domain(s)"; @@ -162,21 +178,11 @@ if (permission_exists("upgrade_domains")) { echo "
\n"; echo "
\n"; - echo " Syncronize Data Types"; - echo " \n"; - echo " "; - echo "
\n"; - echo "
\n"; } if (permission_exists("menu_restore")) { + echo "\n"; echo "\n"; echo " \n"; echo "\n"; + echo "
\n"; echo " Restore Menu Defaults"; @@ -184,7 +190,7 @@ if (permission_exists("menu_restore")) { echo " \n"; echo " "; echo "
"; - echo " "; + echo " "; echo " "; echo "
"; echo "
\n"; } if (permission_exists("group_edit")) { + echo "\n"; echo "\n"; echo " \n"; echo "\n"; + echo "
\n"; echo " Restore Permission Defaults"; @@ -212,19 +220,33 @@ if (permission_exists("group_edit")) { echo "
\n"; echo "
\n"; } +echo "\n"; echo "\n"; echo " \n"; echo "\n"; - - echo "
\n"; echo " \n"; echo "
\n"; + echo "
\n"; +// output result of svn update +if ($_SESSION["response_svn_update"] != '') { + echo "


"; + echo "".$text['header-svn_update_results'].""; + echo "

"; + echo "
";
+	echo implode("\n", $_SESSION["response_svn_update"]);
+	echo "
"; + echo "

"; + unset($_SESSION["response_svn_update"]); +} + + // output result of upgrade schema if ($_SESSION["response_upgrade_schema"] != '') { echo "


"; diff --git a/resources/schema.php b/resources/schema.php index f84d1f564e..94ce2f5047 100644 --- a/resources/schema.php +++ b/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)."
"; - $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)."
"; + $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 + 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); } - elseif ($field_type == "numeric" && $type[0] == "decimal") { - //do nothing + if ($db_type == "sqlite") { + //a change has been made to the field type + $apps[$x]['db'][$y]['rebuild'] = 'true'; } - else { - $sql_update .= "ALTER TABLE ".$table_name." modify ".$field_name." ".$field_type.";\n"; - } - unset($type); - } - if ($db_type == "sqlite") { - //a change has been made to the field type - $apps[$x]['db'][$y]['rebuild'] = 'true'; } } -*/ +// } } unset($column_array);