Commit daa36297d92116b0939c23dcdb3b4542643fd7a7
Exists in
master
and in
1 other branch
Improve script
Showing
2 changed files
with
27 additions
and
6 deletions
Show diff stats
lib/merit_ext.rb
script/process_merit_rules.rb
1 | 1 | #!/usr/bin/env ruby |
2 | 2 | # encoding: UTF-8 |
3 | 3 | |
4 | -def create_action(obj) | |
4 | +def create_action(obj, index, count) | |
5 | 5 | target_model = obj.class.base_class.name.downcase |
6 | 6 | action = Merit::Action.find_by_target_id_and_target_model_and_action_method(obj.id, target_model, 'create') |
7 | 7 | if action.nil? |
8 | - puts "Create merit action for #{target_model} #{obj.id}" | |
8 | + puts "#{index}/#{count} Create merit action for #{target_model} #{obj.id}" | |
9 | 9 | obj.new_merit_action(:create) |
10 | 10 | end |
11 | 11 | end |
12 | 12 | |
13 | +puts "Destroy all merit actions" | |
14 | +Merit::Action.destroy_all | |
15 | + | |
16 | +count = Person.count | |
17 | +Person.all.each.with_index(1) do |person, i| | |
18 | + puts "#{i}/#{count} Remove sash from #{person.identifier}" | |
19 | + person.sash.destroy unless person.sash.nil? | |
20 | +end | |
21 | + | |
13 | 22 | Environment.all.each do |environment| |
14 | 23 | |
15 | 24 | Merit::AppPointRules.clear |
... | ... | @@ -17,11 +26,22 @@ Environment.all.each do |environment| |
17 | 26 | Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) |
18 | 27 | Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) |
19 | 28 | |
20 | - environment.articles.each do |article| | |
21 | - create_action(article) | |
29 | + article_count = environment.articles.count | |
30 | + article_index = 0 | |
31 | + environment.articles.find_each do |article| | |
32 | + article_index += 1 | |
33 | + create_action(article, article_index, article_count) | |
34 | + | |
35 | + comment_count = article.comments.count | |
36 | + article.comments.each.with_index(1) do |comment, i| | |
37 | + create_action(comment, i, comment_count) | |
38 | + end | |
39 | + end | |
22 | 40 | |
23 | - article.comments.each do |comment| | |
24 | - create_action(comment) | |
41 | + environment.people.each.with_index(1) do |person, person_index| | |
42 | + vote_count = person.votes.count | |
43 | + person.votes.each.with_index(1) do |vote, vote_index| | |
44 | + create_action(vote, vote_index, vote_count) | |
25 | 45 | end |
26 | 46 | end |
27 | 47 | ... | ... |