@@ -340,12 +340,31 class Issue < ActiveRecord::Base | |||||
340 | s |
|
340 | s | |
341 | end |
|
341 | end | |
342 |
|
342 | |||
343 | # Update all issues so their versions are not pointing to a |
|
343 | # Unassigns issues from +version+ if it's no longer shared with issue's project | |
344 | # fixed_version that is outside of the issue's project hierarchy. |
|
344 | def self.update_versions_from_sharing_change(version) | |
345 | # |
|
345 | # Update issues assigned to the version | |
346 | # OPTIMIZE: does a full table scan of Issues with a fixed_version. |
|
346 | update_versions(["#{Issue.table_name}.fixed_version_id = ?", version.id]) | |
347 | def self.update_fixed_versions_from_sharing_change(conditions=nil) |
|
347 | end | |
348 | Issue.all(:conditions => merge_conditions('fixed_version_id IS NOT NULL', conditions), |
|
348 | ||
|
349 | # Unassigns issues from versions that are no longer shared | |||
|
350 | # after +project+ was moved | |||
|
351 | def self.update_versions_from_hierarchy_change(project) | |||
|
352 | moved_project_ids = project.self_and_descendants.reload.collect(&:id) | |||
|
353 | # Update issues of the moved projects and issues assigned to a version of a moved project | |||
|
354 | Issue.update_versions(["#{Version.table_name}.project_id IN (?) OR #{Issue.table_name}.project_id IN (?)", moved_project_ids, moved_project_ids]) | |||
|
355 | end | |||
|
356 | ||||
|
357 | private | |||
|
358 | ||||
|
359 | # Update issues so their versions are not pointing to a | |||
|
360 | # fixed_version that is not shared with the issue's project | |||
|
361 | def self.update_versions(conditions=nil) | |||
|
362 | # Only need to update issues with a fixed_version from | |||
|
363 | # a different project and that is not systemwide shared | |||
|
364 | Issue.all(:conditions => merge_conditions("#{Issue.table_name}.fixed_version_id IS NOT NULL" + | |||
|
365 | " AND #{Issue.table_name}.project_id <> #{Version.table_name}.project_id" + | |||
|
366 | " AND #{Version.table_name}.sharing <> 'system'", | |||
|
367 | conditions), | |||
349 | :include => [:project, :fixed_version] |
|
368 | :include => [:project, :fixed_version] | |
350 | ).each do |issue| |
|
369 | ).each do |issue| | |
351 | next if issue.project.nil? || issue.fixed_version.nil? |
|
370 | next if issue.project.nil? || issue.fixed_version.nil? | |
@@ -357,8 +376,6 class Issue < ActiveRecord::Base | |||||
357 | end |
|
376 | end | |
358 | end |
|
377 | end | |
359 |
|
378 | |||
360 | private |
|
|||
361 |
|
||||
362 | # Callback on attachment deletion |
|
379 | # Callback on attachment deletion | |
363 | def attachment_removed(obj) |
|
380 | def attachment_removed(obj) | |
364 | journal = init_journal(User.current) |
|
381 | journal = init_journal(User.current) |
@@ -304,7 +304,7 class Project < ActiveRecord::Base | |||||
304 | # move_to_child_of adds the project in last (ie.right) position |
|
304 | # move_to_child_of adds the project in last (ie.right) position | |
305 | move_to_child_of(p) |
|
305 | move_to_child_of(p) | |
306 | end |
|
306 | end | |
307 |
Issue.update_ |
|
307 | Issue.update_versions_from_hierarchy_change(self) | |
308 | true |
|
308 | true | |
309 | else |
|
309 | else | |
310 | # Can not move to the given target |
|
310 | # Can not move to the given target |
@@ -166,7 +166,7 private | |||||
166 | if VERSION_SHARINGS.index(sharing_was).nil? || |
|
166 | if VERSION_SHARINGS.index(sharing_was).nil? || | |
167 | VERSION_SHARINGS.index(sharing).nil? || |
|
167 | VERSION_SHARINGS.index(sharing).nil? || | |
168 | VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing) |
|
168 | VERSION_SHARINGS.index(sharing_was) > VERSION_SHARINGS.index(sharing) | |
169 | Issue.update_fixed_versions_from_sharing_change ["fixed_version_id = ? AND #{Issue.table_name}.project_id <> ?", id, project_id] |
|
169 | Issue.update_versions_from_sharing_change self | |
170 | end |
|
170 | end | |
171 | end |
|
171 | end | |
172 | end |
|
172 | end |
General Comments 0
You need to be logged in to leave comments.
Login now