Add tool for verifying database table

This commit is contained in:
vedanshujain 2020-05-11 23:43:31 +05:30
parent e11141f577
commit 88e72cd112
1 changed files with 26 additions and 0 deletions

View File

@ -200,6 +200,16 @@ class WC_REST_System_Status_Tools_V2_Controller extends WC_REST_Controller {
),
),
);
if ( method_exists( 'WC_Install', 'verify_base_tables' ) ) {
$tools['verify_db_tables'] = array(
'name' => __( 'Verify base database tables', 'woocommerce-rest-api' ),
'button' => __( 'Verify database', 'woocommerce-rest-api' ),
'desc' => sprintf(
__( 'Verify if all base database tables are present.', 'woocommerce-rest-api' )
),
);
}
// Jetpack does the image resizing heavy lifting so you don't have to.
if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) {
@ -538,6 +548,22 @@ class WC_REST_System_Status_Tools_V2_Controller extends WC_REST_Controller {
$message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce-rest-api' );
break;
case 'verify_db_tables':
if ( ! method_exists( 'WC_Install', 'verify_base_tables' ) ) {
$message = __( 'You need WooCommerce 4.2 or newer to run this tool.', 'woocommerce' );
$ran = false;
break;
}
$missing_tables = WC_Install::verify_base_tables();
if ( 0 === count( $missing_tables ) ) {
$message = __( 'Database verified successfully.', 'woocommerce-rest-api' );
} else {
$message = __( 'Verifying database... One or more tables are still missing: ', 'woocommerce-rest-api' );
$message .= implode( ', ', $missing_tables );
$ran = false;
}
break;
default:
$tools = $this->get_tools();
if ( isset( $tools[ $tool ]['callback'] ) ) {