From a57e441d78a5a8a5d50c40da9220a1af61630aff Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Wed, 6 Dec 2023 09:04:05 +0800 Subject: [PATCH] * Refactor convert::getJiraDataFromFile method. --- module/convert/model.php | 90 ++--------------------- module/convert/tao.php | 150 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 155 insertions(+), 85 deletions(-) create mode 100644 module/convert/tao.php diff --git a/module/convert/model.php b/module/convert/model.php index 03af6a7147..2a9ac8bf63 100644 --- a/module/convert/model.php +++ b/module/convert/model.php @@ -159,15 +159,16 @@ class convertModel extends model } /** + * 从文件中获取jira数据。 * Get jira data from file. * * @param string $module * @param int $lastID * @param int $limit * @access public - * @return void + * @return array */ - public function getJiraDataFromFile($module, $lastID = 0, $limit = 0) + public function getJiraDataFromFile(string $module, int $lastID = 0, int $limit = 0): array { $fileName = $module; if($module == 'build') $fileName = 'version'; @@ -217,89 +218,8 @@ class convertModel extends model foreach($dataList as $key => $data) { - if($module == 'user') - { - $user = new stdclass(); - $user->account = $data['lowerUserName']; - $user->realname = $data['lowerDisplayName']; - $user->email = $data['emailAddress']; - $user->join = $data['createdDate']; - - $dataList[$key] = $user; - } - elseif($module == 'project') - { - $project = new stdclass(); - $project->ID = $data['id']; - $project->pname = $data['name']; - $project->pkey = $data['key']; - $project->ORIGINALKEY = $data['originalkey']; - $project->DESCRIPTION = isset($data['description']) ? $data['description'] : ''; - $project->LEAD = $data['lead']; - - $dataList[$key] = $project; - } - elseif($module == 'issue') - { - $issue = new stdclass(); - $issue->ID = $data['id']; - $issue->SUMMARY = $data['summary']; - $issue->PRIORITY = $data['priority']; - $issue->PROJECT = $data['project']; - $issue->issuestatus = $data['status']; - $issue->CREATED = $data['created']; - $issue->CREATOR = $data['creator']; - $issue->issuetype = $data['type']; - $issue->ASSIGNEE = isset($data['assignee']) ? $data['assignee'] : ''; - $issue->RESOLUTION = isset($data['resolution']) ? $data['resolution'] : ''; - $issue->issuenum = $data['number']; - $issue->DESCRIPTION = isset($data['description']) ? $data['description'] : ''; - - $dataList[$key] = $issue; - } - elseif($module == 'build') - { - $build = new stdclass(); - $build->ID = $data['id']; - $build->PROJECT = $data['project']; - $build->vname = $data['name']; - $build->RELEASEDATE = isset($data['releasedate']) ? $data['releasedate'] : ''; - $build->DESCRIPTION = isset($data['description']) ? $data['description'] : ''; - - $dataList[$key] = $build; - } - elseif($module == 'issuelink') - { - $issueLink = new stdclass(); - $issueLink->LINKTYPE = $data['linktype']; - $issueLink->SOURCE = $data['source']; - $issueLink->DESTINATION = $data['destination']; - - $dataList[$key] = $issueLink; - } - elseif($module == 'action') - { - $action = new stdclass(); - $action->issueid = $data['issue']; - $action->actionbody = $data['body']; - $action->AUTHOR = $data['author']; - $action->CREATED = $data['created']; - - $dataList[$key] = $action; - } - elseif($module == 'file') - { - $file = new stdclass(); - $file->issueid = $data['issue']; - $file->ID = $data['id']; - $file->FILENAME = $data['filename']; - $file->MIMETYPE = $data['mimetype']; - $file->FILESIZE = $data['filesize']; - $file->CREATED = $data['created']; - $file->AUTHOR = $data['author']; - - $dataList[$key] = $file; - } + $buildFunction = 'build' . ucfirst($module) . 'Data'; + $dataList[$key] = $this->convertTao->$buildFunction($data); } return $dataList; diff --git a/module/convert/tao.php b/module/convert/tao.php new file mode 100644 index 0000000000..6bf001081e --- /dev/null +++ b/module/convert/tao.php @@ -0,0 +1,150 @@ +account = $data['lowerUserName']; + $user->realname = $data['lowerDisplayName']; + $user->email = $data['emailAddress']; + $user->join = $data['createdDate']; + + return $user; + } + + /** + * 构建project数据。 + * Build project data. + * + * @param array $data + * @access public + * @return object + */ + protected function buildProjectData(array $data): object + { + $project = new stdclass(); + $project->ID = $data['id']; + $project->pname = $data['name']; + $project->pkey = $data['key']; + $project->ORIGINALKEY = $data['originalkey']; + $project->DESCRIPTION = isset($data['description']) ? $data['description'] : ''; + $project->LEAD = $data['lead']; + + return $project; + } + + /** + * 构建issue数据。 + * Build issue data. + * + * @param array $data + * @access public + * @return object + */ + protected function buildIssueData(array $data): object + { + $issue = new stdclass(); + $issue->ID = $data['id']; + $issue->SUMMARY = $data['summary']; + $issue->PRIORITY = $data['priority']; + $issue->PROJECT = $data['project']; + $issue->issuestatus = $data['status']; + $issue->CREATED = $data['created']; + $issue->CREATOR = $data['creator']; + $issue->issuetype = $data['type']; + $issue->ASSIGNEE = isset($data['assignee']) ? $data['assignee'] : ''; + $issue->RESOLUTION = isset($data['resolution']) ? $data['resolution'] : ''; + $issue->issuenum = $data['number']; + $issue->DESCRIPTION = isset($data['description']) ? $data['description'] : ''; + + return $issue; + } + + /** + * 构建build数据。 + * Build build data. + * + * @param array $data + * @access public + * @return object + */ + protected function buildBuildData(array $data): object + { + $build = new stdclass(); + $build->ID = $data['id']; + $build->PROJECT = $data['project']; + $build->vname = $data['name']; + $build->RELEASEDATE = isset($data['releasedate']) ? $data['releasedate'] : ''; + $build->DESCRIPTION = isset($data['description']) ? $data['description'] : ''; + + return $build; + } + + /** + * 构建issuelink数据。 + * Build issuelink data. + * + * @param array $data + * @access public + * @return object + */ + protected function buildIssuelinkData(array $data): object + { + $issueLink = new stdclass(); + $issueLink->LINKTYPE = $data['linktype']; + $issueLink->SOURCE = $data['source']; + $issueLink->DESTINATION = $data['destination']; + + return $issueLink; + } + + /** + * 构建action数据。 + * Build action data. + * + * @param array $data + * @access public + * @return object + */ + protected function buildActionData(array $data): object + { + $action = new stdclass(); + $action->issueid = $data['issue']; + $action->actionbody = $data['body']; + $action->AUTHOR = $data['author']; + $action->CREATED = $data['created']; + + return $action; + } + + /** + * 构建file数据。 + * Build file data. + * + * @param array $data + * @access public + * @return object + */ + protected function buildFileData(array $data): object + { + $file = new stdclass(); + $file->issueid = $data['issue']; + $file->ID = $data['id']; + $file->FILENAME = $data['filename']; + $file->MIMETYPE = $data['mimetype']; + $file->FILESIZE = $data['filesize']; + $file->CREATED = $data['created']; + $file->AUTHOR = $data['author']; + + return $file; + } +}