Skip to content

Commit

Permalink
feat: Added db verification to WooCommerce Tools
Browse files Browse the repository at this point in the history
  • Loading branch information
seebeen committed Jan 3, 2024
1 parent 8223146 commit 97510f8
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/Base_Plugin_Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ final public function init() {
add_action( 'init', array( $this, 'check_version' ) );
add_action( 'admin_init', array( $this, 'install_actions' ) );
add_action( 'cli_init', array( $this, 'register_commands' ) );
add_filter( 'woocommerce_debug_tools', array( $this, 'add_debug_tools' ), ( 99 + count( static::$instances ) ), 1 );

add_action( "{$this->slug}_run_update_callback", array( $this, 'run_update_callback' ), 10, 2 );
}
Expand Down Expand Up @@ -597,4 +598,44 @@ final public function cli_verify_tables( $args = array(), $assoc_args = array()

WP_CLI::error( __( 'There was an error creating the missing tables.', 'oblak-plugin-installer' ) );
}

/**
* Add database verification to WooCommerce debug tools.
*
* @param array<string, array> $tools Debug tools.
* @return array
*/
final public function add_debug_tools( array $tools ): array {
if ( ! $this->get_schema() ) {
return $tools;
}

return array_merge(
$tools,
array(
"{$this->slug}_verify_db_tables" => array(
'name' => sprintf( '%s: %s', $this->name, __( 'Verify base database tables', 'woocommerce' ) ),
'desc' => __( 'Verify if all base database tables are present.', 'woocommerce' ),
'button' => __( 'Verify database', 'woocommerce' ),
'callback' => array( $this, 'debug_verify_db_tables' ),

),
)
);
}

/**
* Verify if all base database tables are present - from WooCommerce debug tools.
*
* @return string
*/
final public function debug_verify_db_tables() {
Admin_Notice_Manager::get_instance()->remove_notice( "{$this->slug}_missing_tables", true );

$missing_tables = $this->verify_base_tables( false, true );

return 0 === count( $missing_tables )
? __( 'Database verified successfully.', 'woocommerce' )
: __( 'Verifying database... One or more tables are still missing: ', 'woocommerce' ) . implode( ', ', $missing_tables );
}
}

0 comments on commit 97510f8

Please sign in to comment.