Skip to content

Commit 681d4c0

Browse files
Copilotswissspidy
andcommitted
Revert to early continue pattern and fix progress tick to count by batch
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 59217ca commit 681d4c0

1 file changed

Lines changed: 31 additions & 24 deletions

File tree

‎src/Search_Replace_Command.php‎

Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -698,35 +698,42 @@ static function ( $key ) {
698698
// phpcs:ignore WordPress.DB.PreparedSQL.InterpolatedNotPrepared -- escaped through self::esc_sql_ident
699699
$col_value = $wpdb->get_var( "SELECT {$col_sql} FROM {$table_sql} WHERE {$where_sql}" );
700700

701-
if ( '' !== $col_value ) {
702-
$value = $replacer->run( $col_value );
703-
704-
if ( $value !== $col_value && gettype( $value ) === gettype( $col_value ) ) {
705-
// In case a needed re-serialization was unsuccessful, we should not update the value,
706-
// as this implies we hit an exception while processing.
707-
708-
if ( $this->log_handle ) {
709-
$this->log_php_diff( $col, $keys, $table, $old, $new, $replacer->get_log_data() );
710-
$replacer->clear_log_data();
711-
}
712-
713-
++$count;
714-
if ( ! $this->dry_run ) {
715-
$update_where = array();
716-
foreach ( (array) $keys as $k => $v ) {
717-
$update_where[ $k ] = $v;
718-
}
719-
720-
$wpdb->update( $table, [ $col => $value ], $update_where );
721-
}
722-
}
701+
if ( '' === $col_value ) {
702+
continue;
703+
}
704+
705+
$value = $replacer->run( $col_value );
706+
707+
if ( $value === $col_value ) {
708+
continue;
709+
}
710+
711+
// In case a needed re-serialization was unsuccessful, we should not update the value,
712+
// as this implies we hit an exception while processing.
713+
if ( gettype( $value ) !== gettype( $col_value ) ) {
714+
continue;
715+
}
716+
717+
if ( $this->log_handle ) {
718+
$this->log_php_diff( $col, $keys, $table, $old, $new, $replacer->get_log_data() );
719+
$replacer->clear_log_data();
723720
}
724721

725-
if ( $progress ) {
726-
$progress->tick();
722+
++$count;
723+
if ( ! $this->dry_run ) {
724+
$update_where = array();
725+
foreach ( (array) $keys as $k => $v ) {
726+
$update_where[ $k ] = $v;
727+
}
728+
729+
$wpdb->update( $table, [ $col => $value ], $update_where );
727730
}
728731
}
729732

733+
if ( $progress ) {
734+
$progress->tick( count( $rows ) );
735+
}
736+
730737
// Because we are ordering by primary keys from least to greatest,
731738
// we can exclude previous chunks from consideration by adding greater-than conditions
732739
// to insist the next chunk's keys must be greater than the last of this chunk's keys.

0 commit comments

Comments
 (0)