summaryrefslogtreecommitdiffstats
path: root/app/models/tracker.rb
diff options
context:
space:
mode:
authorJean-Philippe Lang <jp_lang@yahoo.fr>2008-03-15 08:27:38 +0000
committerJean-Philippe Lang <jp_lang@yahoo.fr>2008-03-15 08:27:38 +0000
commitaec989707edc47161192eba74f1a88123b12360a (patch)
tree5a810a6a3fb4fb76b9cfdb439eedc666bf4d049a /app/models/tracker.rb
parent993b60d61eb927cff21ea0b06c1631eb986f6a51 (diff)
downloadredmine-aec989707edc47161192eba74f1a88123b12360a.tar.gz
redmine-aec989707edc47161192eba74f1a88123b12360a.zip
Workflow copy:
* added the ability the copy an existing workflow when creating a new role (closes #841) * use a single raw insert statement to copy tracker/role workflow rather than instantiating hundreds/thousands of objects git-svn-id: http://redmine.rubyforge.org/svn/trunk@1252 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'app/models/tracker.rb')
-rw-r--r--app/models/tracker.rb13
1 files changed, 12 insertions, 1 deletions
diff --git a/app/models/tracker.rb b/app/models/tracker.rb
index 07253a227..ecee908eb 100644
--- a/app/models/tracker.rb
+++ b/app/models/tracker.rb
@@ -18,7 +18,18 @@
class Tracker < ActiveRecord::Base
before_destroy :check_integrity
has_many :issues
- has_many :workflows, :dependent => :delete_all
+ has_many :workflows, :dependent => :delete_all do
+ def copy(tracker)
+ raise "Can not copy workflow from a #{tracker.class}" unless tracker.is_a?(Tracker)
+ raise "Can not copy workflow from/to an unsaved tracker" if proxy_owner.new_record? || tracker.new_record?
+ clear
+ connection.insert "INSERT INTO workflows (tracker_id, old_status_id, new_status_id, role_id)" +
+ " SELECT #{proxy_owner.id}, old_status_id, new_status_id, role_id" +
+ " FROM workflows" +
+ " WHERE tracker_id = #{tracker.id}"
+ end
+ end
+
has_and_belongs_to_many :projects
has_and_belongs_to_many :custom_fields, :class_name => 'IssueCustomField', :join_table => "#{table_name_prefix}custom_fields_trackers#{table_name_suffix}", :association_foreign_key => 'custom_field_id'
acts_as_list