Skip to content
This repository was archived by the owner on Jul 6, 2025. It is now read-only.

Commit c504864

Browse files
committed
Add tool for verifying database table
1 parent 721460a commit c504864

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/Controllers/Version2/class-wc-rest-system-status-tools-v2-controller.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,16 @@ public function get_tools() {
200200
),
201201
),
202202
);
203+
if ( method_exists( 'WC_Install', 'verify_base_tables' ) ) {
204+
$tools['verify_db_tables'] = array(
205+
'name' => __( 'Verify base database tables', 'woocommerce-rest-api' ),
206+
'button' => __( 'Verify database', 'woocommerce-rest-api' ),
207+
'desc' => sprintf(
208+
__( 'Verify if all base database tables are present.', 'woocommerce-rest-api' )
209+
),
210+
);
211+
}
212+
203213

204214
// Jetpack does the image resizing heavy lifting so you don't have to.
205215
if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) {
@@ -538,6 +548,22 @@ public function execute_tool( $tool ) {
538548
$message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce-rest-api' );
539549
break;
540550

551+
case 'verify_db_tables':
552+
if ( ! method_exists( 'WC_Install', 'verify_base_tables' ) ) {
553+
$message = __( 'You need WooCommerce 4.2 or newer to run this tool.', 'woocommerce' );
554+
$ran = false;
555+
break;
556+
}
557+
$missing_tables = WC_Install::verify_base_tables();
558+
if ( 0 === count( $missing_tables ) ) {
559+
$message = __( 'Database verified successfully.', 'woocommerce-rest-api' );
560+
} else {
561+
$message = __( 'Verifying database... One or more tables are still missing: ', 'woocommerce-rest-api' );
562+
$message .= implode( ', ', $missing_tables );
563+
$ran = false;
564+
}
565+
break;
566+
541567
default:
542568
$tools = $this->get_tools();
543569
if ( isset( $tools[ $tool ]['callback'] ) ) {

0 commit comments

Comments
 (0)