wiki: fix titles with invalid space characters.

Fix wiki pages that have titles containing space characters.
This commit is contained in:
evazion
2020-07-16 11:42:59 -05:00
parent afef9cc9ab
commit 9f53c459c8

View File

@@ -0,0 +1,21 @@
#!/usr/bin/env ruby
require_relative "../../config/environment"
CurrentUser.user = User.system
CurrentUser.ip_addr = "127.0.0.1"
# Fix wiki page titles containing invalid space characters.
WikiPage.transaction do
WikiPage.where("title ~ '\\s'").find_each do |wiki_page|
wiki_page.normalize_title
wiki_page.save!
# handle name conflicts
rescue ActiveRecord::RecordInvalid
wiki_page.normalize_title
wiki_page.title = "#{wiki_page.title}_#{wiki_page.id}"
wiki_page.save!
ensure
puts "wiki id=#{wiki_page.id} title=#{wiki_page.title}"
end
end