046_fixup_forthcoming_publications.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:
Ajax
开发平台:
Others
- require 'bare_migration'
- class FixupForthcomingPublications < ActiveRecord::Migration
- class Trigger < ActiveRecord::Base
- belongs_to :pending_item, :polymorphic => true
- end
- class Content < ActiveRecord::Base
- end
- class Article < Content
- end
- def self.up
- return if $schema_generator
- Article.transaction do
- Trigger.transaction do
- Article.find(:all, :conditions => ['published = ? AND published_at > ?',
- true, Time.now]).each do |art|
- Trigger.create!(:pending_item => art,
- :due_at => art.published_at,
- :trigger_method => 'publish!')
- art.update_attribute(:published, false)
- end
- end
- end
- end
- def self.down
- return if $schema_generator
- Article.transaction do
- Trigger.transaction do
- Trigger.find(:all,
- :conditions => "pending_item_type = 'Article' AND trigger_method = 'publish!'").each do |t|
- t.pending_item.update_attribute(:published, :true)
- t.destroy
- end
- end
- end
- end
- end