From 305089d1a981517a2088764dbcf849e860c4d4ad Mon Sep 17 00:00:00 2001 From: Mohammad Zubair Ali Date: Mon, 3 Jun 2024 15:57:55 +0530 Subject: [PATCH] fixed migration issue for new users --- mlw_quizmaster2.php | 8 +- php/admin/functions.php | 33 +-- php/classes/class-qmn-quiz-manager.php | 8 +- php/classes/class-qsm-install.php | 251 +++++++++++----------- php/question-types/qsm-question-title.php | 2 +- 5 files changed, 160 insertions(+), 142 deletions(-) diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index d64b51bab..4707a7f02 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -187,7 +187,7 @@ public function qsm_is_admin( $check_permission = 'manage_options' ) { */ public function get_failed_alter_table_queries() { $failed_queries = get_option( 'qmn_failed_alter_table_queries', array() ); - return is_array( $failed_queries ) ? $failed_queries: array(); + return is_array( $failed_queries ) ? $failed_queries : array(); } /** @@ -226,9 +226,9 @@ public function wpdb_alter_table_query( $query ) { update_option( 'qmn_failed_alter_table_queries', $failed_queries ); } return true; - } else if ( empty( $failed_queries ) || ! in_array( $query, $failed_queries ) ) { + } elseif ( empty( $failed_queries ) || ! in_array( $query, $failed_queries ) ) { // Add query to the list. - $failed_queries[] = $query; + $failed_queries[] = $query; // Update failed queries list. update_option( 'qmn_failed_alter_table_queries', $failed_queries ); } @@ -722,7 +722,7 @@ public function setup_admin_menu() { add_submenu_page( 'qsm_dashboard', __( 'Results', 'quiz-master-next' ), __( 'Results', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_results', 'qsm_generate_admin_results_page' ); // Failed Submission. - add_submenu_page( 'qsm_dashboard', __( 'Failed Submission', 'quiz-master-next' ), __( 'Failed Submission', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_failed_submission', array( $this,'admin_failed_submission_page' ) ); + add_submenu_page( 'qsm_dashboard', __( 'Failed Submission', 'quiz-master-next' ), __( 'Failed Submission', 'quiz-master-next' ), 'moderate_comments', 'mlw_quiz_failed_submission', array( $this, 'admin_failed_submission_page' ) ); add_submenu_page( 'options.php', __( 'Result Details', 'quiz-master-next' ), __( 'Result Details', 'quiz-master-next' ), 'moderate_comments', 'qsm_quiz_result_details', 'qsm_generate_result_details' ); add_submenu_page( 'qsm_dashboard', __( 'Settings', 'quiz-master-next' ), __( 'Settings', 'quiz-master-next' ), 'manage_options', 'qmn_global_settings', array( 'QMNGlobalSettingsPage', 'display_page' ) ); diff --git a/php/admin/functions.php b/php/admin/functions.php index 1f169d5fc..991f8b8ce 100644 --- a/php/admin/functions.php +++ b/php/admin/functions.php @@ -83,7 +83,7 @@ function qsm_add_author_column_in_db() { } } - update_option( 'qsm_update_db_column', '1' ); + update_option( 'qsm_update_db_column', 1 ); } // Update result db @@ -97,10 +97,11 @@ function qsm_add_author_column_in_db() { ); if ( empty( $table_result_col_obj ) ) { if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $result_table_name ADD form_type INT NOT NULL" ) ) { - update_option( 'qsm_update_result_db_column', '1' ); } else { $mlwQuizMasterNext->log_manager->add( 'Error Creating Column form_type in' . $result_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); } + }else { + update_option( 'qsm_update_result_db_column', 1 ); } } @@ -119,10 +120,12 @@ function qsm_add_author_column_in_db() { ); if ( ! empty( $table_quiz_col_obj ) ) { if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $quiz_table_name CHANGE `system` `quiz_system` INT(11) NOT NULL;" ) ) { - update_option( 'qsm_update_quiz_db_column', '1' ); + update_option( 'qsm_update_quiz_db_column', 1 ); } else { $mlwQuizMasterNext->log_manager->add( 'Error Changing Columns system,quiz_system in' . $quiz_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); } + }else { + update_option( 'qsm_update_quiz_db_column', 1 ); } } @@ -141,10 +144,12 @@ function qsm_add_author_column_in_db() { ); if ( isset( $table_quiz_result_obj['DATA_TYPE'] ) && 'text' === $table_quiz_result_obj['DATA_TYPE'] ) { if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $result_table_name CHANGE `quiz_results` `quiz_results` LONGTEXT;" ) ) { - update_option( 'qsm_update_result_db_column_datatype', '1' ); + update_option( 'qsm_update_result_db_column_datatype', 1 ); } else { $mlwQuizMasterNext->log_manager->add( 'Error Changing Columns quiz_results in' . $result_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); } + }else { + update_option( 'qsm_update_result_db_column_datatype', 1 ); } } @@ -153,8 +158,7 @@ function qsm_add_author_column_in_db() { * * @since 7.0.3 */ - if ( get_option( 'qsm_add_new_column_question_table_table', '1' ) <= 3 ) { - $total_count_val = get_option( 'qsm_add_new_column_question_table_table', '1' ); + if ( 1 !== intval( get_option( 'qsm_add_new_column_question_table_table', '' ) ) ) { global $wpdb; $question_table_name = $wpdb->prefix . 'mlw_questions'; $table_result_col_obj = $wpdb->get_results( @@ -164,11 +168,12 @@ function qsm_add_author_column_in_db() { ); if ( empty( $table_result_col_obj ) ) { if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $question_table_name ADD deleted_question_bank INT NOT NULL" ) ) { - $inc_val = $total_count_val + 1; - update_option( 'qsm_add_new_column_question_table_table', $inc_val ); + update_option( 'qsm_add_new_column_question_table_table', 1); } else { $mlwQuizMasterNext->log_manager->add( 'Error Creating Columns deleted_question_bank in' . $question_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); } + }else { + update_option( 'qsm_add_new_column_question_table_table', 1); } } /** @@ -176,7 +181,7 @@ function qsm_add_author_column_in_db() { * * @since 7.3.7 */ - if ( get_option( 'qsm_update_result_db_column_page_url', '' ) != '1' ) { + if ( 1 !== intval( get_option( 'qsm_update_result_db_column_page_url', '' ) ) ) { global $wpdb; $result_table_name = $wpdb->prefix . 'mlw_results'; $table_result_col_obj = $wpdb->get_results( @@ -186,11 +191,13 @@ function qsm_add_author_column_in_db() { ); if ( empty( $table_result_col_obj ) ) { if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $result_table_name ADD page_url varchar(255) NOT NULL" ) ) { - update_option( 'qsm_update_result_db_column_page_url', '1' ); + update_option( 'qsm_update_result_db_column_page_url', 1 ); } else { $error = $wpdb->last_error; $mlwQuizMasterNext->log_manager->add( "Error Creating Column page_url in {$result_table_name}", "Tried {$wpdb->last_query} but got {$error}.", 0, 'error' ); } + }else { + update_option( 'qsm_update_result_db_column_page_url', 1 ); } } @@ -199,7 +206,7 @@ function qsm_add_author_column_in_db() { * * @since 7.3.7 */ - if ( get_option( 'qsm_update_result_db_column_page_name', '' ) != '1' ) { + if ( 1 !== intval( get_option( 'qsm_update_result_db_column_page_name', '' ) ) ) { global $wpdb; $result_table_name = $wpdb->prefix . 'mlw_results'; $table_result_col_obj = $wpdb->get_results( @@ -209,10 +216,12 @@ function qsm_add_author_column_in_db() { ); if ( empty( $table_result_col_obj ) ) { if ( $mlwQuizMasterNext->wpdb_alter_table_query( "ALTER TABLE $result_table_name ADD page_name varchar(255) NOT NULL" ) ) { - update_option( 'qsm_update_result_db_column_page_name', '1' ); + update_option( 'qsm_update_result_db_column_page_name', 1 ); } else { $mlwQuizMasterNext->log_manager->add( 'Error Creating Column page_name in' . $result_table_name, "Tried {$wpdb->last_query} but got {$wpdb->last_error}.", 0, 'error' ); } + }else { + update_option( 'qsm_update_result_db_column_page_name', 1 ); } } diff --git a/php/classes/class-qmn-quiz-manager.php b/php/classes/class-qmn-quiz-manager.php index 98c5205db..246a3fb5b 100644 --- a/php/classes/class-qmn-quiz-manager.php +++ b/php/classes/class-qmn-quiz-manager.php @@ -2134,10 +2134,10 @@ public function submit_results( $qmn_quiz_options, $qmn_array_for_variables ) { } $insert_data = array( 'qmn_array_for_variables' => $qmn_array_for_variables, - 'results_array' => $results_array, - 'unique_id' => $unique_id, - 'form_type' => isset( $qmn_quiz_options->form_type ) ? $qmn_quiz_options->form_type : 0, - 'http_referer' => $http_referer, + 'results_array' => $results_array, + 'unique_id' => $unique_id, + 'form_type' => isset( $qmn_quiz_options->form_type ) ? $qmn_quiz_options->form_type : 0, + 'http_referer' => $http_referer, ); $results_insert = $this->add_quiz_results( $insert_data ); $results_id = $wpdb->insert_id; diff --git a/php/classes/class-qsm-install.php b/php/classes/class-qsm-install.php index 5c026f466..a6e708931 100644 --- a/php/classes/class-qsm-install.php +++ b/php/classes/class-qsm-install.php @@ -1362,64 +1362,64 @@ public static function install() { if ( $wpdb->get_var( "SHOW TABLES LIKE '$quiz_table_name'" ) != $quiz_table_name ) { $sql = "CREATE TABLE $quiz_table_name ( - quiz_id mediumint(9) NOT NULL AUTO_INCREMENT, - quiz_name TEXT NOT NULL, - message_before TEXT NOT NULL, - message_after LONGTEXT NOT NULL, - message_comment TEXT NOT NULL, - message_end_template TEXT NOT NULL, - user_email_template LONGTEXT NOT NULL, - admin_email_template TEXT NOT NULL, - submit_button_text TEXT NOT NULL, - name_field_text TEXT NOT NULL, - business_field_text TEXT NOT NULL, - email_field_text TEXT NOT NULL, - phone_field_text TEXT NOT NULL, - comment_field_text TEXT NOT NULL, - email_from_text TEXT NOT NULL, - question_answer_template TEXT NOT NULL, - leaderboard_template TEXT NOT NULL, - quiz_system INT NOT NULL, - randomness_order INT NOT NULL, - loggedin_user_contact INT NOT NULL, - show_score INT NOT NULL, - send_user_email INT NOT NULL, - send_admin_email INT NOT NULL, - contact_info_location INT NOT NULL, - user_name INT NOT NULL, - user_comp INT NOT NULL, - user_email INT NOT NULL, - user_phone INT NOT NULL, - admin_email TEXT NOT NULL, - comment_section INT NOT NULL, - question_from_total INT NOT NULL, - total_user_tries INT NOT NULL, - total_user_tries_text TEXT NOT NULL, - certificate_template TEXT NOT NULL, - social_media INT NOT NULL, - social_media_text TEXT NOT NULL, - pagination INT NOT NULL, - pagination_text TEXT NOT NULL, - timer_limit INT NOT NULL, - quiz_stye TEXT NOT NULL, - question_numbering INT NOT NULL, - quiz_settings TEXT NOT NULL, - theme_selected TEXT NOT NULL, - last_activity DATETIME NOT NULL, - require_log_in INT NOT NULL, - require_log_in_text TEXT NOT NULL, - limit_total_entries INT NOT NULL, - limit_total_entries_text TEXT NOT NULL, - scheduled_timeframe TEXT NOT NULL, - scheduled_timeframe_text TEXT NOT NULL, - disable_answer_onselect INT NOT NULL, - ajax_show_correct INT NOT NULL, - quiz_views INT NOT NULL, - quiz_taken INT NOT NULL, - deleted INT NOT NULL, - quiz_author_id INT NOT NULL, - PRIMARY KEY (quiz_id) - ) $charset_collate;"; + quiz_id mediumint(9) NOT NULL AUTO_INCREMENT, + quiz_name TEXT NOT NULL, + message_before TEXT NOT NULL, + message_after LONGTEXT NOT NULL, + message_comment TEXT NOT NULL, + message_end_template TEXT NOT NULL, + user_email_template LONGTEXT NOT NULL, + admin_email_template TEXT NOT NULL, + submit_button_text TEXT NOT NULL, + name_field_text TEXT NOT NULL, + business_field_text TEXT NOT NULL, + email_field_text TEXT NOT NULL, + phone_field_text TEXT NOT NULL, + comment_field_text TEXT NOT NULL, + email_from_text TEXT NOT NULL, + question_answer_template TEXT NOT NULL, + leaderboard_template TEXT NOT NULL, + quiz_system INT NOT NULL, + randomness_order INT NOT NULL, + loggedin_user_contact INT NOT NULL, + show_score INT NOT NULL, + send_user_email INT NOT NULL, + send_admin_email INT NOT NULL, + contact_info_location INT NOT NULL, + user_name INT NOT NULL, + user_comp INT NOT NULL, + user_email INT NOT NULL, + user_phone INT NOT NULL, + admin_email TEXT NOT NULL, + comment_section INT NOT NULL, + question_from_total INT NOT NULL, + total_user_tries INT NOT NULL, + total_user_tries_text TEXT NOT NULL, + certificate_template TEXT NOT NULL, + social_media INT NOT NULL, + social_media_text TEXT NOT NULL, + pagination INT NOT NULL, + pagination_text TEXT NOT NULL, + timer_limit INT NOT NULL, + quiz_stye TEXT NOT NULL, + question_numbering INT NOT NULL, + quiz_settings TEXT NOT NULL, + theme_selected TEXT NOT NULL, + last_activity DATETIME NOT NULL, + require_log_in INT NOT NULL, + require_log_in_text TEXT NOT NULL, + limit_total_entries INT NOT NULL, + limit_total_entries_text TEXT NOT NULL, + scheduled_timeframe TEXT NOT NULL, + scheduled_timeframe_text TEXT NOT NULL, + disable_answer_onselect INT NOT NULL, + ajax_show_correct INT NOT NULL, + quiz_views INT NOT NULL, + quiz_taken INT NOT NULL, + deleted INT NOT NULL, + quiz_author_id INT NOT NULL, + PRIMARY KEY (quiz_id) + ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); @@ -1429,90 +1429,99 @@ public static function install() { if ( ! $multiple_category ) { add_option( 'qsm_multiple_category_enabled', gmdate( time() ) ); } + update_option( 'qsm_update_db_column', 1 ); + update_option( 'qsm_update_quiz_db_column', 1 ); } if ( $wpdb->get_var( "SHOW TABLES LIKE '$question_table_name'" ) != $question_table_name ) { $sql = "CREATE TABLE $question_table_name ( - question_id mediumint(9) NOT NULL AUTO_INCREMENT, - quiz_id INT NOT NULL, - question_name TEXT NOT NULL, - answer_array TEXT NOT NULL, - answer_one TEXT NOT NULL, - answer_one_points INT NOT NULL, - answer_two TEXT NOT NULL, - answer_two_points INT NOT NULL, - answer_three TEXT NOT NULL, - answer_three_points INT NOT NULL, - answer_four TEXT NOT NULL, - answer_four_points INT NOT NULL, - answer_five TEXT NOT NULL, - answer_five_points INT NOT NULL, - answer_six TEXT NOT NULL, - answer_six_points INT NOT NULL, - correct_answer INT NOT NULL, - question_answer_info TEXT NOT NULL, - comments INT NOT NULL, - hints TEXT NOT NULL, - question_order INT NOT NULL, - question_type INT NOT NULL, - question_type_new TEXT NOT NULL, - question_settings TEXT NOT NULL, - category TEXT NOT NULL, - deleted INT NOT NULL, - deleted_question_bank INT NOT NULL, - PRIMARY KEY (question_id) - ) $charset_collate;"; + question_id mediumint(9) NOT NULL AUTO_INCREMENT, + quiz_id INT NOT NULL, + question_name TEXT NOT NULL, + answer_array TEXT NOT NULL, + answer_one TEXT NOT NULL, + answer_one_points INT NOT NULL, + answer_two TEXT NOT NULL, + answer_two_points INT NOT NULL, + answer_three TEXT NOT NULL, + answer_three_points INT NOT NULL, + answer_four TEXT NOT NULL, + answer_four_points INT NOT NULL, + answer_five TEXT NOT NULL, + answer_five_points INT NOT NULL, + answer_six TEXT NOT NULL, + answer_six_points INT NOT NULL, + correct_answer INT NOT NULL, + question_answer_info TEXT NOT NULL, + comments INT NOT NULL, + hints TEXT NOT NULL, + question_order INT NOT NULL, + question_type INT NOT NULL, + question_type_new TEXT NOT NULL, + question_settings TEXT NOT NULL, + category TEXT NOT NULL, + deleted INT NOT NULL, + deleted_question_bank INT NOT NULL, + PRIMARY KEY (question_id) + ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); + update_option( 'qsm_add_new_column_question_table_table', 1); } if ( $wpdb->get_var( "SHOW TABLES LIKE '$results_table_name'" ) != $results_table_name ) { $sql = "CREATE TABLE $results_table_name ( - result_id mediumint(9) NOT NULL AUTO_INCREMENT, - quiz_id INT NOT NULL, - quiz_name TEXT NOT NULL, - quiz_system INT NOT NULL, - point_score FLOAT NOT NULL, - correct_score INT NOT NULL, - correct INT NOT NULL, - total INT NOT NULL, - name TEXT NOT NULL, - business TEXT NOT NULL, - email TEXT NOT NULL, - phone TEXT NOT NULL, - user INT NOT NULL, - user_ip TEXT NOT NULL, - time_taken TEXT NOT NULL, - time_taken_real DATETIME NOT NULL, - quiz_results MEDIUMTEXT NOT NULL, - deleted INT NOT NULL, - unique_id varchar(100) NOT NULL, - form_type INT NOT NULL, - page_name varchar(255) NOT NULL, - page_url varchar(255) NOT NULL, - UNIQUE KEY (unique_id), - PRIMARY KEY (result_id) - ) $charset_collate;"; + result_id mediumint(9) NOT NULL AUTO_INCREMENT, + quiz_id INT NOT NULL, + quiz_name TEXT NOT NULL, + quiz_system INT NOT NULL, + point_score FLOAT NOT NULL, + correct_score INT NOT NULL, + correct INT NOT NULL, + total INT NOT NULL, + name TEXT NOT NULL, + business TEXT NOT NULL, + email TEXT NOT NULL, + phone TEXT NOT NULL, + user INT NOT NULL, + user_ip TEXT NOT NULL, + time_taken TEXT NOT NULL, + time_taken_real DATETIME NOT NULL, + quiz_results LONGTEXT NOT NULL, + deleted INT NOT NULL, + unique_id varchar(100) NOT NULL, + form_type INT NOT NULL, + page_name varchar(255) NOT NULL, + page_url varchar(255) NOT NULL, + UNIQUE KEY (unique_id), + PRIMARY KEY (result_id) + ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); + update_option( 'qsm_update_db_column', 1 ); + update_option( 'qsm_update_result_db_column_datatype', 1 ); + update_option( 'qsm_update_result_db_column', 1 ); + update_option( 'qsm_update_result_db_column_page_name', 1 ); + update_option( 'qsm_update_result_db_column_page_url', 1 ); } if ( $wpdb->get_var( "SHOW TABLES LIKE '$audit_table_name'" ) != $audit_table_name ) { $sql = "CREATE TABLE $audit_table_name ( - trail_id mediumint(9) NOT NULL AUTO_INCREMENT, - action_user TEXT NOT NULL, - action TEXT NOT NULL, - quiz_id TEXT NOT NULL, - quiz_name TEXT NOT NULL, - form_data TEXT NOT NULL, - time TEXT NOT NULL, - PRIMARY KEY (trail_id) - ) $charset_collate;"; + trail_id mediumint(9) NOT NULL AUTO_INCREMENT, + action_user TEXT NOT NULL, + action TEXT NOT NULL, + quiz_id TEXT NOT NULL, + quiz_name TEXT NOT NULL, + form_data TEXT NOT NULL, + time TEXT NOT NULL, + PRIMARY KEY (trail_id) + ) $charset_collate;"; require_once ABSPATH . 'wp-admin/includes/upgrade.php'; dbDelta( $sql ); + update_option( 'qsm_update_db_column_charset_utf8mb4_unicode_ci', 1 ); } if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}mlw_question_terms'" ) != "{$wpdb->prefix}mlw_question_terms" ) { diff --git a/php/question-types/qsm-question-title.php b/php/question-types/qsm-question-title.php index ecf0b0872..a7d809c26 100644 --- a/php/question-types/qsm-question-title.php +++ b/php/question-types/qsm-question-title.php @@ -26,7 +26,7 @@ function qsm_question_title_func( $question, $question_type = '', $new_question_ if ( '' !== $new_question_title ) { $new_question_title = $mlwQuizMasterNext->pluginHelper->qsm_language_support( htmlspecialchars_decode( $new_question_title, ENT_QUOTES ), "Question-{$question_id}", "QSM Questions"); $new_question_title = apply_filters( 'qsm_question_title_before', $new_question_title, $question_type, $question_id ); - if ( in_array( get_question_type( $question_id ), [12, 7, 3, 5] ) ) { + if ( in_array( get_question_type( $question_id ), [ 12, 7, 3, 5 ] ) ) { ?>