Skip to content
Merged
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
36 changes: 19 additions & 17 deletions inc/class-revisions-cli.php
Original file line number Diff line number Diff line change
Expand Up @@ -292,17 +292,23 @@ function ( $i ) {

$this->start_bulk_operation();

$inc = 0;
foreach ( $posts as $post_id ) {
if ( $filter_keep ) {
$keep = wp_revisions_to_keep( get_post( $post_id ) );
++$inc;
if ( 0 === $inc % 10 ) {
$this->stop_the_insanity();
}
if ( -1 === intval( $keep ) ) {
$notify->tick();
continue;
}
}

// phpcs:ignore WordPressVIPMinimum.Functions.RestrictedFunctions.get_posts_get_children
$revisions = get_children(
$revisions = wp_get_post_revisions(
$post_id,
array(
'order' => 'DESC',
'orderby' => 'date ID',
'post_parent' => $post_id,
'post_type' => 'revision',
'post_status' => 'inherit',
// trust me on these.
'update_post_meta_cache' => false,
'update_post_term_cache' => false,
'fields' => 'ids',
Expand All @@ -314,10 +320,6 @@ function ( $i ) {
continue;
}

if ( $filter_keep ) {
$keep = wp_revisions_to_keep( get_post( $post_id ) );
}

$count = count( $revisions );

if ( $count > $keep ) {
Expand Down Expand Up @@ -429,11 +431,6 @@ public function generate( $args = array(), $assoc_args = array() ) {
$notify = \WP_CLI\Utils\make_progress_bar( sprintf( 'Generating revisions for %d post(s)', $total ), $total );

$this->start_bulk_operation();
if ( ! defined( 'WP_INSTALLING' ) ) {
// Prevent unneeded cache-adds in some object cache implementations
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
define( 'WP_INSTALLING', true );
}

remove_all_filters( 'wp_revisions_to_keep' );
remove_all_filters( 'wp_insert_post_data' );
Expand Down Expand Up @@ -520,6 +517,11 @@ protected function stop_the_insanity() {
protected function start_bulk_operation() {
// Disable term count updates for speed
wp_defer_term_counting( true );
if ( ! defined( 'WP_INSTALLING' ) ) {
Copy link
Copy Markdown

@nlemoine nlemoine Jun 10, 2025

Choose a reason for hiding this comment

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

// Prevent unneeded cache-adds in some object cache implementations
// phpcs:ignore WordPress.NamingConventions.PrefixAllGlobals.NonPrefixedConstantFound
define( 'WP_INSTALLING', true );
}
}

/**
Expand Down