@@ -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