]> source.dussan.org Git - redmine.git/commitdiff
Code cleanup.
authorJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 26 Oct 2014 14:44:11 +0000 (14:44 +0000)
committerJean-Philippe Lang <jp_lang@yahoo.fr>
Sun, 26 Oct 2014 14:44:11 +0000 (14:44 +0000)
git-svn-id: http://svn.redmine.org/redmine/trunk@13513 e93f8b46-1217-0410-a6f0-8f06a7374b81

app/controllers/issues_controller.rb
app/models/issue.rb

index 5623c3bfaccb8208405d4c37531d9fe23ab5bfca..f3e27928d1bf1aadf1f1b910f0b368c42889b221 100644 (file)
@@ -418,22 +418,18 @@ class IssuesController < ApplicationController
         end
       end
       @issue.project = @project
+      @issue.author ||= User.current
+      @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
     else
       @issue = @project.issues.visible.find(params[:id])
     end
 
-    @issue.project = @project
-    @issue.author ||= User.current
-    # Tracker must be set before custom field values
-    tracker_id = (params[:issue] && params[:issue][:tracker_id]) || params[:tracker_id]
-    tracker = tracker_id.present? ? @project.trackers.find(tracker_id) : @project.trackers.first
-    @issue.tracker ||= tracker
+    @issue.safe_attributes = params[:issue]
+    @issue.tracker ||= @project.trackers.first
     if @issue.tracker.nil?
       render_error l(:error_no_tracker_in_project)
       return false
     end
-    @issue.start_date ||= Date.today if Setting.default_issue_start_date_to_creation_date?
-    @issue.safe_attributes = params[:issue]
 
     @priorities = IssuePriority.active
     @allowed_statuses = @issue.new_statuses_allowed_to(User.current, @issue.new_record?)
index 22c09ab650b0c245bfa897dd8aa0cea6e8642ddb..6d5d27631f5e109ad7b942467027b0a8a237683e 100644 (file)
@@ -295,24 +295,31 @@ class Issue < ActiveRecord::Base
     write_attribute(:fixed_version_id, vid)
   end
 
-  def tracker_id=(tid)
-    self.tracker = nil
-    result = write_attribute(:tracker_id, tid)
-    @custom_field_values = nil
-    @workflow_rule_by_attribute = nil
-    result
+  def tracker_id=(tracker_id)
+    if tracker_id.to_s != self.tracker_id.to_s
+      self.tracker = (tracker_id.present? ? Tracker.find_by_id(tracker_id) : nil)
+    end
+    self.tracker_id
+  end
+
+  def tracker=(tracker)
+    if tracker != self.tracker 
+      @custom_field_values = nil
+      @workflow_rule_by_attribute = nil
+    end
+    association(:tracker).writer(tracker)
   end
 
   def project_id=(project_id)
     if project_id.to_s != self.project_id.to_s
       self.project = (project_id.present? ? Project.find_by_id(project_id) : nil)
     end
+    self.project_id
   end
 
   def project=(project, keep_tracker=false)
     project_was = self.project
-    write_attribute(:project_id, project ? project.id : nil)
-    association_instance_set('project', project)
+    association(:project).writer(project)
     if project_was && project && project_was != project
       @assignable_versions = nil