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

Commit bd45d70

Browse files
authored
Merge pull request #188 from woocommerce/enhancement/verify-db-tool
Add tool for verifying database table
2 parents bd5fe42 + 424ded9 commit bd45d70

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@
3737
"classmap": [
3838
"src/Controllers/Version1",
3939
"src/Controllers/Version2",
40-
"src/Controllers/Version3"
40+
"src/Controllers/Version3",
41+
"src/Controllers/Version4"
4142
],
4243
"psr-4": {
4344
"Automattic\\WooCommerce\\RestApi\\": "src"

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

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,15 @@ 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+
}
203212

204213
// Jetpack does the image resizing heavy lifting so you don't have to.
205214
if ( ( class_exists( 'Jetpack' ) && Jetpack::is_module_active( 'photon' ) ) || ! apply_filters( 'woocommerce_background_image_regeneration', true ) ) {
@@ -459,7 +468,7 @@ public function execute_tool( $tool ) {
459468
$wpdb->prepare(
460469
"DELETE FROM {$wpdb->prefix}woocommerce_downloadable_product_permissions
461470
WHERE ( downloads_remaining != '' AND downloads_remaining = 0 ) OR ( access_expires IS NOT NULL AND access_expires < %s )",
462-
date( 'Y-m-d', current_time( 'timestamp' ) )
471+
gmdate( 'Y-m-d', current_time( 'timestamp' ) )
463472
)
464473
)
465474
);
@@ -538,6 +547,23 @@ public function execute_tool( $tool ) {
538547
$message = __( 'Database upgrade routine has been scheduled to run in the background.', 'woocommerce-rest-api' );
539548
break;
540549

550+
case 'verify_db_tables':
551+
if ( ! method_exists( 'WC_Install', 'verify_base_tables' ) ) {
552+
$message = __( 'You need WooCommerce 4.2 or newer to run this tool.', 'woocommerce-rest-api' );
553+
$ran = false;
554+
break;
555+
}
556+
// Try to manually create table again.
557+
$missing_tables = WC_Install::verify_base_tables( true, true );
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)