049_move_feedback_to_new_state_machine.rb
上传用户:netsea168
上传日期:2022-07-22
资源大小:4652k
文件大小:1k
源码类别:

Ajax

开发平台:

Others

  1. class MoveFeedbackToNewStateMachine < ActiveRecord::Migration
  2.   class Content < ActiveRecord::Base
  3.     include BareMigration
  4.   end
  5.   def self.up
  6.     return if $schema_generator
  7.     Content.find(:all,
  8.                  :conditions => ['type = ? or type = ?',
  9.                                     'Trackback', 'Comment']).each do |c|
  10.       c.state = if c.published?
  11.                   'ContentState::PresumedHam'
  12.                 else
  13.                   'ContentState::PresumedSpam'
  14.                 end
  15.       c.save!
  16.     end
  17.   end
  18.   def self.down
  19.     return if $schema_generator
  20.     Content.find(:all,
  21.                  :conditions => ['type = ? or type = ?',
  22.                                     'Trackback', 'Comment']).each do |c|
  23.       c.state = if c.published?
  24.                   'ContentState::Published'
  25.                 else
  26.                   'ContentState::Withdrawn'
  27.                 end
  28.       c.save!
  29.     end
  30.   end
  31. end