From 8abc2a5b1210e24fe7a9f95f33e53bb7a6080e32 Mon Sep 17 00:00:00 2001
From: wangchunsheng
Date: Tue, 12 Jan 2010 14:27:52 +0000
Subject: [PATCH] + add convert module.
---
trunk/module/common/lang/zh-cn.php | 3 +
trunk/module/convert/control.php | 71 +++++++++
trunk/module/convert/converter/bugfree.php | 148 ++++++++++++++++++
trunk/module/convert/lang/zh-cn.php | 101 ++++++++++++
trunk/module/convert/model.php | 58 +++++++
trunk/module/convert/view/index.html.php | 32 ++++
.../module/convert/view/selectsource.html.php | 45 ++++++
trunk/module/convert/view/setbugfree.html.php | 25 +++
trunk/module/convert/view/setconfig.html.php | 36 +++++
9 files changed, 519 insertions(+)
create mode 100644 trunk/module/convert/control.php
create mode 100644 trunk/module/convert/converter/bugfree.php
create mode 100644 trunk/module/convert/lang/zh-cn.php
create mode 100644 trunk/module/convert/model.php
create mode 100644 trunk/module/convert/view/index.html.php
create mode 100644 trunk/module/convert/view/selectsource.html.php
create mode 100644 trunk/module/convert/view/setbugfree.html.php
create mode 100644 trunk/module/convert/view/setconfig.html.php
diff --git a/trunk/module/common/lang/zh-cn.php b/trunk/module/common/lang/zh-cn.php
index 0f6209402b..050ebcb1a7 100644
--- a/trunk/module/common/lang/zh-cn.php
+++ b/trunk/module/common/lang/zh-cn.php
@@ -120,7 +120,9 @@ $lang->user->menu->browse = array('link' => '用户管理|company|browse|', 'f
/* 后台管理菜单设置。*/
$lang->admin->menu->browseCompany = array('link' => '公司管理|admin|browsecompany', 'subModule' => 'company');
+$lang->admin->menu->convert = array('link' => '从其他系统导入|convert|index', 'subModule' => 'convert');
$lang->admin->menu->createCompany = array('link' => '新增公司|company|create', 'float' => 'right');
+$lang->convert->menu = $lang->admin->menu;
/*菜单设置:分组设置。*/
$lang->menugroup->release = 'product';
@@ -128,6 +130,7 @@ $lang->menugroup->story = 'product';
$lang->menugroup->productplan = 'product';
$lang->menugroup->task = 'project';
$lang->menugroup->company = 'admin';
+$lang->menugroup->convert = 'admin';
$lang->menugroup->user = 'company';
$lang->menugroup->group = 'company';
$lang->menugroup->bug = 'qa';
diff --git a/trunk/module/convert/control.php b/trunk/module/convert/control.php
new file mode 100644
index 0000000000..ffe98921f7
--- /dev/null
+++ b/trunk/module/convert/control.php
@@ -0,0 +1,71 @@
+.
+ *
+ * @copyright Copyright: 2009 Chunsheng Wang
+ * @author Chunsheng Wang
+ * @package convert
+ * @version $Id$
+ * @link http://www.zentao.cn
+ */
+class convert extends control
+{
+ /* 安装程序首页。*/
+ public function index()
+ {
+ $this->view->header->title = $this->lang->convert->common;
+ $this->display();
+ }
+
+ /* 选择系统。*/
+ public function selectSource()
+ {
+ $this->view->header->title = $this->lang->convert->common . $this->lang->colon;
+ $this->display();
+ }
+
+ public function setConfig()
+ {
+ list($sourceName, $version) = explode('_', $this->post->source);
+ $setFunc = "set$sourceName";
+ $this->view->header->title = 'setting';
+ $this->view->source = $sourceName;
+ $this->view->setting = $this->fetch('convert', $setFunc, "version=$version");
+ $this->display();
+ }
+
+ public function setBugFree($version)
+ {
+ $this->view->source = 'BugFree';
+ $this->view->version = $version;
+ $this->view->tablePrefix = $version > 1 ? 'bf' : '';
+ $this->view->dbName = 'BugFree';
+ $this->display();
+ }
+
+ public function execute()
+ {
+ $convertFunc = 'convert' . $this->post->source;
+ $this->$convertFunc($this->post->version);
+ }
+
+ public function convertBugFree($version)
+ {
+ helper::import('./converter/bugfree.php');
+ $converter = new bugfreeConvertModel();
+ $converter->execute();
+ }
+}
diff --git a/trunk/module/convert/converter/bugfree.php b/trunk/module/convert/converter/bugfree.php
new file mode 100644
index 0000000000..e8b0512d3b
--- /dev/null
+++ b/trunk/module/convert/converter/bugfree.php
@@ -0,0 +1,148 @@
+clear();
+ }
+
+ public function convertUser()
+ {
+ $sql = "SELECT * FROM BugUser";
+ $result = mysql_query($sql, $myLink);
+ while($user = mysql_fetch_assoc($result))
+ {
+ extract($user);
+ $sql = "INSERT INTO zt_user(company, id, account, password, realname, email) values('$companyID', $UserID, '$UserName', '$UserPassword', '$RealName', '$Email')";
+ mysql_query($sql) or die(mysql_error());
+ }
+ $sql = "SELECT OpenedBy AS UserName FROM BugInfo GROUP BY OpenedBy";
+ $result = mysql_query($sql, $myLink);
+ while($user = mysql_fetch_assoc($result))
+ {
+ extract($user);
+ $sql = "SELECT * FROM zt_user WHERE account = '$UserName'";
+ if(!mysql_fetch_row(mysql_query($sql)))
+ {
+ $sql = "INSERT INTO zt_user(company, account) values('$companyID', '$UserName')";
+ mysql_query($sql) or die(mysql_error());
+ }
+ }
+ $sql = "INSERT INTO zt_user(company, account) values('$companyID', 'liyp')";
+ mysql_query($sql) or die(mysql_error());
+
+ }
+
+ public function convertProject()
+ {
+ global $myLink, $companyID;
+ $sql = "SELECT * FROM BugProject";
+ $result = mysql_query($sql, $myLink);
+ while($project = mysql_fetch_assoc($result))
+ {
+ extract($project);
+ $sql = "INSERT INTO zt_product(id, name, company) values('$ProjectID', '$ProjectName', '$companyID')";
+ mysql_query($sql) or die(mysql_error());
+ }
+ }
+
+ public function convertModule()
+ {
+ global $myLink, $companyID;
+ $sql = "SELECT * FROM BugModule";
+ $result = mysql_query($sql, $myLink);
+ while($module = mysql_fetch_assoc($result))
+ {
+ extract($module);
+ $sql = "INSERT INTO zt_module(id, product, name, parent, grade, view) values($ModuleID, $ProjectID, '$ModuleName', $ParentID, $ModuleGrade, 'bug')";
+ mysql_query($sql) or die(mysql_error());
+ }
+ }
+
+ public function convertBug()
+ {
+ global $myLink, $companyID;
+ $sql = "SELECT * FROM BugInfo";
+ $result = mysql_query($sql, $myLink);
+ while($bug = mysql_fetch_assoc($result))
+ {
+ foreach($bug as $key => $value)
+ {
+ if(strpos($key, 'Date')) $bug[$key] = strtotime($value);
+ }
+ extract($bug);
+ $sql = "INSERT INTO zt_bug(id, product, module, title, severity, type, os,status, mailto,
+ openedby, openedDate,openedBuild, assignedTo,assignedDate,
+ resolvedBy, resolution, resolvedBuild, resolvedDate,
+ closedBy, closedDate, lastEditedBy, lastEditedDate
+ ) values($BugID, '$ProjectID', '$ModuleID', '$BugTitle', '$BugSeverity', '$BugType', '$BugOS', '$BugStatus', '$MailTo',
+ '$OpenedBy', '$OpenedDate', '$OpenedBuild', '$AssignedTo', '$AssignedDate',
+ '$ResolvedBy', '$Resolution', '$ResolvedBuild', '$ResolvedDate',
+ '$ClosedBy', '$ClosedDate', '$LastEditedBy', '$LastEditedDate')";
+ mysql_query($sql) or die(mysql_error());
+ }
+ }
+
+ public function convertAction()
+ {
+ global $myLink, $companyID;
+ $sql = "SELECT * FROM BugHistory ORDER BY BugID, HistoryID";
+ $result = mysql_query($sql, $myLink);
+ while($history = mysql_fetch_assoc($result))
+ {
+ $historys[$history['BugID']][] = $history;
+ }
+ foreach($historys as $bugID => $bugHistorys)
+ {
+ foreach($bugHistorys as $key => $history)
+ {
+ $history['FullInfo'] = addslashes($history['FullInfo']);
+ $history['ActionDate'] = strtotime($history['ActionDate']);
+ if($key == 0)
+ {
+ $sql = "UPDATE zt_bug SET steps = \"$history[FullInfo]\" WHERE id='$bugID'";
+ mysql_query($sql) or die(mysql_error());
+ $history['FullInfo'] = '';
+ }
+
+ extract($history);
+ $sql = "INSERT INTO zt_action values($HistoryID, $companyID, 'bug', $BugID, '$UserName', '$Action', $ActionDate, '$FullInfo')";
+ mysql_query($sql) or die(mysql_error());
+ }
+ }
+
+ }
+
+ public function fixModulePath()
+ {
+ global $myLink, $companyID;
+
+ $sql = "SELECT * FROM zt_module ORDER BY grade";
+ $result = mysql_query($sql, $myLink);
+ while($module = mysql_fetch_assoc($result))
+ {
+ if($module['grade'] == 1)
+ {
+ $sql = "UPDATE zt_module set path = ',$module[id],' WHERE id=$module[id]";
+ mysql_query($sql) or die(mysql_error());
+ }
+ else
+ {
+ $sql = "SELECT path FROM zt_module WHERE id = $module[parent]";
+ $result2 = mysql_query($sql);
+ $parent = mysql_fetch_assoc($result2);
+ $sql = "UPDATE zt_module set path = '$parent[path]$module[id],' WHERE id=$module[id]";
+ mysql_query($sql) or die(mysql_error());
+ }
+ }
+ }
+ public function clear()
+ {
+ global $myLink;
+ $sqls[] = "TRUNCATE TABLE zt_user";
+ $sqls[] = "TRUNCATE TABLE zt_product";
+ $sqls[] = "TRUNCATE TABLE zt_module";
+ $sqls[] = "TRUNCATE TABLE zt_bug";
+ $sqls[] = "TRUNCATE TABLE zt_action";
+ }
+}
diff --git a/trunk/module/convert/lang/zh-cn.php b/trunk/module/convert/lang/zh-cn.php
new file mode 100644
index 0000000000..e2fcac867b
--- /dev/null
+++ b/trunk/module/convert/lang/zh-cn.php
@@ -0,0 +1,101 @@
+.
+ *
+ * @copyright Copyright: 2009 Chunsheng Wang
+ * @author Chunsheng Wang
+ * @package convert
+ * @version $Id: zh-cn.php 246 2010-01-01 14:36:09Z wwccss $
+ * @link http://www.zentao.cn
+ */
+$lang->convert->common = '从其他系统导入';
+$lang->convert->next = '下一步';
+$lang->convert->pre = '返回';
+$lang->convert->reload = '刷新';
+$lang->convert->error = '错误 ';
+
+$lang->convert->start = '开始转换';
+$lang->convert->desc = <<欢迎使用系统转换向导,本程序会帮助您将其他系统的数据转换到禅道项目管理系统中。
+转换存在一定的风险,转换之前,我们强烈建议您备份数据库及相应的数据文件,并保证转换的时候,没有其他人进行操作。
+EOT;
+
+$lang->convert->selectSource = '选择来源系统及版本';
+$lang->convert->source = '来源系统';
+$lang->convert->version = '版本';
+
+$lang->convert->sourceList['BugFree'] = array('bugfree_1' => '1.x');
+$lang->convert->sourceList['Mantis'] = array('mantis_1' => '1.x');
+
+$lang->convert->setting = '进入设置页面';
+
+$lang->convert->checking = '系统检查';
+$lang->convert->ok = '检查通过(√)';
+$lang->convert->fail = '检查失败(×)';
+$lang->convert->loaded = '已加载';
+$lang->convert->unloaded = '未加载';
+$lang->convert->exists = '目录存在 ';
+$lang->convert->notExists = '目录不存在 ';
+$lang->convert->writable = '目录可写 ';
+$lang->convert->notWritable= '目录不可写 ';
+$lang->convert->phpINI = 'PHP配置文件';
+$lang->convert->checkItem = '检查项';
+$lang->convert->current = '当前配置';
+$lang->convert->result = '检查结果';
+$lang->convert->action = '如何修改';
+
+$lang->convert->phpVersion = 'PHP版本';
+$lang->convert->phpFail = 'PHP版本必须大于5.2.0';
+
+$lang->convert->pdo = 'PDO扩展';
+$lang->convert->pdoFail = '修改PHP配置文件,加载PDO扩展。';
+$lang->convert->pdoMySQL = 'PDO_MySQL扩展';
+$lang->convert->pdoMySQLFail = '修改PHP配置文件,加载pdo_mysql扩展。';
+$lang->convert->tmpRoot = '临时文件目录';
+$lang->convert->dataRoot = '上传文件目录';
+$lang->convert->mkdir = '需要创建目录%s。
linux下面命令为:
mkdir -p %s
';
+$lang->convert->chmod = '需要修改目录 "%s" 的权限。
linux下面命令为:
chmod o=rwx -R %s';
+
+$lang->convert->settingDB = '设置数据库';
+$lang->convert->dbHost = '数据库服务器';
+$lang->convert->dbPort = '服务器端口';
+$lang->convert->dbUser = '数据库用户名';
+$lang->convert->dbPassword = '数据库密码';
+$lang->convert->dbName = '%s使用的库';
+$lang->convert->dbPrefix = '%s表前缀';
+$lang->convert->clearDB = '清空现有数据';
+
+$lang->convert->errorConnectDB = '数据库连接失败 ';
+$lang->convert->errorCreateDB = '数据库创建失败';
+$lang->convert->errorCreateTable = '创建表失败';
+
+$lang->convert->setConfig = '生成配置文件';
+$lang->convert->key = '配置项';
+$lang->convert->value = '值';
+$lang->convert->saveConfig = '保存配置文件';
+$lang->convert->save2File = '拷贝上面文本框中的内容,将其保存到 " %s "中。';
+$lang->convert->errorNotSaveConfig = '还没有保存配置文件';
+
+$lang->convert->getPriv = '设置帐号';
+$lang->convert->company = '公司名称';
+$lang->convert->pms = 'PMS地址';
+$lang->convert->pmsNote = '即通过什么地址可以访问到禅道项目管理,设置域名或者IP地址即可,不需要http';
+$lang->convert->account = '管理员帐号';
+$lang->convert->password = '管理员密码';
+$lang->convert->errorEmptyPassword = '密码不能为空';
+
+$lang->convert->success = "安装成功!请删除convert.php,登录禅道管理系统,设置用户及分组!";
+
diff --git a/trunk/module/convert/model.php b/trunk/module/convert/model.php
new file mode 100644
index 0000000000..6df5fd411d
--- /dev/null
+++ b/trunk/module/convert/model.php
@@ -0,0 +1,58 @@
+.
+ *
+ * @copyright Copyright: 2009 Chunsheng Wang
+ * @author Chunsheng Wang
+ * @package convert
+ * @version $Id$
+ * @link http://www.zentao.cn
+ */
+?>
+connectDB();
+ }
+
+ /* 连接到数据库。*/
+ public function connectDB()
+ {
+ $dsn = "mysql:host={$this->post->dbHost}; port={$this->post->dbPort};dbname={$this->post->dbName}";
+ try
+ {
+ $dbh = new PDO($dsn, $this->post->dbUser, $this->post->dbPassword);
+ $dbh->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ);
+ $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
+ $dbh->exec("SET NAMES UTF8");
+ $this->sourceDBH = $dbh;
+ }
+ catch (PDOException $exception)
+ {
+ return $exception->getMessage();
+ }
+ }
+
+ /* 判断数据库是否存在。*/
+ public function dbExists()
+ {
+ $sql = "SHOW DATABASES like '{$this->post->db->name}'";
+ return $this->dbh->query($sql)->fetch();
+ }
+}
diff --git a/trunk/module/convert/view/index.html.php b/trunk/module/convert/view/index.html.php
new file mode 100644
index 0000000000..bb4d91524b
--- /dev/null
+++ b/trunk/module/convert/view/index.html.php
@@ -0,0 +1,32 @@
+.
+ *
+ * @copyright Copyright: 2009 Chunsheng Wang
+ * @author Chunsheng Wang
+ * @package ZenTaoMS
+ * @version $Id$
+ */
+?>
+
+
+
+ convert->common;?>
+ | convert->desc);?> |
+ createLink('convert', 'selectsource'), $lang->convert->start);?> |
+
+
+
diff --git a/trunk/module/convert/view/selectsource.html.php b/trunk/module/convert/view/selectsource.html.php
new file mode 100644
index 0000000000..b07fc4a313
--- /dev/null
+++ b/trunk/module/convert/view/selectsource.html.php
@@ -0,0 +1,45 @@
+.
+ *
+ * @copyright Copyright: 2009 Chunsheng Wang
+ * @author Chunsheng Wang
+ * @package convert
+ * @version $Id$
+ */
+?>
+
+
+
diff --git a/trunk/module/convert/view/setbugfree.html.php b/trunk/module/convert/view/setbugfree.html.php
new file mode 100644
index 0000000000..0d810d1137
--- /dev/null
+++ b/trunk/module/convert/view/setbugfree.html.php
@@ -0,0 +1,25 @@
+
+ | convert->dbHost;?> |
+ |
+
+
+ | convert->dbPort;?> |
+ |
+
+
+ | convert->dbUser;?> |
+ |
+
+
+ | convert->dbPassword;?> |
+ |
+
+
+ | convert->dbName, $source);?> |
+ |
+
+
+ | convert->dbPrefix, $source);?> |
+ |
+
+
diff --git a/trunk/module/convert/view/setconfig.html.php b/trunk/module/convert/view/setconfig.html.php
new file mode 100644
index 0000000000..dc78b16f22
--- /dev/null
+++ b/trunk/module/convert/view/setconfig.html.php
@@ -0,0 +1,36 @@
+.
+ *
+ * @copyright Copyright: 2009 Chunsheng Wang
+ * @author Chunsheng Wang
+ * @package convert
+ * @version $Id$
+ */
+?>
+
+
+