Handle the clear db AJAX request shoulr be outside of check.

This commit is contained in:
Narek Zakarian 2022-12-09 16:48:11 +04:00
parent 2fd1a6f574
commit 6a9c76fa9e
No known key found for this signature in database
GPG key ID: 07AFD7E7A9C164A7
3 changed files with 16 additions and 20 deletions

View file

@ -23,21 +23,18 @@ document.addEventListener(
body: JSON.stringify({
nonce: clearDbConfig.nonce,
})
}).then(function (res) {
}).then((res)=>{
return res.json();
}).then(function (data) {
const resultMessage = document.querySelector(clearDbConfig.messageSelector);
}).then((data)=>{
if (!data.success) {
clearDbConfig.failureMessage.insertAfter(clearButton);
setTimeout(()=> resultMessage.remove(),3000);
jQuery(clearDbConfig.failureMessage).insertAfter(clearButton);
setTimeout(()=> jQuery(clearDbConfig.messageSelector).remove(),3000);
clearButton.removeAttribute('disabled');
console.error(data);
throw Error(data.data.message);
}
clearDbConfig.successMessage.insertAfter(clearButton);
setTimeout(()=> resultMessage.remove(),3000);
jQuery(clearDbConfig.successMessage).insertAfter(clearButton);
setTimeout(()=> jQuery(clearDbConfig.messageSelector).remove(),3000);
clearButton.removeAttribute('disabled');
});
})

View file

@ -57,11 +57,11 @@ return array(
'messageSelector' => '.clear-db-info-message',
'ConfirmationMessage' => __( 'Are you sure? the operation will remove all plugin data.', 'woocommerce-paypal-payments' ),
'successMessage' => sprintf(
'<span class="success clear-db-info-message">%1$s</span>',
'<div class="updated clear-db-info-message"><p><strong>%1$s</strong></p></div>',
esc_html__( 'The plugin data is successfully cleared.', 'woocommerce-paypal-payments' )
),
'failureMessage' => sprintf(
'<span class="error clear-db-info-message">%1$s</span>',
'<div class="error clear-db-info-message"><p><strong>%1$s</strong></p></div>',
esc_html__( 'Operation failed. Check WooCommerce logs for more details.', 'woocommerce-paypal-payments' )
),
),

View file

@ -40,15 +40,15 @@ class UninstallModule implements ModuleInterface {
$page_id = $container->get( 'wcgateway.current-ppcp-settings-page-id' );
if ( Settings::CONNECTION_TAB_ID === $page_id ) {
$this->registerClearDatabaseAssets( $container->get( 'uninstall.clear-db-assets' ) );
$request_data = $container->get( 'button.request-data' );
$clear_db = $container->get( 'uninstall.clear-db' );
$clear_db_endpoint = $container->get( 'uninstall.clear-db-endpoint' );
$option_names = $container->get( 'uninstall.ppcp-all-option-names' );
$scheduled_action_names = $container->get( 'uninstall.ppcp-all-scheduled-action-names' );
$this->handleClearDbAjaxRequest( $request_data, $clear_db, $clear_db_endpoint, $option_names, $scheduled_action_names );
}
$request_data = $container->get( 'button.request-data' );
$clear_db = $container->get( 'uninstall.clear-db' );
$clear_db_endpoint = $container->get( 'uninstall.clear-db-endpoint' );
$option_names = $container->get( 'uninstall.ppcp-all-option-names' );
$scheduled_action_names = $container->get( 'uninstall.ppcp-all-scheduled-action-names' );
$this->handleClearDbAjaxRequest( $request_data, $clear_db, $clear_db_endpoint, $option_names, $scheduled_action_names );
}
/**
@ -83,7 +83,6 @@ class UninstallModule implements ModuleInterface {
try {
// Validate nonce.
$request_data->read_request( $nonce );
$clear_db->delete_options( $option_names );
$clear_db->clear_scheduled_actions( $scheduled_action_names );