| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826 |
- <?php
- /**
- * The model file of redmine convert of ZenTaoPMS.
- *
- * @copyright Copyright 2009-2023 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
- * @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
- * @author Yangyang Shi <shiyangyang@cnezsoft.com>
- * @package convert
- * @version $Id $
- * @link https://www.zentao.net
- */
- class redmine11ConvertModel extends redmineConvertModel
- {
- static $convertGroupCount = 0;
- static $convertUserCount = 0;
- static $convertProductCount = 0;
- static $convertExecutionCount = 0;
- static $convertStoryCount = 0;
- static $convertTaskCount = 0;
- static $convertBugCount = 0;
- static $convertProductPlanCount = 0;
- static $convertTeamCount = 0;
- static $convertReleaseCount = 0;
- static $convertBuildCount = 0;
- static $convertDocLibCount = 0;
- static $convertDocCount = 0;
- static $convertFileCount = 0;
- public $issueType;
- public function __construct($issueType)
- {
- parent::__construct();
- $this->issueType = $issueType;
- }
- /**
- * Execute the converter.
- *
- * @access public
- * @return array
- */
- public function execute($version)
- {
- $this->clear();
- $this->setTable();
- $this->convertGroup();
- $this->convertUser();
- $this->convertUserGroup();
- $this->convertProduct();
- $this->convertExecution();
- $this->convertBuildAndRelease();
- $this->convertProductPlan();
- $this->convertExecutionProduct();
- $this->convertTeam();
- $this->convertDocLib();
- $this->convertDoc();
- $this->convertNews();
- $this->convertIssue();
- $this->convertFile();
- $this->dao->dbh($this->dbh);
- $this->loadModel('tree')->fixModulePath();
- $result['groups'] = self::$convertGroupCount;
- $result['users'] = self::$convertUserCount ;
- $result['products'] = self::$convertProductCount ;
- $result['executions'] = self::$convertExecutionCount ;
- $result['stories'] = self::$convertStoryCount;
- $result['tasks'] = self::$convertTaskCount ;
- $result['bugs'] = self::$convertBugCount ;
- $result['productPlans'] = self::$convertProductPlanCount;
- $result['teams'] = self::$convertTeamCount;
- $result['releases'] = self::$convertReleaseCount;
- $result['builds'] = self::$convertBuildCount;
- $result['docLibs'] = self::$convertDocLibCount ;
- $result['docs'] = self::$convertDocCount;
- $result['files'] = self::$convertFileCount;
- return $result;
- }
- /**
- * Set table names.
- *
- * @access public
- * @return void
- */
- public function setTable()
- {
- //$dbPrefix = $this->post->dbPrefix;
- $dbPrefix = '';
- define('REDMINE_TABLE_ATTACHMENTS', $dbPrefix . 'attachments');
- define('REDMINE_TABLE_AUTH_SOURCES', $dbPrefix . 'auth_sources');
- define('REDMINE_TABLE_BOARDS', $dbPrefix . 'boards');
- define('REDMINE_TABLE_CHANGES', $dbPrefix . 'changes');
- define('REDMINE_TABLE_CHANGESETS', $dbPrefix . 'changesets');
- define('REDMINE_TABLE_CHANGESETS_ISSUES', $dbPrefix . 'changesets_issues');
- define('REDMINE_TABLE_COMMENTS', $dbPrefix . 'comments');
- define('REDMINE_TABLE_CUSTOM_FIELDS', $dbPrefix . 'custom_fields');
- define('REDMINE_TABLE_CUSTOM_FIELDS_EXECUTIONS', $dbPrefix . 'custom_fields_executions');
- define('REDMINE_TABLE_CUSTOM_FIELDS_TRACKERS', $dbPrefix . 'custom_fields_trackers');
- define('REDMINE_TABLE_CUSTOM_VALUES', $dbPrefix . 'custom_values');
- define('REDMINE_TABLE_DOCUMENTS', $dbPrefix . 'documents');
- define('REDMINE_TABLE_ENABLED_MODULES', $dbPrefix . 'enabled_modules');
- define('REDMINE_TABLE_ENUMERATIONS', $dbPrefix . 'enumerations');
- define('REDMINE_TABLE_GROUPS_USERS', $dbPrefix . 'groups_users');
- define('REDMINE_TABLE_ISSUES', $dbPrefix . 'issues');
- define('REDMINE_TABLE_ISSUE_CATEGORIES', $dbPrefix . 'issue_categories');
- define('REDMINE_TABLE_ISSUE_RELATIONS', $dbPrefix . 'issue_relations');
- define('REDMINE_TABLE_ISSUE_STATUSES', $dbPrefix . 'issue_statuses');
- define('REDMINE_TABLE_JOURNALS', $dbPrefix . 'journals');
- define('REDMINE_TABLE_JOURNAL_DETAILS', $dbPrefix . 'journal_details');
- define('REDMINE_TABLE_MEMBERS', $dbPrefix . 'members');
- define('REDMINE_TABLE_MEMBER_ROLES', $dbPrefix . 'member_roles');
- define('REDMINE_TABLE_MESSAGES', $dbPrefix . 'messages');
- define('REDMINE_TABLE_NEWS', $dbPrefix . 'news');
- define('REDMINE_TABLE_OPEN_ID_AUTHENTICATION_ASSOCIATIONS', $dbPrefix . 'open_id_authentication_associations');
- define('REDMINE_TABLE_OPEN_ID_AUTHENTICATION_NONCES', $dbPrefix . 'open_id_authentication_nonces');
- define('REDMINE_TABLE_EXECUTIONS', $dbPrefix . 'executions');
- define('REDMINE_TABLE_EXECUTIONS_TRACKERS', $dbPrefix . 'executions_trackers');
- define('REDMINE_TABLE_QUERIES', $dbPrefix . 'queries');
- define('REDMINE_TABLE_REPOSITORIES', $dbPrefix . 'repositories');
- define('REDMINE_TABLE_ROLES', $dbPrefix . 'roles');
- define('REDMINE_TABLE_SCHEMA_MIGRATIONS', $dbPrefix . 'schema_migrations');
- define('REDMINE_TABLE_SETTINGS', $dbPrefix . 'settings');
- define('REDMINE_TABLE_TIME_ENTRIES', $dbPrefix . 'time_entries');
- define('REDMINE_TABLE_TOKENS', $dbPrefix . 'tokens');
- define('REDMINE_TABLE_TRACKERS', $dbPrefix . 'trackers');
- define('REDMINE_TABLE_USERS', $dbPrefix . 'users');
- define('REDMINE_TABLE_USER_PREFERENCES', $dbPrefix . 'user_preferences');
- define('REDMINE_TABLE_VERSIONS', $dbPrefix . 'versions');
- define('REDMINE_TABLE_WATCHERS', $dbPrefix . 'watchers');
- define('REDMINE_TABLE_WIKIS', $dbPrefix . 'wikis');
- define('REDMINE_TABLE_WIKI_CONTENTS', $dbPrefix . 'wiki_contents');
- define('REDMINE_TABLE_WIKI_CONTENT_VERSIONS', $dbPrefix . 'wiki_content_versions');
- define('REDMINE_TABLE_WIKI_PAGES', $dbPrefix . 'wiki_pages');
- define('REDMINE_TABLE_WIKI_REDIRECTS', $dbPrefix . 'wiki_redirects');
- define('REDMINE_TABLE_WORKFLOWS', $dbPrefix . 'workflows');
- }
- /**
- * Convert groups.
- *
- * @access public
- * @return void
- */
- public function convertGroup()
- {
- /* Get group list */
- $groups = $this->dao->dbh($this->sourceDBH)
- ->select("id, lastName AS name")
- ->from(REDMINE_TABLE_USERS)
- ->where('type')->eq('Group')
- ->fetchAll('id');
- $zentaoGroupNames = $this->dao->dbh($this->dbh)->select('id, name')->from(TABLE_GROUP)->fetchPairs();
- $zentaoGroupIDs = $this->dao->dbh($this->dbh)->select('name, id')->from(TABLE_GROUP)->fetchPairs();
- /* Insert into zentao */
- $convertCount = 0;
- foreach($groups as $groupID =>$group)
- {
- unset($group->id);
- if(in_array("$group->name", $zentaoGroupNames))
- {
- self::$info['groups'][] = sprintf($this->lang->convert->errorGroupExists, $group->name);
- $this->map['groups'][$groupID] = $zentaoGroupIDs[$group->name];
- }
- else
- {
- $this->dao->dbh($this->dbh)->insert(TABLE_GROUP)
- ->data($group)->exec();
- $this->map['groups'][$groupID] = $this->dao->lastInsertID();
- $convertCount ++;
- }
- }
- self::$convertGroupCount += $convertCount;
- }
- /**
- * Convert users.
- *
- * @access public
- * @return void
- */
- public function convertUser()
- {
- /* Get user list. */
- $users = $this->dao->dbh($this->sourceDBH)
- ->select("id, login AS account, firstname, lastname, mail as email")
- ->from(REDMINE_TABLE_USERS)
- ->where('type')->eq('User')
- ->fetchAll('id');
- $zentaoUserNames = $this->dao->dbh($this->dbh)->select('id, account')->from(TABLE_USER)->fetchPairs();
- $zentaoUserIDs = $this->dao->dbh($this->dbh)->select('account, id')->from(TABLE_USER)->fetchPairs();
- /* Insert into zentao. */
- $convertCount = 0;
- foreach($users as $id => $user)
- {
- if(in_array("$user->account", $zentaoUserNames))
- {
- self::$info['users'][] = sprintf($this->lang->convert->errorUserExists, $user->account);
- $this->map['users'][$id] = $zentaoUserIDs[$user->account];
- }
- else
- {
- $user->password = md5('123456');
- $user->realname = $user->lastname . $user->firstname;
- unset($user->id);
- unset($user->lastname);
- unset($user->firstname);
- $this->dao->dbh($this->dbh)->insert(TABLE_USER)->data($user)->exec();
- $this->map['users'][$id] = $this->dao->lastInsertID();
- $convertCount ++;
- }
- }
- self::$convertUserCount += $convertCount;
- }
- /**
- * convert relationship between user and group.
- *
- * @access public
- * @return void
- */
- public function convertUserGroup()
- {
- $this->map['groups'][0] = 0;
- /* Get relation between user and group list. */
- $userGroups = $this->dao->dbh($this->sourceDBH)
- ->select("t1.group_id, t2.login as account")
- ->from(REDMINE_TABLE_GROUPS_USERS)->alias('t1')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t2')->on('t1.user_id = t2.id')
- ->fetchAll();
- $zentaoUserGroups = $this->dao->dbh($this->dbh)->select('*')->from(TABLE_USERGROUP)->fetchAll();
- /* Insert into zentao. */
- $userGroupExist = false;
- foreach($userGroups as $userGroup)
- {
- $userGroup->group = $this->map['groups'][$userGroup->group_id];
- unset($userGroup->group_id);
- foreach($zentaoUserGroups as $zentaoUserGroup)
- {
- if($userGroup->group == $zentaoUserGroup->group and $userGroup->account == $zentaoUserGroup->account)
- {
- $userGroupExist = true;
- }
- }
- if($userGroupExist == false)
- {
- $this->dao->dbh($this->dbh)->insert(TABLE_USERGROUP)->data($userGroup)->exec();
- }
- }
- }
- /**
- * convert products.
- *
- * @access public
- * @return void
- */
- public function convertProduct()
- {
- /* Get product list */
- $products = $this->dao->dbh($this->sourceDBH)
- ->select("id, name, description as `desc`, created_on as createdDate")
- ->from(REDMINE_TABLE_EXECUTIONS)
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($products as $productID => $product)
- {
- unset($product->id);
- $this->dao->dbh($this->dbh)->insert(TABLE_PRODUCT)->data($product)->exec();
- $this->map['products'][$productID] = $this->dao->lastInsertID();
- }
- self::$convertProductCount += count($products);
- }
- /**
- * Convert executions.
- *
- * @access public
- * @return void
- */
- public function convertExecution()
- {
- /* Get execution list */
- $executions = $this->dao->dbh($this->sourceDBH)
- ->select("id, name, execution_id, description as `desc`, effective_date AS end")
- ->from(REDMINE_TABLE_VERSIONS)
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($executions as $executionID => $execution)
- {
- $productID = $execution->execution_id;
- unset($execution->id);
- unset($execution->execution_id);
- $this->dao->dbh($this->dbh)->insert(TABLE_execution)->data($execution)->exec();
- $this->map['executions'][$productID][$executionID] = $this->dao->lastInsertID();
- $this->map['execution'][$executionID] = $this->map['executions'][$productID][$executionID];
- }
- /* Create a same name execution with product */
- foreach($this->map['products'] as $productID)
- {
- $execution = $this->dao->dbh($this->dbh)->select('name')->from(TABLE_PRODUCT)->where('id')->eq($productID)->fetch();
- $this->dao->dbh($this->dbh)->insert(TABLE_execution)->data($execution)->exec();
- $this->map['executionOfProduct'][$productID] = $this->dao->lastinsertID();
- }
- $convertCount = count($executions) + count($this->map['executionOfProduct']);
- self::$convertexecutionCount += $convertCount;
- }
- /**
- * convert builds and releases
- *
- * @access public
- * @return void
- */
- public function convertBuildAndRelease()
- {
- /* Get build list */
- $buildAndReleases = $this->dao->dbh($this->sourceDBH)
- ->select("id, name, execution_id, description as `desc`, effective_date AS date")
- ->from(REDMINE_TABLE_VERSIONS)
- ->fetchAll('id');
- /* Insert into zentao */
- $convertBuildsCount = 0;
- $convertReleasesCount = 0;
- $zentaoBuildNames = $this->dao->dbh($this->dbh)->select('id, name')->from(TABLE_BUILD)->fetchPairs();
- $zentaoBuildIDs = $this->dao->dbh($this->dbh)->select('name, id')->from(TABLE_BUILD)->fetchPairs();
- $zentaoReleaseNames = $this->dao->dbh($this->dbh)->select('id, name')->from(TABLE_RELEASE)->fetchPairs();
- $zentaoReleaseIDs = $this->dao->dbh($this->dbh)->select('name, id')->from(TABLE_RELEASE)->fetchPairs();
- foreach($buildAndReleases as $id => $buildAndRelease)
- {
- $buildAndRelease->execution = $this->map['execution'][$id];
- $buildAndRelease->product = $this->map['products'][$buildAndRelease->execution_id];
- unset($buildAndRelease->id);
- unset($buildAndRelease->execution_id);
- if(in_array($buildAndRelease->name, $zentaoBuildNames))
- {
- self::$info['builds'][] = sprintf($this->lang->convert->errorBuildExists, $buildAndRelease->name);
- $buildAndRelease->build = $zentaoBuildIDs[$buildAndRelease->name];
- }
- else
- {
- $this->dao->dbh($this->dbh)->insert(TABLE_BUILD)->data($buildAndRelease)->exec();
- $buildAndRelease->build = $this->dao->lastInsertID();
- $convertBuildsCount ++;
- }
- unset($buildAndRelease->execution);
- if(in_array($buildAndRelease->name, $zentaoBuildNames))
- {
- self::$info['releases'][] = sprintf($this->lang->convert->errorReleaseExists, $buildAndRelease->name);
- }
- else
- {
- $this->dao->dbh($this->dbh)->insert(TABLE_RELEASE)->data($buildAndRelease)->exec();
- $convertReleasesCount ++;
- }
- }
- self::$convertBuildCount += $convertBuildsCount;
- self::$convertReleaseCount += $convertReleasesCount;
- }
- /**
- * convert productPlans
- *
- * @access public
- * @return void
- */
- public function convertProductPlan()
- {
- /* Get productPlan list */
- $productPlans = $this->dao->dbh($this->sourceDBH)
- ->select("id, name as title, execution_id, description as `desc`, effective_date as end, created_on AS begin")
- ->from(REDMINE_TABLE_VERSIONS)
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($productPlans as $id => $productPlan)
- {
- $productPlan->product = $this->map['products'][$productPlan->execution_id];
- $productPlan->createdBy = $this->app->user->account;
- $productPlan->createdDate = helper::now();
- unset($productPlan->id);
- unset($productPlan->execution_id);
- $this->dao->dbh($this->dbh)->insert(TABLE_PRODUCTPLAN)->data($productPlan)->exec();
- }
- /* Create a same plan with product */
- foreach($this->map['products'] as $productID)
- {
- $productPlan = $this->dao->dbh($this->dbh)->select("name as title, createdDate as begin")->from(TABLE_PRODUCT)->where('id')->eq($productID)->fetch();
- $productPlan->product = $productID;
- $productPlan->createdBy = $this->app->user->account;
- $productPlan->createdDate = helper::now();
- $this->dao->dbh($this->dbh)->insert(TABLE_PRODUCTPLAN)->data($productPlan)->exec();
- $this->map['planOfProduct'][$productID] = $this->dao->lastinsertID();
- }
- $convertCount = count($this->map['products']) + count($productPlans);
- self::$convertProductPlanCount += $convertCount;
- }
- /**
- * convert relationship between execution and product.
- *
- * @access public
- * @return void
- */
- public function convertExecutionProduct()
- {
- foreach($this->map['executions'] as $productID => $executions)
- {
- foreach($executions as $executionID => $execution)
- {
- $this->dao->dbh($this->dbh)->insert(TABLE_PROJECTPRODUCT)
- ->set('project')->eq($execution)
- ->set('product')->eq($this->map['products'][$productID])
- ->exec();
- }
- }
- }
- /**
- * convert teams.
- *
- * @access public
- * @return void
- */
- public function convertTeam()
- {
- /* Get team list */
- $teams = $this->dao->dbh($this->sourceDBH)
- ->select("t2.login as account, t1.execution_id, t1.created_on AS joinDate")
- ->from(REDMINE_TABLE_MEMBERS)->alias('t1')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t2')->on('t1.user_id = t2.id')
- ->where('t2.type')->eq('User')
- ->fetchAll();
- /* Insert into zentao */
- foreach($teams as $team)
- {
- $productID = $team->execution_id;
- unset($team->execution_id);
- foreach($this->map['executions'][$productID] as $executionID)
- {
- $team->execution = $executionID;
- $this->dao->dbh($this->dbh)->insert(TABLE_TEAM)->data($team)->exec();
- }
- }
- self::$convertTeamCount += count($teams);
- }
- /**
- * convert docLibs.
- *
- * @access public
- * @return void
- */
- public function convertDocLib()
- {
- /* Get docLib list */
- $docLibs = $this->dao->dbh($this->sourceDBH)
- ->select("id, name")->from(REDMINE_TABLE_ENUMERATIONS)
- ->where('type')->eq('DocumentCategory')
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($docLibs as $docLibID => $docLib)
- {
- unset($docLib->id);
- $this->dao->dbh($this->dbh)->insert(TABLE_DOCLIB)->data($docLib)->exec();
- $this->map['docLibs'][$docLibID] = $this->dao->lastInsertID();
- }
- self::$convertDocLibCount += count($docLibs);
- }
- /**
- * convert docs.
- *
- * @access public
- * @return void
- */
- public function convertDoc()
- {
- /* Get all docs */
- $docs = $this->dao->dbh($this->sourceDBH)
- ->select("t1.id, t1.execution_id AS product, t2.id AS lib, t1.title, t1.description AS content, t1.created_on AS addedDate")
- ->from(REDMINE_TABLE_DOCUMENTS)->alias('t1')
- ->leftJoin(REDMINE_TABLE_ENUMERATIONS)->alias('t2')->on('t1.category_id = t2.id')
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($docs as $docID => $doc)
- {
- unset($doc->id);
- $doc->type = 'text';
- $doc->execution = 0;
- $doc->product = $this->map['products'][$doc->product];
- $doc->lib = $this->map['docLibs'][$doc->lib];
- $this->dao->dbh($this->dbh)->insert(TABLE_DOC)->data($doc)->exec();
- $this->map['docs'][$docID] = $this->dao->lastInsertID();
- }
- self::$convertDocCount += count($docs);
- }
- /**
- * convert news.
- *
- * @access public
- * @return void
- */
- public function convertNews()
- {
- /* Get news from redmine */
- $news = $this->dao->dbh($this->sourceDBH)
- ->select("t1.execution_id as product, t1.title, t1.summary as digest, t1.description as content, t2.login as addedBy, t1.created_on as addedDate")
- ->from(REDMINE_TABLE_NEWS)->alias('t1')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t2')->on('t1.author_id = t2.id')
- ->fetchAll();
- /* Create a news docLib */
- $newLib->name = 'news';
- $this->dao->dbh($this->dbh)->insert(TABLE_DOCLIB)->data($newLib)->exec();
- $this->map['news'] = $this->dao->lastInsertID();
- self::$convertDocLibCount += 1;
- /* Insert into zentao */
- foreach($news as $new)
- {
- $new->product = $this->map['products'][$new->product];
- $new->execution = 0;
- $new->lib = $this->map['news'];
- $new->type = 'text';
- $this->dao->dbh($this->dbh)->insert(TABLE_DOC)->data($new)->exec();
- }
- self::$convertDocCount += count($news);
- }
- /**
- * convert issue
- *
- * @param array $aimTypes //aimTypes['issueTypeID'] = aimtype eg. aimTypes[1] = 'bug';
- * @param array $statusTypes //statusTypes['task']['statusTypeID'] = statusType eg. statusTypes['task'][1] = 'wait';
- * //statusTypes['bug']['statusTypeID'] = statusType eg. statusTypes['bug'][1] = 'active';
- * @param array $priTypes //priTypes['task']['priTypeID'] = priType; eg. priTypes['task'][1] = 1;
- * @access public
- * @return void
- */
- public function convertIssue()
- {
- $aimTypes = $this->issueType->aimTypes;
- $statusTypes = $this->issueType->statusTypes;
- $priTypes = $this->issueType->priTypes;
- foreach($aimTypes as $issueType => $aimType)
- {
- if('story' == $aimType)
- {
- $this->convertStory($issueType, $statusTypes, $priTypes);
- }
- elseif('task' == $aimType)
- {
- $this->convertTask($issueType, $statusTypes, $priTypes);
- }
- else
- {
- $this->convertBug($issueType, $statusTypes, $priTypes);
- }
- }
- }
- /**
- * convert story
- *
- * @param array $issueType
- * @param array $statusTypes
- * @param array $priTypes
- * @access public
- * @return void
- */
- public function convertStory($issueType, $statusTypes, $priTypes)
- {
- /* Get story list*/
- $stories = $this->dao->dbh($this->sourceDBH)
- ->select("t1.id, t1.execution_id as product, t1.subject as title, t1.description as spec, t1.status_id as status, t2.login as assignedTo, t1.priority_id as pri, t3.login as openedBy, t1.created_on as openedDate, t1.estimated_hours as estimate, t1.updated_on as lastEditedDate")
- ->from(REDMINE_TABLE_ISSUES)->alias('t1')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t2')->on('t1.assigned_to_id = t2.id')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t3')->on('t1.author_id = t3.id')
- ->where('t1.tracker_id')->eq($issueType)
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($stories as $issueID => $story)
- {
- $storySpec->title = $story->title;
- $storySpec->spec = $story->spec;
- unset($story->id);
- unset($story->spec);
- /* Insert story into table story */
- $story->product = $this->map['products'][$story->product];
- $story->module = 0;
- $story->plan = $this->map['planOfProduct'][$story->product];
- $story->fromBug = 0;
- $story->pri = $priTypes['story'][$story->pri];
- $story->status = $statusTypes['story'][$story->status];
- $story->toBug = 0;
- $story->duplicateStory = 0;
- $this->dao->dbh($this->dbh)->insert(TABLE_STORY)->data($story)->exec();
- $this->map['issueID'][$issueID] = $this->dao->lastInsertID();
- $this->map['issueType'][$issueID] = 'story';
- /* Insert data into table storySpec */
- $storySpec->story = $this->map['issueID'][$issueID];
- $storySpec->version = 1;
- $this->dao->dbh($this->dbh)->insert(TABLE_STORYSPEC)->data($storySpec)->exec();
- }
- self::$convertStoryCount += count($stories);
- }
- /**
- * convert task
- *
- * @param array $issueType
- * @param array $statusTypes
- * @param array $priTypes
- * @access public
- * @return void
- */
- public function convertTask($issueType, $statusTypes, $priTypes)
- {
- /* Get task list */
- $tasks = $this->dao->dbh($this->sourceDBH)
- ->select("t1.id, t1.execution_id as product, t1.fixed_version_id as execution, t1.subject as name, t1.description as `desc`, t1.due_date as deadline, t1.status_id as status, t2.login as assignedTo, t1.priority_id as pri, t3.login as openedBy, t1.created_on as openedDate, t1.estimated_hours as estimate, t1.updated_on as lastEditedDate")
- ->from(REDMINE_TABLE_ISSUES)->alias('t1')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t2')->on('t1.assigned_to_id = t2.id')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t3')->on('t1.author_id = t3.id')
- ->where('t1.tracker_id')->eq($issueType)
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($tasks as $issueID => $task)
- {
- $task->story = 0;
- $task->storyVersion = 0;
- $task->type = 'misc';
- $task->pri = $priTypes['task'][$task->pri];
- $task->status = $statusTypes['task'][$task->status];
- if($task->execution == 0)
- {
- $task->execution = $this->map['executionOfProduct'][$task->product];
- }
- else
- {
- $task->execution = $this->map['execution'][$task->execution];
- }
- unset($task->id);
- unset($task->product);
- $this->dao->dbh($this->dbh)->insert(TABLE_TASK)->data($task)->exec();
- $this->map['issueID'][$issueID] = $this->dao->lastInsertID();
- $this->map['issueType'][$issueID] = 'task';
- }
- self::$convertTaskCount += count($tasks);
- }
- /**
- * convert bug
- *
- * @param array $issueType
- * @param array $statusTypes
- * @param array $priTypes
- * @access public
- * @return void
- */
- public function convertBug($issueType, $statusTypes, $priTypes)
- {
- /* Get bug list */
- $bugs = $this->dao->dbh($this->sourceDBH)
- ->select("t1.id, t1.execution_id as product, t1.fixed_version_id execution, t1.subject as title, t1.description as steps, t1.status_id as status, t2.login as assignedTo, t1.priority_id as pri, t3.login as openedBy, t1.created_on as openedDate, t1.updated_on as lastEditedDate")
- ->from(REDMINE_TABLE_ISSUES)->alias('t1')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t2')->on('t1.assigned_to_id = t2.id')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t3')->on('t1.author_id = t3.id')
- ->where('t1.tracker_id')->eq($issueType)
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($bugs as $issueID => $bug)
- {
- $bug->product = $this->map['products'][$bug->product];
- $bug->module = 0;
- $bug->story = 0;
- $bug->storyVersion = 1;
- $bug->task = 0;
- $bug->severity = 3;
- $bug->type = 'others';
- $bug->status = $statusTypes['bug'][$bug->status];
- $bug->openedBuild = 'trunk';
- $bug->duplicateBug = 0;
- $bug->case = 0;
- $bug->caseVersion = 1;
- $bug->result = 0;
- if($bug->execution == 0)
- {
- $bug->execution = $this->map['executionOfProduct'][$bug->product];
- }
- else
- {
- $bug->execution = $this->map['execution'][$bug->execution];
- }
- unset($bug->id);
- $this->dao->dbh($this->dbh)->insert(TABLE_BUG)->data($bug)->exec();
- $this->map['issueID'][$issueID] = $this->dao->lastInsertID();
- $this->map['issueType'][$issueID] = 'bug';
- }
- self::$convertBugCount += count($bugs);
- }
- /**
- * Convert attachments.
- *
- * @access public
- * @return void
- */
- public function convertFile()
- {
- $this->setPath();
- /* Get file list */
- $files = $this->dao->dbh($this->sourceDBH)
- ->select('t1.id, t1.container_id as objectID, t1.container_type as objectType, t1.filename as title, t1.disk_filename as pathname, t1.filesize as size, t2.login as addedBy, t1.created_on as addedDate, description')
- ->from(REDMINE_TABLE_ATTACHMENTS)->alias('t1')
- ->leftJoin(REDMINE_TABLE_USERS)->alias('t2')->on('t1.author_id = t2.id')
- ->fetchAll('id');
- /* Insert into zentao */
- foreach($files as $fileID => $file)
- {
- if($file->description != '')
- {
- $file->title = $file->description;
- unset($file->description);
- }
- else
- {
- unset($file->description);
- }
- /* Transform objectType and objectID */
- if($file->objectType == 'Issue')
- {
- $file->objectType = $this->map['issueType'][$file->objectID];
- $file->objectID = $this->map['issueID'][$file->objectID];
- }
- elseif($file->objectType == 'Document')
- {
- $file->objectType = 'doc' ;
- $file->objectID = $this->map['docs'][$file->objectID];
- }
- elseif($file->objectType == 'WikiPage')
- {
- continue;
- }
- elseif($file->objectType == 'Version')
- {
- $doc->execution = $this->map['execution'][$file->objectID];
- $doc = $this->dao->dbh($this->dbh)->select('product')->from(TABLE_PROJECTPRODUCT)->where('project')->eq($doc->execution)->fetch();
- $doc->lib = 'execution';
- $doc->module = 0;
- $doc->title = $file->title;
- $doc->type = 'file';
- $doc->addedBy = $file->addedBy;
- $doc->addedDate = $file->addedDate;
- $this->dao->dbh($this->dbh)->insert(TABLE_DOC)->data($doc)->exec();
- self::$convertDocCount += 1;
- $file->objectType = 'doc';
- $file->objectID = $this->dao->lastInsertID();
- }
- $pathname = pathinfo($file->pathname);
- $file->extension = $pathname["extension"];
- unset($file->id);
- /* 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))
- {
- self::$info['files'][] = sprintf($this->lang->convert->errorFileNotExits, $soureFile);
- continue;
- }
- $targetFile = $this->app->getAppRoot() . "www/data/upload/{$this->app->company->id}/" . $file->pathname;
- $targetPath = dirname($targetFile);
- if(!is_dir($targetPath)) mkdir($targetPath, 0777, true);
- if(!copy($soureFile, $targetFile))
- {
- self::$info['files'][] = sprintf($this->lang->convert->errorCopyFailed, $targetFile);
- }
- }
- self::$convertFileCount += count($files);
- }
- /**
- * Clear the converted records.
- *
- * @access public
- * @return void
- */
- public function clear()
- {
- foreach($this->session->state as $table => $maxID)
- {
- $this->dao->dbh($this->dbh)->delete()->from($table)->where('id')->gt($maxID)->exec();
- }
- }
- }
|