progress->state ) { return $fix; } $undoing = $fix->with_progress( $fix->progress->with_state( FixState::Undoing ) ); $restored = $this->restore_posts( $undoing ); $stepped = array() === $restored->progress->journal ? $this->revert_links( $restored ) : $restored; $this->fix_repository->save_progress( $stepped ); $this->data_version->bump(); return $stepped; } private function restore_posts( Fix $fix ): Fix { $newest_entries = array_slice( array_reverse( $fix->progress->journal ), 0, StepLimits::POSTS_PER_STEP ); foreach ( $newest_entries as $entry ) { $this->post_content_writer->restore( $entry ); $fix = $fix->with_progress( $fix->progress->without_last_place() ); $this->fix_repository->save_progress( $fix ); } return $fix; } private function revert_links( Fix $fix ): Fix { $reverted = $this->link_outcome_store->revert( $fix->id, StepLimits::LINKS_PER_STEP ); $progress = $fix->progress->with_links_done( $fix->progress->links_done - $reverted ); if ( $reverted >= StepLimits::LINKS_PER_STEP ) { return $fix->with_progress( $progress ); } return $fix->with_progress( $progress->with_links_done( 0 )->with_state( FixState::Undone ) ); } }