From 47102c509e47f9dd36003f47f55a1bb376bf9e7e Mon Sep 17 00:00:00 2001 From: dingguodong Date: Thu, 8 Jul 2021 15:55:11 +0800 Subject: [PATCH] + Finished importing issue to story. --- module/gitlab/control.php | 3 ++- module/story/config.php | 2 +- module/story/model.php | 52 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 54 insertions(+), 3 deletions(-) diff --git a/module/gitlab/control.php b/module/gitlab/control.php index 11a3aed968..076f7e86e8 100644 --- a/module/gitlab/control.php +++ b/module/gitlab/control.php @@ -285,6 +285,7 @@ class gitlab extends control $object = $this->gitlab->issueToZentaoObject($issue, $gitlabID); $object->product = $productList[$issueID]; $object->execution = $executionID; + if($objectType == 'task') { $objectID = $this->loadModel('task')->createTaskFromGitlabIssue($object, $executionID); @@ -302,7 +303,7 @@ class gitlab extends control if($objectID) { - $object->id = $objectID; + $object->id = $objectID; $this->gitlab->saveImportedIssue($gitlabID, $projectID, $objectType, $objectID, $issue, $object); } else diff --git a/module/story/config.php b/module/story/config.php index 5db4554810..985210da95 100644 --- a/module/story/config.php +++ b/module/story/config.php @@ -4,10 +4,10 @@ $config->story = new stdclass(); $config->story->batchCreate = 10; $config->story->affectedFixedNum = 7; $config->story->needReview = 1; +$config->story->removeFields = 'objectTypeList,productList,executionList,gitlabID,gitlabProjectID,execution'; $config->story->batchClose = new stdclass(); $config->story->batchClose->columns = 10; - $config->story->create = new stdclass(); $config->story->edit = new stdclass(); $config->story->change = new stdclass(); diff --git a/module/story/model.php b/module/story/model.php index 9e998cb7b8..5b69837f8f 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -216,7 +216,7 @@ class storyModel extends model /* Check repeat story. */ $result = $this->loadModel('common')->removeDuplicate('story', $story, "product={$story->product}"); - if($result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']); + if(isset($result['stop']) and $result['stop']) return array('status' => 'exists', 'id' => $result['duplicate']); if($this->checkForceReview()) $story->status = 'draft'; if($story->status == 'draft') $story->stage = $this->post->plan > 0 ? 'planned' : 'wait'; @@ -348,6 +348,56 @@ class storyModel extends model return false; } + /** + * Create story from gitlab issue. + * + * @param object $story + * @param int $executionID + * @access public + * @return int + */ + public function createStoryFromGitlabIssue($story, $executionID) + { + foreach($story as $feild => $value) $_POST[$feild] = $value; + $now = helper::now(); + $story = fixer::input('post') + ->cleanInt('product,module,pri,plan') + ->callFunc('title', 'trim') + ->add('assignedDate', 0) + ->add('version', 1) + ->add('status', 'draft') + ->setDefault('plan,verify', '') + ->setDefault('openedBy', $this->app->user->account) + ->setDefault('openedDate', $now) + ->setIF($story->assignedTo != '', 'assignedDate', $now) + ->setIF($executionID > 0, 'status', 'active') + ->setIF($executionID > 0, 'stage', 'projected') + ->join('mailto', ',') + ->stripTags($this->config->story->editor->create['id'], $this->config->allowedTags) + ->remove('files,labels,reviewer,needNotReview,newStory,uid,contactListMenu,URS') + ->remove($this->config->story->removeFields) + ->get(); + + $requiredFields = $this->config->story->create->requiredFields; + $this->dao->insert(TABLE_STORY)->data($story, 'spec,verify,gitlab,gitlabProject')->autoCheck()->batchCheck($requiredFields, 'notempty')->exec(); + if(!dao::isError()) + { + $storyID = $this->dao->lastInsertID(); + + $data = new stdclass(); + $data->story = $storyID; + $data->version = 1; + $data->title = $story->title; + $data->spec = $story->spec; + $data->verify = $story->spec; + $this->dao->insert(TABLE_STORYSPEC)->data($data)->exec(); + + return $storyID; + } + + return false; + } + /** * Batch create stories. *