FIX: close existing polls in closed topics to keep old behaviour

This commit is contained in:
Régis Hanol 2016-03-21 23:09:36 +01:00
parent b8929b906c
commit 6c579ba932
1 changed files with 18 additions and 0 deletions

View File

@ -0,0 +1,18 @@
class ClosePollsInClosedTopics < ActiveRecord::Migration
def up
PostCustomField.joins(post: :topic)
.where("post_custom_fields.name = 'polls'")
.where("topics.closed")
.find_each do |pcf|
polls = ::JSON.parse(pcf.value || "{}")
polls.values.each { |poll| poll["status"] = "closed" }
pcf.value = polls.to_json
pcf.save
end
end
def down
end
end