weibo: normalize weibo urls in artist entries.
Normalize all Weibo URLs in artist entries to one of these forms: * https://www.weibo.com/u/5399876326 * https://www.weibo.com/p/1005055399876326 * https://www.weibo.com/chengziyou666
This commit is contained in:
@@ -61,6 +61,17 @@ class Artist < ApplicationRecord
|
||||
def clear_url_string_changed
|
||||
self.url_string_changed = false
|
||||
end
|
||||
|
||||
class_methods do
|
||||
# Find all artist URLs matching `regex`, and replace the `from` regex with the `to` string.
|
||||
def rewrite_urls(regex, from, to)
|
||||
Artist.transaction do
|
||||
Artist.joins(:urls).where_regex("artist_urls.url", regex).find_each do |artist|
|
||||
artist.update!(url_string: artist.url_string.gsub(from, to))
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
concerning :NameMethods do
|
||||
|
||||
Reference in New Issue
Block a user