From 1581240eb791cf70901389ed6ac271262f9cd24e Mon Sep 17 00:00:00 2001 From: Hugo Melo Date: Mon, 5 Oct 2015 09:53:08 -0300 Subject: [PATCH] Add badge threshold migration --- db/migrate/20151003000212_move_badge_threshold_to_action_key.rb | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+), 0 deletions(-) create mode 100644 db/migrate/20151003000212_move_badge_threshold_to_action_key.rb diff --git a/db/migrate/20151003000212_move_badge_threshold_to_action_key.rb b/db/migrate/20151003000212_move_badge_threshold_to_action_key.rb new file mode 100644 index 0000000..8f3dedd --- /dev/null +++ b/db/migrate/20151003000212_move_badge_threshold_to_action_key.rb @@ -0,0 +1,23 @@ +class MoveBadgeThresholdToActionKey < ActiveRecord::Migration + def up + GamificationPlugin::Badge.all.each do |badge| + next if Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].nil? + Merit::BadgeRules::AVAILABLE_RULES.each do |name, settings| + setting = settings.first + badge.custom_fields[setting[:action]] = {threshold: badge.custom_fields[:threshold]} unless badge.custom_fields[:threshold].nil? + badge.save + end + end + end + + def down + GamificationPlugin::Badge.all.each do |badge| + next if Merit::BadgeRules::AVAILABLE_RULES[badge.name.to_sym].nil? + Merit::BadgeRules::AVAILABLE_RULES.each do |name, settings| + setting = settings.first + badge.custom_fields[:threshold] = badge.custom_fields[setting[:action]][:threshold] unless badge.custom_fields[setting[:action]][:threshold].nil? + badge.save + end + end + end +end -- libgit2 0.21.2