From e9b70ac9cbac0eb3dd897391b4cc1f6cc38e6d43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 30 Apr 2015 17:08:44 +0200 Subject: [PATCH] FIX: migrate old polls rake task --- plugins/poll/lib/tasks/migrate_old_polls.rake | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/plugins/poll/lib/tasks/migrate_old_polls.rake b/plugins/poll/lib/tasks/migrate_old_polls.rake index 44175c9a5..839998060 100644 --- a/plugins/poll/lib/tasks/migrate_old_polls.rake +++ b/plugins/poll/lib/tasks/migrate_old_polls.rake @@ -1,5 +1,6 @@ desc "Migrate old polls to new syntax" task "poll:migrate_old_polls" => :environment do + require "timecop" # iterate over all polls PluginStoreRow.where(plugin_name: "poll") .where("key LIKE 'poll_options_%'") @@ -14,8 +15,10 @@ task "poll:migrate_old_polls" => :environment do Timecop.freeze(post.created_at + 1.minute) do # fix the RAW when needed if post.raw !~ /\[poll\]/ - first_list = /(^- .+?$\n)\n/m.match(post.raw)[0] - post.raw = post.raw.sub(first_list, "[poll]\n#{first_list}\n[/poll]") + lists = /(^[ ]*- .+?$\n)\n/m.match(post.raw) + 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 post.raw = post.raw + " " end