FEATURE: Add rake task to mark old hashtag format for rebake (#19876)

Since the new hashtag format has been added, we want site
admins to be able to rebake old posts with the old hashtag
format. This can now be done with `rake hashtags:mark_old_format_for_rebake`
which goes and marks posts with the old cooked version of hashtags
in this format for rebake:

```
<a class=\"hashtag\" href=\"/c/ux/14\">#<span>ux</span></a>
```

c.f. https://meta.discourse.org/t/what-rebake-is-required-for-the-new-autocomplete-styling/249642/12
This commit is contained in:
Martin Brennan
2023-01-18 10:16:05 +10:00
committed by GitHub
parent 115dfccf3b
commit 56a93f7532
2 changed files with 51 additions and 0 deletions

15
lib/tasks/hashtags.rake Normal file
View File

@ -0,0 +1,15 @@
# frozen_string_literal: true
desc "Mark posts with the old hashtag cooked format (pre enable_experimental_hashtag_autocomplete) for rebake"
task "hashtags:mark_old_format_for_rebake" => :environment do
# See Post#rebake_old, which is called via the PeriodicalUpdates job
# on a schedule.
puts "Finding posts matching old format, this could take some time..."
posts_to_rebake = Post.where("cooked like '%class=\"hashtag\"%'")
STDOUT.puts(
"[!] You are about to mark #{posts_to_rebake.count} posts containing hashtags in the old format to rebake. [CTRL+c] to cancel, [ENTER] to continue",
)
STDIN.gets.chomp if !Rails.env.test?
posts_to_rebake.update_all(baked_version: 0)
puts "Done, rebakes will happen when periodal updates job runs."
end