|
2 | 2 |
|
3 | 3 | use Composer\Semver\Comparator; |
4 | 4 | use WP_CLI\Extractor; |
5 | | -use WP_CLI\Iterators\Table as TableIterator; |
| 5 | +use WP_CLI\Iterators\Table; |
6 | 6 | use WP_CLI\Utils; |
7 | 7 | use WP_CLI\Formatter; |
8 | 8 | use WP_CLI\WpOrgApi; |
@@ -408,32 +408,47 @@ public function is_installed( $args, $assoc_args ) { |
408 | 408 | $tables = $wpdb->tables( 'all', true ); |
409 | 409 | $missing_tables = []; |
410 | 410 |
|
411 | | - // Check if we're using SQLite |
412 | | - $is_sqlite = ( strpos( DB_HOST, 'sqlite' ) !== false || |
| 411 | + // Check if we're using SQLite - check multiple possible indicators |
| 412 | + $is_sqlite = ( |
| 413 | + ( isset( $wpdb->dbdriver ) && 'sqlite' === $wpdb->dbdriver ) || |
413 | 414 | ( defined( 'DB_DRIVER' ) && 'sqlite' === DB_DRIVER ) || |
414 | | - ( defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) |
| 415 | + ( defined( 'DB_ENGINE' ) && 'sqlite' === DB_ENGINE ) || |
| 416 | + ( is_string( DB_HOST ) && ( strpos( DB_HOST, 'sqlite' ) !== false ) ) |
415 | 417 | ); |
416 | 418 |
|
417 | 419 | if ( defined( 'WP_CLI_TEST' ) && WP_CLI_TEST ) { |
418 | | - WP_CLI::debug( 'Running in test mode. Database type: ' . ( $is_sqlite ? 'SQLite' : 'MySQL/MariaDB' ) ); |
| 420 | + WP_CLI::debug( 'Database type: ' . ( $is_sqlite ? 'SQLite' : 'MySQL/MariaDB' ) ); |
419 | 421 | } |
420 | 422 |
|
421 | 423 | foreach ( $tables as $table ) { |
422 | 424 | $table_name = $wpdb->prefix . $table; |
423 | 425 |
|
424 | 426 | 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 ); |
| 427 | + try { |
| 428 | + if ( $is_sqlite ) { |
| 429 | + // SQLite uses a simpler table existence check |
| 430 | + $result = $wpdb->get_var( |
| 431 | + $wpdb->prepare( |
| 432 | + "SELECT name FROM sqlite_master WHERE type='table' AND name=%s", |
| 433 | + $table_name |
| 434 | + ) |
| 435 | + ); |
| 436 | + } else { |
| 437 | + // Standard MySQL/MariaDB check |
| 438 | + $result = $wpdb->get_var( |
| 439 | + $wpdb->prepare( |
| 440 | + 'SHOW TABLES LIKE %s', |
| 441 | + $table_name |
| 442 | + ) |
| 443 | + ); |
| 444 | + } |
| 445 | + } catch ( Exception $e ) { |
| 446 | + // If there's an error, assume the table doesn't exist |
| 447 | + $result = null; |
433 | 448 | } |
434 | 449 |
|
435 | 450 | if ( defined( 'WP_CLI_TEST' ) && WP_CLI_TEST ) { |
436 | | - WP_CLI::debug( sprintf( 'Checking table %s: %s', $table_name, $result ? 'exists' : 'missing' ) ); |
| 451 | + WP_CLI::debug( sprintf( 'Table %s: %s', $table_name, $result ? 'exists' : 'missing' ) ); |
437 | 452 | } |
438 | 453 |
|
439 | 454 | if ( $result !== $table_name ) { |
|
0 commit comments