mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-17 19:12:37 -05:00
FIX: migrate old polls rake task
This commit is contained in:
parent
9e16e03198
commit
e9b70ac9cb
1 changed files with 5 additions and 2 deletions
|
@ -1,5 +1,6 @@
|
||||||
desc "Migrate old polls to new syntax"
|
desc "Migrate old polls to new syntax"
|
||||||
task "poll:migrate_old_polls" => :environment do
|
task "poll:migrate_old_polls" => :environment do
|
||||||
|
require "timecop"
|
||||||
# iterate over all polls
|
# iterate over all polls
|
||||||
PluginStoreRow.where(plugin_name: "poll")
|
PluginStoreRow.where(plugin_name: "poll")
|
||||||
.where("key LIKE 'poll_options_%'")
|
.where("key LIKE 'poll_options_%'")
|
||||||
|
@ -14,8 +15,10 @@ task "poll:migrate_old_polls" => :environment do
|
||||||
Timecop.freeze(post.created_at + 1.minute) do
|
Timecop.freeze(post.created_at + 1.minute) do
|
||||||
# fix the RAW when needed
|
# fix the RAW when needed
|
||||||
if post.raw !~ /\[poll\]/
|
if post.raw !~ /\[poll\]/
|
||||||
first_list = /(^- .+?$\n)\n/m.match(post.raw)[0]
|
lists = /(^[ ]*- .+?$\n)\n/m.match(post.raw)
|
||||||
post.raw = post.raw.sub(first_list, "[poll]\n#{first_list}\n[/poll]")
|
next if lists.blank? || lists.length == 0
|
||||||
|
first_list = lists[0]
|
||||||
|
post.raw = post.raw.sub(first_list, "\n[poll]\n#{first_list}\n[/poll]\n")
|
||||||
else
|
else
|
||||||
post.raw = post.raw + " "
|
post.raw = post.raw + " "
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue