diff --git a/admin/install.php b/admin/install.php index 0669f881f2..6f57240f51 100644 --- a/admin/install.php +++ b/admin/install.php @@ -871,7 +871,20 @@ function print_test( $p_test_description, $p_result, $p_hard_fail = true, $p_mes $t_last_id = count( $g_upgrade ) - 1; $i = $t_last_update + 1; if( $f_log_queries ) { - echo ' Database Creation Suppressed, SQL Queries follow
';
+			echo 'Database Creation Suppressed, SQL Queries follow';
+
+			echo '
'; + echo '
'; + echo "Please note that executing the generated script below may not result in a fully functional " + . "database, particularly in upgrade scenarios. This is due to the fact that some upgrade " + . "steps require the execution of PHP code; these Upgrade Functions are defined in " + . 'install_helper_functions_api.php' + . " and cannot be translated to SQL statements. Use at your own risk."; + echo '
'; + + echo '
';
+			echo "-- MantisBT " . MANTIS_VERSION . " Database creation script". PHP_EOL;
+			echo "-- " . date("c") . PHP_EOL . PHP_EOL;
 		}
 
 		# Make sure we do the upgrades using UTF-8 if needed
@@ -1010,6 +1023,8 @@ function print_test( $p_test_description, $p_result, $p_hard_fail = true, $p_mes
 					break;
 
 				case null:
+					$t_sqlarray = array();
+					$t_sql = false;
 					# No-op upgrade step - required for oci8
 					break;
 
@@ -1029,17 +1044,38 @@ function print_test( $p_test_description, $p_result, $p_hard_fail = true, $p_mes
 					break;
 			}
 			if( $f_log_queries ) {
+				echo "-- Schema step $i" . PHP_EOL;
 				if( $t_sql ) {
-					foreach( $t_sqlarray as $t_sql ) {
+					foreach( $t_sqlarray as $t_statement ) {
 						# "CREATE OR REPLACE TRIGGER" statements must end with "END;\n/" for Oracle sqlplus
-						if( $f_db_type == 'oci8' && stripos( $t_sql, 'CREATE OR REPLACE TRIGGER' ) === 0 ) {
+						if( $f_db_type == 'oci8' && stripos( $t_statement, 'CREATE OR REPLACE TRIGGER' ) === 0 ) {
 							$t_sql_end = PHP_EOL . '/';
 						} else {
 							$t_sql_end = ';';
 						}
-						echo htmlentities( $t_sql ) . $t_sql_end . PHP_EOL . PHP_EOL;
+						echo htmlentities( $t_statement ) . $t_sql_end;
 					}
+				} elseif( $t_sqlarray ) {
+					echo "-- Execute PHP Update Function: install_" . htmlentities( $t_sqlarray[0] ) . "(";
+					# Convert the parameters array to a printable string
+					if( isset( $t_sqlarray[1] ) ) {
+						$t_params = array();
+						foreach( $t_sqlarray[1] as $t_param ) {
+							$t_value = var_export( $t_param, true );
+							if( is_array( $t_param ) ) {
+								# Remove unnecessary array keys, newlines and the trailing comma
+								$t_value = preg_replace( '/\s*[0-9]+ => /', ' ', $t_value );
+								$t_value = str_replace( ",\n", ' ', $t_value );
+							}
+							$t_params[] = $t_value;
+						}
+						echo htmlentities( implode( ', ', $t_params ) );
+					}
+					echo ")";
+				} else {
+					echo "-- No operation";
 				}
+				echo PHP_EOL . PHP_EOL;
 			} else {
 				echo 'Schema step ' . $i . ': ';
 				if( is_null( $g_upgrade[$i][0] ) ) {
@@ -1078,8 +1114,26 @@ function print_test( $p_test_description, $p_result, $p_hard_fail = true, $p_mes
 		}
 		if( $f_log_queries ) {
 			# add a query to set the database version
-			echo 'INSERT INTO ' . db_get_table( 'config' ) . ' ( value, type, access_reqd, config_id, project_id, user_id ) VALUES (\'' . $t_last_id . '\', 1, 90, \'database_version\', 0, 0 );' . PHP_EOL;
-			echo '

Your database has not been created yet. Please create the database, then install the tables and data using the information above before proceeding.

'; + echo "-- Set database version" . PHP_EOL; + if( $t_last_update == -1 ) { + echo "INSERT INTO " . db_get_table( 'config' ) + . " ( value, type, access_reqd, config_id, project_id, user_id )" + . " VALUES ($t_last_id, 1, 90, 'database_version', 0, 0 );" + . PHP_EOL; + } else { + echo "UPDATE " . db_get_table( 'config' ) + . " SET value = $t_last_id" + . " WHERE config_id = 'database_version' AND project_id = 0 AND user_id = 0;" + . PHP_EOL; + } + echo '
'; + + echo '
'; + echo '
'; + echo "Your database is not ready yet ! " + . "Please create it, then install the tables and data using the above script before proceeding."; + echo '
'; + echo ''; } } if( false == $g_failed ) { @@ -1407,12 +1461,17 @@ function print_test( $p_test_description, $p_result, $p_hard_fail = true, $p_mes + + SQL script generated successfully. + Use it to manually create or upgrade your database. + MantisBT was installed successfully. - + Continue to log in. Please log in as the administrator and create your first project. +