Skip to content

Commit 77534f5

Browse files
Copilotswissspidy
andcommitted
Refactor progress tick to reduce code duplication
Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com>
1 parent 61e02c0 commit 77534f5

1 file changed

Lines changed: 21 additions & 37 deletions

File tree

src/Search_Replace_Command.php

Lines changed: 21 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -698,44 +698,28 @@ 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-
if ( $progress ) {
703-
$progress->tick();
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+
}
704722
}
705-
continue;
706-
}
707-
708-
$value = $replacer->run( $col_value );
709-
710-
if ( $value === $col_value ) {
711-
if ( $progress ) {
712-
$progress->tick();
713-
}
714-
continue;
715-
}
716-
717-
// In case a needed re-serialization was unsuccessful, we should not update the value,
718-
// as this implies we hit an exception while processing.
719-
if ( gettype( $value ) !== gettype( $col_value ) ) {
720-
if ( $progress ) {
721-
$progress->tick();
722-
}
723-
continue;
724-
}
725-
726-
if ( $this->log_handle ) {
727-
$this->log_php_diff( $col, $keys, $table, $old, $new, $replacer->get_log_data() );
728-
$replacer->clear_log_data();
729-
}
730-
731-
++$count;
732-
if ( ! $this->dry_run ) {
733-
$update_where = array();
734-
foreach ( (array) $keys as $k => $v ) {
735-
$update_where[ $k ] = $v;
736-
}
737-
738-
$wpdb->update( $table, [ $col => $value ], $update_where );
739723
}
740724

741725
if ( $progress ) {

0 commit comments

Comments
 (0)