diff --git a/module/program/model.php b/module/program/model.php index 6748fbe90b..f0f9ec6fb1 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1326,7 +1326,7 @@ class programModel extends model { $parent = $this->dao->select('id,parent,path,grade')->from(TABLE_PROGRAM)->where('id')->eq($parentID)->fetch(); - $childNodes = $this->dao->select('id,parent,path,grade')->from(TABLE_PROGRAM) + $childNodes = $this->dao->select('id,parent,path,grade,type')->from(TABLE_PROGRAM) ->where('path')->like("{$oldPath}%") ->andWhere('deleted')->eq(0) ->orderBy('grade') @@ -1335,13 +1335,16 @@ class programModel extends model /* Process child node path and grade field. */ foreach($childNodes as $childNode) { - $path = substr($childNode->path, strpos($childNode->path, ",{$programID},")); - $grade = $childNode->grade - $oldGrade + 1; + $path = substr($childNode->path, strpos($childNode->path, ",{$programID},")); + + /* Only program and project sets update grade. */ + $grade = in_array($childNode->type, array('program', 'project')) ? $childNode->grade - $oldGrade + 1 : $childNode->grade; if($parent) { $path = rtrim($parent->path, ',') . $path; - $grade = $parent->grade + $grade; + $grade = in_array($childNode->type, array('program', 'project'))? $parent->grade + $grade : $grade; } + $this->dao->update(TABLE_PROGRAM)->set('path')->eq($path)->set('grade')->eq($grade)->where('id')->eq($childNode->id)->exec(); } diff --git a/module/upgrade/model.php b/module/upgrade/model.php index 73e2edea46..8d8d3a8325 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -513,6 +513,7 @@ class upgradeModel extends model break; case '17_0': $this->replaceSetLanePriv(); + $this->updateProjectData(); break; } @@ -6358,4 +6359,82 @@ class upgradeModel extends model return true; } + + /** + * Update path and grade of program, project and execution. + * + * @access public + * @return bool + */ + public function updateProjectData() + { + /* Process programs. */ + $programs = $this->dao->select('id,parent,grade,path')->from(TABLE_PROJECT)->where('type')->eq('program')->orderBy('parent_asc')->fetchAll('id'); + foreach($programs as $program) + { + if(!$program->parent) + { + $program->grade = 1; + $program->path = ",$program->id,"; + } + else + { + $program->grade = $programs[$program->parent]->grade + 1; + $program->path = $programs[$program->parent]->path . "$program->id,"; + } + + $this->dao->update(TABLE_PROGRAM) + ->set('path')->eq($program->path) + ->set('grade')->eq($program->grade) + ->where('id')->eq($program->id)->exec(); + } + + /* Process projects. */ + $projects = $this->dao->select('id,project,parent,grade,path')->from(TABLE_PROJECT)->where('type')->eq('project')->orderBy('parent_asc')->fetchAll('id'); + foreach($projects as $project) + { + if(!$project->parent) + { + $project->grade = 1; + $project->path = ",$project->id,"; + } + else + { + $project->grade = $programs[$project->parent]->grade + 1; + $project->path = $programs[$project->parent]->path . "$project->id,"; + } + + $this->dao->update(TABLE_PROJECT) + ->set('path')->eq($project->path) + ->set('grade')->eq($project->grade) + ->where('id')->eq($project->id)->exec(); + } + + /* Process executions. */ + $sprints = $this->dao->select('id,project,parent,grade,path')->from(TABLE_PROJECT) + ->where('type')->ne('project') + ->andWhere('type')->ne('program') + ->orderBy('parent_asc')->fetchAll('id'); + + foreach($sprints as $sprint) + { + if($sprint->parent == $sprint->project) + { + $sprint->grade = 1; + $sprint->path = ",$sprint->project,$sprint->id,"; + } + else + { + $sprint->grade = 2; + $sprint->path = $sprints[$sprint->parent]->path . "$sprint->id,"; + } + + $this->dao->update(TABLE_EXECUTION) + ->set('path')->eq($sprint->path) + ->set('grade')->eq($sprint->grade) + ->where('id')->eq($sprint->id)->exec(); + } + + return true; + } }