Commit a3529df791e8c54a192b93569165a69fba1d8630
1 parent
c36a0459
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 | -def create_action(obj) | |
1 | +def create_action(obj, index, count) | |
2 | 2 | target_model = obj.class.base_class.name.downcase |
3 | 3 | action = Merit::Action.find_by_target_id_and_target_model_and_action_method(obj.id, target_model, 'create') |
4 | 4 | if action.nil? |
5 | - puts "Create merit action for #{target_model} #{obj.id}" | |
5 | + puts "#{index}/#{count} Create merit action for #{target_model} #{obj.id}" | |
6 | 6 | obj.new_merit_action(:create) |
7 | 7 | end |
8 | 8 | end |
9 | 9 | |
10 | +puts "Destroy all merit actions" | |
11 | +Merit::Action.destroy_all | |
12 | + | |
13 | +count = Person.count | |
14 | +Person.all.each.with_index(1) do |person, i| | |
15 | + puts "#{i}/#{count} Remove sash from #{person.identifier}" | |
16 | + person.sash.destroy unless person.sash.nil? | |
17 | +end | |
18 | + | |
10 | 19 | Environment.all.each do |environment| |
11 | 20 | |
12 | 21 | Merit::AppPointRules.clear |
... | ... | @@ -14,11 +23,22 @@ Environment.all.each do |environment| |
14 | 23 | Merit::AppPointRules.merge!(Merit::PointRules.new(environment).defined_rules) |
15 | 24 | Merit::AppBadgeRules.merge!(Merit::BadgeRules.new(environment).defined_rules) |
16 | 25 | |
17 | - environment.articles.each do |article| | |
18 | - create_action(article) | |
26 | + article_count = environment.articles.count | |
27 | + article_index = 0 | |
28 | + environment.articles.find_each do |article| | |
29 | + article_index += 1 | |
30 | + create_action(article, article_index, article_count) | |
31 | + | |
32 | + comment_count = article.comments.count | |
33 | + article.comments.each.with_index(1) do |comment, i| | |
34 | + create_action(comment, i, comment_count) | |
35 | + end | |
36 | + end | |
19 | 37 | |
20 | - article.comments.each do |comment| | |
21 | - create_action(comment) | |
38 | + environment.people.each.with_index(1) do |person, person_index| | |
39 | + vote_count = person.votes.count | |
40 | + person.votes.each.with_index(1) do |vote, vote_index| | |
41 | + create_action(vote, vote_index, vote_count) | |
22 | 42 | end |
23 | 43 | end |
24 | 44 | ... | ... |