From 79a7989421fab10325c045bb68f54784e63ff7ff Mon Sep 17 00:00:00 2001 From: tanghucheng Date: Thu, 5 Jan 2023 09:01:03 +0800 Subject: [PATCH] * Fix bug #31451. --- module/zanode/lang/de.php | 1 + module/zanode/lang/en.php | 1 + module/zanode/lang/fr.php | 1 + module/zanode/lang/zh-cn.php | 1 + module/zanode/model.php | 9 ++++++--- 5 files changed, 10 insertions(+), 3 deletions(-) diff --git a/module/zanode/lang/de.php b/module/zanode/lang/de.php index b329ef661a..5395884dda 100644 --- a/module/zanode/lang/de.php +++ b/module/zanode/lang/de.php @@ -129,3 +129,4 @@ $lang->zanode->tips = "The execution node is a virtual machine or container inst $lang->zanode->scriptTips = 'Write the directory where the script is located on the execution node.'; $lang->zanode->shellTips = 'Before running the automated test script on the execution node, you can execute a custom shell command.'; $lang->zanode->automationTips = 'Before executing the test task on the execution node, you need to set up the execution node corresponding to the product, the directory of the automated test script, and the custom Shell command to execute.'; +$lang->zanode->nameUnique = $lang->zanode->name . 'already exist'; diff --git a/module/zanode/lang/en.php b/module/zanode/lang/en.php index b329ef661a..5395884dda 100644 --- a/module/zanode/lang/en.php +++ b/module/zanode/lang/en.php @@ -129,3 +129,4 @@ $lang->zanode->tips = "The execution node is a virtual machine or container inst $lang->zanode->scriptTips = 'Write the directory where the script is located on the execution node.'; $lang->zanode->shellTips = 'Before running the automated test script on the execution node, you can execute a custom shell command.'; $lang->zanode->automationTips = 'Before executing the test task on the execution node, you need to set up the execution node corresponding to the product, the directory of the automated test script, and the custom Shell command to execute.'; +$lang->zanode->nameUnique = $lang->zanode->name . 'already exist'; diff --git a/module/zanode/lang/fr.php b/module/zanode/lang/fr.php index b329ef661a..5395884dda 100644 --- a/module/zanode/lang/fr.php +++ b/module/zanode/lang/fr.php @@ -129,3 +129,4 @@ $lang->zanode->tips = "The execution node is a virtual machine or container inst $lang->zanode->scriptTips = 'Write the directory where the script is located on the execution node.'; $lang->zanode->shellTips = 'Before running the automated test script on the execution node, you can execute a custom shell command.'; $lang->zanode->automationTips = 'Before executing the test task on the execution node, you need to set up the execution node corresponding to the product, the directory of the automated test script, and the custom Shell command to execute.'; +$lang->zanode->nameUnique = $lang->zanode->name . 'already exist'; diff --git a/module/zanode/lang/zh-cn.php b/module/zanode/lang/zh-cn.php index ada5b4f432..aae5f4237f 100644 --- a/module/zanode/lang/zh-cn.php +++ b/module/zanode/lang/zh-cn.php @@ -129,3 +129,4 @@ $lang->zanode->tips = '执行节点是由宿主机创建的虚拟机或容器实 $lang->zanode->scriptTips = '填写执行节点上自动化测试脚本所在的目录。'; $lang->zanode->shellTips = '在执行节点上运行自动化测试脚本前,可以执行自定义的shell命令。'; $lang->zanode->automationTips = '在执行节点上执行测试任务前,需要设置产品对应的执行节点,自动化测试脚本的目录以及需要执行的自定义Shell命令。'; +$lang->zanode->nameUnique = $lang->zanode->name . '已存在'; diff --git a/module/zanode/model.php b/module/zanode/model.php index 068796e5cb..0a0bf58f6f 100644 --- a/module/zanode/model.php +++ b/module/zanode/model.php @@ -52,11 +52,10 @@ class zanodemodel extends model $data = fixer::input('post')->get(); /* Batch check fields. */ - $this->lang->vm = $this->lang->zanode; $data->type = 'node'; $this->dao->update(TABLE_ZAHOST)->data($data) - ->batchCheck($this->config->zanode->create->requiredFields, 'notempty') - ->check('name', 'unique', "type='node'"); + ->batchCheck($this->config->zanode->create->requiredFields, 'notempty'); + if(dao::isError()) return false; if(!preg_match("/^(?!_)(?!-)(?!\.)[a-zA-Z0-9\_\.\-]+$/", $data->name)) @@ -65,6 +64,10 @@ class zanodemodel extends model return false; } + /* If name already exists return error. */ + $node = $this->dao->select('*')->from(TABLE_ZAHOST)->where('name')->eq($data->name)->andWhere('type')->eq('node')->fetch(); + if($node) return dao::$errors[] = $this->lang->zanode->nameUnique; + /* Get image. */ $image = $this->getImageByID($data->image);