From 23eaa5e58a9664953217b2636bcece99da64f470 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Thu, 7 Dec 2023 14:58:04 +0800 Subject: [PATCH] * Refactor convert::importJiraFile method. --- module/convert/model.php | 74 ++-------------------------------------- module/convert/tao.php | 71 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+), 72 deletions(-) diff --git a/module/convert/model.php b/module/convert/model.php index 56ddac02d5..4f129d0efb 100644 --- a/module/convert/model.php +++ b/module/convert/model.php @@ -299,7 +299,7 @@ class convertModel extends model if($module == 'build') $this->convertTao->importJiraBuild($dataList); if($module == 'issuelink') $this->convertTao->importJiraIssueLink($dataList); if($module == 'action') $this->convertTao->importJiraAction($dataList); - if($module == 'file') $this->importJiraFile($dataList); + if($module == 'file') $this->convertTao->importJiraFile($dataList); return array('type' => $module, 'count' => count($dataList), 'lastID' => max(array_keys($dataList))); } @@ -348,7 +348,7 @@ class convertModel extends model if($module == 'build') $this->convertTao->importJiraBuild($dataList, 'file'); if($module == 'issuelink') $this->convertTao->importJiraIssueLink($dataList, 'file'); if($module == 'action') $this->convertTao->importJiraAction($dataList, 'file'); - if($module == 'file') $this->importJiraFile($dataList, 'file'); + if($module == 'file') $this->convertTao->importJiraFile($dataList, 'file'); $offset = $lastID + $limit; return array('type' => $module, 'count' => count($dataList), 'lastID' => $offset); @@ -359,76 +359,6 @@ class convertModel extends model return array('finished' => true); } - /** - * Import jira file. - * - * @param object $dataList - * @param string $method - * @access public - * @return void - */ - public function importJiraFile($dataList, $method = 'db') - { - $this->loadModel('file'); - - $issueObjectType = $this->dao->dbh($this->dbh)->select('AID,extra')->from(JIRA_TMPRELATION) - ->where('AType')->eq('jissueid') - ->andWhere('BType')->eq('zissuetype') - ->fetchPairs(); - - $issueStories = $this->dao->dbh($this->dbh)->select('AID,BID')->from(JIRA_TMPRELATION) - ->where('AType')->eq('jstory') - ->andWhere('BType')->eq('zstory') - ->fetchPairs(); - - $issueTasks = $this->dao->dbh($this->dbh)->select('AID,BID')->from(JIRA_TMPRELATION) - ->where('AType')->eq('jtask') - ->andWhere('BType')->eq('ztask') - ->fetchPairs(); - - $issueBugs = $this->dao->dbh($this->dbh)->select('AID,BID')->from(JIRA_TMPRELATION) - ->where('AType')->eq('jbug') - ->andWhere('BType')->eq('zbug') - ->fetchPairs(); - - $filePaths = $this->dao->dbh($this->dbh)->select('AID,extra')->from(JIRA_TMPRELATION) - ->where('AType')->eq('jissueid') - ->andWhere('BType')->eq('jfilepath') - ->fetchPairs(); - - foreach($dataList as $fileAttachment) - { - $issueID = $fileAttachment->issueid; - if(!isset($issueObjectType[$issueID])) continue; - - $objectType = $issueObjectType[$issueID]; - if($objectType != 'bug' and $objectType != 'task' and $objectType != 'story') continue; - - $fileID = $fileAttachment->ID; - $fileName = $fileAttachment->FILENAME; - list($mime, $extension) = explode('/', $fileAttachment->MIMETYPE); - - if($objectType == 'bug') $objectID = $issueBugs[$issueID]; - if($objectType == 'task') $objectID = $issueTasks[$issueID]; - if($objectType == 'story') $objectID = $issueStories[$issueID]; - if(empty($objectID)) continue; - - $file = new stdclass(); - $file->pathname = $this->file->setPathName($fileID, $extension); - $file->title = str_ireplace(".{$extension}", '', $fileName); - $file->extension = $extension; - $file->size = $fileAttachment->FILESIZE; - $file->objectType = $objectType; - $file->objectID = $objectID; - $file->addedBy = $this->getJiraAccount($fileAttachment->AUTHOR, $method); - $file->addedDate = substr($fileAttachment->CREATED, 0, 19); - $this->dao->dbh($this->dbh)->insert(TABLE_FILE)->data($file)->exec(); - - $jiraFile = $this->app->getTmpRoot() . 'attachments/' . $filePaths[$issueID] . $fileID; - if(is_file($jiraFile)) copy($jiraFile, $this->file->savePath . $file->pathname); - } - } - /** * Split jira file. * diff --git a/module/convert/tao.php b/module/convert/tao.php index b2aa3699e9..fe782b5fb1 100644 --- a/module/convert/tao.php +++ b/module/convert/tao.php @@ -593,6 +593,77 @@ class convertTao extends convertModel } } + /** + * 导入file数据。 + * Import jira file. + * + * @param array $dataList + * @param string $method db|file + * @access public + * @return void + */ + public function importJiraFile(array $dataList, string $method = 'db') + { + $this->loadModel('file'); + + $issueObjectType = $this->dao->dbh($this->dbh)->select('AID,extra')->from(JIRA_TMPRELATION) + ->where('AType')->eq('jissueid') + ->andWhere('BType')->eq('zissuetype') + ->fetchPairs(); + + $issueStories = $this->dao->dbh($this->dbh)->select('AID,BID')->from(JIRA_TMPRELATION) + ->where('AType')->eq('jstory') + ->andWhere('BType')->eq('zstory') + ->fetchPairs(); + + $issueTasks = $this->dao->dbh($this->dbh)->select('AID,BID')->from(JIRA_TMPRELATION) + ->where('AType')->eq('jtask') + ->andWhere('BType')->eq('ztask') + ->fetchPairs(); + + $issueBugs = $this->dao->dbh($this->dbh)->select('AID,BID')->from(JIRA_TMPRELATION) + ->where('AType')->eq('jbug') + ->andWhere('BType')->eq('zbug') + ->fetchPairs(); + + $filePaths = $this->dao->dbh($this->dbh)->select('AID,extra')->from(JIRA_TMPRELATION) + ->where('AType')->eq('jissueid') + ->andWhere('BType')->eq('jfilepath') + ->fetchPairs(); + + foreach($dataList as $fileAttachment) + { + $issueID = $fileAttachment->issueid; + if(!isset($issueObjectType[$issueID])) continue; + + $objectType = $issueObjectType[$issueID]; + if($objectType != 'bug' and $objectType != 'task' and $objectType != 'story') continue; + + if($objectType == 'bug') $objectID = $issueBugs[$issueID]; + if($objectType == 'task') $objectID = $issueTasks[$issueID]; + if($objectType == 'story') $objectID = $issueStories[$issueID]; + if(empty($objectID)) continue; + + $fileID = $fileAttachment->ID; + $fileName = $fileAttachment->FILENAME; + list($mime, $extension) = explode('/', $fileAttachment->MIMETYPE); + + $file = new stdclass(); + $file->pathname = $this->file->setPathName($fileID, $extension); + $file->title = str_ireplace(".{$extension}", '', $fileName); + $file->extension = $extension; + $file->size = $fileAttachment->FILESIZE; + $file->objectType = $objectType; + $file->objectID = $objectID; + $file->addedBy = $this->getJiraAccount($fileAttachment->AUTHOR, $method); + $file->addedDate = substr($fileAttachment->CREATED, 0, 19); + $this->dao->dbh($this->dbh)->insert(TABLE_FILE)->data($file)->exec(); + + $jiraFile = $this->app->getTmpRoot() . 'attachments/' . $filePaths[$issueID] . $fileID; + if(is_file($jiraFile)) copy($jiraFile, $this->file->savePath . $file->pathname); + } + } + /** * 创建项目。 * Create project.