From 800a0efd9ec6fed9d55d266d04c1352246778296 Mon Sep 17 00:00:00 2001 From: wangyidong Date: Mon, 14 Mar 2016 09:05:58 +0800 Subject: [PATCH] * check unique add branch condition when create build and release. --- module/build/model.php | 11 ++++++++--- module/release/model.php | 13 ++++++++++--- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/module/build/model.php b/module/build/model.php index 88185f7434..e25c1bbda4 100644 --- a/module/build/model.php +++ b/module/build/model.php @@ -181,13 +181,18 @@ class buildModel extends model $build = fixer::input('post') ->setDefault('product', 0) + ->setDefault('branch', 0) ->add('project', (int)$projectID) ->stripTags($this->config->build->editor->create['id'], $this->config->allowedTags) ->remove('resolvedBy,allchecker,files,labels') ->get(); $build = $this->loadModel('file')->processEditor($build, $this->config->build->editor->create['id']); - $this->dao->insert(TABLE_BUILD)->data($build)->autoCheck()->batchCheck($this->config->build->create->requiredFields, 'notempty')->check('name', 'unique', "product = {$build->product} AND deleted = '0'")->exec(); + $this->dao->insert(TABLE_BUILD)->data($build) + ->autoCheck() + ->batchCheck($this->config->build->create->requiredFields, 'notempty') + ->check('name', 'unique', "product = {$build->product} AND branch = {$build->branch} AND deleted = '0'") + ->exec(); if(!dao::isError()) { $buildID = $this->dao->lastInsertID(); @@ -206,7 +211,7 @@ class buildModel extends model public function update($buildID) { $oldBuild = $this->getByID($buildID); - $build = fixer::input('post')->stripTags($this->config->build->editor->edit['id'], $this->config->allowedTags) + $build = fixer::input('post')->setDefault('branch', $oldBuild->branch)->stripTags($this->config->build->editor->edit['id'], $this->config->allowedTags) ->remove('allchecker,resolvedBy,files,labels') ->get(); @@ -215,7 +220,7 @@ class buildModel extends model ->autoCheck() ->batchCheck($this->config->build->edit->requiredFields, 'notempty') ->where('id')->eq((int)$buildID) - ->check('name', 'unique', "id != $buildID AND product = {$build->product} AND deleted = '0'") + ->check('name', 'unique', "id != $buildID AND product = {$build->product} AND branch = {$build->branch} AND deleted = '0'") ->exec(); if(isset($build->branch) and $oldBuild->branch != $build->branch) $this->dao->update(TABLE_RELEASE)->set('branch')->eq($build->branch)->where('build')->eq($buildID)->exec(); if(!dao::isError()) return common::createChanges($oldBuild, $build); diff --git a/module/release/model.php b/module/release/model.php index f799ad235c..36ad3147bc 100644 --- a/module/release/model.php +++ b/module/release/model.php @@ -113,7 +113,10 @@ class releaseModel extends model ->remove('build,files,labels') ->get(); $build = $this->loadModel('file')->processEditor($build, $this->config->release->editor->create['id']); - $this->dao->insert(TABLE_BUILD)->data($build)->autoCheck()->check('name', 'unique', "product = {$build->product} AND deleted = '0'")->exec(); + $this->dao->insert(TABLE_BUILD)->data($build) + ->autoCheck() + ->check('name', 'unique', "product = {$build->product} AND branch = $branch AND deleted = '0'") + ->exec(); $buildID = $this->dao->lastInsertID(); } @@ -130,7 +133,11 @@ class releaseModel extends model ->get(); $release = $this->loadModel('file')->processEditor($release, $this->config->release->editor->create['id']); - $this->dao->insert(TABLE_RELEASE)->data($release)->autoCheck()->batchCheck($this->config->release->create->requiredFields, 'notempty')->check('name', 'unique', "product = {$release->product} AND deleted = '0'")->exec(); + $this->dao->insert(TABLE_RELEASE)->data($release) + ->autoCheck() + ->batchCheck($this->config->release->create->requiredFields, 'notempty') + ->check('name', 'unique', "product = {$release->product} AND branch = $branch AND deleted = '0'") + ->exec(); if(!dao::isError()) { @@ -162,7 +169,7 @@ class releaseModel extends model $this->dao->update(TABLE_RELEASE)->data($release) ->autoCheck() ->batchCheck($this->config->release->edit->requiredFields, 'notempty') - ->check('name', 'unique', "id != $releaseID AND product = {$release->product} AND deleted = '0'") + ->check('name', 'unique', "id != $releaseID AND product = {$release->product} AND branch = $branch AND deleted = '0'") ->where('id')->eq((int)$releaseID) ->exec(); if(!dao::isError()) return common::createChanges($oldRelease, $release);