| Class | Admin::HomeController |
| In: |
app/controllers/admin/home_controller.rb
|
| Parent: | Admin::BaseController |
| MAINTENANCE | = | false |
archive and then delete data
# File app/controllers/admin/home_controller.rb, line 47
47: def archive
48: if (@maintenance = MAINTENANCE) && request.post?
49: # dump db
50: db = PRODUCTION ? 'photocracy' : 'photocracy_stage'
51: %x(~/mysqldump_script.sh #{db} VL1nd33er #{db} '#{Constants::SHARED_ROOT}db')
52: # archive attachments and delete data
53: path_to_attachments = "#{RAILS_ROOT}/public/system/"
54: %x(~/tar_dump.sh 0000 #{path_to_attachments} && rm -rf #{path_to_attachments}0000)
55: Attachment.delete_all
56: Item.delete_all
57: ItemsQuestion.delete_all
58: Prompt.delete_all
59: ActiveRecord::Base.connection.execute("DELETE FROM `items_prompts`")
60: Response.delete_all
61: ActiveRecord::Base.connection.execute("DELETE FROM `items_responses`")
62: Comment.delete_all
63: Flag.delete_all
64: Visit.delete_all
65: Tracking.delete_all
66: session[:last_prompt_id] = nil
67: session[:question_prompts_shown] = nil
68: session[:prompts_shown] = nil
69: session[:active_prompt] = nil
70: session[:next_prompt_id] = nil
71: session[:question] = nil
72: session[:next_question] = nil
73: session[:question_responses] = nil
74: session[:visit] = nil
75: current_visit!
76: flash[:notice] = 'Deleted and archived'
77: end
78: redirect_to admin_path
79: end
# File app/controllers/admin/home_controller.rb, line 119
119: def clean_questions
120: nil_links = ItemsQuestion.find_by_sql("SELECT items_questions.id FROM items_questions LEFT OUTER JOIN items ON (items.id=items_questions.item_id) WHERE items.id IS NULL")
121: nil_links.map(&:delete)
122: flash[:notice] = nil_links.map(&:id).inspect
123: redirect_to admin_path
124: end
# File app/controllers/admin/home_controller.rb, line 113
113: def deactivate_admin_responses
114: response_ids = Systems::Syncing.deactivate_admin_responses
115: flash[:notice] = "#{response_ids.length} responses deactivated"
116: redirect_to admin_path
117: end
# File app/controllers/admin/home_controller.rb, line 81
81: def generate_stats
82: items = Item.all(:include => :questions)
83: groups = Group.all
84: Stat.transaction do
85: for item in items
86: for question in item.questions
87: for group in groups
88: losses = Response.count(
89: :joins => "INNER JOIN items_responses ON (items_responses.response_id=responses.id AND items_responses.item_id IS NOT NULL AND items_responses.item_id!=#{item.id}) INNER JOIN prompts ON (responses.prompt_id=prompts.id AND prompts.question_id=#{question.id}) INNER JOIN items_prompts ON (items_prompts.prompt_id=prompts.id AND items_prompts.item_id=#{item.id})",
90: :conditions => { 'responses.active''responses.active' => true, 'responses.ip_country_code' => group.code }
91: )
92: Stat.create(
93: :item_id => item.id,
94: :question_id => question.id,
95: :group_id => group.id,
96: :ratings => item.ratings_for_country(group.code, question.id, false),
97: :wins => item.wins_for_country(group.code, question.id),
98: :losses => losses
99: )
100: end
101: end
102: end
103: end
104: redirect_to admin_path
105: end
# File app/controllers/admin/home_controller.rb, line 12
12: def index
13: @maintenance = false
14: @debug_percents = false
15: @questions = Question.all.inject([]) do |array, el|
16: array << stats_for_question(el).unshift(el.items)
17: end if @debug_percents
18: end
# File app/controllers/admin/home_controller.rb, line 20
20: def settings
21: if id = params.delete(:id)
22: param = Param.find_by_code(id)
23: if request.xhr?
24: value = percent_value?(id) ? 100 - params[:value].to_f : params[:value]
25: if param
26: param.update_attribute(:value, value)
27: else
28: Param.create(:name => id, :value => value)
29: end
30: render :update do |page|
31: page.redirect_to :action => :settings, :id => nil
32: end
33: else
34: if param && param.value == 'f'
35: param.update_attribute(:value, 't')
36: elsif param
37: param.update_attribute(:value, 'f')
38: else
39: Param.create_for_code(id, 'f')
40: end
41: redirect_to :action => :settings, :id => nil
42: end
43: end
44: end