* [task#131010] Add name check.

This commit is contained in:
liyang
2024-11-08 08:31:19 +08:00
committed by 李阳
parent a0eb424d9b
commit 57dd789df8
+11 -2
View File
@@ -103,7 +103,11 @@ class hostModel extends model
*/
public function create(object $formData): bool
{
$this->dao->insert(TABLE_HOST)->data($formData)->batchCheck($this->config->host->create->requiredFields, 'notempty')->autoCheck()->exec();
$this->dao->insert(TABLE_HOST)->data($formData)
->check('name', 'unique')
->batchCheck($this->config->host->create->requiredFields, 'notempty')
->autoCheck()
->exec();
if(dao::isError()) return false;
$hostID = $this->dao->lastInsertID();
@@ -125,7 +129,12 @@ class hostModel extends model
if(empty($formData->id)) return false;
$oldHost = $this->fetchByID($formData->id);
$this->dao->update(TABLE_HOST)->data($formData)->batchCheck($this->config->host->edit->requiredFields, 'notempty')->autoCheck()->where('id')->eq($formData->id)->exec();
$this->dao->update(TABLE_HOST)->data($formData)
->check('name', 'unique', '`id` != ' . $formData->id)
->batchCheck($this->config->host->edit->requiredFields, 'notempty')
->autoCheck()
->where('id')->eq($formData->id)
->exec();
if(dao::isError()) return false;
$changes = common::createChanges($oldHost, $formData);