* Add unique check.

This commit is contained in:
caoyanyi
2022-07-05 12:10:52 +08:00
parent 4031944a73
commit 5fe4e3f9be
3 changed files with 26 additions and 7 deletions
+22 -3
View File
@@ -220,7 +220,16 @@ class repoModel extends model
->join('product', ',')
->get();
if($this->post->SCM == 'Gitlab') $data->path = $this->post->gitlabProject;
if($this->post->SCM == 'Gitlab')
{
$repo = $this->dao->select('id')->from(TABLE_REPO)
->where('SCM')->eq('Gitlab')
->andWhere('client')->eq($data->client)
->andWhere('path')->eq($data->path)
->fetch();
if(!empty($repo)) dao::$errors['gitlabProject'] = sprintf($this->lang->error->unique, $this->lang->repo->gitlabProject, $repo->id);
if(dao::isError()) return false;
}
$data->acl = empty($data->acl) ? '' : json_encode($data->acl);
@@ -239,7 +248,6 @@ class repoModel extends model
->batchCheck($this->config->repo->create->requiredFields, 'notempty')
->checkIF($data->SCM == 'Gitlab', 'gitlabProject', 'notempty')
->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty')
->checkIF($data->SCM == 'Gitlab', 'path', 'unique', "`SCM` = 'Gitlab' and `client` = {$data->gitlabHost}")
->checkIF($data->SCM == 'Git', 'path', 'unique', "`SCM` = 'Git'")
->checkIF($data->SCM == 'Subversion', 'path', 'unique', "`SCM` = 'Subversion'")
->autoCheck()
@@ -309,6 +317,18 @@ class repoModel extends model
$data->prefix = '';
}
if($this->post->SCM == 'Gitlab')
{
$repo = $this->dao->select('id')->from(TABLE_REPO)
->where('SCM')->eq('Gitlab')
->andWhere('client')->eq($data->client)
->andWhere('path')->eq($data->path)
->andWhere('id')->ne($id)
->fetch();
if(!empty($repo)) dao::$errors['gitlabProject'] = sprintf($this->lang->error->unique, $this->lang->repo->gitlabProject, $repo->id);
if(dao::isError()) return false;
}
if($data->client != $repo->client and !$this->checkClient()) return false;
if(!$this->checkConnection()) return false;
@@ -317,7 +337,6 @@ class repoModel extends model
->batchCheck($this->config->repo->edit->requiredFields, 'notempty')
->checkIF($data->SCM == 'Subversion', $this->config->repo->svn->requiredFields, 'notempty')
->checkIF($data->SCM == 'Gitlab', 'extra', 'notempty')
->checkIF($data->SCM == 'Gitlab', 'path', 'unique', "`SCM` = 'Gitlab' and `client` = {$data->gitlabHost} and `id` <> $id")
->checkIF($data->SCM == 'Git', 'path', 'unique', "`SCM` = 'Git' and `id` <> $id")
->checkIF($data->SCM == 'Subversion', 'path', 'unique', "`SCM` = 'Subversion' and `id` <> $id")
->autoCheck()
+2 -2
View File
@@ -34,11 +34,11 @@
</tr>
<tr class='gitlab hide'>
<th><?php echo $lang->repo->gitlabHost;?></th>
<td class='required'><?php echo html::select('gitlabHost', $gitlabHosts, '', "class='form-control chosen' placeholder='{$lang->repo->placeholder->gitlabHost}'");?>
<td class='required'><?php echo html::select('gitlabHost', $gitlabHosts, '', "class='form-control chosen' placeholder='{$lang->repo->placeholder->gitlabHost}'");?></td>
</tr>
<tr class='gitlab hide'>
<th><?php echo $lang->repo->gitlabProject;?></th>
<td class='required'><?php echo html::select('gitlabProject', array(''), '', "class='form-control chosen'");?>
<td class='required'><?php echo html::select('gitlabProject', array(''), '', "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->repo->name; ?></th>
+2 -2
View File
@@ -38,11 +38,11 @@
</tr>
<tr class='gitlab hide'>
<th><?php echo $lang->repo->gitlabHost;?></th>
<td class='required'><?php echo html::select('gitlabHost', $gitlabHosts, isset($repo->gitlab) ? $repo->gitlab : '', "class='form-control chosen' placeholder='{$lang->repo->placeholder->gitlabHost}'");?>
<td class='required'><?php echo html::select('gitlabHost', $gitlabHosts, isset($repo->gitlab) ? $repo->gitlab : '', "class='form-control chosen' placeholder='{$lang->repo->placeholder->gitlabHost}'");?></td>
</tr>
<tr class='gitlab hide'>
<th><?php echo $lang->repo->gitlabProject;?></th>
<td class='required'><?php echo html::select('gitlabProject', $projects, isset($repo->project) ? $repo->project : '', "class='form-control chosen'");?>
<td class='required'><?php echo html::select('gitlabProject', $projects, isset($repo->project) ? $repo->project : '', "class='form-control chosen'");?></td>
</tr>
<tr>
<th><?php echo $lang->repo->name; ?></th>