*/ public static function status( bool $attempt_install = true ): array { $installed = $attempt_install ? self::ensure_installed() : self::all_tables_exist(); $tables = []; foreach ( self::tables() as $table ) { $tables[] = [ 'name' => $table->get_name(), 'exists' => self::table_exists( $table ), ]; } return [ 'installed' => $installed, 'storageMode' => $installed ? 'database' : 'option_fallback', 'tables' => $tables, ]; } /** * @return array */ private static function tables(): array { return [ new Checkout_FlowRuns(), new Checkout_TraceEvents(), ]; } private static function all_tables_exist(): bool { foreach ( self::tables() as $table ) { if ( ! self::table_exists( $table ) ) { return false; } } return true; } private static function install_table( Database_Table $table ): bool { if ( ! function_exists( 'dbDelta' ) ) { $upgrade_file = defined( 'ABSPATH' ) ? ABSPATH . 'wp-admin/includes/upgrade.php' : ''; if ( '' !== $upgrade_file && file_exists( $upgrade_file ) ) { require_once $upgrade_file; } } if ( ! function_exists( 'dbDelta' ) ) { return false; } dbDelta( $table->get_install_query() ); return self::table_exists( $table ); } private static function table_exists( Database_Table $table ): bool { global $wpdb; if ( ! is_object( $wpdb ) || ! method_exists( $wpdb, 'get_var' ) || ! method_exists( $wpdb, 'prepare' ) ) { return false; } $table_name = $table->get_name(); return $wpdb->get_var( $wpdb->prepare( 'SHOW TABLES LIKE %s', $table_name ) ) === $table_name; } }