Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"files": [ "revisions-cli.php" ]
},
"require-dev": {
"wp-cli/entity-command": "^1.3 || ^2",
"wp-cli/wp-cli-tests": "^4"
},
"minimum-stability": "dev",
Expand Down
14 changes: 14 additions & 0 deletions features/list.feature
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,17 @@ Feature: Revisions
"""
[]
"""

When I run `wp revisions generate 5 --post_type=page`
And I run `wp revisions list --post_type=page --format=count`
Then STDOUT should contain:
"""
10
"""

When I run `wp post delete $(wp post list --post_type=page --field=ID) --force`
And I run `wp revisions list --post_type=page --format=count`
Then STDOUT should contain:
"""
0
"""
22 changes: 12 additions & 10 deletions inc/class-revisions-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,19 +104,21 @@ function ( $i ) {
wp_parse_slug_list( $assoc_args['post_type'] )
);
$where = sprintf( 'AND post_type IN ( %s )', implode( ',', $post_types ) );

// get all IDs for posts in given post type(s).
$ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE 1=2 {$where}" );

// Prepare the IDs for inclusion in the query.
$post__in = array_map( 'esc_sql', $ids );
$post__in = implode( ',', $ids );
$ids = $wpdb->get_col( "SELECT ID FROM $wpdb->posts WHERE 1=1 {$where}" );

// get revisions of those IDs.
$revs = $wpdb->get_results(
"SELECT * FROM $wpdb->posts WHERE post_type = 'revision' AND post_parent IN ({$post__in}) ORDER BY post_parent DESC"
);
if ( $ids ) {
// Prepare the IDs for inclusion in the query.
$post__in = array_map( 'esc_sql', $ids );
$post__in = implode( ',', $ids );

// get revisions of those IDs.
$revs = $wpdb->get_results(
"SELECT * FROM $wpdb->posts WHERE post_type = 'revision' AND post_parent IN ({$post__in}) ORDER BY post_parent DESC"
);
} else {
$revs = [];
}
} else {

$revs = $wpdb->get_results(
Expand Down