FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Implement exclude revision flag to remove revision results from the search by imrraaj · Pull Request #255 · wp-cli/db-command · GitHub

Implement exclude revision flag to remove revision results from the search - #255

Open
imrraaj wants to merge 13 commits into
wp-cli:mainfrom
imrraaj:exclude_revisions
Open

Implement exclude revision flag to remove revision results from the search#255
imrraaj wants to merge 13 commits into
wp-cli:mainfrom
imrraaj:exclude_revisions

Conversation

imrraaj commented May 27, 2024

Copy link
Copy Markdown

This PR implements the exclude_revisions flag for wp db search command. This flag allows users to exclude revisions from the search results.

PR fixes following issues:

Usage

wp db search <search> [--tables=<tables>] [--exclude_revisions]

imrraaj marked this pull request as ready for review June 18, 2024 11:22
imrraaj requested a review from a team as a code owner June 18, 2024 11:22
Comment thread src/DB_Command.php Outdated
* @var string[] Array of SQL mode names that are incompatible with WordPress.
*/
protected $sql_incompatible_modes = [
protected $sql_incompatible_modes = array(

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Can you please revert changes in this and similar unrelated lines? For fixing code sniffer issues, please use composer run phpcbf. It seems you are using separate sniffer rules here.

Copy link
Copy Markdown
Member

@imrraaj Also can you please add Behat test for this new feature? Ref - https://make.wordpress.org/cli/handbook/contributions/pull-requests/#functional-tests

imrraaj commented Jun 19, 2024

Copy link
Copy Markdown
Author

@ernilambar I'll do the necessary changes and I'll add the tests for the same

imrraaj marked this pull request as draft June 20, 2024 08:29
imrraaj marked this pull request as ready for review June 25, 2024 12:26

Copy link
Copy Markdown

I hope you merge this into the new version of the WP CLI soon. I am still looking for a workaround to exclude revisions while exporting the database, but I can't find it yet.

swissspidy requested a review from Copilot November 2, 2025 14:46

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull Request Overview

This PR adds an --exclude_revisions flag to the wp db search command to filter out revision posts from search results in the wp_posts table.

Key changes:

  • Added --exclude_revisions parameter documentation to the search command
  • Implemented logic to exclude posts with post_type = 'revision' when the flag is enabled
  • Added test coverage for the new functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
src/DB_Command.php Added --exclude_revisions flag implementation with WHERE clause filtering for wp_posts table
features/db-search.feature Added test scenario verifying revision exclusion behavior

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/DB_Command.php Outdated
Comment thread src/DB_Command.php Outdated
Comment thread src/DB_Command.php Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>

codecov Bot commented Nov 2, 2025
edited
Loading

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 87.50000% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
src/DB_Command.php 87.50% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

github-actions Bot added command:db-search Related to 'db search' command scope:distribution Related to distribution labels Dec 22, 2025
swissspidy requested a review from Copilot March 12, 2026 12:42

Copy link
Copy Markdown
Member

/gemini review

This comment was marked as resolved.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated 4 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Comment thread src/DB_Command.php
Comment on lines 1560 to 1563
foreach ( $text_columns as $column ) {
$column_sql = self::esc_sql_ident( $column );
$column_sql = self::esc_sql_ident( $column );
$post_type_sql = self::esc_sql_ident( 'post_type' );
if ( $regex ) {

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

$post_type_sql is computed for every text column, but it never changes and is only needed when $exclude_revisions applies. Moving this identifier escaping outside the inner $text_columns loop (or only computing it when needed) would reduce repeated work and make the control flow easier to follow.

Copilot uses AI. Check for mistakes.
Comment thread features/db-search.feature Outdated
Comment thread features/db-search.feature Outdated
Comment thread src/DB_Command.php
Comment on lines +1564 to +1573
if ( $exclude_revisions && $wpdb->posts === $table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped through esc_sql_ident/esc_like.
$results = $wpdb->get_results( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql} WHERE {$post_type_sql} NOT IN ( 'revision' )" );
} else {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped through esc_sql_ident/esc_like.
$results = $wpdb->get_results( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql}" );
}
} elseif ( $exclude_revisions && $wpdb->posts === $table ) {
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- Escaped through esc_sql_ident/esc_like.
$results = $wpdb->get_results( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql}" );
$results = $wpdb->get_results( $wpdb->prepare( "SELECT {$primary_key_sql}{$column_sql} FROM {$table_sql} WHERE {$column_sql} LIKE %s AND {$post_type_sql} NOT IN ( 'revision' )", $esc_like_search ) );

Copilot AI Mar 12, 2026

Copy link

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

--exclude_revisions is only applied when $table === $wpdb->posts, which means revisions will still appear when searching a different posts table name (e.g. wp_2_posts during --network/--all-tables-with-prefix, or when the user explicitly passes another posts table). Consider applying the filter based on the table being a posts table (e.g. suffix check + verifying a post_type column exists), rather than only the current site's $wpdb->posts value.

Copilot uses AI. Check for mistakes.
swissspidy and others added 2 commits March 12, 2026 14:05
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

command:db-search Related to 'db search' command scope:distribution Related to distribution

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants


Back | FazBrowse Home | New Git URL