From f3f92631e36b102cf31560e65fb2dd79af39a6d4 Mon Sep 17 00:00:00 2001 From: zenggang Date: Wed, 26 Oct 2022 08:38:23 +0000 Subject: [PATCH] * Fix bug#28983 --- module/programplan/lang/de.php | 1 + module/programplan/lang/en.php | 1 + module/programplan/lang/fr.php | 1 + module/programplan/lang/zh-cn.php | 1 + module/programplan/model.php | 51 ++++++++++++++++++++++++- module/programplan/view/create.html.php | 15 ++++++++ module/programplan/view/edit.html.php | 6 +++ 7 files changed, 75 insertions(+), 1 deletion(-) diff --git a/module/programplan/lang/de.php b/module/programplan/lang/de.php index 889b03bcaa..9b53aba68a 100644 --- a/module/programplan/lang/de.php +++ b/module/programplan/lang/de.php @@ -107,6 +107,7 @@ $lang->programplan->error->createdTask = 'The task has been decomposed. Sub $lang->programplan->error->parentWorkload = 'The sum of the workload of the child phase cannot be greater than that of the parent phase: %s.'; $lang->programplan->error->parentDuration = 'The planned start and planned completion of the child phase cannot exceed the parent phase.'; $lang->programplan->error->sameName = 'Stage name cannot be the same!'; +$lang->programplan->error->sameCode = 'Stage code cannot be the same!'; $lang->programplan->error->taskDrag = 'The %s task cannot be dragged'; $lang->programplan->error->planDrag = 'The %s stage cannot be dragged'; diff --git a/module/programplan/lang/en.php b/module/programplan/lang/en.php index 6ed9867b61..032f967e09 100644 --- a/module/programplan/lang/en.php +++ b/module/programplan/lang/en.php @@ -107,6 +107,7 @@ $lang->programplan->error->createdTask = 'The task is decomposed. Sub stages $lang->programplan->error->parentWorkload = 'The sum of the workload in the sub stage cannot be > that in the parent stage: %s.'; $lang->programplan->error->parentDuration = 'The planned start and planned completion of the child phase cannot exceed the parent phase.'; $lang->programplan->error->sameName = 'Stage name cannot be the same!'; +$lang->programplan->error->sameCode = 'Stage code cannot be the same!'; $lang->programplan->error->taskDrag = 'The %s task cannot be dragged'; $lang->programplan->error->planDrag = 'The %s stage cannot be dragged'; diff --git a/module/programplan/lang/fr.php b/module/programplan/lang/fr.php index 889b03bcaa..9b53aba68a 100644 --- a/module/programplan/lang/fr.php +++ b/module/programplan/lang/fr.php @@ -107,6 +107,7 @@ $lang->programplan->error->createdTask = 'The task has been decomposed. Sub $lang->programplan->error->parentWorkload = 'The sum of the workload of the child phase cannot be greater than that of the parent phase: %s.'; $lang->programplan->error->parentDuration = 'The planned start and planned completion of the child phase cannot exceed the parent phase.'; $lang->programplan->error->sameName = 'Stage name cannot be the same!'; +$lang->programplan->error->sameCode = 'Stage code cannot be the same!'; $lang->programplan->error->taskDrag = 'The %s task cannot be dragged'; $lang->programplan->error->planDrag = 'The %s stage cannot be dragged'; diff --git a/module/programplan/lang/zh-cn.php b/module/programplan/lang/zh-cn.php index 1e4fdfbacd..a2da6cf531 100644 --- a/module/programplan/lang/zh-cn.php +++ b/module/programplan/lang/zh-cn.php @@ -107,6 +107,7 @@ $lang->programplan->error->createdTask = '已分解任务,不可添加子 $lang->programplan->error->parentWorkload = '子阶段的工作量之和不能大于父阶段的工作量:%s'; $lang->programplan->error->parentDuration = '子阶段计划开始、计划完成不能超过父阶段'; $lang->programplan->error->sameName = '阶段名称不能相同!'; +$lang->programplan->error->sameCode = '阶段代号不能相同!'; $lang->programplan->error->taskDrag = '%s的任务不可以拖动'; $lang->programplan->error->planDrag = '%s的阶段不可以拖动'; diff --git a/module/programplan/model.php b/module/programplan/model.php index a3d20ecfad..d64c9a9f8d 100755 --- a/module/programplan/model.php +++ b/module/programplan/model.php @@ -702,6 +702,15 @@ class programplanModel extends model return false; } + $setCode = (!isset($this->config->setCode) or $this->config->setCode == 1) ? true : false; + $checkCode = $this->checkCodeUnique($codes, isset($planIDList) ? $planIDList : ''); + if($setCode and $checkCode !== true) + { + if($checkCode) dao::$errors['message'][] = sprintf($this->lang->error->repeat, $this->lang->execution->code, $checkCode); + else dao::$errors['message'][] = $this->lang->programplan->error->sameCode; + return false; + } + $datas = array(); foreach($names as $key => $name) { @@ -713,6 +722,7 @@ class programplanModel extends model $plan->project = $projectID; $plan->parent = $parentID ? $parentID : $projectID; $plan->name = $names[$key]; + if($setCode) $plan->code = $codes[$key]; $plan->percent = $percents[$key]; $plan->attribute = empty($parentID) ? $attributes[$key] : $parentAttribute; $plan->milestone = $milestone[$key]; @@ -782,6 +792,11 @@ class programplanModel extends model if(helper::isZeroDate($plan->begin)) $plan->begin = ''; if(helper::isZeroDate($plan->end)) $plan->end = ''; + if($setCode and empty($plan->code)) + { + dao::$errors['message'][] = sprintf($this->lang->error->notempty, $this->lang->execution->code); + return false; + } foreach(explode(',', $this->config->programplan->create->requiredFields) as $field) { $field = trim($field); @@ -1006,6 +1021,13 @@ class programplanModel extends model if($projectID) $this->loadModel('execution')->checkBeginAndEndDate($projectID, $plan->begin, $plan->end); if(dao::isError()) return false; + $setCode = (!isset($this->config->setCode) or $this->config->setCode == 1) ? true : false; + if($setCode and empty($plan->code)) + { + dao::$errors['code'][] = sprintf($this->lang->error->notempty, $this->lang->execution->code); + return false; + } + $planChanged = ($oldPlan->name != $plan->name || $oldPlan->milestone != $plan->milestone || $oldPlan->begin != $plan->begin || $oldPlan->end != $plan->end); if($plan->parent > 0) @@ -1045,15 +1067,19 @@ class programplanModel extends model if($planChanged) $plan->version = $oldPlan->version + 1; if(empty($plan->parent)) $plan->parent = $projectID; + $parentStage = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($plan->parent)->andWhere('type')->eq('stage')->fetch(); + /* Fix bug #22030. Reset field name for show dao error. */ $this->lang->project->name = $this->lang->programplan->name; + $this->lang->project->code = $this->lang->execution->code; $this->dao->update(TABLE_PROJECT)->data($plan) ->autoCheck() ->batchCheck($this->config->programplan->edit->requiredFields, 'notempty') ->checkIF($plan->end != '0000-00-00', 'end', 'ge', $plan->begin) ->checkIF($plan->percent != false, 'percent', 'float') - ->checkIF((!empty($plan->name) and $this->config->systemMode == 'new'), 'name', 'unique', "id != {$planID} and type in ('sprint','stage') and `project` = {$oldPlan->project}") + ->checkIF((!empty($plan->name) and $this->config->systemMode == 'new'), 'name', 'unique', "id != {$planID} and type in ('sprint','stage') and `project` = {$oldPlan->project} and `deleted` = '0'" . ($parentStage ? " and `parent` = {$oldPlan->parent}" : '')) + ->checkIF(!empty($plan->code), 'code', 'unique', "id != $planID and type in ('sprint','stage','kanban') and `deleted` = '0'") ->where('id')->eq($planID) ->exec(); @@ -1232,6 +1258,29 @@ class programplanModel extends model return true; } + /** + * Check code unique. + * + * @param array $codes + * @param array $planIDList + * @access public + * @return mix + */ + public function checkCodeUnique($codes, $planIDList) + { + $codes = array_filter($codes); + if(count(array_unique($codes)) != count($codes)) return false; + + $code = $this->dao->select('code')->from(TABLE_EXECUTION) + ->where('type')->in('sprint,stage,kanban') + ->andWhere('deleted')->eq('0') + ->andWhere('code')->in($codes) + ->beginIF($planIDList)->andWhere('id')->notin($planIDList)->fi() + ->fetch('code'); + if($code) return $code; + return true; + } + /** * Get the stage set to milestone. * diff --git a/module/programplan/view/create.html.php b/module/programplan/view/create.html.php index 9779a0db69..8c76cc819b 100644 --- a/module/programplan/view/create.html.php +++ b/module/programplan/view/create.html.php @@ -56,6 +56,9 @@ + setCode) or $config->setCode == 1):?> + execution->code;?> + '>programplan->PM;?> '> programplan->percent;?> @@ -82,6 +85,9 @@ + setCode) or $config->setCode == 1):?> + code, "class='form-control'");?> + > >
@@ -113,6 +119,9 @@ id);?> + setCode) or $config->setCode == 1):?> + code, "class='form-control'");?> + >PM, "class='form-control picker-select'");?> >
@@ -142,6 +151,9 @@ + setCode) or $config->setCode == 1):?> + + > >
@@ -183,6 +195,9 @@ + setCode) or $config->setCode == 1):?> + + + setCode) or $config->setCode == 1):?> + + + + +