* Optimize code.
This commit is contained in:
@@ -95,143 +95,6 @@ class projectreleaseModel extends model
|
||||
return array_keys($releases);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a release.
|
||||
*
|
||||
* @access public
|
||||
* @return int
|
||||
*/
|
||||
public function create($projectID = 0)
|
||||
{
|
||||
/* Init vars. */
|
||||
$productID = $this->post->product;
|
||||
$branch = $this->post->branch;
|
||||
$buildID = 0;
|
||||
$projectID = $projectID ? $projectID : $this->session->project;
|
||||
|
||||
/* Check build if build is required. */
|
||||
if(strpos($this->config->release->create->requiredFields, 'build') !== false and $this->post->build == false) return dao::$errors[] = sprintf($this->lang->error->notempty, $this->lang->release->build);
|
||||
|
||||
/* Check date must be not more than today. */
|
||||
if($this->post->date > date('Y-m-d')) return dao::$errors[] = $this->lang->release->errorDate;
|
||||
|
||||
if($this->post->build)
|
||||
{
|
||||
$build = $this->loadModel('build')->getByID($this->post->build);
|
||||
$productID = $build->product;
|
||||
$branch = $build->branch;
|
||||
}
|
||||
|
||||
$release = fixer::input('post')
|
||||
->add('project', $projectID)
|
||||
->add('product', (int)$productID)
|
||||
->add('branch', (int)$branch)
|
||||
->setDefault('stories', '')
|
||||
->join('stories', ',')
|
||||
->join('bugs', ',')
|
||||
->join('mailto', ',')
|
||||
->setIF($this->post->build == false, 'build', $buildID)
|
||||
->setIF($productID, 'product', $productID)
|
||||
->setIF($branch, 'branch', $branch)
|
||||
->stripTags($this->config->release->editor->create['id'], $this->config->allowedTags)
|
||||
->remove('allchecker,files,labels,uid,sync')
|
||||
->get();
|
||||
|
||||
/* Auto create build when release is not link build. */
|
||||
if(empty($release->build) and $release->name)
|
||||
{
|
||||
$build = $this->dao->select('*')->from(TABLE_BUILD)
|
||||
->where('deleted')->eq('0')
|
||||
->andWhere('name')->eq($release->name)
|
||||
->andWhere('product')->eq($productID)
|
||||
->andWhere('branch')->eq($branch)
|
||||
->fetch();
|
||||
if($build)
|
||||
{
|
||||
return dao::$errors['build'] = sprintf($this->lang->release->existBuild, $release->name);
|
||||
}
|
||||
else
|
||||
{
|
||||
$build = new stdclass();
|
||||
$build->project = $projectID;
|
||||
$build->product = (int)$productID;
|
||||
$build->branch = (int)$branch;
|
||||
$build->name = $release->name;
|
||||
$build->date = $release->date;
|
||||
$build->builder = $this->app->user->account;
|
||||
$build->desc = $release->desc;
|
||||
$build->execution = 0;
|
||||
|
||||
$build = $this->loadModel('file')->processImgURL($build, $this->config->release->editor->create['id']);
|
||||
$this->dao->insert(TABLE_BUILD)->data($build)
|
||||
->autoCheck()
|
||||
->check('name', 'unique', "product = '{$productID}' AND branch = '{$branch}' AND deleted = '0'")
|
||||
->batchCheck('name', 'notempty')
|
||||
->exec();
|
||||
if(dao::isError()) return false;
|
||||
|
||||
$buildID = $this->dao->lastInsertID();
|
||||
$release->build = $buildID;
|
||||
}
|
||||
}
|
||||
|
||||
if($release->build)
|
||||
{
|
||||
$buildInfo = $this->dao->select('branch, stories, bugs')->from(TABLE_BUILD)->where('id')->eq($release->build)->fetch();
|
||||
$release->branch = $buildInfo->branch;
|
||||
if($this->post->sync == 'true')
|
||||
{
|
||||
$release->stories = $buildInfo->stories;
|
||||
$release->bugs = $buildInfo->bugs;
|
||||
}
|
||||
}
|
||||
|
||||
$release = $this->loadModel('file')->processImgURL($release, $this->config->release->editor->create['id'], $this->post->uid);
|
||||
$this->dao->insert(TABLE_RELEASE)->data($release)
|
||||
->autoCheck()
|
||||
->batchCheck($this->config->release->create->requiredFields, 'notempty')
|
||||
->check('name', 'unique', "product = {$release->product} AND branch = {$release->branch} AND deleted = '0'");
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
if(!empty($buildID)) $this->dao->delete()->from(TABLE_BUILD)->where('id')->eq($buildID)->exec();
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->dao->exec();
|
||||
|
||||
if(dao::isError())
|
||||
{
|
||||
if(!empty($buildID)) $this->dao->delete()->from(TABLE_BUILD)->where('id')->eq($buildID)->exec();
|
||||
}
|
||||
else
|
||||
{
|
||||
$releaseID = $this->dao->lastInsertID();
|
||||
$this->file->updateObjectID($this->post->uid, $releaseID, 'release');
|
||||
$this->file->saveUpload('release', $releaseID);
|
||||
$this->loadModel('score')->create('release', 'create', $releaseID);
|
||||
|
||||
/* Set stage to released. */
|
||||
if($release->stories)
|
||||
{
|
||||
$this->loadModel('story');
|
||||
$this->loadModel('action');
|
||||
|
||||
$storyIDList = array_filter(explode(',', $release->stories));
|
||||
foreach($storyIDList as $storyID)
|
||||
{
|
||||
$this->story->setStage($storyID);
|
||||
|
||||
$this->action->create('story', $storyID, 'linked2release', '', $releaseID);
|
||||
}
|
||||
}
|
||||
|
||||
return $releaseID;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update a release.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user