diff --git a/module/action/control.php b/module/action/control.php index 4aa8efa079..b2f65c748a 100755 --- a/module/action/control.php +++ b/module/action/control.php @@ -129,6 +129,8 @@ class action extends control $oldAction = $this->actionZen->checkActionExist($actionID); $extra = $oldAction->extra == actionModel::BE_HIDDEN ? 'hidden' : 'all'; + /* 当对象类型为program、project、execution、product时,需要检查是否有重复的对象。 */ + /* When the object type is program, project, execution, product, you need to check if there are duplicate objects. */ if(in_array($oldAction->objectType, array('program', 'project', 'execution', 'product'))) { $table = $oldAction->objectType == 'product' ? TABLE_PRODUCT : TABLE_PROJECT; @@ -136,23 +138,11 @@ class action extends control if($repeatObject) { + list($replaceName, $replaceCode) = $this->actionZen->getReplaceNameAndCode($repeatObject, $object, $table); if($confirmChange == 'no') { - $message = ''; - if($repeatObject->name == $object->name && $repeatObject->code && $repeatObject->code == $object->code) - { - $message = sprintf($this->lang->action->repeatChange, $this->lang->{$oldAction->objectType}->common, $replaceName, $replaceCode); - } - elseif($repeatObject->name == $object->name) - { - $message = sprintf($this->lang->action->nameRepeatChange, $this->lang->{$oldAction->objectType}->common, $replaceName); - } - elseif($repeatObject->code && $repeatObject->code == $object->code) - { - $message = sprintf($this->lang->action->codeRepeatChange, $this->lang->{$oldAction->objectType}->common, $replaceCode); - } - + $message = $this->actionZen->getConfirmNoMessage($repeatObject, $object, $oldAction, $replaceName, $replaceCode); if($message) { $url = $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes"); @@ -161,27 +151,13 @@ class action extends control } elseif($confirmChange == 'yes') { - $recoverData = array(); - if($repeatObject->name == $object->name && $repeatObject->code && $repeatObject->code == $object->code) - { - $recoverData = array('code' => $replaceCode, 'name' => $replaceName); - } - elseif($repeatObject->name == $object->name) - { - $recoverData = array('name' => $replaceName); - } - elseif($repeatObject->code && $repeatObject->code == $object->code) - { - $recoverData = array('code' => $replaceCode); - } - - if(!empty($recoverData)) $this->action->updateObjectByID($table, $oldAction->objectID, $recoverData); + $this->actionZen->recoverObject($repeatObject, $object, $replaceName, $replaceCode); } } if($oldAction->objectType == 'execution') { - $confirmLang = $this->restoreStages($oldAction, $confirmChange); + $confirmLang = $this->actionZen->restoreStages($oldAction, $confirmChange); $url = $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes"); if($confirmLang !== true) return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$confirmLang}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '{$url}'});});")); } @@ -309,95 +285,4 @@ class action extends control } return $this->send(array('result' => 'success', 'load' => true)); } - - /** - * Restore stages. - * - * @param object $action - * @param string $confirmChange - * @access public - * @return bool|string - */ - public function restoreStages(object $action, string $confirmChange = 'no'): bool|string - { - /* 检查父阶段是否创建过任务。 */ - /* Check parent stage isCreateTask. */ - $execution = $this->loadModel('execution')->getByID($action->objectID); - $hasCreatedTask = $this->loadModel('programplan')->isCreateTask($execution->parent); - if(!$hasCreatedTask) return $this->lang->action->hasCreatedTask; - - /* 检查同级执行的类型。 */ - /* Check type of siblings. */ - $siblings = $this->execution->getSiblingsTypeByParentID($execution->parent); - - if($execution->type == 'stage' && (isset($siblings['sprint']) || isset($siblings['kanban']))) return $this->lang->action->hasOtherType[$execution->type]; - if(($execution->type == 'sprint' || $execution->type == 'kanban') && isset($siblings['stage'])) return $this->lang->action->hasOtherType[$execution->type]; - - /* 如果父阶段不存在,你应该恢复父级阶段,并且刷新状态。 */ - /* If parent stage is not exists, you should recover its parent stages, refresh status. */ - $stagePathList = explode(',', trim($execution->path, ',')); - $deletedStageList = $this->action->getDeletedStagedByList($stagePathList); - $deletedParents = $deletedStageList; - array_pop($deletedParents); - - $needChangeAttr = false; //是否需要修改attribute值 - $deletedTitle = ''; //被删除的标题 - $startChangedStage = $execution; - - if(!empty($deletedParents)) - { - foreach($deletedParents as $deletedParent) $deletedTitle .= "'{$deletedParent->name}',"; - - /* 如果父阶段的状态已经被改变,子阶段的的状态也要改变。 */ - /* If parent stage's attribute has changed, sub-stage's attribute need change. */ - $deletedTopParent = current($deletedStageList); - $isTopStage = $this->loadModel('programplan')->isTopStage($deletedTopParent->id); - $parentAttr = $deletedTopParent->attribute; - if(!$isTopStage) $parentAttr = $this->action->getAttributeByExecutionID(); - - /* 从父阶段开始逐级下查,如果发现有跟父阶段不一样的attribute,对后面所有的attrubite值进行修改。 */ - /* Check down step by step from the parent stage, if you find that there is an attribute different from the parent stage, modify all the later attrubite values*. */ - $startChangedStage = $execution; - foreach($deletedStageList as $deletedStage) - { - if($parentAttr != 'mix' && $parentAttr != $deletedStage->attribute) - { - $startChangedStage = $deletedStage; - $needChangeAttr = true; - break; - } - $parentAttr = $deletedStage->attribute; - } - } - - /* 确认是否要恢复父阶段并且修改不一样的attribute值。 */ - /* Confirm whether you want to restore the parent stage and modify the different attribute value. */ - if(!empty($deletedTitle) || $needChangeAttr) - { - $this->app->loadLang('stage'); - - $confirmLang = sprintf($this->lang->action->hasDeletedParent, trim($deletedTitle, ',')) . $this->lang->action->whetherToRestore; - if($needChangeAttr) $confirmLang = sprintf($this->lang->action->hasChangedAttr, zget($this->lang->stage->typeList, $parentAttr)) . $this->lang->action->whetherToRestore; - if(!empty($deletedTitle) && $needChangeAttr) $confirmLang = sprintf($this->lang->action->hasDeletedParent, $deletedTitle) . sprintf($this->lang->action->hasChangedAttr, zget($this->lang->stage->typeList, $parentAttr)) . $this->lang->action->whetherToRestore; - - if($confirmChange == 'no') return $confirmLang; - - /* 如果被删除的标题集合不为空,则更新所有的阶段。 */ - /* If the collection of titles being deleted is not empty, all stages are updated. */ - if(!empty($deletedTitle)) $this->action->restoreStages($deletedParents); - - /* 如果需要更新attribute的值,则恢复路径上所有的父节点以及更新attrubute值。 */ - /* If the attribute value needs to be updated, restore all parent nodes on the path and update the attribute value. */ - if($needChangeAttr) - { - $needChangedStages = substr($execution->path, strpos($execution->path, ",{$startChangedStage->id},")); - $needChangedStages = explode(',', trim($needChangedStages, ',')); - $this->action->updateStageAttribute($parentAttr, $needChangedStages); - } - } - - $this->programplan->computeProgress($startChangedStage->parent); - - return true; - } } diff --git a/module/action/zen.php b/module/action/zen.php index 8340d728a9..5aeb78d549 100644 --- a/module/action/zen.php +++ b/module/action/zen.php @@ -179,4 +179,154 @@ class actionZen extends action if(!$action) return $this->send(array('result' => 'fail', 'message' => $this->lang->notFound)); return $action; } + + /** + * 获取需要确认为否状态下的信息。 + * Get the information that needs to be confirmed as no. + * + * @param object $object + * @param object $repeatObject + * @access public + * @return string + */ + public function getConfirmNoMessage(object $repeatObject, object $object, object $oldAction, string $replaceName, string $replaceCode): string + { + $message = ''; + if($repeatObject->name == $object->name && $repeatObject->code && $repeatObject->code == $object->code) + { + $message = sprintf($this->lang->action->repeatChange, $this->lang->{$oldAction->objectType}->common, $replaceName, $replaceCode); + } + elseif($repeatObject->name == $object->name) + { + $message = sprintf($this->lang->action->nameRepeatChange, $this->lang->{$oldAction->objectType}->common, $replaceName); + } + elseif($repeatObject->code && $repeatObject->code == $object->code) + { + $message = sprintf($this->lang->action->codeRepeatChange, $this->lang->{$oldAction->objectType}->common, $replaceCode); + } + + return $message; + } + + /** + * 恢复对象。 + * Recover the object. + * + * @param object $repeatObject + * @param object $object + * @param string $replaceName + * @param string $replaceCode + * @access public + * @return array + */ + public function recoverObject(object $repeatObject, object $object, string $replaceName, string $replaceCode): array + { + $recoverData = array(); + if($repeatObject->name == $object->name && $repeatObject->code && $repeatObject->code == $object->code) + { + $recoverData = array('code' => $replaceCode, 'name' => $replaceName); + } + elseif($repeatObject->name == $object->name) + { + $recoverData = array('name' => $replaceName); + } + elseif($repeatObject->code && $repeatObject->code == $object->code) + { + $recoverData = array('code' => $replaceCode); + } + + if(!empty($recoverData)) $this->action->updateObjectByID($table, $oldAction->objectID, $recoverData); + } + + /** + * 恢复阶段。 + * Restore stages. + * + * @param object $action + * @param string $confirmChange + * @access public + * @return bool|string + */ + public function restoreStages(object $action, string $confirmChange = 'no'): bool|string + { + /* 检查父阶段是否创建过任务。 */ + /* Check parent stage isCreateTask. */ + $execution = $this->loadModel('execution')->getByID($action->objectID); + $hasCreatedTask = $this->loadModel('programplan')->isCreateTask($execution->parent); + if(!$hasCreatedTask) return $this->lang->action->hasCreatedTask; + + /* 检查同级执行的类型。 */ + /* Check type of siblings. */ + $siblings = $this->execution->getSiblingsTypeByParentID($execution->parent); + + if($execution->type == 'stage' && (isset($siblings['sprint']) || isset($siblings['kanban']))) return $this->lang->action->hasOtherType[$execution->type]; + if(($execution->type == 'sprint' || $execution->type == 'kanban') && isset($siblings['stage'])) return $this->lang->action->hasOtherType[$execution->type]; + + /* 如果父阶段不存在,你应该恢复父级阶段,并且刷新状态。 */ + /* If parent stage is not exists, you should recover its parent stages, refresh status. */ + $stagePathList = explode(',', trim($execution->path, ',')); + $deletedStageList = $this->action->getDeletedStagedByList($stagePathList); + $deletedParents = $deletedStageList; + array_pop($deletedParents); + + $needChangeAttr = false; //是否需要修改attribute值 + $deletedTitle = ''; //被删除的标题 + $startChangedStage = $execution; + + if(!empty($deletedParents)) + { + foreach($deletedParents as $deletedParent) $deletedTitle .= "'{$deletedParent->name}',"; + + /* 如果父阶段的状态已经被改变,子阶段的的状态也要改变。 */ + /* If parent stage's attribute has changed, sub-stage's attribute need change. */ + $deletedTopParent = current($deletedStageList); + $isTopStage = $this->loadModel('programplan')->isTopStage($deletedTopParent->id); + $parentAttr = $deletedTopParent->attribute; + if(!$isTopStage) $parentAttr = $this->action->getAttributeByExecutionID(); + + /* 从父阶段开始逐级下查,如果发现有跟父阶段不一样的attribute,对后面所有的attrubite值进行修改。 */ + /* Check down step by step from the parent stage, if you find that there is an attribute different from the parent stage, modify all the later attrubite values*. */ + $startChangedStage = $execution; + foreach($deletedStageList as $deletedStage) + { + if($parentAttr != 'mix' && $parentAttr != $deletedStage->attribute) + { + $startChangedStage = $deletedStage; + $needChangeAttr = true; + break; + } + $parentAttr = $deletedStage->attribute; + } + } + + /* 确认是否要恢复父阶段并且修改不一样的attribute值。 */ + /* Confirm whether you want to restore the parent stage and modify the different attribute value. */ + if(!empty($deletedTitle) || $needChangeAttr) + { + $this->app->loadLang('stage'); + + $confirmLang = sprintf($this->lang->action->hasDeletedParent, trim($deletedTitle, ',')) . $this->lang->action->whetherToRestore; + if($needChangeAttr) $confirmLang = sprintf($this->lang->action->hasChangedAttr, zget($this->lang->stage->typeList, $parentAttr)) . $this->lang->action->whetherToRestore; + if(!empty($deletedTitle) && $needChangeAttr) $confirmLang = sprintf($this->lang->action->hasDeletedParent, $deletedTitle) . sprintf($this->lang->action->hasChangedAttr, zget($this->lang->stage->typeList, $parentAttr)) . $this->lang->action->whetherToRestore; + + if($confirmChange == 'no') return $confirmLang; + + /* 如果被删除的标题集合不为空,则更新所有的阶段。 */ + /* If the collection of titles being deleted is not empty, all stages are updated. */ + if(!empty($deletedTitle)) $this->action->restoreStages($deletedParents); + + /* 如果需要更新attribute的值,则恢复路径上所有的父节点以及更新attrubute值。 */ + /* If the attribute value needs to be updated, restore all parent nodes on the path and update the attribute value. */ + if($needChangeAttr) + { + $needChangedStages = substr($execution->path, strpos($execution->path, ",{$startChangedStage->id},")); + $needChangedStages = explode(',', trim($needChangedStages, ',')); + $this->action->updateStageAttribute($parentAttr, $needChangedStages); + } + } + + $this->programplan->computeProgress($startChangedStage->parent); + + return true; + } }