* Finish task #45161.

This commit is contained in:
孙广明
2021-11-29 10:29:56 +08:00
parent a2f81d7d85
commit 19e08aafdc
9 changed files with 111 additions and 12 deletions
+35
View File
@@ -581,6 +581,41 @@ class upgrade extends control
$this->display();
}
/**
* Rename object in upgrade.
*
* @param string $type project|product|execution
* @param string $duplicateList
* @access public
* @return void
*/
public function renameObject($type = 'project', $duplicateList = '')
{
$this->app->loadLang($type);
if($_POST)
{
foreach($this->post->project as $projectID => $projectName)
{
if(!$projectName) continue;
$this->dao->update(TABLE_PROJECT)->set('name')->eq($projectName)->where('id')->eq($projectID)->exec();
}
die(js::closeModal('parent.parent', ''));
}
$objectGroup = array();
if($type == 'project' or $type == 'execution')
{
$objectGroup = $this->dao->select('id,name')->from(TABLE_PROJECT)
->where('id')->in($duplicateList)
->fetchGroup('name');
}
$this->view->type = $type;
$this->view->objectGroup = $objectGroup;
$this->display();
}
/**
* Merge Repos.
*
+3
View File
@@ -136,4 +136,7 @@ $lang->upgrade->createExecutionTip = <<<EOT
<p>ZenTao will upgrade existing {$lang->projectCommon} as execution.</p>
<p>After the upgrade, the data of existing {$lang->projectCommon} will be in a Project - Execute of the new version .</p>
EOT;
$lang->upgrade->duplicateProject = "Project name in the same program cannot be duplicate. Please adjust the duplicate names.";
include dirname(__FILE__) . '/version.php';
+1 -1
View File
@@ -138,6 +138,6 @@ $lang->upgrade->createExecutionTip = <<<EOT
<p>After the upgrade, the data of existing {$lang->projectCommon} will be in a Project - Execute of the new version .</p>
EOT;
$lang->upgrade->projectNameUnique = "『%s』has the same『%s』. Click {$lang->projectCommon} on the left and edit the name of {$lang->projectCommon}.";
$lang->upgrade->duplicateProject = "Project name in the same program cannot be duplicate. Please adjust the duplicate names.";
include dirname(__FILE__) . '/version.php';
+3
View File
@@ -137,4 +137,7 @@ $lang->upgrade->createExecutionTip = <<<EOT
<p>ZenTao will upgrade existing {$lang->projectCommon} as execution.</p>
<p>After the upgrade, the data of existing {$lang->projectCommon} will be in a Project - Execute of the new version .</p>
EOT;
$lang->upgrade->duplicateProject = "Project name in the same program cannot be duplicate. Please adjust the duplicate names.";
include dirname(__FILE__) . '/version.php';
+3
View File
@@ -137,4 +137,7 @@ $lang->upgrade->createExecutionTip = <<<EOT
<p>ZenTao will upgrade existing {$lang->projectCommon} as execution.</p>
<p>After the upgrade, the data of existing {$lang->projectCommon} will be in a Project - Execute of the new version .</p>
EOT;
$lang->upgrade->duplicateProject = "Project name in the same program cannot be duplicate. Please adjust the duplicate names.";
include dirname(__FILE__) . '/version.php';
+3 -1
View File
@@ -138,6 +138,8 @@ $lang->upgrade->createExecutionTip = <<<EOT
<p>升级后历史的{$lang->projectCommon}数据将对应新版本中项目下的执行。</p>
EOT;
$lang->upgrade->projectNameUnique = "『%s』已经有『%s』这条记录了。请至左侧{$lang->projectCommon}处修改该{$lang->projectCommon}名称";
$lang->upgrade->duplicateProject = "同一个项目集内项目名称不能重复,请调整重名的项目名称";
$lang->upgrade->editedName = '调整后名称';
include dirname(__FILE__) . '/version.php';
+19 -10
View File
@@ -4418,18 +4418,27 @@ class upgradeModel extends model
/* Use historical projects as project upgrades. */
$projects = $this->dao->select('id,name,begin,end,status,PM,acl')->from(TABLE_PROJECT)->where('id')->in($projectIdList)->fetchAll('id');
$hasExistedProjects = $this->dao->select('name')->from(TABLE_PROJECT)->where('type')->eq('project')->fetchPairs('name');
$projectPairs = $this->dao->select('name,id')->from(TABLE_PROJECT)
->where('deleted')->eq('0')
->andWhere('type')->eq('project')
->andWhere('parent')->eq($programID)
->fetchPairs();
$this->lang->error->unique = $this->lang->upgrade->projectNameUnique;
$nameList = array();
foreach($projectIdList as $projectID)
$duplicateList = '';
foreach($projects as $projectID => $project)
{
$projectName = $projects[$projectID]->name;
if(isset($hasExistedProjects[$projectName]) or isset($nameList[$projectName])) dao::$errors['name'][] = 'project#' . $projectID . sprintf($this->lang->error->unique, $this->lang->project->name, $projectName);
$nameList[$projectName] = $projectName;
if(isset($projectPairs[$project->name]))
{
$duplicateList .= "$projectID,";
$duplicateList .= "{$projectPairs[$project->name]},";
}
}
if($duplicateList)
{
echo "<script>new parent.$.zui.ModalTrigger({url: parent.$.createLink('upgrade', 'renameObject', 'type=project&duplicateList=$duplicateList', '', 1), type: 'iframe', width:'40%'}).show();</script>";
die;
}
if(dao::isError()) die(js::error(dao::getError()));
foreach($projectIdList as $projectID)
{
@@ -4492,7 +4501,7 @@ class upgradeModel extends model
$this->dao->insert(TABLE_PROJECT)->data($project)
->batchcheck('name', 'notempty')
->check('name', 'unique', "type='project'")
->check('name', 'unique', "type='project' AND deleted=0")
->exec();
if(dao::isError()) return false;
+9
View File
@@ -0,0 +1,9 @@
<?php include '../../common/view/header.lite.html.php';?>
<div id='mainContent' class='main-content'>
<div class='center-block'>
<div class='main-header'>
<h2>同一个项目集下不能有重名项目</h2>
</div>
</div>
</div>
<?php include '../../common/view/footer.lite.html.php';?>
+35
View File
@@ -0,0 +1,35 @@
<?php include '../../common/view/header.lite.html.php';?>
<style>
.group-end {border-bottom: 1px solid #efefef;}
</style>
<div id='mainContent' class='main-content'>
<div class='center-block'>
<div class='main-header'>
<h2>
<?php if($type == 'project') echo $lang->upgrade->duplicateProject;?>
</h2>
</div>
<form method='post' enctype='multipart/form-data' target='hiddenwin'>
<table class='table table-form'>
<tr>
<th class='w-40px text-left'><?php echo $lang->$type->id;?></th>
<th class='c-name text-left'><?php echo $lang->$type->name;?></th>
<th class='c-name text-left'><?php echo $lang->upgrade->editedName;?></th>
</tr>
<?php foreach($objectGroup as $objectName => $objectList):?>
<?php foreach($objectList as $key => $object):?>
<tr <?php if($object->id == end($objectList)->id) echo "class='group-end'";?>>
<td><?php echo $object->id;?></td>
<td><?php echo $object->name;?></td>
<td><?php echo html::input("project[$object->id]", '', "class='form-control'");?></td>
</tr>
<?php endforeach;?>
<?php endforeach;?>
<tr>
<td colspan='3' class='text-center form-actions'><?php echo html::submitButton();?></td>
</tr>
</table>
</form>
</div>
</div>
<?php include '../../common/view/footer.lite.html.php';?>