From fb1174c6e94aadc3fd09a9cb34f81ea589fcd846 Mon Sep 17 00:00:00 2001 From: randhirexpresstech Date: Tue, 21 May 2024 18:27:16 +0530 Subject: [PATCH] Added button in admin database notification to check if issue has been fixed. --- js/qsm-admin.js | 27 ++++++++++ mlw_quizmaster2.php | 26 +--------- php/classes/class-qmn-quiz-manager.php | 69 ++++++++++++++++++++++++++ readme.txt | 3 +- 4 files changed, 100 insertions(+), 25 deletions(-) diff --git a/js/qsm-admin.js b/js/qsm-admin.js index 109549894..e4802be59 100644 --- a/js/qsm-admin.js +++ b/js/qsm-admin.js @@ -4075,4 +4075,31 @@ var import_button; quiz_action:'retrieve' } ); } ); + + // On click retrieve link + $( document ).on( 'click', '.notice.qmn-database-user-incorrect-permission .check-db-fix-btn', function( e ) { + e.preventDefault(); + let dbFixBtn = $( this ); + let formData = { + action: 'qsm_check_fix_db', + qmnnonce: $( this ).attr( 'qmnnonce' ), + }; + dbFixBtn.text("processing..."); + dbFixBtn.removeClass( 'check-db-fix-btn' ); + dbFixBtn.removeClass( 'button-primary' ); + $.ajax({ + type: 'POST', + url: ajaxurl, + data: formData, + success: function (response) { + if ( undefined !== response.data ) { + dbFixBtn.text( response.data.message ); + } + }, + error: function ( jqXHR, textStatus, errorThrown ) { + console.log( "error", errorThrown ); + } + }); + } ); + }(jQuery)); \ No newline at end of file diff --git a/mlw_quizmaster2.php b/mlw_quizmaster2.php index 6f4638061..d64b51bab 100644 --- a/mlw_quizmaster2.php +++ b/mlw_quizmaster2.php @@ -185,7 +185,7 @@ public function qsm_is_admin( $check_permission = 'manage_options' ) { * @since 9.0.2 * @return array alter qmn table query list */ - private function get_failed_alter_table_queries() { + 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(); } @@ -336,28 +336,6 @@ private function add_hooks() { add_action( 'admin_init', array( $this, 'qsm_overide_old_setting_options' ) ); add_action( 'admin_notices', array( $this, 'qsm_admin_notices' ) ); add_filter( 'manage_edit-qsm_category_columns', array( $this, 'modify_qsm_category_columns' ) ); - add_action( 'admin_init', array( $this, 'has_alter_table_issue_solved' ), 999 ); - } - - /** - * Check if alter table issue has been solved by trying failed alter table query - * - * @since 9.0.2 - * - * @return void - */ - public function has_alter_table_issue_solved() { - // Get failed alter table query list. - $failed_queries = $this->get_failed_alter_table_queries(); - if ( ! empty( $failed_queries ) ) { - foreach ( $failed_queries as $failed_query ) { - $failed_query = $this->wpdb_alter_table_query( $failed_query ); - // exit loop if query failed to execute - if ( false === $failed_query ) { - break; - } - } - } } /** @@ -856,7 +834,7 @@ public function qsm_admin_notices() { if ( ! empty( $failed_queries ) && 0 < count( $failed_queries ) ) { ?>
-

+

'error', + 'message' => __( 'Unauthorized!', 'quiz-master-next' ), + ) + ); + } else { + global $mlwQuizMasterNext, $wpdb; + $wperror = ''; + $query = array(); + // Failed Query has been saved in wrong order sometimes due to order of execution. So run twice + for ( $i = 0; $i < 2 ; $i++ ) { + // Get failed alter table query list. + $failed_queries = $mlwQuizMasterNext->get_failed_alter_table_queries(); + if ( ! empty( $failed_queries ) ) { + if ( 0 === $i ) { + $failed_queries = array_reverse( $failed_queries ); + } + foreach ( $failed_queries as $failed_query ) { + $res = $mlwQuizMasterNext->wpdb_alter_table_query( $failed_query ); + + // exit loop if query failed to execute + if ( false === $res ) { + $wperror = $wpdb->last_error; + if ( false !== stripos( $wperror, 'Duplicate' ) ) { + // Remove failed query from list. + $failed_queries = array_diff( $failed_queries, array( $failed_query ) ); + // Update failed queries list. + update_option( 'qmn_failed_alter_table_queries', $failed_queries ); + $query['update'] = $failed_queries; + } + } + } + } + } + + $failed_queries = $mlwQuizMasterNext->get_failed_alter_table_queries(); + if ( ! empty( $failed_queries ) ) { + $query['latest'] = $failed_queries; + wp_send_json_error( + array( + 'status' => 'error', + 'query' => $query, + 'message' => $wperror, + ) + ); + } else { + wp_send_json_success( + array( + 'status' => 'success', + 'message' => __( 'Fixed!', 'quiz-master-next' ), + ) + ); + } + } } /** diff --git a/readme.txt b/readme.txt index cbe460179..ad2f973c3 100644 --- a/readme.txt +++ b/readme.txt @@ -166,8 +166,9 @@ This is usually a theme conflict. You can [checkout out our common conflict solu = 9.0.2 ( Beta ) = * Bug: Fixed display shortcode php buffer due to invalid quiz id * Feature: Added Failed submission list in QSM menu -* Feature: Added retrieve or delete failed submission +* Feature: Added resubmit or delete failed submission * Enhancement: Added admin notification if database user does not have proper permission. +* Feature: Added button in admin database notification to check if issue has been fixed. = 9.0.1 (April 25, 2024) = * Bug: Fixed date format in %ANSWER_X% variable