diff --git a/.gitignore b/.gitignore index ca12f81a9..af337a4e7 100644 --- a/.gitignore +++ b/.gitignore @@ -7,8 +7,11 @@ /config/configuration.yml /files/* /log/* +/public/tmp/* /tmp/* +/public/cache/* .gitignore +/config/newrelic.yml /public/images/avatars/* /Gemfile /Gemfile.lock diff --git a/.metadata/.plugins/org.eclipse.core.resources/.root/4.tree b/.metadata/.plugins/org.eclipse.core.resources/.root/4.tree new file mode 100644 index 000000000..942a97c51 Binary files /dev/null and b/.metadata/.plugins/org.eclipse.core.resources/.root/4.tree differ diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.core.io.15 b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.core.io.15 new file mode 100644 index 000000000..971c3ef7e --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.core.io.15 @@ -0,0 +1,3 @@ +#safe table +#Mon Jan 05 10:27:54 CST 2015 +connections=connections.15 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.syncing.core.15 b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.syncing.core.15 new file mode 100644 index 000000000..01bf076fe --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.syncing.core.15 @@ -0,0 +1,4 @@ +#safe table +#Mon Jan 05 10:27:54 CST 2015 +defaultConnection=defaultConnection.15 +sites=sites.15 diff --git a/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.webserver.core.12 b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.webserver.core.12 new file mode 100644 index 000000000..26cede301 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.core.resources/.safetable/com.aptana.webserver.core.12 @@ -0,0 +1,3 @@ +#safe table +#Mon Jan 05 10:27:28 CST 2015 +webservers=webservers.12 diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.history b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.history new file mode 100644 index 000000000..664784aa9 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.history @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.index b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.index new file mode 100644 index 000000000..d5428a792 --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.core.refactoring/.refactorings/.workspace/2015/1/2/refactorings.index @@ -0,0 +1,2 @@ +1420424676858 Delete resource 'trustie2' +1420424775104 Delete resource 'trustie2' diff --git a/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml new file mode 100644 index 000000000..27eb4040f --- /dev/null +++ b/.metadata/.plugins/org.eclipse.ltk.ui.refactoring/dialog_settings.xml @@ -0,0 +1,7 @@ + +
+
+ + +
+
diff --git a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml index eba54f80b..09856e2e7 100644 --- a/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.ui.ide/dialog_settings.xml @@ -11,4 +11,16 @@ +
+ + +
+
+ + +
+
+ + +
diff --git a/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml b/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml index f7e4d66f0..c8c1e4f77 100644 --- a/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml +++ b/.metadata/.plugins/org.eclipse.ui.workbench/dialog_settings.xml @@ -1,7 +1,9 @@
+
+
- + diff --git a/Gemfile b/Gemfile index af85ff339..d3581d75e 100644 --- a/Gemfile +++ b/Gemfile @@ -20,7 +20,8 @@ gem "builder", "3.0.0" gem 'acts-as-taggable-on', '2.4.1' gem 'spreadsheet' gem 'ruby-ole' -#gem 'email_verifier' +gem 'email_verifier' +gem 'newrelic_rpm' group :development do gem 'grape-swagger' diff --git a/app/assets/javascripts/system_log.js.coffee b/app/assets/javascripts/system_log.js.coffee new file mode 100644 index 000000000..761567942 --- /dev/null +++ b/app/assets/javascripts/system_log.js.coffee @@ -0,0 +1,3 @@ +# Place all the behaviors and hooks related to the matching controller here. +# All this logic will automatically be available in application.js. +# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/ diff --git a/app/assets/stylesheets/system_log.css.scss b/app/assets/stylesheets/system_log.css.scss new file mode 100644 index 000000000..aa1f18587 --- /dev/null +++ b/app/assets/stylesheets/system_log.css.scss @@ -0,0 +1,3 @@ +// Place all the styles related to the system_log controller here. +// They will automatically be included in application.css. +// You can use Sass (SCSS) here: http://sass-lang.com/ diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index a2e793a10..899997456 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -31,16 +31,14 @@ class ProjectsController < ApplicationController menu_item :feedback, :only => :feedback menu_item l(:label_course_file), :only => :index menu_item l(:label_course_news), :only => :index + -# edit - before_filter :authorize1, :only => [:show] -# - before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches,:join_project] + before_filter :find_project, :except => [ :index, :search,:list, :new, :create, :copy, :statistics, :new_join, :course, :enterprise_course, :course_enterprise,:view_homework_attaches] # before_filter :authorize, :except => [:new_join, :new_homework, :homework, :statistics, :search, :watcherlist, :index, :list, :new, :create, :copy, :archive, :unarchive, :destroy, :member, :focus, :file, # :statistics, :feedback, :course, :enterprise_course, :course_enterprise, :project_respond, :share, # :show_projects_score, :issue_score_index, :news_score_index, :file_score_index, :code_submit_score_index, :projects_topic_score_index] #此条勿删 课程相关权限 ,:new_homework,:homework,:feedback,,:member - before_filter :authorize, :only => [:settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] + before_filter :authorize, :only => [:show, :settings, :edit, :sort_project_members, :update, :modules, :close, :reopen,:view_homework_attaches,:course] before_filter :authorize_global, :only => [:new, :create,:view_homework_attaches] before_filter :require_admin, :only => [ :copy, :archive, :unarchive, :destroy, :calendar] before_filter :file, :statistics, :watcherlist @@ -118,8 +116,8 @@ class ProjectsController < ApplicationController joins("LEFT JOIN #{ProjectStatus.table_name} ON #{Project.table_name}.id = #{ProjectStatus.table_name}.project_id").joins("LEFT JOIN #{ProjectScore.table_name} ON #{Project.table_name}.id = #{ProjectScore.table_name}.project_id"). where("#{Project.table_name}.project_type = ? ", Project::ProjectType_project) - @poll_questions_count = @projects_all.count - @poll_questions_pages = Paginator.new @project_count, per_page_option, params['page'] + @project_count = @projects_all.count + @project_pages = Paginator.new @project_count, per_page_option, params['page'] #gcm activity count @@ -558,11 +556,6 @@ class ProjectsController < ApplicationController # Show @project def show - if(@project && !@project.is_public && !User.current.member_of?(@project)) - render_403 - return - end - @project_type = params[:project_type] # try to redirect to the requested menu item @@ -594,7 +587,7 @@ class ProjectsController < ApplicationController end has = { - "show_issues" => true, + "show_issues" => true , "show_files" => true, "show_documents" => true, "show_messages" => true, @@ -604,8 +597,8 @@ class ProjectsController < ApplicationController "show_wiki_edits"=>true, "show_journals_for_messages" => true } - - + @date_to ||= Date.today + 1 + @date_from = @date_to - @days#-1.years #modified by lizanle 去掉這個1年的時間跨度 @with_subprojects = params[:with_subprojects].nil? ? Setting.display_subprojects_issues? : (params[:with_subprojects] == '1') @author = (params[:user_id].blank? ? nil : User.active.find(params[:user_id])) # 决定显示所用用户或单个用户活动 @@ -619,9 +612,9 @@ class ProjectsController < ApplicationController # modify by nwb # 添加私密性判断 if User.current.member_of?(@project)|| User.current.admin? - events = @activity.events(@days) + events = @activity.events(@date_from, @date_to) else - events = @activity.events(@days,nil, :is_public => 1) + events = @activity.events(@date_from, @date_to, :is_public => 1) end @offset, @limit = api_offset_and_limit({:limit => 10}) @@ -917,14 +910,6 @@ class ProjectsController < ApplicationController end end end - - #加入私有项目 - def join_project - respond_to do |format| - format.js - end - end - private def memberAccess diff --git a/app/controllers/system_log_controller.rb b/app/controllers/system_log_controller.rb new file mode 100644 index 000000000..274cb18a9 --- /dev/null +++ b/app/controllers/system_log_controller.rb @@ -0,0 +1,59 @@ +# Time 2015-01-26 17:12:23 +# Author lizanle +# Description 显示和清理系统日志 +class SystemLogController < ApplicationController + + before_filter :require_admin + # 默认每页显示20条记录 + PER_PAGE = 20 + layout "base" + include SystemLogHelper + + # Time 2015-01-26 17:12:46 + # Author lizanle + # Description 查看所有日志 + def index + @logs = SystemLog.logo_data(params[:page]||1, params[:per]||PER_PAGE, params[:search], params[:day]) + end + + # Time 2015-01-26 14:42:38 + # Author lizanle + # Description 清除日志 + def clear + SystemLog.clear params[:day] + redirect_to :action => :index + end + + # Time 2015-01-26 17:24:25 + # Author lizanle + # Description 访问分析 + def access_analysis + #解析日志,然后逆序 + @log_result = SystemLog.analysis(params[:day]).reverse[1...-1] + @access_module = Hash.new + #日誌可能為空 + if @log_result && !@log_result.empty? + #将数组中的模块访问统计出来放到hash中 每条记录的第四个值是Controller#action的形式 + @log_result.collect! { |r| @access_module[r[3]].nil? ? + @access_module[r[3]] = 1 : @access_module[r[3]] +=1 } + # 去掉key可能为空记录 排序,然后取逆序 + @access_module = @access_module.delete_if { |k, v| k.nil? }.sort_by { |key, val| val }.reverse + else + @access_module + end + end + + # Time 2015-01-26 17:24:36 + # Author lizanle + # Description 耗时分析 + def time_analysis + #解析日志 + @log_result = SystemLog.analysis(params[:day]).reverse[1...-1] + if @log_result && !@log_result.empty? + #分页 + @log_result = Kaminari.paginate_array(@log_result).page(params[:page]||1).per(params[:per]||PER_PAGE) + else + @log_result = [] + end + end +end diff --git a/app/helpers/expire_helper.rb b/app/helpers/expire_helper.rb new file mode 100644 index 000000000..0a9cab69c --- /dev/null +++ b/app/helpers/expire_helper.rb @@ -0,0 +1,16 @@ +module ExpireHelper + #index.html 中 “projects”塊 緩存過期 + def expire_project_cache + ActionController::Base.new.expire_fragment('projects') + end + + #index.html 中 “activities”塊 緩存過期 + def expire_activitie_cache + ActionController::Base.new.expire_fragment('activities') + end + + #welcome/index.html 中 “forums”塊 緩存過期 + def expire_forum_cache + ActionController::Base.new.expire_fragment('forums') + end +end diff --git a/app/helpers/system_log_helper.rb b/app/helpers/system_log_helper.rb new file mode 100644 index 000000000..918d6a608 --- /dev/null +++ b/app/helpers/system_log_helper.rb @@ -0,0 +1,180 @@ +# Time 2015-01-26 17:30:16 +# Author lizanle +# Description 日志帮助类 +module SystemLogHelper + class SystemLog + class << self + # Time 2015-01-26 17:29:17 + # Author lizanle + # Description 分页(支持多关键字查询) + def logo_data(page, per, search, day) + logs = find_all_logs day + if logs.empty? #如果返回的是空數組,就說明日誌文件不存在 + return logs + end + # 根据search参数来决定是否需要查询 + keywords = search + if keywords && !keywords.strip.blank? + # 把keywords转化成正则表达式数组 + keywords = keywords.strip.split(/\s+/).collect! { |w| Regexp.new(w, 'i') } + # 一条记录应该匹配每个关键字 log =~ r 是对log记录进行判断是否符合r的正则表达式 + logs = logs.find_all do |log| + keywords.all? { |r| log =~ r } + end + #用Kaminari分页 + logs = Kaminari.paginate_array(logs).page(page).per(per).collect! { |log| parse(log) } + #将分页后的记录的搜索结果添加样式,样式中的\0是给给r占位置的。 + logs.collect! do |log| + keywords.each { |r| log.gsub!(r, '\0') } + log + end + else + logs = Kaminari.paginate_array(logs).page(page).per(per).collect! { |log| parse(log) } + end + logs + end + + # Time 2015-01-26 17:28:57 + # Author lizanle + # Description 清除日誌 + def clear day + if File::exists?(logfile_path day) + File.open(logfile_path(day), 'w') do |f| + f.print '' + end + else + end + end + + # Time 2015-01-26 17:28:49 + # Author lizanle + # Description 讀取日誌 + private + def find_all_logs day + if File::exists?(logfile_path day) + File.open(logfile_path day) do |f| + #打开文件,并按照正则表达式切分,逆序,最新一个记录可以扔掉(因为最新的记录永远都是访问System_log) + f.read.split("Processing").reverse[1..-1] + end + else + [] + end + end + + # Time 2015-01-26 17:28:34 + # Author lizanle + # Description 日志文件的路径,一般在Rails.root/log下,根据环境配置 + # 依次记录到product.log development.log test.log中 + def logfile_path day + #将日期处理成2015-01-01的形式 + unless day.nil? + dayArr = day.split('-') + if dayArr[1].length == 1 + dayArr[1] = "0" + dayArr[1] + end + if dayArr[2].length == 1 + dayArr[2] = "0" + dayArr[2] + end + day = dayArr.join('-') + end + #如果不是當天,則需要加後綴 + if !day.nil? && !day.strip.blank? && day != Time.now.strftime("%Y-%m-%d") + File.join(Rails.root, "log", "#{Rails.env}.log.#{day.gsub('-', '')}") + else + File.join(Rails.root, "log", "#{Rails.env}.log") + end + end + + # Time 2015-01-26 17:28:22 + # Author lizanle + # Description 替換換行符 + def parse(log) + ERB::Util.html_escape(log.gsub(/\e\[[\d;m]+/, '')).gsub("\n", "
") + end + + # Time 2015-01-26 17:28:07 + # Author lizanle + # Description 定义响应正则表达式 2015-01-20 11:31:13 INFO -- Completed 200 OK in 125ms (Views: 81.0ms | ActiveRecord: 2.0ms) + def response_regex + 'Completed \d+ \w+ in (\d+)ms \(Views: (\d+\.\d+)?ms \| ActiveRecord: (\d+\.\d+)?ms\)' + end + + # Time 2015-01-26 17:27:51 + # Author lizanle + # Description 将一条记录中的地址主机等都分析出来 + def get_status(paragraph) + request_regex = 'Started GET \"(\/.*)\" for ([\d]+\.[\d]+\.[\d]+\.[\d]+) at [\d]*-([\d]*-[\d]* [\d]*:[\d]*:[\d]*)' + controller_regex = 'Processing by ([\w]+#[\w]+)' + page_time_regex = 'Views: \d+(\.\d+)?ms' + activeRecord_time_regex = 'ActiveRecord: \d+(\.\d+)?ms' + + #解析请求中的正则,主机,时间 + if paragraph.match(request_regex) != nil + request_url = paragraph.match(request_regex)[1] #正则表达式中的括号能够截取成数组 + request_host = paragraph.match(request_regex)[2] + request_at = paragraph.match(request_regex)[3] + end + + #解析控制器 + if paragraph.match(controller_regex) != nil + controller_name = paragraph.match(controller_regex)[1] + end + + #解析响应时间以及计算百分比 + if paragraph.match(response_regex) != nil + #print(paragraph.match(response_regex)) + total_time = paragraph.match(response_regex)[1] + page_time = paragraph.match(response_regex)[2] + activeRecord_time = paragraph.match(response_regex)[3] + page_time_percent = page_time.to_f/(total_time.to_f) + activeRecord_time_percent = activeRecord_time.to_f/(total_time.to_f) + else + end + #将解析结果当做一条记录数组返回 + request_status = [request_url, request_host, request_at, + controller_name, total_time, page_time, page_time_percent, activeRecord_time, activeRecord_time_percent] + request_status + end + + # Time 2015-01-26 16:41:51 + # Author lizanle + # Description 分析日志 + public + def analysis day + csv = Array.new + #如果文件不存在,则直接返回空数组 + if File::exists?(logfile_path day) + File.open(logfile_path(day), "r:utf-8") do |file| + paragraph = "" + begin_flag = false + # 对每一行进行判断 + file.each do |line| + # 以"Started GET "开头为一个paragraph + #print(line.match('[\d]*-([\d]*-[\d]* [\d]*:[\d]*:[\d]*) INFO -- Started GET ') == nil) + if (line.match('[\d]*-([\d]*-[\d]* [\d]*:[\d]*:[\d]*) \w+ -- Started GET ') != nil) + if !begin_flag + begin_flag = true + paragraph.concat(line) + else + # 另一个paragraph的开头 + if (paragraph.match(response_regex) != nil) + csv << get_status(paragraph) + end + begin_flag = true + paragraph = line + end + else + if begin_flag + paragraph.concat(line) + else + end + end + end + end + end + csv + end + end + end +end + diff --git a/app/models/bid.rb b/app/models/bid.rb index 88014477b..f423266b8 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -17,6 +17,7 @@ class Bid < ActiveRecord::Base HomeworkProject = 2 attr_accessible :author_id, :budget, :deadline, :name, :description, :homework_type, :password include Redmine::SafeAttributes + include ExpireHelper belongs_to :author, :class_name => 'User', :foreign_key => :author_id belongs_to :course @@ -32,7 +33,11 @@ class Bid < ActiveRecord::Base has_many :join_in_contests, :dependent => :destroy has_many :praise_tread, as: :praise_tread_object, dependent: :destroy # has_many :fork_homework, :class_name => 'Bid', :conditions => "#{Bid.table_name}.parent_id = #{id}" - + + + after_create :expire_activitie_cache + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache acts_as_attachable @@ -149,4 +154,6 @@ class Bid < ActiveRecord::Base end end end + + end diff --git a/app/models/changeset.rb b/app/models/changeset.rb index e05a7d2da..101647824 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -16,6 +16,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. class Changeset < ActiveRecord::Base + include ExpireHelper belongs_to :repository belongs_to :user include UserScoreHelper @@ -64,8 +65,9 @@ class Changeset < ActiveRecord::Base includes(:repository => :project).where(Project.allowed_to_condition(args.shift || User.current, :view_changesets, *args)) } - after_create :scan_for_issues,:refresh_changests#:be_user_score # user_score - after_update :be_user_score + after_create :scan_for_issues,:refresh_changests,:expire_activitie_cache#:be_user_score # user_score + after_update :be_user_score,:expire_activitie_cache + before_destroy :expire_activitie_cache after_destroy :down_user_score before_create :before_create_cs diff --git a/app/models/contest_notification.rb b/app/models/contest_notification.rb index 1613f1378..0ccd0d5a7 100644 --- a/app/models/contest_notification.rb +++ b/app/models/contest_notification.rb @@ -1,4 +1,10 @@ class ContestNotification < ActiveRecord::Base + include ExpireHelper attr_accessible :content, :title validates :title, length: {maximum: 30} + after_create :expire_forum_cache + after_update :expire_forum_cache + before_destroy :expire_forum_cache + + end diff --git a/app/models/document.rb b/app/models/document.rb index 7c2fa5a6d..48a0151eb 100644 --- a/app/models/document.rb +++ b/app/models/document.rb @@ -17,18 +17,22 @@ class Document < ActiveRecord::Base include Redmine::SafeAttributes + include ExpireHelper belongs_to :project belongs_to :user belongs_to :category, :class_name => "DocumentCategory", :foreign_key => "category_id" include UserScoreHelper after_save :be_user_score # user_score after_destroy :down_user_score - + after_create :expire_activitie_cache + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache acts_as_attachable :delete_permission => :delete_documents acts_as_searchable :columns => ['title', "#{table_name}.description"], :include => :project acts_as_event :title => Proc.new {|o| "#{l(:label_document)}: #{o.title}"}, - :author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) }, + #:author => Proc.new {|o| o.attachments.reorder("#{Attachment.table_name}.created_on ASC").first.try(:author) }, + :author => Proc.new {|o| User.find(o.user_id)}, :url => Proc.new {|o| {:controller => 'documents', :action => 'show', :id => o.id}} acts_as_activity_provider :find_options => {:include => :project}, :is_public => 'documents.is_public' @@ -76,4 +80,6 @@ class Document < ActiveRecord::Base update_document(self.user,1) update_document(self.user,2,self.project) end + + end diff --git a/app/models/forum.rb b/app/models/forum.rb index eb8bb19d2..e47d18b02 100644 --- a/app/models/forum.rb +++ b/app/models/forum.rb @@ -1,8 +1,13 @@ class Forum < ActiveRecord::Base include Redmine::SafeAttributes + include ExpireHelper has_many :topics, :class_name => 'Memo', :conditions => "#{Memo.table_name}.parent_id IS NULL", :order => "#{Memo.table_name}.created_at DESC", :dependent => :destroy has_many :memos, :dependent => :destroy, conditions: "parent_id IS NULL" - belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' + belongs_to :creator, :class_name => "User", :foreign_key => 'creator_id' + + after_create :expire_forum_cache + after_update :expire_forum_cache + before_destroy :expire_forum_cache safe_attributes 'name', 'description', 'topic_count', @@ -45,5 +50,7 @@ class Forum < ActiveRecord::Base " memo_count = (SELECT COUNT(*) FROM #{Memo.table_name} WHERE forum_id=#{forum_id} AND parent_id IS NOT NULL)," + " last_memo_id = (SELECT MAX(id) FROM #{Memo.table_name} WHERE forum_id=#{forum_id})", ["id = ?", forum_id]) - end + end + + end diff --git a/app/models/issue.rb b/app/models/issue.rb index 4dc685b3b..a7b1a5943 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -19,7 +19,7 @@ class Issue < ActiveRecord::Base include Redmine::SafeAttributes include Redmine::Utils::DateCalculation include UserScoreHelper - + include ExpireHelper belongs_to :project belongs_to :tracker belongs_to :status, :class_name => 'IssueStatus', :foreign_key => 'status_id' @@ -80,6 +80,9 @@ class Issue < ActiveRecord::Base after_create :act_as_activity,:be_user_score_new_issue after_update :be_user_score after_destroy :down_user_score + after_create :expire_activitie_cache + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache # after_create :be_user_score # end @@ -1553,4 +1556,5 @@ class Issue < ActiveRecord::Base end + end diff --git a/app/models/journals_for_message.rb b/app/models/journals_for_message.rb index 4819cd253..c71fbaf47 100644 --- a/app/models/journals_for_message.rb +++ b/app/models/journals_for_message.rb @@ -4,6 +4,7 @@ class JournalsForMessage < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ExpireHelper safe_attributes "jour_type", # 留言所属类型 "jour_id", # 留言所属类型的id "notes", # 留言内容 @@ -54,7 +55,9 @@ class JournalsForMessage < ActiveRecord::Base has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy validates :notes, presence: true - after_create :act_as_activity #huang + after_create :act_as_activity ,:expire_activitie_cache#huang + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache after_create :reset_counters! after_destroy :reset_counters! after_save :be_user_score @@ -162,4 +165,6 @@ class JournalsForMessage < ActiveRecord::Base end end end + + end diff --git a/app/models/memo.rb b/app/models/memo.rb index f9482911a..165f8e144 100644 --- a/app/models/memo.rb +++ b/app/models/memo.rb @@ -1,9 +1,13 @@ class Memo < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper + include ExpireHelper belongs_to :forum - belongs_to :author, :class_name => "User", :foreign_key => 'author_id' + belongs_to :author, :class_name => "User", :foreign_key => 'author_id' + after_create :expire_cache + after_update :expire_cache + before_destroy :expire_cache validates_presence_of :author_id, :forum_id, :subject,:content # 若是主题帖,则内容可以是空 #validates :content, presence: true, if: Proc.new{|o| !o.parent_id.nil? } @@ -170,5 +174,8 @@ class Memo < ActiveRecord::Base update_memo_number(User.current,1) update_replay_for_memo(User.current,1) end - + def expire_cache + expire_forum_cache + expire_activitie_cache + end end diff --git a/app/models/message.rb b/app/models/message.rb index 8af3265cc..9ce4d583a 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -18,7 +18,7 @@ class Message < ActiveRecord::Base include Redmine::SafeAttributes include UserScoreHelper - + include ExpireHelper belongs_to :board belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :praise_tread, as: :praise_tread_object, dependent: :destroy @@ -59,8 +59,9 @@ class Message < ActiveRecord::Base validates_length_of :subject, :maximum => 255 validate :cannot_reply_to_locked_topic, :on => :create - after_create :add_author_as_watcher, :reset_counters! - after_update :update_messages_board + after_create :add_author_as_watcher, :reset_counters!,:expire_activitie_cache + after_update :update_messages_board,:expire_activitie_cache + before_destroy :expire_activitie_cache after_destroy :reset_counters!,:down_user_score # fq @@ -195,4 +196,6 @@ class Message < ActiveRecord::Base end end end + + end diff --git a/app/models/news.rb b/app/models/news.rb index 4d153e81f..9c37719f3 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -17,6 +17,7 @@ class News < ActiveRecord::Base include Redmine::SafeAttributes + include ExpireHelper belongs_to :project #added by nwb belongs_to :course @@ -47,6 +48,9 @@ class News < ActiveRecord::Base # fq after_create :act_as_activity # end + after_create :expire_activitie_cache + after_update :expire_activitie_cache + before_destroy :expire_activitie_cache scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) @@ -91,4 +95,6 @@ class News < ActiveRecord::Base def act_as_activity self.acts << Activity.new(:user_id => self.author_id) end + + end diff --git a/app/models/project.rb b/app/models/project.rb index 14763347f..ca80d90f8 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -17,6 +17,7 @@ class Project < ActiveRecord::Base include Redmine::SafeAttributes + include ExpireHelper ProjectType_project = 0 ProjectType_course = 1 @@ -125,10 +126,12 @@ class Project < ActiveRecord::Base #此代码功能:为原redmine中项目的树形结构按名称首字母排序,本系统项目非树形结构,且项目排序方式无按首字母排序,另该代码执行会使空数据库时创建项目时出异常故注释掉 #after_save :update_position_under_parent, :if => Proc.new {|project| project.name_changed?} + #ActiveModel::Dirty 这里有一个changed方法。对任何对象都可以用 after_save :update_inherited_members, :if => Proc.new {|project| project.inherit_members_changed?} # 创建project之后默认创建一个board,之后的board去掉了board的概念 - after_create :create_board_sync - before_destroy :delete_all_members + after_create :create_board_sync,:expire_project_cache + after_update :expire_project_cache + before_destroy :delete_all_members,:expire_project_cache def remove_references_before_destroy return if self.id.nil? Watcher.delete_all ['watchable_id = ?', id] @@ -1148,7 +1151,7 @@ class Project < ActiveRecord::Base logger.error "[Project Model] ===> Auto create board when Project saved, because #{@board.full_messages}" end end - - + + end diff --git a/app/views/layouts/system_log.html.erb b/app/views/layouts/system_log.html.erb new file mode 100644 index 000000000..ba1fe1ad1 --- /dev/null +++ b/app/views/layouts/system_log.html.erb @@ -0,0 +1,54 @@ +<%# +# To change this template, choose Tools | Templates +# and open the template in the editor. +%> + + + + + System Log + + + + + <%= yield %> + + \ No newline at end of file diff --git a/app/views/system_log/access_analysis.html.erb b/app/views/system_log/access_analysis.html.erb new file mode 100644 index 000000000..631530370 --- /dev/null +++ b/app/views/system_log/access_analysis.html.erb @@ -0,0 +1,36 @@ +<% @nav_dispaly_home_path_label = 1 + @nav_dispaly_main_course_label = 1 + @nav_dispaly_main_project_label = 1 + @nav_dispaly_main_contest_label = 1 %> +<% @nav_dispaly_forum_label = 1%> + + +
+

+

+ " maxlength="100" readonly="true" onclick="HS_setDate(this)"/> + +
+

+
+ <%=link_to l(:label_log_detail), system_log_path %> | + <%=link_to l(:label_log_delete_log), system_log_clear_path, {:confirm => l(:label_log_delete_confirm),:day=>params[:day].nil? ? Time.now.strftime("%Y-%m-%d") : params[:day]}%> | + <%=link_to l(:label_log_access_analysis), system_log_access_analysis_path %> | + <%=link_to l(:label_log_time_analysis), system_log_time_analysis_path %> | + <%=link_to_function l(:label_log_refresh), 'redo()' %> +
+
+
  
+ + + + + <% unless @access_module.nil? %> +<% @access_module.each do |k, v| %> + <% unless k.blank? %> + + + <% end %> +<%end %> + <%end %> +
<%= l(:label_log_access_analysis)%>
<%= l(:label_log_access_controller_action)%><%= l(:label_log_access_count)%>
<%= raw k %><%= raw v %>
diff --git a/app/views/system_log/index.html.erb b/app/views/system_log/index.html.erb new file mode 100644 index 000000000..668d79a6e --- /dev/null +++ b/app/views/system_log/index.html.erb @@ -0,0 +1,45 @@ +<% @nav_dispaly_home_path_label = 1 + @nav_dispaly_main_course_label = 1 + @nav_dispaly_main_project_label = 1 + @nav_dispaly_main_contest_label = 1 %> +<% @nav_dispaly_forum_label = 1%> + +
+ +
+ <%=link_to l(:label_log_detail), system_log_path %> | + <%=link_to l(:label_log_delete_log), system_log_clear_path, {:confirm => l(:label_log_delete_confirm),:day=>params[:day].nil? ? Time.now.strftime("%Y-%m-%d") : params[:day]}%> | + <%=link_to l(:label_log_access_analysis), system_log_access_analysis_path %> | + <%=link_to l(:label_log_time_analysis), system_log_time_analysis_path %> | + <%=link_to_function l(:label_log_refresh), 'redo()' %> +
+ +
+
  
+
+<%= paginate @logs unless @logs.empty? %>
+ + <% unless @logs.empty? %> + + +<% @logs.each do |log| %> + <% unless log.blank? %> + + <% end %> +<%end %> +
<%=l(:label_log_detail)%>
<%= raw log %>
+ <%end %> +<%= paginate @logs unless @logs.empty? %> +
\ No newline at end of file diff --git a/app/views/system_log/time_analysis.html.erb b/app/views/system_log/time_analysis.html.erb new file mode 100644 index 000000000..bdf01ca27 --- /dev/null +++ b/app/views/system_log/time_analysis.html.erb @@ -0,0 +1,51 @@ +<% @nav_dispaly_home_path_label = 1 + @nav_dispaly_main_course_label = 1 + @nav_dispaly_main_project_label = 1 + @nav_dispaly_main_contest_label = 1 %> +<% @nav_dispaly_forum_label = 1%> +
+

+

+ " maxlength="100" readonly="true" onclick="HS_setDate(this)"/> + +
+

+
+ <%=link_to l(:label_log_detail), system_log_path %> | + <%=link_to l(:label_log_delete_log), system_log_clear_path, {:confirm => l(:label_log_delete_confirm),:day=>params[:day].nil? ? Time.now.strftime("%Y-%m-%d") : params[:day]}%> | + <%=link_to l(:label_log_access_analysis), system_log_access_analysis_path %> | + <%=link_to l(:label_log_time_analysis), system_log_time_analysis_path %> | + <%=link_to_function l(:label_log_refresh), 'redo()' %> +
+
+
  
+<%= paginate @log_result unless @log_result.empty? %>
+ + + + + + + + + + + + <% unless @log_result.nil? %> +<% @log_result.each do |r| %> + <% unless r.blank? %> + + + + + + + + + + + <% end %> +<%end %> + <%end %> +
<%= l(:label_log_time_analysis) %>
<%= l(:label_log_url) %><%= l(:label_log_ip) %><%= l(:label_log_access_time) %><%= l(:label_log_access_controller_action) %><%= l(:label_log_response_time) %><%= l(:label_log_views_time) %><%= l(:label_log_views_time_percent) %><%= l(:label_log_active_record_time) %><%= l(:label_log_active_record_time_percent) %>
<%= raw r[0].length>50?r[0].truncate(20) : r[0] unless r[0].nil? %><%= raw r[1] %><%= raw r[2] %><%= raw r[3] %><%= raw r[4] %><%= raw r[5] %><%= raw r[6] %><%= raw r[7] %><%= raw r[8] %>
+<%= paginate @log_result unless @log_result.empty? %>
\ No newline at end of file diff --git a/app/views/welcome/index.html.erb b/app/views/welcome/index.html.erb index 3e341bd27..df2ee4e65 100644 --- a/app/views/welcome/index.html.erb +++ b/app/views/welcome/index.html.erb @@ -73,8 +73,10 @@
    + <% cache("projects") do %> <% @projects.map do |project| %> -
  • + <% cache project do %> +
  • <%= image_tag(get_project_avatar(project), :class => "avatar-4") %>
    @@ -101,8 +103,9 @@ :id => "tooltip-#{project.id}" %>
- + <% end %> <% end; reset_cycle %> + <% end %> @@ -115,8 +118,10 @@
+ <% cache("activities") do %> <%activities = find_all_activities%> <% activities.each do |event| %> + <% cache event do %>
  • <%= image_tag url_to_avatar(event.event_author), :class => "avatar-3" %> @@ -130,7 +135,7 @@

    <%= l(:field_updated_on) %> - <%= time_tag_welcome event.event_datetime %>前 + <%= format_time event.event_datetime %>       @@ -139,7 +144,9 @@

  • + <% end %> <% end %> + <% end %>
    @@ -160,9 +167,10 @@
    + <% cache("forums") do %> <% topics = find_new_forum_topics(6) %> <% topics.includes(:forum, :last_reply, :author).each do |topic|%> - + <% cache topic do %>
  • <%= link_to '['+topic.forum.name + ']',forum_path(topic.forum),:class => 'memo_Bar_title' %> @@ -170,7 +178,9 @@
    - <%= "#{l(:label_updated_time, value: time_tag_welcome(topic_last_time topic))}".html_safe %> + <%#= "#{l(:field_updated_on, value: format_time(topic_last_time topic))}" %> + <%= l(:field_updated_on) %> + <%= format_time topic_last_time topic %> <%= l(:label_question_sponsor)%>: @@ -188,8 +198,9 @@
  • - - <% end %> + <%end %> + <% end %> + <% end %>
    diff --git a/config/environments/development.rb b/config/environments/development.rb index 8bec9789c..3b894d207 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -7,11 +7,11 @@ RedmineApp::Application.configure do # Log error messages when you accidentally call methods on nil. config.whiny_nils = true - + config.logger = Logger.new('log/development.log', 'daily') # daily, weekly or monthly # Show full error reports and disable caching config.consider_all_requests_local = true config.action_controller.perform_caching = false - + config.cache_store = :file_store, "#{Rails.root }/public/tmp/" # Don't care if the mailer can't send config.action_mailer.raise_delivery_errors = true diff --git a/config/environments/production.rb b/config/environments/production.rb index ab4cd4011..48b2514cf 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -17,8 +17,9 @@ RedmineApp::Application.configure do # config.logger.level = Logger::INFO # Full error reports are disabled and caching is turned on + config.logger = Logger.new('log/production.log', 'daily',1048576) # daily, weekly or monthly config.action_controller.perform_caching = true - + config.cache_store = :file_store, "#{Rails.root }/public/tmp/" # Enable serving of images, stylesheets, and javascripts from an asset server # config.action_controller.asset_host = "http://assets.example.com" diff --git a/config/initializers/logger.rb b/config/initializers/logger.rb new file mode 100644 index 000000000..e9b61ce06 --- /dev/null +++ b/config/initializers/logger.rb @@ -0,0 +1,229 @@ +# logger.rb - simple logging utility +# Copyright (C) 2000-2003, 2005, 2008, 2011 NAKAMURA, Hiroshi . +# +# Documentation:: NAKAMURA, Hiroshi and Gavin Sinclair +# License:: +# You can redistribute it and/or modify it under the same terms of Ruby's +# license; either the dual license version in 2003, or any later version. +# Revision:: $Id: logger.rb 31641 2011-05-19 00:07:25Z nobu $ +# +# A simple system for logging messages. See Logger for more documentation. + +require 'monitor' +require 'fileutils' +# == Description +# +# The Logger class provides a simple but sophisticated logging utility that +# you can use to output messages. +# +# The messages have associated levels, such as +INFO+ or +ERROR+ that indicate +# their importance. You can then give the Logger a level, and only messages +# at that level of higher will be printed. +# +# The levels are: +# +# +FATAL+:: an unhandleable error that results in a program crash +# +ERROR+:: a handleable error condition +# +WARN+:: a warning +# +INFO+:: generic (useful) information about system operation +# +DEBUG+:: low-level information for developers +# +# For instance, in a production system, you may have your Logger set to +# +INFO+ or even +WARN+ +# When you are developing the system, however, you probably +# want to know about the program's internal state, and would set the Logger to +# +DEBUG+. +# +# *Note*: Logger does not escape or sanitize any messages passed to it. +# Developers should be aware of when potentially malicious data (user-input) +# is passed to Logger, and manually escape the untrusted data: +# +# logger.info("User-input: #{input.dump}") +# logger.info("User-input: %p" % input) +# +# You can use #formatter= for escaping all data. +# +# original_formatter = Logger::Formatter.new +# logger.formatter = proc { |severity, datetime, progname, msg| +# original_formatter.call(severity, datetime, progname, msg.dump) +# } +# logger.info(input) +# +# === Example +# +# This creates a logger to the standard output stream, with a level of +WARN+ +# +# log = Logger.new(STDOUT) +# log.level = Logger::WARN +# +# log.debug("Created logger") +# log.info("Program started") +# log.warn("Nothing to do!") +# +# begin +# File.each_line(path) do |line| +# unless line =~ /^(\w+) = (.*)$/ +# log.error("Line in wrong format: #{line}") +# end +# end +# rescue => err +# log.fatal("Caught exception; exiting") +# log.fatal(err) +# end +# +# Because the Logger's level is set to +WARN+, only the warning, error, and +# fatal messages are recorded. The debug and info messages are silently +# discarded. +# +# === Features +# +# There are several interesting features that Logger provides, like +# auto-rolling of log files, setting the format of log messages, and +# specifying a program name in conjunction with the message. The next section +# shows you how to achieve these things. +# +# +# == HOWTOs +# +# === How to create a logger +# +# The options below give you various choices, in more or less increasing +# complexity. +# +# 1. Create a logger which logs messages to STDERR/STDOUT. +# +# logger = Logger.new(STDERR) +# logger = Logger.new(STDOUT) +# +# 2. Create a logger for the file which has the specified name. +# +# logger = Logger.new('logfile.log') +# +# 3. Create a logger for the specified file. +# +# file = File.open('foo.log', File::WRONLY | File::APPEND) +# # To create new (and to remove old) logfile, add File::CREAT like; +# # file = open('foo.log', File::WRONLY | File::APPEND | File::CREAT) +# logger = Logger.new(file) +# +# 4. Create a logger which ages logfile once it reaches a certain size. Leave +# 10 "old log files" and each file is about 1,024,000 bytes. +# +# logger = Logger.new('foo.log', 10, 1024000) +# +# 5. Create a logger which ages logfile daily/weekly/monthly. +# +# logger = Logger.new('foo.log', 'daily') +# logger = Logger.new('foo.log', 'weekly') +# logger = Logger.new('foo.log', 'monthly') +# +# === How to log a message +# +# Notice the different methods (+fatal+, +error+, +info+) being used to log +# messages of various levels? Other methods in this family are +warn+ and +# +debug+. +add+ is used below to log a message of an arbitrary (perhaps +# dynamic) level. +# +# 1. Message in block. +# +# logger.fatal { "Argument 'foo' not given." } +# +# 2. Message as a string. +# +# logger.error "Argument #{ @foo } mismatch." +# +# 3. With progname. +# +# logger.info('initialize') { "Initializing..." } +# +# 4. With severity. +# +# logger.add(Logger::FATAL) { 'Fatal error!' } +# +# The block form allows you to create potentially complex log messages, +# but to delay their evaluation until and unless the message is +# logged. For example, if we have the following: +# +# logger.debug { "This is a " + potentially + " expensive operation" } +# +# If the logger's level is +INFO+ or higher, no debug messages will be logged, +# and the entire block will not even be evaluated. Compare to this: +# +# logger.debug("This is a " + potentially + " expensive operation") +# +# Here, the string concatenation is done every time, even if the log +# level is not set to show the debug message. +# +# === How to close a logger +# +# logger.close +# +# === Setting severity threshold +# +# 1. Original interface. +# +# logger.sev_threshold = Logger::WARN +# +# 2. Log4r (somewhat) compatible interface. +# +# logger.level = Logger::INFO +# +# DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN +# +# +# == Format +# +# Log messages are rendered in the output stream in a certain format by +# default. The default format and a sample are shown below: +# +# Log format: +# SeverityID, [Date Time mSec #pid] SeverityLabel -- ProgName: message +# +# Log sample: +# I, [Wed Mar 03 02:34:24 JST 1999 895701 #19074] INFO -- Main: info. +# +# You may change the date and time format via #datetime_format= +# +# logger.datetime_format = "%Y-%m-%d %H:%M:%S" +# # e.g. "2004-01-03 00:54:26" +# +# Or, you may change the overall format with #formatter= method. +# +# logger.formatter = proc do |severity, datetime, progname, msg| +# "#{datetime}: #{msg}\n" +# end +# # e.g. "Thu Sep 22 08:51:08 GMT+9:00 2005: hello world" +# +class Logger + #具体内容请看https://bugs.ruby-lang.org/issues/7303 + # Device used for logging messages. + class LogDevice + def shift_log_period(period_end) + postfix = period_end.strftime("%Y%m%d") # YYYYMMDD + age_file = "#{@filename}.#{postfix}" + if FileTest.exist?(age_file) + # try to avoid filename crash caused by Timestamp change. + idx = 0 + # .99 can be overridden; avoid too much file search with 'loop do' + while idx < 100 + idx += 1 + age_file = "#{@filename}.#{postfix}.#{idx}" + break unless FileTest.exist?(age_file) + end + end + # @dev.close rescue nil + # File.rename("#{@filename}", age_file) + # @dev = create_logfile(@filename) + #覆盖原来lib库的方法,将上边三行删除,增加下边两行 + FileUtils.cp(@filename, age_file) + reset_logfile(@dev) # see below for this new method return true + return true + end + #打开原来lib库,新增一个方法 + def reset_logfile(logdev) + logdev.truncate( 0 ) + logdev.sync = true + add_log_header(logdev) + end + end +end diff --git a/config/locales/zh.yml b/config/locales/zh.yml index d058a6c1b..a33b967a0 100644 --- a/config/locales/zh.yml +++ b/config/locales/zh.yml @@ -2310,6 +2310,31 @@ zh: label_poll_answer_valid_result: 以上为有效问答题答案! label_answer_total: 总计: label_join_project: 加入项目 - label_technical_support: 技术支持: label_feedback: 意见反馈 + label_log_detail: "日志详情" + label_log_delete_log: "删除日志" + label_log_access_analysis: "访问统计" + label_log_time_analysis: "耗时分析" + label_log_refresh: "刷新" + label_log_key: "关键字:" + label_log_time: "时间:" + label_log_delete_confirm: "确认清除该天日志内容?" + label_log_access_count: "访问次数" + label_log_url: "URL路径" + label_log_ip: "访问IP" + label_log_access_time: "访问时间" + label_log_access_controller_action: "模块路径" + label_log_response_time: "响应时间" + label_log_views_time: "页面渲染时间" + label_log_views_time_percent: "页面渲染时间百分比" + label_log_active_record_time: "AR响应时间" + label_log_active_record_time_percent: "AR响应时间百分比" + views: + pagination: + first: "« 首页" + last: "末页 »" + previous: "« 上一页" + next: "下一页 »" + truncate: "..." + diff --git a/config/newrelic.yml b/config/newrelic.yml new file mode 100644 index 000000000..df431805d --- /dev/null +++ b/config/newrelic.yml @@ -0,0 +1,224 @@ +# +# This file configures the New Relic Agent. New Relic monitors Ruby, Java, +# .NET, PHP, Python and Node applications with deep visibility and low +# overhead. For more information, visit www.newrelic.com. +# +# Generated January 23, 2015 +# +# This configuration file is custom generated for Trustie + + +# Here are the settings that are common to all environments +common: &default_settings + # ============================== LICENSE KEY =============================== + + # You must specify the license key associated with your New Relic + # account. This key binds your Agent's data to your account in the + # New Relic service. + license_key: '9b481f5c9ec07de722dcaaa17b38d0d1efff32c0' + + # Agent Enabled (Ruby/Rails Only) + # Use this setting to force the agent to run or not run. + # Default is 'auto' which means the agent will install and run only + # if a valid dispatcher such as Mongrel is running. This prevents + # it from running with Rake or the console. Set to false to + # completely turn the agent off regardless of the other settings. + # Valid values are true, false and auto. + # + # agent_enabled: auto + + # Application Name Set this to be the name of your application as + # you'd like it show up in New Relic. The service will then auto-map + # instances of your application into an "application" on your + # dashboard page. If you want to map this instance into multiple + # apps, like "AJAX Requests" and "All UI" then specify a semicolon + # separated list of up to three distinct names, or a yaml list. + # Defaults to the capitalized RAILS_ENV or RACK_ENV (i.e., + # Production, Staging, etc) + # + # Example: + # + # app_name: + # - Ajax Service + # - All Services + # + # Caution: If you change this name, a new application will appear in the New + # Relic user interface with the new name, and data will stop reporting to the + # app with the old name. + # + # See https://newrelic.com/docs/site/renaming-applications for more details + # on renaming your New Relic applications. + # + app_name: My Application + + # When "true", the agent collects performance data about your + # application and reports this data to the New Relic service at + # newrelic.com. This global switch is normally overridden for each + # environment below. (formerly called 'enabled') + monitor_mode: true + + # Developer mode should be off in every environment but + # development as it has very high overhead in memory. + developer_mode: false + + # The newrelic agent generates its own log file to keep its logging + # information separate from that of your application. Specify its + # log level here. + log_level: info + + # Optionally set the path to the log file This is expanded from the + # root directory (may be relative or absolute, e.g. 'log/' or + # '/var/log/') The agent will attempt to create this directory if it + # does not exist. + # log_file_path: 'log' + + # Optionally set the name of the log file, defaults to 'newrelic_agent.log' + # log_file_name: 'newrelic_agent.log' + + # The newrelic agent communicates with the service via https by default. This + # prevents eavesdropping on the performance metrics transmitted by the agent. + # The encryption required by SSL introduces a nominal amount of CPU overhead, + # which is performed asynchronously in a background thread. If you'd prefer + # to send your metrics over http uncomment the following line. + # ssl: false + + #============================== Browser Monitoring =============================== + # New Relic Real User Monitoring gives you insight into the performance real users are + # experiencing with your website. This is accomplished by measuring the time it takes for + # your users' browsers to download and render your web pages by injecting a small amount + # of JavaScript code into the header and footer of each page. + browser_monitoring: + # By default the agent automatically injects the monitoring JavaScript + # into web pages. Set this attribute to false to turn off this behavior. + auto_instrument: true + + # Proxy settings for connecting to the New Relic server. + # + # If a proxy is used, the host setting is required. Other settings + # are optional. Default port is 8080. + # + # proxy_host: hostname + # proxy_port: 8080 + # proxy_user: + # proxy_pass: + + # The agent can optionally log all data it sends to New Relic servers to a + # separate log file for human inspection and auditing purposes. To enable this + # feature, change 'enabled' below to true. + # See: https://newrelic.com/docs/ruby/audit-log + audit_log: + enabled: false + + # Tells transaction tracer and error collector (when enabled) + # whether or not to capture HTTP params. When true, frameworks can + # exclude HTTP parameters from being captured. + # Rails: the RoR filter_parameter_logging excludes parameters + # Java: create a config setting called "ignored_params" and set it to + # a comma separated list of HTTP parameter names. + # ex: ignored_params: credit_card, ssn, password + capture_params: false + + # Transaction tracer captures deep information about slow + # transactions and sends this to the New Relic service once a + # minute. Included in the transaction is the exact call sequence of + # the transactions including any SQL statements issued. + transaction_tracer: + + # Transaction tracer is enabled by default. Set this to false to + # turn it off. This feature is only available at the Professional + # and above product levels. + enabled: true + + # Threshold in seconds for when to collect a transaction + # trace. When the response time of a controller action exceeds + # this threshold, a transaction trace will be recorded and sent to + # New Relic. Valid values are any float value, or (default) "apdex_f", + # which will use the threshold for an dissatisfying Apdex + # controller action - four times the Apdex T value. + transaction_threshold: apdex_f + + # When transaction tracer is on, SQL statements can optionally be + # recorded. The recorder has three modes, "off" which sends no + # SQL, "raw" which sends the SQL statement in its original form, + # and "obfuscated", which strips out numeric and string literals. + record_sql: obfuscated + + # Threshold in seconds for when to collect stack trace for a SQL + # call. In other words, when SQL statements exceed this threshold, + # then capture and send to New Relic the current stack trace. This is + # helpful for pinpointing where long SQL calls originate from. + stack_trace_threshold: 0.500 + + # Determines whether the agent will capture query plans for slow + # SQL queries. Only supported in mysql and postgres. Should be + # set to false when using other adapters. + # explain_enabled: true + + # Threshold for query execution time below which query plans will + # not be captured. Relevant only when `explain_enabled` is true. + # explain_threshold: 0.5 + + # Error collector captures information about uncaught exceptions and + # sends them to New Relic for viewing + error_collector: + + # Error collector is enabled by default. Set this to false to turn + # it off. This feature is only available at the Professional and above + # product levels. + enabled: true + + # To stop specific errors from reporting to New Relic, set this property + # to comma-separated values. Default is to ignore routing errors, + # which are how 404's get triggered. + ignore_errors: "ActionController::RoutingError,Sinatra::NotFound" + + # If you're interested in capturing memcache keys as though they + # were SQL uncomment this flag. Note that this does increase + # overhead slightly on every memcached call, and can have security + # implications if your memcached keys are sensitive + # capture_memcache_keys: true + +# Application Environments +# ------------------------------------------ +# Environment-specific settings are in this section. +# For Rails applications, RAILS_ENV is used to determine the environment. +# For Java applications, pass -Dnewrelic.environment to set +# the environment. + +# NOTE if your application has other named environments, you should +# provide newrelic configuration settings for these environments here. + +development: + <<: *default_settings + # Turn on communication to New Relic service in development mode + monitor_mode: true + app_name: My Application (Development) + + # Rails Only - when running in Developer Mode, the New Relic Agent will + # present performance information on the last 100 transactions you have + # executed since starting the mongrel. + # NOTE: There is substantial overhead when running in developer mode. + # Do not use for production or load testing. + developer_mode: true + +test: + <<: *default_settings + # It almost never makes sense to turn on the agent when running + # unit, functional or integration tests or the like. + monitor_mode: false + +# Turn on the agent in production for 24x7 monitoring. NewRelic +# testing shows an average performance impact of < 5 ms per +# transaction, you can leave this on all the time without +# incurring any user-visible performance degradation. +production: + <<: *default_settings + monitor_mode: true + +# Many applications have a staging environment which behaves +# identically to production. Support for that environment is provided +# here. By default, the staging environment has the agent turned on. +staging: + <<: *default_settings + monitor_mode: true + app_name: My Application (Staging) diff --git a/config/routes.rb b/config/routes.rb index 122481d38..755ce6c29 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -26,6 +26,8 @@ # Example: :via => :get ====> :via => :get RedmineApp::Application.routes.draw do + + #match '/contests/:id/contestnotifications', :controller => 'contestnotifications', :action => 'index' mount Mobile::API => '/api' @@ -841,6 +843,14 @@ RedmineApp::Application.routes.draw do match 'words/add_brief_introdution' + ##added by lizanle 日志查看路由 + match 'system_log/index' + match 'system_log/access_analysis' + match 'system_log/time_analysis' + match "/system_log" ,:to => 'system_log#index' + match 'system_log/clear' + ##ended by lizanle + Dir.glob File.expand_path("plugins/*", Rails.root) do |plugin_dir| file = File.join(plugin_dir, "config/routes.rb") diff --git a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb index 17f834c84..f4712fa3e 100644 --- a/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb +++ b/lib/plugins/acts_as_activity_provider/lib/acts_as_activity_provider.rb @@ -49,8 +49,11 @@ module Redmine end module ClassMethods + # Time 2015-01-27 16:30:47 + # Author lizanle + # Description 用原来的写法from,to更加容易懂 # Returns events of type event_type visible by user that occured between from and to - def find_events(event_type, user, days, created_time, options) + def find_events(event_type, user, from, to, options) provider_options = activity_provider_options[event_type] raise "#{self.name} can not provide #{event_type} events." if provider_options.nil? @@ -91,17 +94,18 @@ module Redmine ActiveSupport::Deprecation.warn "acts_as_activity_provider with implicit :permission option is deprecated. Add a visible scope to the #{self.name} model or use explicit :permission option." scope = scope.scoped(:conditions => Project.allowed_to_condition(user, "view_#{self.name.underscore.pluralize}".to_sym, options)) end - unless scope.all(provider_options[:find_options].dup).first.nil? + # Time 2015-01-27 15:18:33 + # Author lizanle + # Description 删除 unless scope.all,因为这个执行查询,并且没有加入时间限制,与下边 scope.all(provider_options[:find_options].dup)重复 + if options[:course] if provider_options[:timestamp].include? "updated_on" to = scope.scoped(:order => "#{provider_options[:timestamp]} desc").all(provider_options[:find_options].dup).first.updated_on else to = scope.scoped(:order => "#{provider_options[:timestamp]} desc").all(provider_options[:find_options].dup).first.created_on end - if options[:course] from = (to - days.days) > created_time ? (to - days.days) : created_time.to_date - else - from = to - days.days - 1.years - end + else + #from = to - Setting.activity_days_default.to_i end if from && to diff --git a/lib/plugins/acts_as_event/lib/acts_as_event.rb b/lib/plugins/acts_as_event/lib/acts_as_event.rb index e323c2b3e..42673cde7 100644 --- a/lib/plugins/acts_as_event/lib/acts_as_event.rb +++ b/lib/plugins/acts_as_event/lib/acts_as_event.rb @@ -43,6 +43,7 @@ module Redmine base.extend ClassMethods end + %w(datetime title description author type).each do |attr| src = <<-END_SRC def event_#{attr} diff --git a/lib/redmine/activity/fetcher.rb b/lib/redmine/activity/fetcher.rb index b3f473893..c4adc6adb 100644 --- a/lib/redmine/activity/fetcher.rb +++ b/lib/redmine/activity/fetcher.rb @@ -77,9 +77,12 @@ module Redmine @scope = Redmine::Activity.default_event_types end + # Time 2015-01-27 16:31:58 + # Author lizanle + # Description 用from to 更加浅显易懂 # Returns an array of events for the given date range # sorted in reverse chronological order - def events(days = nil, created_time = nil, options={}) + def events(from = nil, to = nil, options={}) e = [] @options[:limit] = options[:limit] # modify by nwb @@ -87,7 +90,7 @@ module Redmine @scope.each do |event_type| constantized_providers(event_type).each do |provider| - e += provider.find_events(event_type, @user, days, created_time, @options) + e += provider.find_events(event_type, @user, from, to, @options) end end diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 1dedc1b8c..5692ebe83 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -685,3 +685,165 @@ function PrecentChange(obj){ $("select[id='issue_status_id']").find("option[value='2']").attr("selected","selected"); } } + +//added by lizanle 日期選擇js +function HS_DateAdd(interval,number,date){ + number = parseInt(number); + if (typeof(date)=="string"){var date = new Date(date.split("-")[0],date.split("-")[1],date.split("-")[2])} + if (typeof(date)=="object"){var date = date} + switch(interval){ + case "y":return new Date(date.getFullYear()+number,date.getMonth(),date.getDate()); break; + case "m":return new Date(date.getFullYear(),date.getMonth()+number,checkDate(date.getFullYear(),date.getMonth()+number,date.getDate())); break; + case "d":return new Date(date.getFullYear(),date.getMonth(),date.getDate()+number); break; + case "w":return new Date(date.getFullYear(),date.getMonth(),7*number+date.getDate()); break; + } +} +function checkDate(year,month,date){ + var enddate = ["31","28","31","30","31","30","31","31","30","31","30","31"]; + var returnDate = ""; + if (year%4==0){enddate[1]="29"} + if (date>enddate[month]){returnDate = enddate[month]}else{returnDate = date} + return returnDate; +} + +function WeekDay(date){ + var theDate; + if (typeof(date)=="string"){theDate = new Date(date.split("-")[0],date.split("-")[1],date.split("-")[2]);} + if (typeof(date)=="object"){theDate = date} + return theDate.getDay(); +} +function HS_calender(){ + var lis = ""; + var style = ""; + /*可以把下面的css剪切出去独立一个css文件*/ + style +=""; + + var now; + if (typeof(arguments[0])=="string"){ + selectDate = arguments[0].split("-"); + var year = selectDate[0]; + var month = parseInt(selectDate[1])-1+""; + var date = selectDate[2]; + now = new Date(year,month,date); + }else if (typeof(arguments[0])=="object"){ + now = arguments[0]; + } + var lastMonthEndDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+now.getMonth()+"-01").getDate(); + var lastMonthDate = WeekDay(now.getFullYear()+"-"+now.getMonth()+"-01"); + var thisMonthLastDate = HS_DateAdd("d","-1",now.getFullYear()+"-"+(parseInt(now.getMonth())+1).toString()+"-01"); + var thisMonthEndDate = thisMonthLastDate.getDate(); + var thisMonthEndDay = thisMonthLastDate.getDay(); + var todayObj = new Date(); + today = todayObj.getFullYear()+"-"+todayObj.getMonth()+"-"+todayObj.getDate(); + + for (i=0; i" + lis; + lastMonthEndDate--; + } + for (i=1; i<=thisMonthEndDate; i++){ // Current Month's Date + + if(today == now.getFullYear()+"-"+now.getMonth()+"-"+i){ + var todayString = now.getFullYear()+"-"+(parseInt(now.getMonth())+1).toString()+"-"+i; + lis += "
  • "+i+"
  • "; + }else{ + lis += "
  • "+i+"
  • "; + } + + } + var j=1; + for (i=thisMonthEndDay; i<6; i++){ // Next Month's Date + lis += "
  • "+j+"
  • "; + j++; + } + lis += style; + + var CalenderTitle = "»"; + CalenderTitle += "«"; + CalenderTitle += ""+now.getFullYear()+""+(parseInt(now.getMonth())+1).toString()+"月"; + + if (arguments.length>1){ + arguments[1].parentNode.parentNode.getElementsByTagName("ul")[1].innerHTML = lis; + arguments[1].parentNode.innerHTML = CalenderTitle; + + }else{ + var CalenderBox = style+"
    "+CalenderTitle+"
      "+lis+"
    "; + return CalenderBox; + } +} +function _selectThisDay(d){ + var boxObj = d.parentNode.parentNode.parentNode.parentNode.parentNode; + boxObj.targetObj.value = d.title; + boxObj.parentNode.removeChild(boxObj); +} +function closeCalender(d){ + var boxObj = d.parentNode.parentNode.parentNode; + boxObj.parentNode.removeChild(boxObj); +} + +function CalenderselectYear(obj){ + var opt = ""; + var thisYear = obj.innerHTML; + for (i=1970; i<=2020; i++){ + if (i==thisYear){ + opt += ""; + }else{ + opt += ""; + } + } + opt = ""; + obj.parentNode.innerHTML = opt; +} + +function selectThisYear(obj){ + HS_calender(obj.value+"-"+obj.parentNode.parentNode.getElementsByTagName("span")[1].getElementsByTagName("a")[0].innerHTML+"-1",obj.parentNode); +} + +function CalenderselectMonth(obj){ + var opt = ""; + var thisMonth = obj.innerHTML; + for (i=1; i<=12; i++){ + if (i==thisMonth){ + opt += ""; + }else{ + opt += ""; + } + } + opt = ""; + obj.parentNode.innerHTML = opt; +} +function selectThisMonth(obj){ + HS_calender(obj.parentNode.parentNode.getElementsByTagName("span")[0].getElementsByTagName("a")[0].innerHTML+"-"+obj.value+"-1",obj.parentNode); +} +function HS_setDate(inputObj){ + var calenderObj = document.createElement("span"); + calenderObj.innerHTML = HS_calender(new Date()); + calenderObj.style.position = "absolute"; + calenderObj.targetObj = inputObj; + inputObj.parentNode.insertBefore(calenderObj,inputObj.nextSibling); +} +//lizanle 刷新函数 +function redo() { + window.location.reload() +} diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css index db57596bc..3b482f333 100644 --- a/public/stylesheets/application.css +++ b/public/stylesheets/application.css @@ -2917,4 +2917,34 @@ input[class~='m3p10'], .m3p10 { display: inline-block; color: #ffffff; cursor:pointer; +} + +/*lizanle 日誌搜索結果樣式*/ +.search_results { + color: red; +} +/*lizanle 分页样式*/ +.pagination ul li a, .pagination ul li span{ + background-color: #FFFFFF; + border-color: #DDDDDD; + border-image: none; + border-style: solid; + border-width: 1px 1px 1px 1px; + float: left; + line-height: 20px; + padding: 4px 12px; + text-decoration: none; +} +.pagination ul a { + color: #9B9B9B; +} +.pagination ul li a:hover, .pagination ul li a:focus, .pagination ul .active a, .pagination ul .active span{ + background-color: #ffc02f; + border: 1px solid #ffc02f; +} +.pagination ul li{ + float: left; + margin-right: 3px; + list-style: none outside none; + } \ No newline at end of file diff --git a/test/functional/system_log_controller_test.rb b/test/functional/system_log_controller_test.rb new file mode 100644 index 000000000..0d8f6a181 --- /dev/null +++ b/test/functional/system_log_controller_test.rb @@ -0,0 +1,7 @@ +require 'test_helper' + +class SystemLogControllerTest < ActionController::TestCase + # test "the truth" do + # assert true + # end +end diff --git a/test/unit/helpers/expire_helper_test.rb b/test/unit/helpers/expire_helper_test.rb new file mode 100644 index 000000000..318e451cc --- /dev/null +++ b/test/unit/helpers/expire_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class ExpireHelperTest < ActionView::TestCase +end diff --git a/test/unit/helpers/system_log_helper_test.rb b/test/unit/helpers/system_log_helper_test.rb new file mode 100644 index 000000000..7cf025d9d --- /dev/null +++ b/test/unit/helpers/system_log_helper_test.rb @@ -0,0 +1,4 @@ +require 'test_helper' + +class SystemLogHelperTest < ActionView::TestCase +end diff --git a/tmp/plugins/README b/tmp/plugins/README deleted file mode 100644 index edef25679..000000000 --- a/tmp/plugins/README +++ /dev/null @@ -1 +0,0 @@ -Put your Redmine plugins here.