Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 36 additions & 1 deletion src/Core_Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,45 @@
* @param array{network?: bool} $assoc_args Associative arguments.
*/
public function is_installed( $args, $assoc_args ) {
// Check if WordPress is installed by verifying required tables exist.
if ( ! function_exists( 'is_blog_installed' ) ) {
require_once ABSPATH . 'wp-includes/load.php';
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this needed? Clearly we have been using this function successfully before.

If this is needed, it requires a test proving it.


if ( is_blog_installed() && ( ! Utils\get_flag_value( $assoc_args, 'network' ) || is_multisite() ) ) {
global $wpdb;
// List of required core tables (prefix will be added automatically)
$required_tables = [
'options',
'users',
'usermeta',
'posts',
'comments',
'commentmeta',
'terms',
'termmeta',
'term_taxonomy',
'term_relationships',
'links',
'postmeta',
];
Copy link
Member

@swissspidy swissspidy Sep 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not hardcode this list, but instead get it from $wpbd. We need to check for multisite tables as well.

$missing_tables = [];

Check warning on line 418 in src/Core_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
foreach ( $required_tables as $table ) {
$table_name = $wpdb->prefix . $table;
// Check if table exists
$result = $wpdb->get_var( $wpdb->prepare(

Check failure on line 422 in src/Core_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Opening parenthesis of a multi-line function call must be the last content on the line
"SHOW TABLES LIKE %s", $table_name

Check failure on line 423 in src/Core_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Only one argument is allowed per line in a multi-line function call

Check failure on line 423 in src/Core_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

String "SHOW TABLES LIKE %s" does not require double quotes; use single quotes instead
) );

Check failure on line 424 in src/Core_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

Closing parenthesis of a multi-line function call must be on a line by itself
if ( $result !== $table_name ) {
$missing_tables[] = $table_name;
}
}
if ( ! empty( $missing_tables ) ) {
// Output missing tables for debugging
WP_CLI::error( "WordPress is not installed. Missing tables: " . implode( ', ', $missing_tables ), 1 );

Check failure on line 431 in src/Core_Command.php

View workflow job for this annotation

GitHub Actions / code-quality / PHPCS

String "WordPress is not installed. Missing tables: " does not require double quotes; use single quotes instead
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Regarding test coverage, there is for instance no test yet that verifies that this message is printed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed table existence check using $wpdb->tables()
Removed redundant function check ✅ Added test coverage for missing tables Ready for review

The command now reliably detects missing tables and returns appropriate exit codes. Let me know if you'd like any adjustments.

}
WP_CLI::halt( 0 );
}

WP_CLI::halt( 1 );
}

Expand Down
Loading