From 191e44ae1f0cc11bc1f2483aaee239b0b7c4e041 Mon Sep 17 00:00:00 2001 From: daitingting Date: Thu, 7 Sep 2023 01:55:33 +0000 Subject: [PATCH] * Refactor the fetchByJSON function. --- module/testcase/zen.php | 41 ++++++++++++++++------------------------- 1 file changed, 16 insertions(+), 25 deletions(-) diff --git a/module/testcase/zen.php b/module/testcase/zen.php index 48a6fc02f0..1cebfabee8 100644 --- a/module/testcase/zen.php +++ b/module/testcase/zen.php @@ -2976,46 +2976,37 @@ class testcaseZen extends testcase } /** + * 获取 content.json 的内容。 * Fetch by json. * - * @param string $extractFolder - * @param int $productID - * @param int $branch + * @param string $filePath + * @param int $productID + * @param int|string $branch * @access public - * @return void + * @return array */ - function fetchByJSON($extractFolder, $productID, $branch) + function fetchByJSON(string $filePath, int $productID, int|string $branch): array { - $filePath = $extractFolder."/content.json"; - $jsonStr = file_get_contents($filePath); + $file = $filePath . '/content.json'; + $jsonStr = file_get_contents($file); $jsonDatas = json_decode($jsonStr, true); - $title = $jsonDatas[0]['rootTopic']['title']; - if(strlen($title) == 0) - { - return array('result'=>'fail','message'=>$this->lang->testcase->errorXmindUpload); - } + $title = $jsonDatas[0]['rootTopic']['title']; + if(strlen($title) == 0) return array('result' => 'fail', 'message' => $this->lang->testcase->errorXmindUpload); $pID = $productID; - $this->classXmind = $this->app->loadClass('xmind'); - if($this->classXmind->endsWith($title,"]") == true) + if($this->classXmind->endsWith($title, ']')) { - $tmpID = $this->classXmind->getBetween($title,"[","]"); - if(empty($tmpID) == false) + $tmpID = $this->classXmind->getBetween($title, '[', ']'); + if(!empty($tmpID)) { - $projectCount = $this->dao->select('count(*) as count') - ->from(TABLE_PRODUCT) - ->where('id') - ->eq((int)$tmpID) - ->andWhere('deleted')->eq('0') - ->fetch('count'); - - if((int)$projectCount == 0) return array('result'=>'fail','message'=>$this->lang->testcase->errorImportBadProduct); + $product = $this->loadModel('product')->getByID($tmpID); + if(!$product || $product->deleted) return array('result' => 'fail', 'message' => $this->lang->testcase->errorImportBadProduct); $pID = $tmpID; } } - return array('result'=>'success','pID'=>$pID,'type'=>'json'); + return array('result' => 'success', 'pID' => $pID, 'type' => 'json'); } }