mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-11-27 09:36:19 -05:00
keep closed status when migrating poll to new style
This commit is contained in:
parent
d90063fc59
commit
43755a6fab
1 changed files with 32 additions and 0 deletions
|
@ -1,3 +1,28 @@
|
|||
CLOSED_POLL_PREFIXES = {
|
||||
"ar" => "هذا التصويت مغلق",
|
||||
"ca" => "Enquesta tancada",
|
||||
"de" => "Beendete Umfrage",
|
||||
"es" => "Encuesta cerrada",
|
||||
"fi" => "Suljettu kysely",
|
||||
"fr" => "Sondage fermé",
|
||||
"he" => "הצבעה סגורה",
|
||||
"it" => "Sondaggio Chiuso",
|
||||
"ko" => "투표 닫기",
|
||||
"pl_PL" => "Zamknięta ankieta",
|
||||
"pt" => "Votação encerrada",
|
||||
"pt_BR" => "Votação encerrada",
|
||||
"ru" => "Завершившийся опрос",
|
||||
"sq" => "Sondazh i Mbyllur",
|
||||
"te" => "మూసేసిన ఓటు",
|
||||
"tr_TR" => "Bitmiş Anket",
|
||||
"zh_CN" => "已关闭的投票:",
|
||||
}
|
||||
|
||||
def poll_was_closed?(title)
|
||||
prefix = CLOSED_POLL_PREFIXES[SiteSetting.default_locale] || "Closed Poll"
|
||||
title.start_with?(prefix)
|
||||
end
|
||||
|
||||
desc "Migrate old polls to new syntax"
|
||||
task "poll:migrate_old_polls" => :environment do
|
||||
require "timecop"
|
||||
|
@ -11,6 +36,8 @@ task "poll:migrate_old_polls" => :environment do
|
|||
# load the post from the db
|
||||
if post = Post.find_by(id: post_id)
|
||||
putc "."
|
||||
# skip if already migrated
|
||||
next if post.custom_fields.include?("polls")
|
||||
# go back in time
|
||||
Timecop.freeze(post.created_at + 1.minute) do
|
||||
post.raw = post.raw.gsub(/\n\n([ ]*[-\*\+] )/, "\n\\1") + "\n\n"
|
||||
|
@ -42,6 +69,11 @@ task "poll:migrate_old_polls" => :environment do
|
|||
# submit vote
|
||||
DiscoursePoll::Poll.vote(post_id, "poll", [selected_option["id"]], user_id) rescue nil
|
||||
end
|
||||
# close the poll
|
||||
if post.topic.archived? || post.topic.closed? || poll_was_closed?(post.topic.title)
|
||||
post.custom_fields["polls"]["poll"]["status"] = "closed"
|
||||
post.save_custom_fields(true)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue