* finish task #2003.

This commit is contained in:
wangyidong
2014-08-18 07:14:09 +00:00
parent f5c3728f53
commit ddc3fd28ea
11 changed files with 143 additions and 24 deletions
+8 -1
View File
@@ -219,7 +219,14 @@ class bug extends control
$response['result'] = 'success';
$response['message'] = '';
$bugID = $this->bug->create();
$bugResult = $this->bug->create();
$bugID = $bugResult['id'];
if($bugResult['status'] == 'existed')
{
$response['locate'] = $this->createLink('bug', 'view', "bugID=$bugID");
$this->send($response);
}
if(dao::isError())
{
$response['result'] = 'fail';
+14 -5
View File
@@ -54,12 +54,17 @@ class bugModel extends model
->join('mailto', ',')
->remove('files, labels')
->get();
/* Check repeat bug. */
$bugID = $this->loadModel('common')->checkRepeat('bug', 'check', $bug->title, "product={$bug->product}");
if($bugID) return array('status' => 'existed', 'id' => $bugID);
$this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec();
if(!dao::isError())
{
$bugID = $this->dao->lastInsertID();
$this->loadModel('file')->saveUpload('bug', $bugID);
return $bugID;
return array('status' => 'created', 'id' => $bugID);
}
return false;
}
@@ -74,10 +79,11 @@ class bugModel extends model
public function batchCreate($productID)
{
$this->loadModel('action');
$now = helper::now();
$actions = array();
$data = fixer::input('post')->get();
$batchNum = count(reset($data));
$now = helper::now();
$actions = array();
$data = fixer::input('post')->get();
$batchNum = count(reset($data));
$latestBugs = $this->loadModel('common')->checkRepeat('bug', 'get', '', "product=$productID");
for($i = 0; $i < $batchNum; $i++)
{
@@ -124,8 +130,11 @@ class bugModel extends model
$bug->assignedDate = $now;
}
if($latestBugs and in_array($bug->title, $latestBugs)) continue;
$this->dao->insert(TABLE_BUG)->data($bug)->autoCheck()->batchCheck($this->config->bug->create->requiredFields, 'notempty')->exec();
$bugID = $this->dao->lastInsertID();
$latestBugs[$bugID] = $bug->title;
if(dao::isError()) die(js::error('bug#' . ($i+1) . dao::getError(true)));
$actions[$bugID] = $this->action->create('bug', $bugID, 'Opened');
+43
View File
@@ -739,4 +739,47 @@ class commonModel extends model
$this->session->set($objectType . 'OrderBy', '');
}
}
/**
* Check repeat for story,task,bug,case,doc.
*
* @param string $type
* @param string $mode
* @param string $title
* @param string $condition
* @access public
* @return bool|array
*/
public function checkRepeat($type, $mode = 'check', $title = '', $condition = '')
{
$table = $this->config->objectTables[$type];
$field = $type == 'task' ? 'name' : 'title';
$date = date(DT_DATETIME1, time() - 1 * 60);
if($mode == 'check' and empty($title)) return false;
if($mode == 'check')
{
$repeatObject = $this->dao->select('*')->from($table)
->where('deleted')->eq(0)
->andWhere($field)->eq($title)
->beginIF($type == 'doc')->andWhere('addedDate')->ge($date)->fi()
->beginIF($type != 'doc')->andWhere('openedDate')->ge($date)->fi()
->beginIF($condition)->andWhere($condition)->fi()
->fetch();
if($repeatObject) return $repeatObject->id;
return false;
}
elseif($mode == 'get')
{
return $this->dao->select("id,$field")->from($table)
->where('deleted')->eq(0)
->beginIF($type == 'doc')->andWhere('addedDate')->ge($date)->fi()
->beginIF($type != 'doc')->andWhere('openedDate')->ge($date)->fi()
->beginIF($condition)->andWhere($condition)->fi()
->fetchPairs();
}
return false;
}
}
+4 -1
View File
@@ -249,7 +249,10 @@ class doc extends control
$projectID = (int)$projectID;
if(!empty($_POST))
{
$docID = $this->doc->create();
$docResult = $this->doc->create();
$docID = $docResult['id'];
if($docResult['status'] == 'existed') die(js::locate($this->createLink('doc', 'view', "docID=$docID"), 'parent'));
if(dao::isError()) die(js::error(dao::getError()));
$this->action->create('doc', $docID, 'Created');
+4
View File
@@ -189,6 +189,10 @@ class docModel extends model
->remove('files, labels')
->get();
$condition = "lib = '$doc->lib' AND module = $doc->module";
$docID = $this->loadModel('common')->checkRepeat('doc', 'check', $doc->title, $condition);
if($docID) return array('status' => 'existed', 'id' => $docID);
$this->dao->insert(TABLE_DOC)
->data($doc)
->autoCheck()
+15 -1
View File
@@ -42,7 +42,21 @@ class story extends control
$response['result'] = 'success';
$response['message'] = '';
$storyID = $this->story->create($projectID, $bugID);
$storyResult = $this->story->create($projectID, $bugID);
$storyID = $storyResult['id'];
if($storyResult['status'] == 'existed')
{
if($projectID == 0)
{
$response['locate'] = $this->createLink('story', 'view', "storyID={$storyID}");
}
else
{
$response['locate'] = $this->createLink('project', 'story', "projectID=$projectID");
}
$this->send($response);
}
if(dao::isError())
{
$response['result'] = 'fail';
+12 -4
View File
@@ -137,6 +137,10 @@ class storyModel extends model
->remove('files,labels,spec,verify,needNotReview,newStory')
->get();
/* Check repeat story. */
$storyID = $this->loadModel('common')->checkRepeat('story', 'check', $story->title, "product={$story->product}");
if($storyID) return array('status' => 'existed', 'id' => $storyID);
$this->dao->insert(TABLE_STORY)->data($story)->autoCheck()->batchCheck($this->config->story->create->requiredFields, 'notempty')->exec();
if(!dao::isError())
{
@@ -193,7 +197,7 @@ class storyModel extends model
}
}
}
return $storyID;
return array('status' => 'created', 'id' => $storyID);
}
return false;
}
@@ -206,9 +210,10 @@ class storyModel extends model
*/
public function batchCreate($productID = 0)
{
$now = helper::now();
$stories = fixer::input('post')->get();
$batchNum = count(current($stories));
$now = helper::now();
$stories = fixer::input('post')->get();
$batchNum = count(reset($stories));
$latestStories = $this->loadModel('common')->checkRepeat('story', 'get', '', "product={$productID}");
for($i = 0; $i < $batchNum; $i++)
{
@@ -226,6 +231,8 @@ class storyModel extends model
$data[$i]->openedDate = $now;
$data[$i]->version = 1;
if($latestStories and in_array($data[$i]->title, $latestStories)) continue;
$this->dao->insert(TABLE_STORY)
->data($data[$i])
->autoCheck()
@@ -238,6 +245,7 @@ class storyModel extends model
}
$storyID = $this->dao->lastInsertID();
$latestStories[$storyID] = $data[$i]->title;
$this->setStage($storyID);
$specData[$i] = new stdclass();
+4
View File
@@ -80,6 +80,10 @@ class task extends control
$this->loadModel('action');
foreach($tasksID as $taskID)
{
/* if status is existed then this task has existed not new create. */
if($taskID['status'] == 'existed') continue;
$taskID = $taskID['id'];
$actionID = $this->action->create('task', $taskID, 'Opened', '');
$this->sendmail($taskID, $actionID);
}
+19 -7
View File
@@ -22,8 +22,9 @@ class taskModel extends model
*/
public function create($projectID)
{
$tasksID = array();
$taskFile = '';
$tasksID = array();
$taskFile = '';
$latestTasks = $this->loadModel('common')->checkRepeat('task', 'get', '', "project=$projectID");
foreach($this->post->assignedTo as $assignedTo)
{
if($this->post->type == 'affair' and empty($assignedTo)) continue;
@@ -45,6 +46,13 @@ class taskModel extends model
if($assignedTo) $task->assignedDate = helper::now();
/* Check repeat story. */
if($latestTasks and $taskID = array_search($task->name, $latestTasks))
{
$tasksID[$assignedTo] = array('status' => 'existed', 'id' => $taskID);
continue;
}
$this->dao->insert(TABLE_TASK)->data($task)
->autoCheck()
->batchCheck($this->config->task->create->requiredFields, 'notempty')
@@ -67,7 +75,7 @@ class taskModel extends model
$taskFile = $this->dao->select('*')->from(TABLE_FILE)->where('id')->eq(key($taskFileTitle))->fetch();
unset($taskFile->id);
}
$tasksID[$assignedTo] = $taskID;
$tasksID[$assignedTo] = array('status' => 'created', 'id' => $taskID);
}
else
{
@@ -87,10 +95,11 @@ class taskModel extends model
public function batchCreate($projectID)
{
$this->loadModel('action');
$now = helper::now();
$mails = array();
$tasks = fixer::input('post')->get();
$batchNum = count(current($tasks));
$now = helper::now();
$mails = array();
$tasks = fixer::input('post')->get();
$batchNum = count(reset($tasks));
$latestTasks = $this->loadModel('common')->checkRepeat('task', 'get', '', "project=$projectID");
/* check estimate. */
for($i = 0; $i < $batchNum; $i++)
@@ -123,6 +132,8 @@ class taskModel extends model
if($tasks->story[$i] != '') $data[$i]->storyVersion = $this->loadModel('story')->getVersion($data[$i]->story);
if($tasks->assignedTo[$i] != '') $data[$i]->assignedDate = $now;
if($latestTasks and in_array($data[$i]->name, $latestTasks)) continue;
$this->dao->insert(TABLE_TASK)->data($data[$i])
->autoCheck()
->batchCheck($this->config->task->create->requiredFields, 'notempty')
@@ -132,6 +143,7 @@ class taskModel extends model
if(dao::isError()) die(js::error(dao::getError()));
$taskID = $this->dao->lastInsertID();
$latestTasks[$taskID] = $data[$i]->name;
if($tasks->story[$i] != false) $this->story->setStage($tasks->story[$i]);
$actionID = $this->action->create('task', $taskID, 'Opened', '');
+8 -1
View File
@@ -226,7 +226,14 @@ class testcase extends control
$response['result'] = 'success';
$response['message'] = '';
$caseID = $this->testcase->create($bugID);
$caseResult = $this->testcase->create($bugID);
$caseID = $caseResult['id'];
if($caseResult['status'] == 'existed')
{
$response['locate'] = $this->createLink('testcase', 'view', "caseID=$caseID");
$this->send($response);
}
if(dao::isError())
{
$response['result'] = 'fail';
+12 -4
View File
@@ -53,6 +53,10 @@ class testcaseModel extends model
->setDefault('story', 0)
->join('stage', ',')
->get();
$caseID = $this->loadModel('common')->checkRepeat('case', 'check', $case->title, "product={$case->product}");
if($caseID) return array('status' => 'existed', 'id' => $caseID);
$this->dao->insert(TABLE_CASE)->data($case)->autoCheck()->batchCheck($this->config->testcase->create->requiredFields, 'notempty')->exec();
if(!$this->dao->isError())
{
@@ -68,7 +72,7 @@ class testcaseModel extends model
$step->expect = htmlspecialchars($this->post->expects[$stepID]);
$this->dao->insert(TABLE_CASESTEP)->data($step)->autoCheck()->exec();
}
return $caseID;
return array('status' => 'created', 'id' => $caseID);
}
}
@@ -82,9 +86,10 @@ class testcaseModel extends model
*/
function batchCreate($productID, $storyID)
{
$now = helper::now();
$cases = fixer::input('post')->get();
$batchNum = count(current($cases));
$now = helper::now();
$cases = fixer::input('post')->get();
$batchNum = count(reset($cases));
$latestCases = $this->loadModel('common')->checkRepeat('case', 'get', '', "product=$productID");
for($i = 0; $i < $batchNum; $i++)
{
@@ -113,6 +118,8 @@ class testcaseModel extends model
$data[$i]->storyVersion = $this->loadModel('story')->getVersion($this->post->story);
}
if($latestCases and in_array($data[$i]->title, $latestCases)) continue;
$this->dao->insert(TABLE_CASE)->data($data[$i])
->autoCheck()
->batchCheck($this->config->testcase->create->requiredFields, 'notempty')
@@ -125,6 +132,7 @@ class testcaseModel extends model
}
$caseID = $this->dao->lastInsertID();
$latestCases[$caseID] = $data[$i]->title;
$actionID = $this->loadModel('action')->create('case', $caseID, 'Opened');
}
else