* Add merge user.

This commit is contained in:
孙广明
2022-02-10 11:03:57 +08:00
parent 1086d07bf4
commit efe77ec0fd
4 changed files with 131 additions and 17 deletions
+12 -12
View File
@@ -1,13 +1,13 @@
<?php
define('JIRA_USER', 'app_user`');
define('JIRA_USERINFO', 'cwd_user`');
define('JIRA_PROJECT', 'project`');
define('JIRA_ISSUE', 'jiraissue`');
define('JIRA_ISSUETYPE', 'issuetype');
define('JIRA_ISSUELINK', 'issuelink');
define('JIRA_ISSUELINKTYPE', 'issuelinktype');
define('JIRA_ISSUESTATUS', 'issuestatus');
define('JIRA_RESOLUTION', 'resolution');
define('JIRA_PROJECTVERSION', 'projectversion');
define('JIRA_NODEASSOCIATION', 'nodeassociation');
define('JIRA_FILEATTACHMENT', 'fileattachment');
define('JIRA_USER', '`app_user`');
define('JIRA_USERINFO', '`cwd_user`');
define('JIRA_PROJECT', '`project`');
define('JIRA_ISSUE', '`jiraissue`');
define('JIRA_ISSUETYPE', '`issuetype`');
define('JIRA_ISSUELINK', '`issuelink`');
define('JIRA_ISSUELINKTYPE', '`issuelinktype`');
define('JIRA_ISSUESTATUS', '`issuestatus`');
define('JIRA_RESOLUTION', '`resolution`');
define('JIRA_PROJECTVERSION', '`projectversion`');
define('JIRA_NODEASSOCIATION', '`nodeassociation`');
define('JIRA_FILEATTACHMENT', '`fileattachment`');
+46 -2
View File
@@ -248,12 +248,25 @@ class convert extends control
$this->display();
}
/**
* Import jira index.
*
* @access public
* @return void
*/
public function jira()
{
$this->view->title = $this->lang->convert->jira->method;
$this->display();
}
/**
* Import jira notice.
*
* @param string $type db|file
* @access public
* @return void
*/
public function importNotice($type = 'db')
{
if($_POST)
@@ -273,6 +286,7 @@ class convert extends control
return print($this->send($response));
}
$this->session->set('jiraDB', $dbName);
$response['result'] = 'success';
$response['message'] = $this->lang->saveSuccess;
$response['locate'] = $this->createLink('convert', 'mapJira2Zentao', "type=db&dbName={$this->post->dbName}");
@@ -284,6 +298,14 @@ class convert extends control
$this->display();
}
/**
* Map jira objects to zentao.
*
* @param string $type db|file
* @param string $dbName
* @access public
* @return void
*/
public function mapJira2Zentao($type = 'db', $dbName = '')
{
$this->app->loadLang('story');
@@ -318,6 +340,13 @@ class convert extends control
$this->display();
}
/**
* Init jira user.
*
* @param string $type db|file
* @access public
* @return void
*/
public function initJiraUser($type = 'db')
{
$this->app->loadLang('user');
@@ -353,6 +382,15 @@ class convert extends control
$this->display();
}
/**
* Import jira main logic.
*
* @param string $method db|file
* @param string $type user|issue|project|attachment
* @param int $lastID
* @access public
* @return void
*/
public function importJira($method = 'db', $type = 'user', $lastID = 0)
{
set_time_limit(0);
@@ -365,12 +403,18 @@ class convert extends control
if(dao::isError()) return $this->send(array('result' => 'fail', 'message' => dao::getError()));
if(isset($result['finished']) and $result['finished'])
{
return $this->send(array('result' => 'finished', 'message' => $this->lang->convert->jira->importSuccessfully));
return print $this->send(array('result' => 'finished', 'message' => $this->lang->convert->jira->importSuccessfully));
}
else
{
$type = zget($this->lang->convert->jira->objectList, $result['type'], $result['type']);
return $this->send(array('result' => 'unfinished', 'message' => sprintf($this->lang->convert->jira->importResult, $type, $type, $result['count']), 'type' => $type, 'count' => $result['count'], 'next' => inlink('importJira', "type={$result['type']}&lastID={$result['lastID']}") ));
$response['result'] = 'unfinished';
$response['message'] = sprintf($this->lang->convert->jira->importResult, $type, $type, $result['count']);
$response['type'] = $type;
$response['count'] = $result['count'];
$response['next'] = inlink('importJira', "method=$method&type={$result['type']}&lastID={$result['lastID']}");
return print $this->send($response);
}
}
}
+1 -1
View File
@@ -148,7 +148,7 @@ $lang->convert->jira->groupNotice = "<span class='text-red'>设置Jira用
$lang->convert->jira->passwordDifferent = '两次密码不一致!';
$lang->convert->jira->passwordEmpty = '密码不能为空!';
$lang->convert->jira->importSuccessfully = 'Jira导入完成!';
$lang->convert->jira->importResult = "导入 %s 数据, 已导入 <strong class='%scount'>%s</strong> 条记录;";
$lang->convert->jira->importResult = "导入 <strong class='text-red'>%s</strong> 数据, 已导入 <strong class='%scount'>%s</strong> 条记录;";
$lang->convert->jira->zentaoObjectList['task'] = '任务';
$lang->convert->jira->zentaoObjectList['requirement'] = '用户需求';
+72 -2
View File
@@ -94,8 +94,18 @@ class convertModel extends model
$this->session->set('state', $state);
}
/**
* Import jira from db.
*
* @param string $type
* @param int $lastID
* @access public
* @return void
*/
public function importJiraFromDB($type = '', $lastID = 0)
{
$this->connectDB($this->session->jiraDB);
$limit = 1000;
$nextObject = false;
if(empty($type)) $type = key($this->lang->convert->jira->objectList);
@@ -107,13 +117,73 @@ class convertModel extends model
while(true)
{
$query = $this->buildQuery($module);
$dataList = $this->getJiraData($module, $lastID, $limit);
if(empty($dataList))
{
$lastID = 0;
break;
}
if($module == 'user') $this->importJiraUser($dataList);
return array('type' => $module, 'count' => count($dataList), 'lastID' => max(array_keys($dataList)));
}
return array('finished' => true);
}
}
public function buildQuery($module)
/**
* Get jira data.
*
* @param int $module
* @access public
* @return void
*/
public function getJiraData($module = '', $lastID = 0, $limit = 0)
{
if($module == 'user')
{
$dataList = $this->dao->dbh($this->sourceDBH)->select('t1.`ID`, t1.`lower_user_name` as account, t1.`lower_display_name` as realname, t1.`lower_email_address` as email, t1.created_date as `join`, t2.user_key as userCode')->from(JIRA_USERINFO)->alias('t1')
->leftJoin(JIRA_USER)->alias('t2')->on('t1.`lower_user_name` = t2.`lower_user_name`')
->where('t1.active')->eq(1)
->beginIF($lastID)->andWhere('t1.ID')->gt($lastID)->fi()
->orderBy('t1.ID asc')->limit($limit)
->fetchAll('ID');
}
return $dataList;
}
public function importJiraUser($dataList)
{
$localUsers = $this->dao->dbh($this->dbh)->select('account')->from(TABLE_USER)->where('deleted')->eq('0')->fetchPairs();
$userConfig = $this->session->jiraUser;
foreach($dataList as $id => $data)
{
if(isset($localUsers[$data->account])) continue;
$user = new stdclass();
$user->account = $data->account;
$user->realname = $data->realname;
$user->password = $userConfig['password'];
$user->group = $userConfig['group'];
$user->email = $data->email;
$user->gender = 'f';
$user->type = 'inside';
$user->join = $data->join;
$this->dao->dbh($this->dbh)->insert(TABLE_USER)->data($user, 'group')->exec();
if(!dao::isError())
{
$data = new stdclass();
$data->account = $user->account;
$data->group = $user->group;
$this->dao->dbh($this->dbh)->replace(TABLE_USERGROUP)->set('account')->eq($user->account)->set('`group`')->eq($user->group)->exec();
}
}
}
}