Skip to content

Commit

Permalink
fixed migration issue for new users
Browse files Browse the repository at this point in the history
  • Loading branch information
zubairraeen committed Jun 3, 2024
1 parent 48d148a commit 305089d
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 142 deletions.
8 changes: 4 additions & 4 deletions mlw_quizmaster2.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down Expand Up @@ -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 );
}
Expand Down Expand Up @@ -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' ) );
Expand Down
33 changes: 21 additions & 12 deletions php/admin/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 );
}
}

Expand All @@ -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 );
}
}

Expand All @@ -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 );
}
}

Expand All @@ -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(
Expand All @@ -164,19 +168,20 @@ 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);
}
}
/**
* Add new column in the results table
*
* @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(
Expand All @@ -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 );
}
}

Expand All @@ -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(
Expand All @@ -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 );
}
}

Expand Down
8 changes: 4 additions & 4 deletions php/classes/class-qmn-quiz-manager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading

0 comments on commit 305089d

Please sign in to comment.