@@ -209,6 +209,15 @@ public function get_tools() {
209209 ),
210210 ),
211211 );
212+ if ( method_exists ( 'WC_Install ' , 'verify_base_tables ' ) ) {
213+ $ tools ['verify_db_tables ' ] = array (
214+ 'name ' => __ ( 'Verify base database tables ' , 'woocommerce-rest-api ' ),
215+ 'button ' => __ ( 'Verify database ' , 'woocommerce-rest-api ' ),
216+ 'desc ' => sprintf (
217+ __ ( 'Verify if all base database tables are present. ' , 'woocommerce-rest-api ' )
218+ ),
219+ );
220+ }
212221
213222 // Jetpack does the image resizing heavy lifting so you don't have to.
214223 if ( ( class_exists ( 'Jetpack ' ) && Jetpack::is_module_active ( 'photon ' ) ) || ! apply_filters ( 'woocommerce_background_image_regeneration ' , true ) ) {
@@ -472,7 +481,7 @@ public function execute_tool( $tool ) {
472481 $ wpdb ->prepare (
473482 "DELETE FROM {$ wpdb ->prefix }woocommerce_downloadable_product_permissions
474483 WHERE ( downloads_remaining != '' AND downloads_remaining = 0 ) OR ( access_expires IS NOT NULL AND access_expires < %s ) " ,
475- date ( 'Y-m-d ' , current_time ( 'timestamp ' ) )
484+ gmdate ( 'Y-m-d ' , current_time ( 'timestamp ' ) )
476485 )
477486 )
478487 );
@@ -557,6 +566,20 @@ public function execute_tool( $tool ) {
557566 $ message = __ ( 'Template cache cleared. ' , 'woocommerce-rest-api ' );
558567 } else {
559568 $ message = __ ( 'The active version of WooCommerce does not support template cache clearing. ' , 'woocommerce-rest-api ' );
569+ case 'verify_db_tables ' :
570+ if ( ! method_exists ( 'WC_Install ' , 'verify_base_tables ' ) ) {
571+ $ message = __ ( 'You need WooCommerce 4.2 or newer to run this tool. ' , 'woocommerce-rest-api ' );
572+ $ ran = false ;
573+ break ;
574+ }
575+ // Try to manually create table again.
576+ $ missing_tables = WC_Install::verify_base_tables ( true , true );
577+ if ( 0 === count ( $ missing_tables ) ) {
578+ $ message = __ ( 'Database verified successfully. ' , 'woocommerce-rest-api ' );
579+ } else {
580+ $ message = __ ( 'Verifying database... One or more tables are still missing: ' , 'woocommerce-rest-api ' );
581+ $ message .= implode ( ', ' , $ missing_tables );
582+ $ ran = false ;
560583 }
561584 break ;
562585
0 commit comments