diff -bNaur redSVN1797/app/controllers/projects_controller.rb redmine/app/controllers/projects_controller.rb --- redSVN1797/app/controllers/projects_controller.rb 2008-09-11 16:44:59.337389000 +0200 +++ redmine/app/controllers/projects_controller.rb 2008-09-11 08:57:41.546391600 +0200 @@ -65,8 +65,11 @@ @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") @trackers = Tracker.all @root_projects = Project.find(:all, - :conditions => "parent_id IS NULL AND status = #{Project::STATUS_ACTIVE}", + :conditions => "status = #{Project::STATUS_ACTIVE}", :order => 'name') + if @project != nil + @root_projects = @root_projects - @project.fetch_all_subprojects_id_recursively() + end @project = Project.new(params[:project]) if request.get? @project.identifier = Project.next_identifier if Setting.sequential_project_identifiers? @@ -108,8 +111,11 @@ def settings @root_projects = Project.find(:all, - :conditions => ["parent_id IS NULL AND status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id], + :conditions => ["status = #{Project::STATUS_ACTIVE} AND id <> ?", @project.id], :order => 'name') + if @project != nil + @root_projects = @root_projects - @project.fetch_all_subprojects_id_recursively() + end @issue_custom_fields = IssueCustomField.find(:all, :order => "#{CustomField.table_name}.position") @issue_category ||= IssueCategory.new @member ||= @project.members.new diff -bNaur redSVN1797/app/models/project.rb redmine/app/models/project.rb --- redSVN1797/app/models/project.rb 2008-09-11 16:44:56.446912000 +0200 +++ redmine/app/models/project.rb 2008-09-11 16:27:18.421875000 +0200 @@ -71,10 +71,32 @@ errors[:identifier].nil? && !(new_record? || identifier.blank?) end + def fetch_all_subprojects_recursively + ret = Array.new + if self.children.size > 0 + self.children.each { |subproject| + ret << subproject + ret += subproject.fetch_all_subprojects_recursively() + } + end + return ret + end + + def fetch_all_subprojects_id_recursively + ret = Array.new + if self.children.size > 0 + self.children.each { |subproject| + ret << subproject.id.to_s + ret += subproject.fetch_all_subprojects_id_recursively() + } + end + return ret + end + def issues_with_subprojects(include_subprojects=false) conditions = nil if include_subprojects - ids = [id] + child_ids + ids = [id] + fetch_all_subprojects_id_recursively() conditions = ["#{Project.table_name}.id IN (#{ids.join(',')}) AND #{Project.visible_by}"] end conditions ||= ["#{Project.table_name}.id = ?", id] @@ -247,8 +269,6 @@ protected def validate - errors.add(parent_id, " must be a root project") if parent and parent.parent - errors.add_to_base("A project with subprojects can't be a subproject") if parent and children.size > 0 errors.add(:identifier, :activerecord_error_invalid) if !identifier.blank? && identifier.match(/^\d*$/) end diff -bNaur redSVN1797/app/models/query.rb redmine/app/models/query.rb --- redSVN1797/app/models/query.rb 2008-09-11 16:44:56.384415200 +0200 +++ redmine/app/models/query.rb 2008-09-11 08:52:04.204289400 +0200 @@ -269,10 +269,10 @@ # main project only else # all subprojects - ids += project.child_ids + ids += project.fetch_all_subprojects_id_recursively() end elsif Setting.display_subprojects_issues? - ids += project.child_ids + ids += project.fetch_all_subprojects_id_recursively() end project_clauses << "#{Issue.table_name}.project_id IN (%s)" % ids.join(',') elsif project