Project

General

Profile

Feature #11152 » corrected_time_log_comment.patch

Jonathan Rajotte, 2012-08-14 20:59

View differences:

changet.rb.o 2012-08-14 14:49:02.294227825 -0400
1

  
1 2
# Redmine - project management software
2 3
# Copyright (C) 2006-2012  Jean-Philippe Lang
3 4
#
......
104 105

  
105 106
  TIMELOG_RE = /
106 107
    (
107
    ((\d+)(h|hours?))((\d+)(m|min)?)?
108
    ((\d+)(h|hours?))((\d+)(min|m)?)?
108 109
    |
109
    ((\d+)(h|hours?|m|min))
110
    ((\d+)(h|hours?|min|m))
110 111
    |
111 112
    (\d+):(\d+)
112 113
    |
......
125 126
    kw_regexp = (ref_keywords + fix_keywords).collect{|kw| Regexp.escape(kw)}.join("|")
126 127

  
127 128
    referenced_issues = []
129
  
130
	comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+((\s+@#{TIMELOG_RE})?(\s+&(.*?)&)?)([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?(\s+&(.*?)&)?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
128 131

  
129
    comments.scan(/([\s\(\[,-]|^)((#{kw_regexp})[\s:]+)?(#\d+(\s+@#{TIMELOG_RE})?([\s,;&]+#\d+(\s+@#{TIMELOG_RE})?)*)(?=[[:punct:]]|\s|<|$)/i) do |match|
130
      action, refs = match[2], match[3]
131
      next unless action.present? || ref_keywords_any
132

  
133
      refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})?/).each do |m|
134
        issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
135
        if issue
132
	action, refs = match[2], match[3]
133
     next unless action.present? || ref_keywords_any
134
    	refs.scan(/#(\d+)(\s+@#{TIMELOG_RE})(\s+&(.*?)&)?/).each do |m|	      
135
		issue, hours = find_referenced_issue_by_id(m[0].to_i), m[2]
136
        log_comment = m[17]
137
	if issue
136 138
          referenced_issues << issue
137 139
          fix_issue(issue) if fix_keywords.include?(action.to_s.downcase)
138
          log_time(issue, hours) if hours && Setting.commit_logtime_enabled?
140
          log_time(issue, hours, log_comment) if hours && Setting.commit_logtime_enabled?
139 141
        end
140 142
      end
141 143
    end
......
243 245
    issue
244 246
  end
245 247

  
246
  def log_time(issue, hours)
247
    time_entry = TimeEntry.new(
248
  def log_time(issue, hours, comment)
249
    if comment.nil? 
250
	comment=l(:text_time_logged_by_changeset, :value => text_tag(issue.project),:locale => Setting.default_language) 
251
    else 
252
	comment+= " [" +  text_tag(issue.project) +"]" 
253
    end		
254
	time_entry = TimeEntry.new(
248 255
      :user => user,
249 256
      :hours => hours,
250 257
      :issue => issue,
251 258
      :spent_on => commit_date,
252
      :comments => l(:text_time_logged_by_changeset, :value => text_tag(issue.project),
253
                     :locale => Setting.default_language)
254
      )
259
      :comments => comment
260
	)
255 261
    time_entry.activity = log_time_activity unless log_time_activity.nil?
256 262

  
257 263
    unless time_entry.save
(5-5/5)