Commit c36a0459872f3d63e07cd2764b1d966d8afd92bd
1 parent
5b0ecadc
Exists in
master
and in
1 other branch
Script to load merit actions that happened before plugin activation
Showing
1 changed file
with
25 additions
and
0 deletions
Show diff stats
| ... | ... | @@ -0,0 +1,25 @@ |
| 1 | +def create_action(obj) | |
| 2 | + target_model = obj.class.base_class.name.downcase | |
| 3 | + action = Merit::Action.find_by_target_id_and_target_model_and_action_method(obj.id, target_model, 'create') | |
| 4 | + if action.nil? | |
| 5 | + puts "Create merit action for #{target_model} #{obj.id}" | |
| 6 | + obj.new_merit_action(:create) | |
| 7 | + end | |
| 8 | +end | |
| 9 | + | |
| 10 | +Environment.all.each do |environment| | |
| 11 | + | |
| 12 | + Merit::AppPointRules.clear | |
| 13 | + Merit::AppBadgeRules.clear | |
| 14 | + Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) | |
| 15 | + Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) | |
| 16 | + | |
| 17 | + environment.articles.each do |article| | |
| 18 | + create_action(article) | |
| 19 | + | |
| 20 | + article.comments.each do |comment| | |
| 21 | + create_action(comment) | |
| 22 | + end | |
| 23 | + end | |
| 24 | + | |
| 25 | +end | ... | ... |