FEATURE: new rake task to rebake posts using regex matching

This commit is contained in:
Arpit Jalan 2016-08-16 22:48:28 +05:30
parent d29ccb5e48
commit 054ee4dc55
1 changed files with 29 additions and 0 deletions

View File

@ -26,6 +26,35 @@ task 'posts:fix_letter_avatars' => :environment do
puts "", "#{rebaked} posts done!", ""
end
desc 'Rebake all posts matching string/regex'
task 'posts:rebake_match', [:pattern, :type] => [:environment] do |_,args|
pattern = args[:pattern]
type = args[:type]
if !pattern
puts "ERROR: Expecting rake posts:rebake_match[pattern,type]"
exit 1
end
if type.downcase == "regex"
search = Post.where("raw ~ ?", pattern)
elsif type.downcase == "string" || !type
search = Post.where("raw ILIKE ?", "%#{pattern}%")
else
puts "ERROR: Expecting rake posts:rebake_match[pattern,type] where type is string or regex"
exit 1
end
rebaked = 0
total = search.count
search.order(updated_at: :asc).find_each do |post|
rebake_post(post)
print_status(rebaked += 1, total)
end
puts "", "#{rebaked} posts done!", ""
end
def rebake_posts_all_sites(opts = {})
RailsMultisite::ConnectionManagement.each_connection do |db|
rebake_posts(opts)