* Finish task #83954.

This commit is contained in:
hufangzhou
2023-02-14 02:46:34 +00:00
parent dbad8ab513
commit 56c2cdcb21
8 changed files with 125 additions and 4 deletions
+75
View File
@@ -246,6 +246,12 @@ class action extends control
if($confirmChange == 'yes') $this->dao->update($table)->set('code')->eq($replaceCode)->where('id')->eq($oldAction->objectID)->exec();
}
}
if($oldAction->objectType == 'execution')
{
$confirmLang = $this->restoreStages($oldAction, $browseType, $confirmChange);
if($confirmLang !== true) return print(js::confirm($confirmLang, $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes")));
}
}
$this->action->undelete($actionID);
@@ -351,4 +357,73 @@ class action extends control
}
return $this->send(array('result' => 'success', 'locate' => 'reload'));
}
/**
* Restore stages.
*
* @param object $action
* @param string $browseType
* @param string $confirmChange
* @access public
* @return bool|string
*/
public function restoreStages($action, $browseType, $confirmChange)
{
/* Check parent stage isCreateTask. */
$execution = $this->dao->select('*')->from(TABLE_EXECUTION)->where('id')->eq($action->objectID)->fetch();
$hasCreatedTask = $this->loadModel('programplan')->isCreateTask($execution->parent);
if(!$hasCreatedTask) return print(js::alert($this->lang->action->hasCreatedTask));
/* If parent stage is not exists, you should recover its parent stages, refresh status. */
$stagePathList = explode(',', trim($execution->path, ','));
$deletedStageList = $this->dao->select('*')->from(TABLE_EXECUTION)->where('id')->in($stagePathList)->andWhere('deleted')->eq(1)->andWhere('type')->eq('stage')->orderBy('id_asc')->fetchAll('id');
$deletedParents = $deletedStageList;
array_pop($deletedParents);
$deletedTitle = '';
foreach($deletedParents as $deletedParent) $deletedTitle .= "'{$deletedParent->name}',";
/* If parent stage's attribute has changed, sub-stage's attribute need change. */
$deletedTopParent = current($deletedStageList);
$checkTopStage = $this->loadModel('programplan')->checkTopStage($deletedTopParent->id);
$parentAttr = $deletedTopParent->attribute;
if(!$checkTopStage) $parentAttr = $this->dao->select('attribute')->from(TABLE_EXECUTION)->where('id')->eq($deletedTopParent->parent)->fetch('attribute');
$needChangeAttr = false;
$startChangedStage = $execution;
foreach($deletedStageList as $deletedStage)
{
if($parentAttr != 'mix' and $parentAttr != $deletedStage->attribute)
{
$startChangedStage = $deletedStage;
$needChangeAttr = true;
break;
}
$parentAttr = $deletedStage->attribute;
}
/* Confirm. */
if(!empty($deletedTitle) or $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) and $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;
}
else
{
if(!empty($deletedTitle)) $this->action->restoreStages($deletedParents);
if($needChangeAttr) $this->programplan->updateSubStageAttr($startChangedStage->parent, $parentAttr, true);
}
}
$this->programplan->computeProgress($startChangedStage->parent);
return true;
}
}