@@ -393,24 +393,54 @@ function () use ( $temp ) {
393393 * @param array{network?: bool} $assoc_args Associative arguments.
394394 */
395395 public function is_installed ( $ args , $ assoc_args ) {
396- if ( is_blog_installed () && ( ! Utils \get_flag_value ( $ assoc_args , 'network ' ) || is_multisite () ) ) {
396+ try {
397+ if ( ! is_blog_installed () ) {
398+ WP_CLI ::halt ( 1 );
399+ }
400+
401+ if ( Utils \get_flag_value ( $ assoc_args , 'network ' ) && ! is_multisite () ) {
402+ WP_CLI ::halt ( 1 );
403+ }
404+
397405 global $ wpdb ;
398406
399- // Get core tables from $wpdb
400- $ tables = $ wpdb ->tables ();
407+ // Get all tables including multisite if needed
408+ $ tables = $ wpdb ->tables ( ' all ' , true );
401409 $ missing_tables = [];
402410
403- // Check if all core tables exist
411+ // Check if we're using SQLite
412+ $ is_sqlite = ( strpos ( DB_HOST , 'sqlite ' ) !== false ||
413+ ( defined ( 'DB_DRIVER ' ) && 'sqlite ' === DB_DRIVER ) ||
414+ ( defined ( 'DB_ENGINE ' ) && 'sqlite ' === DB_ENGINE )
415+ );
416+
417+ if ( defined ( 'WP_CLI_TEST ' ) && WP_CLI_TEST ) {
418+ WP_CLI ::debug ( 'Running in test mode. Database type: ' . ( $ is_sqlite ? 'SQLite ' : 'MySQL/MariaDB ' ) );
419+ }
420+
404421 foreach ( $ tables as $ table ) {
405422 $ table_name = $ wpdb ->prefix . $ table ;
406- $ result = $ wpdb ->get_var (
407- $ wpdb ->prepare (
408- 'SHOW TABLES LIKE %s ' ,
409- $ table_name
410- )
411- );
423+
424+ try {
425+ if ( $ is_sqlite ) {
426+ // SQLite uses a simpler table existence check
427+ $ query = $ wpdb ->prepare ( "SELECT name FROM sqlite_master WHERE type='table' AND name=%s " , $ table_name );
428+ $ result = $ wpdb ->get_var ( $ query );
429+ } else {
430+ // Standard MySQL/MariaDB check
431+ $ query = $ wpdb ->prepare ( 'SHOW TABLES LIKE %s ' , $ table_name );
432+ $ result = $ wpdb ->get_var ( $ query );
433+ }
412434
413- if ( $ result !== $ table_name ) {
435+ if ( defined ( 'WP_CLI_TEST ' ) && WP_CLI_TEST ) {
436+ WP_CLI ::debug ( sprintf ( 'Checking table %s: %s ' , $ table_name , $ result ? 'exists ' : 'missing ' ) );
437+ }
438+
439+ if ( $ result !== $ table_name ) {
440+ $ missing_tables [] = $ table_name ;
441+ }
442+ } catch ( Exception $ e ) {
443+ WP_CLI ::debug ( sprintf ( 'Error checking table %s: %s ' , $ table_name , $ e ->getMessage () ) );
414444 $ missing_tables [] = $ table_name ;
415445 }
416446 }
@@ -426,9 +456,11 @@ public function is_installed( $args, $assoc_args ) {
426456 }
427457
428458 WP_CLI ::halt ( 0 );
429- }
430459
431- WP_CLI ::halt ( 1 );
460+ } catch ( Exception $ e ) {
461+ WP_CLI ::debug ( 'Error in is_installed: ' . $ e ->getMessage () );
462+ WP_CLI ::halt ( 1 );
463+ }
432464 }
433465
434466 /**
0 commit comments