class Admin::DashboardController < AdminController layout "cms" def user_comment comment = Comment.sys(_sid).where(:id=>params[:id]).first if comment comment.update_attributes(params[:comment]) end render :js=>"updated(#{comment.id}, #{comment.is_moderated}, #{comment.is_visible});" end def user_comments if params.size==2 params[:unmoderated] = "1" params[:visible] = "1" params[:invisible] = "1" end @comments = Comment.sys(_sid).order("created_at desc") conditions = [] conditions << "is_moderated = -1" conditions << "is_moderated = 1" if params[:moderated] conditions << "is_moderated = 0" if params[:unmoderated] @comments = @comments.where(conditions.join(" or ")) conditions = [] conditions << "is_visible = -1" conditions << "is_visible = 1" if params[:visible] conditions << "is_visible = 0" if params[:invisible] @comments = @comments.where(conditions.join(" or ")) @comments = @comments.page(params[:page]).per(params[:per] || 50) end def error raise Exception("Simulated error") end def plumb end def maintenance message = params[:message] if message.not_blank? Preference.set(_sid, "down_for_maintenance_message", message) else Preference.delete(_sid, "down_for_maintenance_message") end redirect_to "/admin/system", :notice=>"Message set" end def salesforce client = Databasedotcom::Client.new :client_id => "3MVG99qusVZJwhsnYBQ82sOeClHKBKrjEb5GTvhWfI_QwP72acY3t0TkXkjjFp7SadN3j7uywOrS5S8fAMYhX", :client_secret => "6488955455249765126" client.authenticate :username => "trial@dsc.net", :password => "sales1016c0S0Bc5EXrX2dRnRs8vb2bOm" @cats = client.materialize("Cat__c") end def logfile filename = Rails.root.join('log', Rails.env + '.log') if params[:grep].not_blank? @output = `grep "#{params[:grep]}" #{filename}` else @lines = [] File.open(filename) do |file| @file = file @file.extend(File::Tail) @file.backward((params[:lines] || "500").to_i ) render "logfile" end end end def events raise Exception("permissions") unless can?(:dashboard, :super) if request.delete? Event.delete_all end @events = Event.order("created_at desc").page(params[:page]).per(50) end def event raise Exception("permissions") unless can?(:dashboard, :super) @event = Event.where(:id=>params[:id]).first end def index end def system raise Exception("permissions") unless can?(:dashboard, :super) @preferences = Preference.sys(_sid).where("user_id is null").order(:name) @preferences = @preferences.all end def build_system raise Exception("permissions") unless can?(:dashboard, :super) if request.post? if params[:password] != params[:password_confirm] flash[:notice] = "Passwords don't match" return end if params[:password].length < 8 flash[:notice] = "This password controls the whole system - it must be at least 8 characters" return end if params[:name].strip.length < 1 flash[:notice] = "You must enter a system name" return end if params[:domain_name].strip.length < 1 flash[:notice] = "You must enter a domain name" return end params[:full_name] ||= params[:name] system = System.new(:name=>params[:name]) system.save SystemIdentifier.create(:system_id=>system.id, :ident_type=>"hostname", :ident_value=>params[:domain_name]) user = User.create(:system_id=>system.id, :email=>params[:email], :password=>params[:password]) role = Role.create(:system_id=>system.id, :name=>"SuperAdmin") user.roles << role Preference.get!(system.id, 'app_name', params[:name], nil) Preference.get!(system.id, 'site_name', params[:full_name], nil) Preference.get!(system.id, 'host', "http://#{params[:domain_name]}") redirect_to "/admin/integrity?system_id=#{system.id}" end end def integrity raise Exception("permissions") unless can?(:dashboard, :super) [ "js", "css", "other" ].each do |d| dir = File.join(Rails.root, "public", "kit", d) Dir::mkdir(dir) unless File.exists?(dir) end @checks = [] sid = params[:system_id] HtmlAsset.sys(sid).each do |ha| HtmlAsset.fetch(sid, ha.name, ha.file_type) end @system_id = sid prefs = { date_time_format: "%H:%M %d-%m-%y", app_name: System.find(sid).name.downcase, spam_points_to_ban_user: 5, error_layout: "application", notify: "tech@dsc.net" } prefs.each do |name, value| @checks << "Check preference '#{name}' exists and creating it if not" Preference.get!(sid, name.to_s, value, nil) end if Topic.sys(sid).count == 0 @checks << warning_message('There are no forum topics') end Topic.sys(sid).find_each do |topic| @checks << "Setting thread count and last post on topic '#{topic.name}'" topic.thread_count = topic.topic_threads.count last_post = TopicPost.joins(:topic_thread).order("topic_posts.id desc").where("topic_threads.topic_id = #{topic.id}").limit(1).first topic.last_post_at = last_post.updated_at rescue nil topic.save end if params[:forums] @checks << "Setting post count and last post info on threads" Topic.find_each do |topic| topic.last_thread_id = nil topic.post_count = 0 topic.last_post_at = nil topic.post_count = 0 topic.save end last_post_per_topic = {} TopicThread.find_each do |thread| posts = thread.topic_posts.order("topic_posts.created_at") n = 0 posts.reverse.each do |post| if post.is_visible==1 n += 1 post.post_number = n else post.post_number = 0 end begin post.save rescue end end last_post = posts.first first_post = posts.last thread.post_count = n thread.last_post_at = last_post.created_at thread.last_post_by_user_id = last_post.created_by_user_id thread.created_by_user_display_name = thread.created_by_user.display_name rescue '' thread.last_post_by_user_display_name = last_post.created_by_user.display_name thread.first_post_id = first_post.id thread.save thread.topic.thread_count += 1 rescue 1 thread.topic.post_count += n rescue 1 thread.topic.last_thread_id = thread.id if last_post_per_topic[thread.topic_id]==nil || last_post.id > last_post_per_topic[thread.topic_id] last_post_per_topic[thread.topic_id] = last_post.id end thread.topic.save end last_post_per_topic.each do |topic_id, last_post_id| topic = Topic.find(topic_id) next unless topic topic.last_post_id = last_post_id topic.last_post_at = TopicPost.find(last_post_id).created_at topic.save end @checks << "Forum votes" post_scores = {} user_scores = {} user_votes = {} TopicPostVote.find_each do |topic_post_vote| post_scores[topic_post_vote.topic_post_id] ||= 0 post_scores[topic_post_vote.topic_post_id] += topic_post_vote.score user_scores[topic_post_vote.topic_post.created_by_user_id] ||= 0 user_scores[topic_post_vote.topic_post.created_by_user_id] += topic_post_vote.score user_votes[topic_post_vote.topic_post.created_by_user_id] ||= 0 user_votes[topic_post_vote.topic_post.created_by_user_id] += 1 end post_scores.each do |k,v| TopicPost.connection.execute("update topic_posts set score = #{v} where id = #{k}") end user_scores.each do |k,v| User.connection.execute("update users set forum_points = #{v}, forum_votes = #{user_votes[k]} where id = #{k}") end end @checks << "Checking statuses" i = 0 ["Editing", "For review", "Ready for publication", "Published", "Withdrawn", "Stub"].each do |status| i += 1 if Status.sys(sid).where(:name=>status).count==0 @checks << "Creating '#{status}'" Status.create(:name=>status, :order_by=>i, :is_published=>(status=="Published"), :is_default=>(status=='Editing'), :is_stub=>(status=='Stub'), :system_id=>sid) end end @checks << "Check editor-styles block exists and creating if not" Block.ensure(sid, "editor-styles", "
") @checks << "Check editor-blocks block exists and creating if not" Block.ensure(sid, "editor-blocks", "