diff --git a/module/convert/control.php b/module/convert/control.php index 5559843706..73edcde6da 100644 --- a/module/convert/control.php +++ b/module/convert/control.php @@ -11,7 +11,12 @@ */ class convert extends control { - /* 安装程序首页。*/ + /** + * Index page of convert. + * + * @access public + * @return void + */ public function index() { $this->convert->saveState(); @@ -19,14 +24,26 @@ class convert extends control $this->display(); } - /* 选择系统。*/ + /** + * Select the source system. + * + * @access public + * @return void + */ public function selectSource() { $this->view->header->title = $this->lang->convert->common . $this->lang->colon; $this->display(); } - /* 转换参数设置。*/ + /** + * Set configs of converter. + * + * This is the extrance of every system. It will call the set function of corresponding module. + * + * @access public + * @return void + */ public function setConfig() { if(!$this->post->source) @@ -43,7 +60,13 @@ class convert extends control $this->display(); } - /* BugFree的设置界面。*/ + /** + * The setting page of bugfree. + * + * @param string $version + * @access public + * @return void + */ public function setBugFree($version) { $this->view->source = 'BugFree'; @@ -54,7 +77,12 @@ class convert extends control $this->display(); } - /* 检查配置。*/ + /** + * Check config. Same as setConfig. + * + * @access public + * @return void + */ public function checkConfig() { $checkFunc = 'check' . $this->post->source; @@ -64,22 +92,28 @@ class convert extends control $this->display(); } - /* 检查BugFree的设置。*/ + /** + * Check settings of bugfree. + * + * @param int $version + * @access public + * @return void + */ public function checkBugFree($version) { helper::import('./converter/bugfree.php'); $converter = new bugfreeConvertModel(); - /* 分别检查数据库、表和安装路径。*/ + /* Check it. */ $checkInfo['db'] = $converter->connectDB(); //if(is_object($checkInfo['db'])) $checkInfo['table'] = $converter->checkTables(); $checkInfo['path'] = $converter->checkPath(); - /* 计算检查结果。*/ + /* Compute the checking result. */ $result = 'pass'; if(!is_object($checkInfo['db']) or !$checkInfo['path']) $result = 'fail'; - /* 赋值。*/ + /* Assign. */ $this->view->version = $version; $this->view->source = 'bugfree'; $this->view->result = $result; @@ -87,7 +121,12 @@ class convert extends control $this->display(); } - /* 执行转换。*/ + /** + * Execute the converting. + * + * @access public + * @return void + */ public function execute() { $convertFunc = 'convert' . $this->post->source; @@ -98,7 +137,13 @@ class convert extends control $this->display(); } - /* 转换BugFree。*/ + /** + * Convert bugfree. + * + * @param int $version + * @access public + * @return void + */ public function convertBugFree($version) { helper::import('./converter/bugfree.php'); diff --git a/module/convert/converter/bugfree.php b/module/convert/converter/bugfree.php index 104efc643c..e3d10bd7ca 100644 --- a/module/convert/converter/bugfree.php +++ b/module/convert/converter/bugfree.php @@ -15,38 +15,69 @@ class bugfreeConvertModel extends convertModel public $filePath = ''; static public $info = array(); - /* 构造函数,连接到数据库。*/ + /** + * Connect to db auto. + * + * @access public + * @return void + */ public function __construct() { parent::__construct(); parent::connectDB(); } - /* 检查Tables。*/ + /** + * Check table. + * + * @access public + * @return bool + */ public function checkTables() { return true; } - /* 检查安装路径。*/ + /** + * Check the install path. + * + * @access public + * @return bool + */ public function checkPath() { $this->setPath(); return file_exists($this->filePath); } - /* 设置附件路径。*/ + /** + * Set the path of attachments. + * + * @access public + * @return bool + */ public function setPath() { $this->filePath = realpath($this->post->installPath) . $this->app->getPathFix() . 'BugFile' . $this->app->getPathFix(); } - /* 执行转换。*/ + /** + * Excute the convert. + * + * @param int $version + * @access public + * @return void + */ public function execute($version) { } - /* 清空导入之后的数据。*/ + /** + * Clear rows added in converting. + * + * @access public + * @return void + */ public function clear() { foreach($this->session->state as $table => $maxID) diff --git a/module/convert/converter/bugfree1.php b/module/convert/converter/bugfree1.php index 4e3149b9a8..476033293c 100644 --- a/module/convert/converter/bugfree1.php +++ b/module/convert/converter/bugfree1.php @@ -11,7 +11,12 @@ */ class bugfree1ConvertModel extends bugfreeConvertModel { - /* 执行转换。*/ + /** + * Execute the convert. + * + * @access public + * @return array + */ public function execute() { $this->clear(); @@ -27,7 +32,12 @@ class bugfree1ConvertModel extends bugfreeConvertModel return $result; } - /* 转换用户分组。*/ + /** + * Convert groups. + * + * @access public + * @return void + */ public function convertGroup() { $groups = $this->dao->dbh($this->sourceDBH) @@ -36,16 +46,16 @@ class bugfree1ConvertModel extends bugfreeConvertModel ->fetchAll('id', $autoCompany = false); foreach($groups as $groupID => $group) { - /* 将分组用户拆分成数组。*/ + /* Explode into array. */ $groupUsers = explode(',', $group->users); unset($group->id); unset($group->users); - /* 插入到group表中。*/ + /* Insert the group. */ $this->dao->dbh($this->dbh)->insert(TABLE_GROUP)->data($group)->exec(); $zentaoGroupID = $this->dao->lastInsertId(); - /* 设置账户和group的对应关系。*/ + /* Insert account. */ foreach($groupUsers as $account) { if(empty($account)) continue; @@ -54,10 +64,15 @@ class bugfree1ConvertModel extends bugfreeConvertModel } } - /* 转换用户。*/ + /** + * Convert user. + * + * @access public + * @return int converted user count + */ public function convertUser() { - /* 查询当前系统中存在的用户。*/ + /* Get users exist in the system. */ $activeUsers = $this->dao ->dbh($this->sourceDBH) ->select("username AS account, userpassword AS password, realname, email") @@ -65,10 +80,10 @@ class bugfree1ConvertModel extends bugfreeConvertModel ->orderBy('userID ASC') ->fetchAll('account', $autoCompany = false); - /* 查找曾经出现过的用户。*/ + /* Get users in histories. */ $allUsers = $this->dao->select("distinct(username) AS account")->from('BugHistory')->fetchPairs('', '', $autoCompany = false); - /* 合并二者。*/ + /* Merge them. */ foreach($allUsers as $key => $account) { if(isset($activeUsers[$account])) @@ -82,7 +97,7 @@ class bugfree1ConvertModel extends bugfreeConvertModel } foreach($activeUsers as $account => $user) if(!isset($allUsers[$account])) $allUsers[$account] = $user; - /* 导入到zentao数据库中。*/ + /* Insert into zentao. */ $convertCount = 0; foreach($allUsers as $account => $user) { @@ -99,7 +114,12 @@ class bugfree1ConvertModel extends bugfreeConvertModel return $convertCount; } - /* 转换项目为产品。*/ + /** + * Convert project in bugfree to product in zentao. + * + * @access public + * @return int converted project count + */ public function convertProject() { $projects = $this->dao->dbh($this->sourceDBH)->select("projectID AS id, projectName AS name")->from('BugProject')->fetchAll('id', $autoCompany = false); @@ -112,7 +132,12 @@ class bugfree1ConvertModel extends bugfreeConvertModel return count($projects); } - /* 转换原来的模块为Bug视图模块。*/ + /** + * Convert modules. + * + * @access public + * @return int converted modules count + */ public function convertModule() { $this->map['module'][0] = 0; @@ -136,7 +161,7 @@ class bugfree1ConvertModel extends bugfreeConvertModel $this->map['module'][$moduleID] = $this->dao->lastInsertID(); } - /* 更新parent。*/ + /* Update parents. */ foreach($modules as $oldModuleID => $module) { $newModuleID = $this->map['module'][$oldModuleID]; @@ -146,7 +171,12 @@ class bugfree1ConvertModel extends bugfreeConvertModel return count($modules); } - /* 转换Bug。*/ + /** + * Convert bugs. + * + * @access public + * @return int converted bugs count. + */ public function convertBug() { $bugs = $this->dao @@ -173,7 +203,7 @@ class bugfree1ConvertModel extends bugfreeConvertModel ->fetchAll('id', $autoCompany = false); foreach($bugs as $bugID => $bug) { - /* 修正Bug数据。*/ + /* Adjust some fields of bug. */ $bugID = (int)$bugID; unset($bug->id); if($bug->assignedTo == 'Closed') $bug->assignedTo = 'closed'; @@ -187,7 +217,7 @@ class bugfree1ConvertModel extends bugfreeConvertModel $this->map['bug'][$bugID] = $this->dao->lastInsertID(); } - /* 更新duplicateBug。 */ + /* Update duplicated bugs. */ foreach($this->map['bug'] as $oldBugID => $newBugID) { $this->dao->dbh($this->dbh)->update(TABLE_BUG)->set('duplicateBug')->eq($newBugID)->where('duplicateBug')->eq($oldBugID)->exec(); @@ -195,7 +225,12 @@ class bugfree1ConvertModel extends bugfreeConvertModel return count($bugs); } - /* 转换历史记录。*/ + /** + * Convert actions. + * + * @access public + * @return int converted actions count. + */ public function convertAction() { $actions = $this->dao @@ -213,11 +248,11 @@ class bugfree1ConvertModel extends bugfreeConvertModel $convertCount = 0; foreach($actions as $bugID => $bugActions) { - /* 获得转换之后的bugID。*/ + /* Get the related bugID. */ $bugID = (int)$bugID; $zentaoBugID = $this->map['bug'][$bugID]; - /* 处理action。*/ + /* Process actions. */ foreach($bugActions as $key => $action) { $action->objectID = $zentaoBugID; @@ -233,7 +268,12 @@ class bugfree1ConvertModel extends bugfreeConvertModel return $convertCount; } - /* 转换附件。*/ + /** + * Convert files. + * + * @access public + * @return int converted files count. + */ public function convertFile() { $this->setPath(); @@ -258,7 +298,7 @@ class bugfree1ConvertModel extends bugfreeConvertModel if(strpos($file->size, 'MB')) $file->size = (int)(str_replace('MB', '', $file->size) * 1024 * 1024); $this->dao->dbh($this->dbh)->insert(TABLE_FILE)->data($file)->exec(); - /* 拷贝文件。*/ + /* Copy files. */ $soureFile = $this->filePath . $file->pathname; if(!file_exists($soureFile)) { diff --git a/module/convert/converter/bugfree2.php b/module/convert/converter/bugfree2.php index 8f9485c3ee..d7856196ca 100644 --- a/module/convert/converter/bugfree2.php +++ b/module/convert/converter/bugfree2.php @@ -11,7 +11,12 @@ */ class bugfree2ConvertModel extends bugfreeConvertModel { - /* 执行转换。*/ + /** + * Execute the converter. + * + * @access public + * @return array + */ public function execute() { $this->clear(); @@ -30,7 +35,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel return $result; } - /* 设置表名。*/ + /** + * Set table names. + * + * @access public + * @return void + */ public function setTable() { $dbPrefix = $this->post->dbPrefix; @@ -46,10 +56,15 @@ class bugfree2ConvertModel extends bugfreeConvertModel define('BUGFREE_TABLE_GROUP', $dbPrefix . 'TestGroup'); } - /* 转换用户。*/ + /** + * Convert user. + * + * @access public + * @return int converted user count + */ public function convertUser() { - /* 获得所有的用户列表。*/ + /* Get all user list. */ $users = $this->dao ->dbh($this->sourceDBH) ->select("username AS account, userpassword AS password, realname, email, isDroped AS deleted") @@ -57,7 +72,7 @@ class bugfree2ConvertModel extends bugfreeConvertModel ->orderBy('userID ASC') ->fetchAll('account', $autoCompany = false); - /* 导入到zentao数据库中。*/ + /* Insert into zentao. */ $convertCount = 0; foreach($users as $account => $user) { @@ -74,7 +89,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel return $convertCount; } - /* 转换用户分组。*/ + /** + * Convert groups. + * + * @access public + * @return void converted group count. + */ public function convertGroup() { $groups = $this->dao->dbh($this->sourceDBH) @@ -83,17 +103,17 @@ class bugfree2ConvertModel extends bugfreeConvertModel ->fetchAll('id', $autoCompany = false); foreach($groups as $groupID => $group) { - /* 处理group数据。*/ + /* Fix the group data. */ if($group->name == '[All Users]') continue; $groupUsers = explode(',', $group->users); unset($group->id); unset($group->users); - /* 插入到group表。*/ + /* Insert into zentao's group table. */ $this->dao->dbh($this->dbh)->insert(TABLE_GROUP)->data($group)->exec(); $zentaoGroupID = $this->dao->lastInsertId(); - /* 插入到userGroup表。*/ + /* Insert into zentao's usergroup table. */ foreach($groupUsers as $account) { if(empty($account)) continue; @@ -105,7 +125,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel } } - /* 转换项目为产品。*/ + /** + * Convert projects. + * + * @access public + * @return int converted projects count. + */ public function convertProject() { $projects = $this->dao->dbh($this->sourceDBH) @@ -121,7 +146,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel return count($projects); } - /* 转换原来的模块为Bug视图模块。*/ + /** + * Convert modules. + * + * @access public + * @return int converted modules count. + */ public function convertModule() { $this->map['module'][0] = 0; @@ -147,7 +177,7 @@ class bugfree2ConvertModel extends bugfreeConvertModel $this->map['module'][$moduleID] = $this->dao->lastInsertID(); } - /* 更新parent。*/ + /* Update parent. */ foreach($modules as $oldModuleID => $module) { $newModuleID = $this->map['module'][$oldModuleID]; @@ -157,7 +187,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel return count($modules); } - /* 转换Bug。*/ + /** + * Convert bugs. + * + * @access public + * @return int converted bugs count. + */ public function convertBug() { $bugs = $this->dao @@ -195,7 +230,7 @@ class bugfree2ConvertModel extends bugfreeConvertModel ->fetchAll('id', $autoCompany = false); foreach($bugs as $bugID => $bug) { - /* 修正Bug数据。*/ + /* Fix some fileds of bug. */ $bugID = (int)$bugID; unset($bug->id); @@ -221,7 +256,7 @@ class bugfree2ConvertModel extends bugfreeConvertModel $this->map['bug'][$bugID] = $this->dao->lastInsertID(); } - /* 更新duplicateBug。 */ + /* Update duplicated bugs. */ foreach($this->map['bug'] as $oldBugID => $newBugID) { $this->dao->dbh($this->dbh)->update(TABLE_BUG)->set('duplicateBug')->eq($newBugID)->where('duplicateBug')->eq($oldBugID)->exec(); @@ -229,7 +264,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel return count($bugs); } - /* 转换case。*/ + /** + * Convert cases. + * + * @access public + * @return int converted cases count. + */ public function convertCase() { $cases = $this->dao @@ -259,7 +299,7 @@ class bugfree2ConvertModel extends bugfreeConvertModel ->fetchAll('id', $autoCompany = false); foreach($cases as $caseID => $case) { - /* 修正case的数据。*/ + /* Fix fields of case. */ $caseID = (int)$caseID; $step = $case->step; $bugs = explode(',', $case->bugID); @@ -277,22 +317,22 @@ class bugfree2ConvertModel extends bugfreeConvertModel if($case->type == 'functional') $case->type = 'feature'; if($case->status == 'active') $case->status = 'normal'; - /* 将产品和模块替换成禅道系统中的id。*/ + /* Change product and module by zentao's product and module. */ $case->product = $this->map['product'][$case->product]; $case->module = $this->map['module'][$case->module]; - /* 插入到case表中。*/ + /* Insert into case table. */ $this->dao->dbh($this->dbh)->insert(TABLE_CASE)->data($case)->exec(); $zentaoCaseID = $this->dao->lastInsertID(); $this->map['case'][$caseID] = $zentaoCaseID; - /* 用例步骤表。*/ + /* Insert into case step table. */ $caseStep->case = $zentaoCaseID; $caseStep->version = 1; $caseStep->desc = $step; $this->dao->dbh($this->dbh)->insert(TABLE_CASESTEP)->data($caseStep)->exec(); - /* 更新相关bug。*/ + /* Update related bugs. */ foreach($bugs as $bugID) { if(!isset($this->map['bug'][$bugID])) continue; @@ -303,7 +343,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel return count($cases); } - /* 转换测试执行结果。*/ + /** + * Convert results. + * + * @access public + * @return int converted results count. + */ public function convertResult() { $results = $this->dao->dbh($this->sourceDBH) @@ -322,23 +367,28 @@ class bugfree2ConvertModel extends bugfreeConvertModel { unset($result->id); - /* 记录对应的bug信息。*/ + /* The bug id of zentao. */ $bugID = (int)$result->bugID; $zentaoBugID = $this->map['bug'][$bugID]; unset($result->bugID); - /* 插入到testResult表中。*/ + /* Insert into test result table. */ $this->dao->dbh($this->dbh)->insert(TABLE_TESTRESULT)->data($result)->exec(); $zentaoResultID = $this->dao->lastInsertId(); $this->map['result'][$resultID] = $zentaoResultID; - /* 更新bug表中的result字段。*/ + /* Update result table. */ $this->dao->dbh($this->dbh)->update(TABLE_BUG)->set('result')->eq($zentaoResultID)->where('id')->eq($zentaoBugID)->limit(1)->exec(); } return count($results); } - /* 转换历史记录。*/ + /** + * Convert actions. + * + * @access public + * @return int converted actions count. + */ public function convertAction() { $actions = $this->dao @@ -370,7 +420,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel return count($actions); } - /* 转换历史修改记录。*/ + /** + * Convert histories. + * + * @access public + * @return int the converted histories count. + */ public function convertHistory() { $histories = $this->dao->dbh($this->sourceDBH) @@ -385,7 +440,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel } } - /* 转换附件。*/ + /** + * Convert attachments. + * + * @access public + * @return int the converted files count. + */ public function convertFile() { $this->setPath(); @@ -402,7 +462,7 @@ class bugfree2ConvertModel extends bugfreeConvertModel ->fetchAll('', $autoCompany = false); foreach($files as $file) { - /* 查找对应的action信息,以获得文件的相关字段。*/ + /* Get the actionID in zentao, to get file info. */ $zentaoActionID = $this->map['action'][$file->actionID]; $zentaoAction = $this->dao->dbh($this->dbh)->findById($zentaoActionID)->from(TABLE_ACTION)->fetch(); $file->objectType = $zentaoAction->objectType; @@ -411,14 +471,14 @@ class bugfree2ConvertModel extends bugfreeConvertModel $file->addedDate = $zentaoAction->date; unset($file->actionID); - /* 处理文件大小。*/ + /* Compute the file size. */ if(strpos($file->size, 'KB')) $file->size = (int)(str_replace('KB', '', $file->size) * 1024); if(strpos($file->size, 'MB')) $file->size = (int)(str_replace('MB', '', $file->size) * 1024 * 1024); - /* 插入到数据库。*/ + /* Insert into database. */ $this->dao->dbh($this->dbh)->insert(TABLE_FILE)->data($file)->exec(); - /* 拷贝文件。*/ + /* Copy file. */ $soureFile = $this->filePath . $file->pathname; if(!file_exists($soureFile)) { @@ -436,7 +496,12 @@ class bugfree2ConvertModel extends bugfreeConvertModel return count($files); } - /* 清空导入之后的数据。*/ + /** + * Clear the converted records. + * + * @access public + * @return void + */ public function clear() { foreach($this->session->state as $table => $maxID) diff --git a/module/convert/model.php b/module/convert/model.php index 7465317265..a0693446a2 100644 --- a/module/convert/model.php +++ b/module/convert/model.php @@ -13,7 +13,12 @@ post->dbHost}; port={$this->post->dbPort};dbname={$this->post->dbName}"; @@ -32,21 +37,31 @@ class convertModel extends model } } - /* 判断数据库是否存在。*/ + /** + * Check database exits or not. + * + * @access public + * @return object + */ public function dbExists() { $sql = "SHOW DATABASES like '{$this->post->db->name}'"; return $this->dbh->query($sql)->fetch(); } - /* 记录当前数据库中的每个表最大id。*/ + /** + * Save the max id of every table. Thus when we convert again, when can delete id larger then the saved max id. + * + * @access public + * @return void + */ public function saveState() { - /* 获得用户级别的常量定义列表。*/ + /* Get user defined tables. */ $constants = get_defined_constants(true); $userConstants = $constants['user']; - /* 去掉不需要保存状态的表。*/ + /* These tables needn't save. */ unset($userConstants['TABLE_BURN']); unset($userConstants['TABLE_GROUPPRIV']); unset($userConstants['TABLE_PROJECTPRODUCT']); @@ -55,7 +70,7 @@ class convertModel extends model unset($userConstants['TABLE_TEAM']); unset($userConstants['TABLE_USERGROUP']); - /* 查找每个表的id字段的最大值。*/ + /* Get max id of every table. */ foreach($userConstants as $key => $value) { if(strpos($key, 'TABLE') === false) continue;