FIX: update 'migrate_old_polls' rake task to support more cases
FIX: support list that uses double newlines FIX: support list that uses spaces before the '-' FIX: don't break lamentably when a poll wasn't created
This commit is contained in:
parent
29631f65f1
commit
4df868a420
|
@ -13,16 +13,18 @@ task "poll:migrate_old_polls" => :environment do
|
||||||
putc "."
|
putc "."
|
||||||
# go back in time
|
# go back in time
|
||||||
Timecop.freeze(post.created_at + 1.minute) do
|
Timecop.freeze(post.created_at + 1.minute) do
|
||||||
|
post.raw = post.raw.gsub(/\n\n([ ]*- )/, "\n\\1") + "\n\n"
|
||||||
# fix the RAW when needed
|
# fix the RAW when needed
|
||||||
post.raw << "\n\n"
|
|
||||||
if post.raw !~ /\[poll\]/
|
if post.raw !~ /\[poll\]/
|
||||||
lists = /^[ ]*- .+?$\n\n/m.match(post.raw)
|
lists = /^[ ]*- .+?$\n\n/m.match(post.raw)
|
||||||
next if lists.blank? || lists.length == 0
|
next if lists.blank? || lists.length == 0
|
||||||
first_list = lists[0]
|
first_list = lists[0]
|
||||||
post.raw = post.raw.sub(first_list, "\n[poll]\n#{first_list.strip}\n[/poll]\n")
|
post.raw = post.raw.sub(first_list, "\n[poll]\n#{first_list}\n[/poll]\n")
|
||||||
end
|
end
|
||||||
# save the poll
|
# save the poll
|
||||||
post.save
|
post.save
|
||||||
|
# make sure we have a poll
|
||||||
|
next if post.custom_fields.blank? || !post.custom_fields.include?("polls")
|
||||||
# retrieve the new options
|
# retrieve the new options
|
||||||
options = post.custom_fields["polls"]["poll"]["options"]
|
options = post.custom_fields["polls"]["poll"]["options"]
|
||||||
# iterate over all votes
|
# iterate over all votes
|
||||||
|
|
Loading…
Reference in New Issue