* Refactor action control undelete.
This commit is contained in:
@@ -1,9 +1,10 @@
|
||||
<?php
|
||||
$config->action->actionList = array();
|
||||
$config->action->actionList['undelete']['icon'] = 'back';
|
||||
$config->action->actionList['undelete']['text'] = $lang->action->undelete;
|
||||
$config->action->actionList['undelete']['hint'] = $lang->action->undelete;
|
||||
$config->action->actionList['undelete']['url'] = array('module' => 'action', 'method' => 'undelete', 'params' => 'actionid={id}');
|
||||
$config->action->actionList['undelete']['icon'] = 'back';
|
||||
$config->action->actionList['undelete']['text'] = $lang->action->undelete;
|
||||
$config->action->actionList['undelete']['hint'] = $lang->action->undelete;
|
||||
$config->action->actionList['undelete']['url'] = array('module' => 'action', 'method' => 'undelete', 'params' => 'actionid={id}');
|
||||
$config->action->actionList['undelete']['className'] = 'ajax-submit';
|
||||
|
||||
$config->action->actionList['hideone']['icon'] = 'eye-off';
|
||||
$config->action->actionList['hideone']['text'] = $lang->action->hideOne;
|
||||
|
||||
+30
-42
@@ -233,6 +233,7 @@ class action extends control
|
||||
}
|
||||
|
||||
/**
|
||||
* 恢复一个回收站对象。
|
||||
* Undelete an object.
|
||||
*
|
||||
* @param int $actionID
|
||||
@@ -241,49 +242,20 @@ class action extends control
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function undelete($actionID, $browseType = 'all', $confirmChange = 'no')
|
||||
public function undelete(int $actionID, string $browseType = 'all', string $confirmChange = 'no')
|
||||
{
|
||||
$oldAction = $this->action->getById($actionID);
|
||||
$extra = $oldAction->extra == ACTIONMODEL::BE_HIDDEN ? 'hidden' : 'all';
|
||||
|
||||
if(in_array($oldAction->objectType, array('program', 'project', 'execution', 'product')))
|
||||
{
|
||||
if($oldAction->objectType == 'product')
|
||||
{
|
||||
$product = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->eq($oldAction->objectID)->fetch();
|
||||
$programID = isset($product->program) ? $product->program : 0;
|
||||
$repeatObject = $this->dao->select('*')->from(TABLE_PRODUCT)
|
||||
->where('id')->ne($oldAction->objectID)
|
||||
->andWhere("(name = '{$product->name}' and program = {$programID})", true)
|
||||
->beginIF($product->code)->orWhere("code = '{$product->code}'")->fi()
|
||||
->markRight(1)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->fetch();
|
||||
}
|
||||
else
|
||||
{
|
||||
$project = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($oldAction->objectID)->fetch();
|
||||
$sprintProject = isset($project->project) ? $project->project : '0';
|
||||
$repeatObject = $this->dao->select('*')->from(TABLE_PROJECT)
|
||||
->where('id')->ne($oldAction->objectID)
|
||||
->beginIF($oldAction->objectType == 'program' or $oldAction->objectType == 'project')->andWhere("(name = '{$project->name}' and parent = {$project->parent})", true)->fi()
|
||||
->beginIF($oldAction->objectType == 'execution')->andWhere("(name = '{$project->name}' and project = {$sprintProject})", true)->fi()
|
||||
->beginIF($oldAction->objectType == 'project' and $project->code)->orWhere("(code = '{$project->code}' and model = '$project->model')")->fi()
|
||||
->beginIF($oldAction->objectType == 'execution' and $project->code)->orWhere("code = '{$project->code}'")->fi()
|
||||
->markRight(1)
|
||||
->beginIF($oldAction->objectType == 'program')->andWhere('type')->eq('program')->fi()
|
||||
->beginIF($oldAction->objectType == 'project')->andWhere('type')->eq('project')->fi()
|
||||
->beginIF($oldAction->objectType == 'execution')->andWhere('type')->in('sprint,stage,kanban')->fi()
|
||||
->andWhere('deleted')->eq('0')
|
||||
->fetch();
|
||||
}
|
||||
|
||||
$object = new stdclass();
|
||||
$repeatObject = $this->action->getRepeatObject($oldAction, $object);
|
||||
if($repeatObject)
|
||||
{
|
||||
$table = $oldAction->objectType == 'product' ? TABLE_PRODUCT : TABLE_PROJECT;
|
||||
$object = $oldAction->objectType == 'product' ? $product : $project;
|
||||
|
||||
$existNames = $this->dao->select('name')->from($table)->where('name')->like($repeatObject->name . '_%')->fetchPairs();
|
||||
$existNames = $this->action->getLikeObject($table, 'name', 'name', $repeatObject->name . '_%');
|
||||
for($i = 1; $i < 10000; $i ++)
|
||||
{
|
||||
$replaceName = $repeatObject->name . '_' . $i;
|
||||
@@ -292,7 +264,7 @@ class action extends control
|
||||
$replaceCode = '';
|
||||
if($object->code)
|
||||
{
|
||||
$existCodes = $this->dao->select('code')->from($table)->where('code')->like($repeatObject->code . '_%')->fetchPairs();
|
||||
$existCodes = $this->action->getLikeObject($table, 'code', 'code', $repeatObject->code . '_%');
|
||||
for($i = 1; $i < 10000; $i ++)
|
||||
{
|
||||
$replaceCode = $repeatObject->code . '_' . $i;
|
||||
@@ -300,27 +272,43 @@ class action extends control
|
||||
}
|
||||
}
|
||||
|
||||
if($repeatObject->name == $object->name and $repeatObject->code and $repeatObject->code == $object->code)
|
||||
if($repeatObject->name == $object->name && $repeatObject->code && $repeatObject->code == $object->code)
|
||||
{
|
||||
if($confirmChange == 'no') return print(js::confirm(sprintf($this->lang->action->repeatChange, $this->lang->{$oldAction->objectType}->common, $replaceName, $replaceCode), $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes")));
|
||||
if($confirmChange == 'yes') $this->dao->update($table)->set('name')->eq($replaceName)->set('code')->eq($replaceCode)->where('id')->eq($oldAction->objectID)->exec();
|
||||
if($confirmChange == 'no')
|
||||
{
|
||||
$message = sprintf($this->lang->action->repeatChange, $this->lang->{$oldAction->objectType}->common, $replaceName, $replaceCode);
|
||||
$url = $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes");
|
||||
return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$message}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '{$url}'}); });"));
|
||||
}
|
||||
if($confirmChange == 'yes') $this->action->updateObjectByID($table, $oldAction->id, array('code' => $replaceCode, 'name' => $replaceName));
|
||||
}
|
||||
elseif($repeatObject->name == $object->name)
|
||||
{
|
||||
if($confirmChange == 'no') return print(js::confirm(sprintf($this->lang->action->nameRepeatChange, $this->lang->{$oldAction->objectType}->common, $replaceName), $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes")));
|
||||
if($confirmChange == 'yes') $this->dao->update($table)->set('name')->eq($replaceName)->where('id')->eq($oldAction->objectID)->exec();
|
||||
if($confirmChange == 'no')
|
||||
{
|
||||
$message = sprintf($this->lang->action->nameRepeatChange, $this->lang->{$oldAction->objectType}->common, $replaceName);
|
||||
$url = $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes");
|
||||
return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$message}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '{$url}'}); });"));
|
||||
}
|
||||
if($confirmChange == 'yes') $this->action->updateObjectByID($table, $oldAction->id, array('name' => $replaceName));
|
||||
}
|
||||
elseif($repeatObject->code and $repeatObject->code == $object->code)
|
||||
{
|
||||
if($confirmChange == 'no') return print(js::confirm(sprintf($this->lang->action->codeRepeatChange, $this->lang->{$oldAction->objectType}->common, $replaceCode), $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes")));
|
||||
if($confirmChange == 'yes') $this->dao->update($table)->set('code')->eq($replaceCode)->where('id')->eq($oldAction->objectID)->exec();
|
||||
if($confirmChange == 'no')
|
||||
{
|
||||
$message = sprintf($this->lang->action->codeRepeatChange, $this->lang->{$oldAction->objectType}->common, $replaceCode);
|
||||
$url = $this->createLink('action', 'undelete', "action={$actionID}&browseType={$browseType}&confirmChange=yes");
|
||||
return $this->send(array('result' => 'fail', 'callback' => "zui.Modal.confirm({message: '{$message}', icon: 'icon-exclamation-sign', iconClass: 'warning-pale rounded-full icon-2x'}).then((res) => {if(res) $.ajaxSubmit({url: '{$url}'}); });"));
|
||||
}
|
||||
if($confirmChange == 'yes') $this->action->updateObjectByID($table, $oldAction->id, array('code' => $replaceCode));
|
||||
}
|
||||
}
|
||||
|
||||
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")));
|
||||
$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}'}); });"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -72,9 +72,9 @@ $lang->action->hasOtherType['stage'] = "当前阶段的父级现在只允许创
|
||||
$lang->action->hasOtherType['sprint'] = "当前{$lang->executionCommon}的父级现在只允许创建阶段类型的子级,故无法恢复当前{$lang->executionCommon}。";
|
||||
$lang->action->hasOtherType['kanban'] = "当前看板的父级现在只允许创建阶段类型的子级,故无法恢复当前看板。";
|
||||
|
||||
$lang->action->repeatChange = '系统内已有同名、同代号的%s,恢复后名称为\"%s\"、代号为\"%s\"。';
|
||||
$lang->action->nameRepeatChange = '系统内已有同名的%s,恢复后名称为\"%s\"。';
|
||||
$lang->action->codeRepeatChange = '系统内已有同代号的%s,恢复后代号为\"%s\"。';
|
||||
$lang->action->repeatChange = '系统内已有同名、同代号的%s,恢复后名称为"%s"、代号为"%s"。';
|
||||
$lang->action->nameRepeatChange = '系统内已有同名的%s,恢复后名称为"%s"。';
|
||||
$lang->action->codeRepeatChange = '系统内已有同代号的%s,恢复后代号为"%s"。';
|
||||
|
||||
$lang->action->history = new stdclass();
|
||||
$lang->action->history->action = '关联日志';
|
||||
|
||||
+80
-3
@@ -667,16 +667,18 @@ class actionModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取一条操作记录。
|
||||
* Get an action record.
|
||||
*
|
||||
* @param int $actionID
|
||||
* @access public
|
||||
* @return object
|
||||
* @return object|bool
|
||||
*/
|
||||
public function getById($actionID)
|
||||
public function getById(int $actionID): object|bool
|
||||
{
|
||||
$action = $this->dao->findById((int)$actionID)->from(TABLE_ACTION)->fetch();
|
||||
$action = $this->actionTao->fetchBaseInfo($actionID);
|
||||
|
||||
/* 当action值为repocreated的时候拼接域名。 */
|
||||
/* Splice domain name for connection when the action is equal to 'repocreated'.*/
|
||||
if($action->action == 'repocreated') $action->extra = str_replace("href='", "href='" . common::getSysURL(), $action->extra);
|
||||
|
||||
@@ -2412,4 +2414,79 @@ class actionModel extends model
|
||||
$this->create($deletedAction->objectType, $deletedAction->objectID, 'undeleted');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取属性相同的对象。
|
||||
* Get repeat object.
|
||||
*
|
||||
* @param object $action
|
||||
* @access public
|
||||
* @return object|bool
|
||||
*/
|
||||
public function getRepeatObject(object $action, object &$object): object|bool
|
||||
{
|
||||
if($action->objectType == 'product')
|
||||
{
|
||||
$object = $this->dao->select('*')->from(TABLE_PRODUCT)->where('id')->eq($action->objectID)->fetch();
|
||||
$programID = isset($object->program) ?? 0;
|
||||
$repeatObject = $this->dao->select('*')->from(TABLE_PRODUCT)
|
||||
->where('id')->ne($action->objectID)
|
||||
->andWhere("(name = '{$product->name}' and program = {$programID})", true)
|
||||
->beginIF($product->code)->orWhere("code = '{$product->code}'")->fi()
|
||||
->markRight(1)
|
||||
->andWhere('deleted')->eq('0')
|
||||
->fetch();
|
||||
}
|
||||
else
|
||||
{
|
||||
$object = $this->dao->select('*')->from(TABLE_PROJECT)->where('id')->eq($action->objectID)->fetch();
|
||||
$sprintProject = isset($object->project) ?? 0;
|
||||
$repeatObject = $this->dao->select('*')->from(TABLE_PROJECT)
|
||||
->where('id')->ne($action->objectID)
|
||||
->beginIF($action->objectType == 'program' || $action->objectType == 'project')->andWhere("(name = '{$object->name}' and parent = {$object->parent})", true)->fi()
|
||||
->beginIF($action->objectType == 'execution')->andWhere("(name = '{$object->name}' and project = {$sprintProject})", true)->fi()
|
||||
->beginIF($action->objectType == 'project' && $object->code)->orWhere("(code = '{$object->code}' and model = '$object->model')")->fi()
|
||||
->beginIF($action->objectType == 'execution' && $object->code)->orWhere("code = '{$object->code}'")->fi()
|
||||
->markRight(1)
|
||||
->beginIF($action->objectType == 'program')->andWhere('type')->eq('program')->fi()
|
||||
->beginIF($action->objectType == 'project')->andWhere('type')->eq('project')->fi()
|
||||
->beginIF($action->objectType == 'execution')->andWhere('type')->in('sprint,stage,kanban')->fi()
|
||||
->andWhere('deleted')->eq('0')
|
||||
->fetch();
|
||||
}
|
||||
return $repeatObject;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取和需求属性相近的对象。
|
||||
* Get like object.
|
||||
*
|
||||
* @param string $table
|
||||
* @param string $columns
|
||||
* @param string $param
|
||||
* @param string $value
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getLikeObject(string $table, string $columns, string $param, string $value): array
|
||||
{
|
||||
return $this->dao->select($columns)->from($table)->where($param)->like($value)->fetchPairs();
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过id更新对象。
|
||||
* Update object by id.
|
||||
*
|
||||
* @param string $table
|
||||
* @param int $id
|
||||
* @param array $params
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function updateObjectByID(string $table, int $id, array $params)
|
||||
{
|
||||
$updateParams = array();
|
||||
foreach($params as $key => $value) $updateParams[] = '`' . $key . '`' . '="' . $value . '"';
|
||||
$this->dao->update($table)->set(implode(',', $updateParams))->where('id')->eq($id)->exec();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
class actionTao extends actionModel
|
||||
{
|
||||
/**
|
||||
* 获取一个action的基础数据。
|
||||
* Fetch base info of a action.
|
||||
*
|
||||
* @param int $actionID
|
||||
* @access protected
|
||||
* @return object|null
|
||||
*/
|
||||
protected function fetchBaseInfo(int $actionID): object|null
|
||||
{
|
||||
return $this->dao->select('*')->from(TABLE_ACTION)->where('id')->eq($actionID)->fetch();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user