Created
April 2, 2009 19:55
-
-
Save jgagne33/89400 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def downgrade | |
self.max_photos = 3 | |
self.coverage_id = Coverage.free.id | |
end | |
def repost | |
# downgrade. the logic that fills premium, should_float and payment_required is already on coverage_id setter | |
self.downgrade | |
# change expires | |
self.expires_at = 6.months.from_now | |
save! | |
end | |
desc 'Downgrade expired premium posts' | |
task :downgrade_expired do | |
require File.join(File.dirname(__FILE__)) + '/../../config/environment' | |
ActiveRecord::Base.establish_connection | |
posts = Post.find(:all , :conditions => "expires_at < '#{Time.now.to_s(:db)}' AND premium = true") | |
posts.each do |post| | |
post.downgrade | |
save! | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment