From b438c9882a1818d4bfdbe3dd23eeb8812fe7138a Mon Sep 17 00:00:00 2001 From: tianshujie Date: Thu, 16 Jun 2022 16:31:01 +0800 Subject: [PATCH] * Fix bug #23855. --- db/update17.0.sql | 2 -- module/program/model.php | 2 +- module/upgrade/model.php | 76 ++++++++++++++++++++++++++++++++++------ 3 files changed, 67 insertions(+), 13 deletions(-) diff --git a/db/update17.0.sql b/db/update17.0.sql index ed16ae7743..832ca723af 100644 --- a/db/update17.0.sql +++ b/db/update17.0.sql @@ -11,5 +11,3 @@ DELETE FROM `zt_workflowaction` WHERE `module`='task' AND `action`='browse'; DELETE FROM `zt_workflowaction` WHERE `module`='build' AND `action`='browse'; ALTER TABLE `zt_projectproduct` MODIFY COLUMN `plan` varchar(255) NOT NULL; - -UPDATE `zt_project` SET `grade`=1 WHERE `type` in ('sprint', 'kanban'); diff --git a/module/program/model.php b/module/program/model.php index 0cf5803292..f0f9ec6fb1 100644 --- a/module/program/model.php +++ b/module/program/model.php @@ -1337,7 +1337,7 @@ class programModel extends model { $path = substr($childNode->path, strpos($childNode->path, ",{$programID},")); - /* Only program sets update grade. */ + /* Only program and project sets update grade. */ $grade = in_array($childNode->type, array('program', 'project')) ? $childNode->grade - $oldGrade + 1 : $childNode->grade; if($parent) { diff --git a/module/upgrade/model.php b/module/upgrade/model.php index abf768c9aa..a66103c282 100644 --- a/module/upgrade/model.php +++ b/module/upgrade/model.php @@ -513,7 +513,7 @@ class upgradeModel extends model break; case '17_0': $this->replaceSetLanePriv(); - $this->updateGradeOfStage(); + $this->updateObjectData(); break; } @@ -6361,24 +6361,80 @@ class upgradeModel extends model } /** - * Update grade of stage. + * Update path and grade of program, project and execution. * * @access public - * @return void + * @return bool */ - public function updateGradeOfStage() + public function updateObjectData() { - $allStages = $this->dao->select('*')->from(TABLE_EXECUTION)->where('type')->eq('stage')->fetchAll('id'); - $updateIDList = array(); - foreach($allStages as $stageID => $stage) + /* 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($stage->project != $stage->parent) $updateIDList[$stageID] = $stageID; + 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(); } - if(!empty($updateIDList)) + /* 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) { - $this->dao->update(TABLE_EXECUTION)->set('grade')->eq(2)->where('type')->eq('stage')->andWhere('id')->in($updateIDList)->exec(); + 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; } }