From fae28afeec640615eaf0dbd7eef704a8419f477a Mon Sep 17 00:00:00 2001 From: jukui Date: Fri, 12 May 2023 15:34:09 +0800 Subject: [PATCH] * Optimized update function for programplan model. --- module/programplan/model.php | 11 +++-------- module/programplan/tao.php | 17 ++++++----------- 2 files changed, 9 insertions(+), 19 deletions(-) diff --git a/module/programplan/model.php b/module/programplan/model.php index 2e2a208d3e..14e3b40931 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -921,15 +921,10 @@ class programplanModel extends model $relatedExecutionsID = $this->loadModel('execution')->getRelatedExecutions($planID); $relatedExecutionsID = !empty($relatedExecutionsID) ? implode(',', array_keys($relatedExecutionsID)) : '0'; - $conditions = array(); - $conditions['requiredFields'] = $this->config->programplan->edit->requiredFields ?? ''; - $conditions['relatedExecutionsID'] = $relatedExecutionsID; - $conditions['oldProject'] = $oldPlan->project; - $conditions['oldParent'] = $oldPlan->parent; - $conditions['parentStage'] = $parentStage; - $conditions['setCode'] = $setCode; + $plan->relatedExecutionsID = $relatedExecutionsID; + $plan->parentStage = $setCode; - $result = $this->programplanTao->updateRow($plan, $conditions); + $result = $this->programplanTao->updateRow($plan, $oldPlan, $parentStage); if(!$result) return false; $this->setTreePath($planID); diff --git a/module/programplan/tao.php b/module/programplan/tao.php index 4253edd781..ddc9bd2f42 100644 --- a/module/programplan/tao.php +++ b/module/programplan/tao.php @@ -20,25 +20,20 @@ class programplanTao extends programplanModel * @access protected * @return bool */ - protected function updateRow(object $plan, array $conditions): bool + protected function updateRow(object $plan, object $oldPlan, object|null $parentStage): bool { - $requiredFields = $conditions['requiredFields'] ?? ''; - $projectIDList = $conditions['relatedExecutionsID'] ?? ''; - $project = $conditions['project'] ?? ''; - $parentStage = $conditions['parentStage'] ?? ''; - $parent = $conditions['parent'] ?? ''; - $setCode = $conditions['setCode'] ?? ''; + $requiredFields = $this->config->programplan->edit->requiredFields ?? ''; - $getName = false; - if($projectIDList && $project && $parentStage && $parent) $getName = true; + $getname = ''; + if($plan->relatedExecutionsID && $oldPlan->project && $parentStage && $oldPlan->parent) $getname = true; $this->dao->update(TABLE_PROJECT)->data($plan) ->autoCheck() ->batchCheckIF($requiredFields, $requiredFields, 'notempty') ->checkIF($plan->end != '0000-00-00', 'end', 'ge', $plan->begin) ->checkIF(!empty($plan->percent), 'percent', 'float') - ->checkIF(!empty($plan->name) && $getName, 'name', 'unique', "id in ({$projectIDList}) and type in ('sprint','stage') and `project` = {$project} and `deleted` = '0'" . ($parentStage ? " and `parent` = {$parent}" : '')) - ->checkIF(!empty($plan->code) and $setCode, 'code', 'unique', "id != {$plan->id} and type in ('sprint','stage','kanban') and `deleted` = '0'") + ->checkIF(!empty($plan->name) && $getname, 'name', 'unique', "id in ({$plan->relatedExecutionsID}) and type in ('sprint','stage') and `project` = {$oldPlan->project} and `deleted` = '0' and `parent` = {$oldPlan->parent}") + ->checkIF(!empty($plan->code) and $plan->setCode, 'code', 'unique', "id != {$plan->id} and type in ('sprint','stage','kanban') and `deleted` = '0'") ->where('id')->eq($plan->id) ->exec();