diff --git a/core/upgrade/app_config.php b/core/upgrade/app_config.php index fa6f3416df..f0bea8b381 100644 --- a/core/upgrade/app_config.php +++ b/core/upgrade/app_config.php @@ -1,12 +1,12 @@ + Portions created by the Initial Developer are Copyright (C) 2008-2012 + the Initial Developer. All Rights Reserved. + + Contributor(s): + Mark J Crane +*/ + +set_time_limit(600); //sec (10 min) + +include "root.php"; +require_once "resources/require.php"; +require_once "resources/check_auth.php"; + +//check the permission +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') + ) { + echo "access denied"; + exit; +} + +if (sizeof($_POST) > 0) { + + $do = $_POST['do']; + + // run svn update + if ($do["svn"] && permission_exists("upgrade_svn")) { + + $response_message[] = "SVN Updated"; + } + + // load the default database into memory and compare it with the active database + if ($do["schema"] && permission_exists("upgrade_schema")) { + $included = true; + $response_output = "return"; + $response_format = "html"; + require_once "core/upgrade/upgrade_schema.php"; + if ($response_upgrade_schema != '') { + $_SESSION["response_upgrade_schema"] = $response_upgrade_schema; + } + unset($apps); + $response_message[] = "Schema Upgraded"; + } + + // upgrade the domains + if ($do["domains"] && permission_exists("upgrade_domains")) { + $included = true; + $domain_language_code = $_SESSION['domain']['language']['code']; + require_once "core/upgrade/upgrade_domains.php"; + $_SESSION['domain']['language']['code'] = $domain_language_code; + unset($domain_language_code); + $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"]); + $menu_uuid = $sel_menu[0]; + $menu_language = $sel_menu[1]; + $included = true; + require_once("core/menu/menu_restore_default.php"); + unset($sel_menu); + $response_message[] = "Menu Restored"; + } + + // restore default permissions + if ($do["permissions"] && permission_exists("group_edit")) { + $included = true; + require_once("core/users/permissions_default.php"); + $response_message[] = "Permissions Restored"; + } + + $_SESSION["message"] = implode("
", $response_message); + header("Location: ".PROJECT_PATH."/core/upgrade/index.php"); + exit; + +} // if + + +//add multi-lingual support +require_once "app_languages.php"; +foreach($text as $key => $value) { + $text[$key] = $value[$_SESSION['domain']['language']['code']]; +} + +require_once "resources/header.php"; +$document['title'] = $text['title-upgrade']; + +//set defaults +$display_type = 'html'; + +echo "".$text['header-upgrade']."
"; +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"; +} + +if (permission_exists("upgrade_schema")) { + echo "\n"; + 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"; +} + +if (permission_exists("menu_restore")) { + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; +} + +if (permission_exists("group_edit")) { + echo "\n"; + echo " \n"; + echo " \n"; + echo "\n"; +} + +echo "\n"; +echo " \n"; +echo "\n"; + + +echo "
\n"; + echo " SVN Update"; + echo " \n"; + echo " "; + echo "
\n"; + echo "
\n"; + echo " Upgrade Schema"; + echo " \n"; + echo " "; + echo "
\n"; + echo "
\n"; + echo " Upgrade Domain(s)"; + echo " \n"; + echo " "; + echo "
\n"; + echo "
\n"; + echo " Syncronize Data Types"; + echo " \n"; + echo " "; + echo "
\n"; + echo "
\n"; + echo " Restore Menu Defaults"; + echo " \n"; + echo " "; + echo " "; + echo "
"; + echo " "; + echo " "; + echo " \n"; + echo "
"; + echo "
\n"; + echo " Restore Permission Defaults"; + echo " \n"; + echo " "; + echo "
\n"; + echo "
\n"; +echo " \n"; +echo "
\n"; +echo "
\n"; + + +// output result of upgrade schema +if ($_SESSION["response_upgrade_schema"] != '') { + echo "


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

"; + echo $_SESSION["response_upgrade_schema"]; + unset($_SESSION["response_upgrade_schema"]); +} + +require_once "resources/footer.php"; +?> \ No newline at end of file diff --git a/core/upgrade/upgrade.php b/core/upgrade/upgrade.php index d90c203ee9..e10d2f8ecd 100644 --- a/core/upgrade/upgrade.php +++ b/core/upgrade/upgrade.php @@ -32,7 +32,7 @@ set_include_path($document_root); require_once "resources/require.php"; $_SERVER["DOCUMENT_ROOT"] = $document_root; - $display_type = 'text'; //html, text + $response_format = 'text'; //html, text //add multi-lingual support require_once "app_languages.php"; @@ -61,16 +61,16 @@ } //set the default - if (!isset($display_results)) { - $display_results = false; + if (!isset($response_output)) { + $response_output = "echo"; } //include the header - if ($display_results) { + if ($response_output == "echo") { require_once "resources/header.php"; } -if ($display_type == 'text') { +if ($response_format == 'text') { echo "\n"; echo $text['label-upgrade']."\n"; echo "-----------------------------------------\n"; @@ -82,7 +82,7 @@ if ($display_type == 'text') { require_once "core/upgrade/upgrade_schema.php"; //show the content - if ($display_type == 'html') { + if ($response_format == 'html') { echo "
\n"; echo "\n"; echo "\n"; @@ -102,12 +102,12 @@ if ($display_type == 'text') { echo "
\n"; echo "
\n"; } - elseif ($display_type == 'text') { + elseif ($response_format == 'text') { echo "\n"; } //include the footer - if ($display_results) { + if ($response_output == "echo") { require_once "resources/footer.php"; } ?> \ No newline at end of file diff --git a/core/upgrade/upgrade_domains.php b/core/upgrade/upgrade_domains.php index ed724b62c2..dadcf6c935 100644 --- a/core/upgrade/upgrade_domains.php +++ b/core/upgrade/upgrade_domains.php @@ -24,6 +24,9 @@ Mark J Crane */ +// set included, if not + if (!isset($included)) { $included = false; } + //check the permission if(defined('STDIN')) { $document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]); @@ -34,7 +37,7 @@ $_SERVER["DOCUMENT_ROOT"] = $document_root; $display_type = 'text'; //html, text } - else { + else if (!$included) { include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; diff --git a/core/upgrade/upgrade_schema.php b/core/upgrade/upgrade_schema.php index 812a4ac91e..f1b5a64791 100644 --- a/core/upgrade/upgrade_schema.php +++ b/core/upgrade/upgrade_schema.php @@ -24,6 +24,10 @@ Mark J Crane */ +// set included, if not + if (!isset($included)) { $included = false; } + + //check the permission if(defined('STDIN')) { $document_root = str_replace("\\", "/", $_SERVER["PHP_SELF"]); @@ -32,15 +36,9 @@ set_include_path($document_root); require_once "resources/require.php"; $_SERVER["DOCUMENT_ROOT"] = $document_root; - $display_type = 'text'; //html, text - - //add multi-lingual support - require_once "app_languages.php"; - foreach($text as $key => $value) { - $text[$key] = $value[$_SESSION['domain']['language']['code']]; - } + $response_format = 'text'; //html, text } - else { + else if (!$included) { include "root.php"; require_once "resources/require.php"; require_once "resources/check_auth.php"; @@ -52,35 +50,33 @@ exit; } - //add multi-lingual support - require_once "app_languages.php"; - foreach($text as $key => $value) { - $text[$key] = $value[$_SESSION['domain']['language']['code']]; - } - require_once "resources/header.php"; $document['title'] = $text['title-upgrade_schema']; - $display_type = 'html'; //html, text + $response_format = 'html'; //html, text } -//set the default - if (!isset($display_results)) { - $display_results = true; + +//add multi-lingual support + require_once "app_languages.php"; + foreach($text as $key => $value) { + $text[$key] = $value[$_SESSION['domain']['language']['code']]; } + +//set the default + if (!isset($response_output)) { + $response_output = "echo"; + } + + //load the default database into memory and compare it with the active database require_once "resources/schema.php"; - db_upgrade_schema ($db, $db_type, $db_name, $display_results); + $response_upgrade_schema = db_upgrade_schema($db, $db_type, $db_name, $response_output); unset($apps); -//upgrade the domains - $domain_language_code = $_SESSION['domain']['language']['code']; - require_once "core/upgrade/upgrade_domains.php"; - $_SESSION['domain']['language']['code'] = $domain_language_code; - unset($domain_language_code); -if ($display_results && $display_type == "html") { +if (!$included && $response_output == 'echo' && $response_format == 'html') { echo "
\n"; echo "
\n"; require_once "resources/footer.php"; diff --git a/resources/schema.php b/resources/schema.php index d5d2c3c5ae..f84d1f564e 100644 --- a/resources/schema.php +++ b/resources/schema.php @@ -271,9 +271,9 @@ function db_insert_into ($apps, $db_type, $table) { } } -function db_upgrade_schema ($db, $db_type, $db_name, $display_results) { +function db_upgrade_schema ($db, $db_type, $db_name, $response_output) { global $text; // pulls in language variable array - global $display_type; + global $response_format; //PHP PDO check if table or column exists //check if table exists @@ -289,7 +289,7 @@ function db_upgrade_schema ($db, $db_type, $db_name, $display_results) { //check if table exists // SELECT * FROM pg_tables WHERE schemaname='public' AND table_name = 'v_groups' //check if column exists - // SELECT attname FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'v_cdr') AND attname = 'caller_id_name'; + // SELECT attname FROM pg_attribute WHERE attrelid = (SELECT oid FROM pg_class WHERE relname = 'v_cdr') AND attname = 'caller_id_name'; //mysql //list all tables in the database // SELECT TABLE_NAME FROM information_schema.tables WHERE table_schema = 'fusionpbx' @@ -523,31 +523,35 @@ function db_upgrade_schema ($db, $db_type, $db_name, $display_results) { } } } + + // initialize response variable + $response = ''; + //display results as html - if ($display_results && $display_type == "html") { + if ($response_output != '' && $response_format == "html") { //show the database type - echo "".$text['header-database_type'].": ".$db_type. "

"; + $response .= "".$text['header-database_type'].": ".$db_type. "

"; //start the table - echo "
\n"; + $response .= "
\n"; //show the changes if (strlen($sql_update) > 0) { - echo "\n"; - echo "\n"; - echo "\n"; + $response .= "\n"; + $response .= "\n"; + $response .= "\n"; } //list all tables - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + $response .= "\n"; + $response .= "\n"; + $response .= "\n"; + $response .= "\n"; + $response .= "\n"; //build the html while looping through the app db array $sql = ''; foreach ($apps as &$app) { @@ -558,22 +562,22 @@ function db_upgrade_schema ($db, $db_type, $db_name, $display_results) { else { $table_name = $row['table']; } - echo "\n"; + $response .= "\n"; //check if the table exists if ($row['exists'] == "true") { - echo "\n"; - echo "\n"; + $response .= "\n"; + $response .= "\n"; if (count($row['fields']) > 0) { - echo "\n"; + $response .= "
\n"; - echo "
\n"; - echo "".$text['label-sql_changes'].":
\n"; - echo "
\n";
-					echo $sql_update;
-					echo "
\n"; - echo "
\n"; - echo "
\n"; + $response .= "
\n"; + $response .= "".$text['label-sql_changes'].":
\n"; + $response .= "
\n";
+					$response .= $sql_update;
+					$response .= "
\n"; + $response .= "
\n"; + $response .= "
".$text['label-table']."".$text['label-exists']."".$text['label-details']."
".$text['label-table']."".$text['label-exists']."".$text['label-details']."
".$table_name."".$text['option-true']."".$table_name."".$text['option-true']."\n"; + $response .= "\n"; //show the list of columns - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; - echo "\n"; + $response .= "
".$text['label-name']."".$text['label-type']."".$text['label-exists']."
\n"; + $response .= "\n"; + $response .= "\n"; + $response .= "\n"; + $response .= "\n"; + $response .= "\n"; foreach ($row['fields'] as $field) { if ($field['deprecated'] == "true") { //skip this field @@ -591,47 +595,48 @@ function db_upgrade_schema ($db, $db_type, $db_name, $display_results) { else { $field_type = $field['type']; } - echo "\n"; - echo "\n"; - echo "\n"; + $response .= "\n"; + $response .= "\n"; + $response .= "\n"; if ($field['exists'] == "true") { - echo "\n"; - echo "\n"; + $response .= "\n"; + $response .= "\n"; } else { - echo "\n"; - echo "\n"; + $response .= "\n"; + $response .= "\n"; } - echo "\n"; + $response .= "\n"; } } unset($column_array); - echo "
".$text['label-name']."".$text['label-type']."".$text['label-exists']."
".$field_name."".$field_type."
".$field_name."".$field_type."".$text['option-true']." ".$text['option-true']." ".$text['option-false']." ".$text['option-false']." 
\n"; - echo "
\n"; + $response .= "\n"; } } else { - echo "$table_name\n"; - echo "".$text['label-exists']."
".$text['option-false']."\n"; - echo " \n"; + $response .= "$table_name\n"; + $response .= "".$text['label-exists']."
".$text['option-false']."\n"; + $response .= " \n"; } - echo "\n"; + $response .= "\n"; } } unset ($prep_statement); //end the list of tables - echo "\n"; - echo "
\n"; + $response .= "\n"; + $response .= "
\n"; + } //loop line by line through all the lines of sql code $x = 0; - if (strlen($sql_update) == 0 && $display_type == "text") { - echo " ".$text['label-schema'].": ".$text['label-no_change']."\n"; + if (strlen($sql_update) == 0 && $response_format == "text") { + $response .= " ".$text['label-schema'].": ".$text['label-no_change']."\n"; } else { - if ($display_type == "text") { - echo " ".$text['label-schema'].":\n"; + if ($response_format == "text") { + $response .= " ".$text['label-schema'].":\n"; } //$db->beginTransaction(); $update_array = explode(";", $sql_update); @@ -639,22 +644,31 @@ function db_upgrade_schema ($db, $db_type, $db_name, $display_results) { if (strlen(trim($sql))) { try { $db->query(trim($sql)); - if ($display_type == "text") { - echo " $sql\n"; + if ($response_format == "text") { + $response .= " $sql\n"; } } catch (PDOException $error) { - if ($display_results) { - echo " error: " . $error->getMessage() . " sql: $sql
"; + if ($response_output != '') { + $response .= " error: " . $error->getMessage() . " sql: $sql
"; } } } } //$db->commit(); - echo "\n"; + $response .= "\n"; unset ($file_contents, $sql_update, $sql); } + + //handle response + if ($response_output == "echo") { + echo $response; + } + else if ($response_output == "return") { + return $response; + } + } //end function ?> \ No newline at end of file