+ add convert module.

This commit is contained in:
wangchunsheng
2010-01-12 14:27:52 +00:00
parent f76d7e73f9
commit 8abc2a5b12
9 changed files with 519 additions and 0 deletions

View File

@@ -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';

View File

@@ -0,0 +1,71 @@
<?php
/**
* The control file of convert currentModule of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @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();
}
}

View File

@@ -0,0 +1,148 @@
<?php
class bugfreeConvertModel extends convertModel
{
public function execute()
{
$this->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";
}
}

View File

@@ -0,0 +1,101 @@
<?php
/**
* The convert module zh-cn file of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @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
<p>欢迎使用系统转换向导,本程序会帮助您将其他系统的数据转换到禅道项目管理系统中。</p>
<strong>转换存在一定的风险,转换之前,我们强烈建议您备份数据库及相应的数据文件,并保证转换的时候,没有其他人进行操作。</strong>
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 = '<p>需要创建目录%s。<br /> linux下面命令为<br /> mkdir -p %s</p>';
$lang->convert->chmod = '需要修改目录 "%s" 的权限。<br />linux下面命令为<br />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登录禅道管理系统设置用户及分组";

View File

@@ -0,0 +1,58 @@
<?php
/**
* The model file of convert module of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @package convert
* @version $Id$
* @link http://www.zentao.cn
*/
?>
<?php
class convertModel extends model
{
public function __construct()
{
parent::__construct();
$this->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();
}
}

View File

@@ -0,0 +1,32 @@
<?php
/**
* The html template file of index method of convert module of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @package ZenTaoMS
* @version $Id$
*/
?>
<?php include '../../common/header.html.php';?>
<div class='yui-d0'>
<table align='center' class='table-6'>
<caption><?php echo $lang->convert->common;?></caption>
<tr><td><?php echo nl2br($lang->convert->desc);?></td></tr>
<tr><td><h3 class='a-center'><?php echo html::a($this->createLink('convert', 'selectsource'), $lang->convert->start);?></h3></td></tr>
</table>
</div>
<?php include '../../common/footer.html.php';?>

View File

@@ -0,0 +1,45 @@
<?php
/**
* The html template file of select source method of convert module of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @package convert
* @version $Id$
*/
?>
<?php include '../../common/header.html.php';?>
<div class='yui-d0'>
<form method='post' action='<?php echo inlink('setConfig');?>'>
<table align='center' class='table-5 f-14px'>
<caption><?php echo $lang->convert->selectSource;?></caption>
<tr>
<th class='w-p20'><?php echo $lang->convert->source;?></th>
<th><?php echo $lang->convert->version;?></th>
</tr>
<?php foreach($lang->convert->sourceList as $name => $versions):?>
<tr>
<th class='rowhead'><?php echo $name;?></th>
<td><?php echo html::radio('source', $versions);?></td>
</tr>
<?php endforeach;?>
<tr>
<td colspan='2' class='a-center'><?php echo html::submitButton($lang->convert->setting);?></td>
</tr>
</table>
</form>
</div>
<?php include '../../common/footer.html.php';?>

View File

@@ -0,0 +1,25 @@
<tr>
<th><?php echo $lang->convert->dbHost;?></th>
<td><?php echo html::input('dbHost', 'localhost');?></td>
</tr>
<tr>
<th><?php echo $lang->convert->dbPort;?></th>
<td><?php echo html::input('dbPort', '3306');?></td>
</tr>
<tr>
<th><?php echo $lang->convert->dbUser;?></th>
<td><?php echo html::input('dbUser', 'root');?></td>
</tr>
<tr>
<th><?php echo $lang->convert->dbPassword;?></th>
<td><?php echo html::input('dbPassword');?></td>
</tr>
<tr>
<th><?php printf($lang->convert->dbName, $source);?></th>
<td><?php echo html::input('dbName', $dbName);?></td>
</tr>
<tr>
<th><?php printf($lang->convert->dbPrefix, $source);?></th>
<td><?php echo html::input('dbPrefix', $tablePrefix);?></td>
</tr>
<?php echo html::hidden('source', $source) . html::hidden('version', $version);?>

View File

@@ -0,0 +1,36 @@
<?php
/**
* The html template file of select source method of convert module of ZenTaoMS.
*
* ZenTaoMS is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ZenTaoMS is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with ZenTaoMS. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright: 2009 Chunsheng Wang
* @author Chunsheng Wang <wwccss@263.net>
* @package convert
* @version $Id$
*/
?>
<?php include '../../common/header.html.php';?>
<div class='yui-d0'>
<form method='post' action='<?php echo inlink('execute');?>'>
<table align='center' class='table-5 f-14px'>
<caption><?php echo $source;?></caption>
<?php echo $setting;?>
<tr>
<td colspan='2' class='a-center'><?php echo html::submitButton();?></td>
</tr>
</table>
</form>
</div>
<?php include '../../common/footer.html.php';?>