* [task#143975,doing,2h] Copy template before processing template data.
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
INSERT INTO `zt_config` (`vision`, `owner`, `module`, `section`, `key`, `value`) VALUES ('rnd', 'system', 'doc', '', 'builtInScopeMaps', '{"product":0,"project":0,"execution":0,"personal":0}');
|
||||
INSERT INTO `zt_config` (`vision`, `owner`, `module`, `section`, `key`, `value`) VALUES ('lite', 'system', 'doc', '', 'builtInScopeMaps', '{"project":0,"personal":0}');
|
||||
INSERT INTO `zt_config` (`vision`, `owner`, `module`, `section`, `key`, `value`) VALUES ('or', 'system', 'doc', '', 'builtInScopeMaps', '{"market":0,"product":0,"personal":0}');
|
||||
|
||||
@@ -2581,6 +2581,10 @@ INSERT INTO `zt_config` (`owner`, `module`, `section`, `key`, `value`) VALUES ('
|
||||
INSERT INTO `zt_config` (`owner`, `module`, `section`, `key`, `value`) VALUES ('system', 'requirement', '', 'gradeRule', 'stepwise');
|
||||
INSERT INTO `zt_config` (`owner`, `module`, `section`, `key`, `value`) VALUES ('system', 'epic', '', 'gradeRule', 'stepwise');
|
||||
|
||||
INSERT INTO `zt_config` (`vision`, `owner`, `module`, `section`, `key`, `value`) VALUES ('rnd', 'system', 'doc', '', 'builtInScopeMaps', '{"product":0,"project":0,"execution":0,"personal":0}');
|
||||
INSERT INTO `zt_config` (`vision`, `owner`, `module`, `section`, `key`, `value`) VALUES ('lite', 'system', 'doc', '', 'builtInScopeMaps', '{"project":0,"personal":0}');
|
||||
INSERT INTO `zt_config` (`vision`, `owner`, `module`, `section`, `key`, `value`) VALUES ('or', 'system', 'doc', '', 'builtInScopeMaps', '{"market":0,"product":0,"personal":0}');
|
||||
|
||||
-- DROP TABLE IF EXISTS `zt_relationoftasks`;
|
||||
CREATE TABLE IF NOT EXISTS `zt_relationoftasks` (
|
||||
`id` MEDIUMINT(8) UNSIGNED NOT NULL AUTO_INCREMENT ,
|
||||
|
||||
+82
-38
@@ -3989,16 +3989,27 @@ class docModel extends model
|
||||
public function upgradeTemplateTypes()
|
||||
{
|
||||
$this->app->loadLang('baseline');
|
||||
$templateTypes = $this->lang->baseline->objectList;
|
||||
$currentLang = $this->app->getClientLang();
|
||||
$templateTypes = $this->dao->select('`key`, `value`')->from(TABLE_LANG)
|
||||
->where('module')->eq('baseline')
|
||||
->andWhere('section')->eq('objectList')
|
||||
->andWhere('lang')->eq($currentLang)
|
||||
->andWhere('vision')->eq($this->config->vision)
|
||||
->fetchPairs();
|
||||
if(empty($templateTypes)) $templateTypes = $this->lang->baseline->objectList;
|
||||
|
||||
$currentLang = $this->app->getClientLang();
|
||||
$usedTemplateTypes = $this->dao->select('`key`, `value`')->from(TABLE_LANG)->alias('t1')
|
||||
->leftJoin(TABLE_DOC)->alias('t2')->on('t1.key = t2.templateType')
|
||||
->where('t1.module')->eq('baseline')
|
||||
->andWhere('t1.section')->eq('objectList')
|
||||
->andWhere('t1.lang')->ne($currentLang)
|
||||
->andWhere('t1.lang', true)->ne($currentLang)
|
||||
->orWhere('t1.vision')->ne($this->config->vision)
|
||||
->markRight(1)
|
||||
->andWhere('t1.key')->notin(array_keys($templateTypes))
|
||||
->andWhere('t2.templateType')->ne('')
|
||||
->andWhere('t2.lib')->eq('')
|
||||
->andWhere('t2.module')->eq('')
|
||||
->andWhere('t2.deleted')->eq(0)
|
||||
->fetchPairs();
|
||||
|
||||
$oldTemplateTypes = array_filter(arrayUnion($templateTypes, $usedTemplateTypes));
|
||||
@@ -4058,6 +4069,7 @@ class docModel extends model
|
||||
$builtInScopes = $this->dao->select('*')->from(TABLE_DOCLIB)->where('type')->eq('template')->andWhere('main')->eq('1')->fetchAll();
|
||||
if(!empty($builtInScopes)) return;
|
||||
|
||||
$this->loadModel('setting');
|
||||
$scope = new stdClass();
|
||||
$scope->type = 'template';
|
||||
$scope->main = '1';
|
||||
@@ -4065,14 +4077,19 @@ class docModel extends model
|
||||
$scope->addedDate = helper::now();
|
||||
foreach($this->lang->docTemplate->builtInScopes as $vision => $scopeList)
|
||||
{
|
||||
$scopeMaps = array();
|
||||
$scope->vision = $vision;
|
||||
foreach($scopeList as $scopeName)
|
||||
foreach($scopeList as $scopeKey => $scopeName)
|
||||
{
|
||||
if(empty($scopeName)) continue;
|
||||
|
||||
$scope->name = $scopeName;
|
||||
$this->dao->insert(TABLE_DOCLIB)->data($scope)->exec();
|
||||
|
||||
$scopeID = $this->dao->lastInsertID();
|
||||
$scopeMaps[$scopeKey] = $scopeID;
|
||||
}
|
||||
if(!empty($scopeMaps)) $this->setting->setItem("system.doc.builtInScopeMaps@{$vision}", json_encode($scopeMaps));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4089,18 +4106,19 @@ class docModel extends model
|
||||
$templateList = $this->dao->select('*')->from(TABLE_DOC)->where('id')->in($templateIdList)->fetchAll('id');
|
||||
if(empty($templateList)) return true;
|
||||
|
||||
$scopeID = $this->dao->select('id')->from(TABLE_DOCLIB)
|
||||
->where('type')->eq('template')
|
||||
->andWhere('main')->eq('1')
|
||||
->andWhere('name')->eq($this->lang->docTemplate->builtInScopes['rnd']['project'])
|
||||
->andWhere('vision')->eq('rnd')
|
||||
->fetch('id');
|
||||
|
||||
$modulePairs = $this->dao->select('short,id')->from(TABLE_MODULE)->where('deleted')->eq('0')->andWhere('root')->eq($scopeID)->fetchPairs();
|
||||
$this->loadModel('setting');
|
||||
$rndScopeMaps = $this->setting->getItem('vision=rnd&owner=system&module=doc&key=builtInScopeMaps');
|
||||
$orScopeMaps = $this->setting->getItem('vision=or&owner=system&module=doc&key=builtInScopeMaps');
|
||||
$rndScopeMaps = json_decode($rndScopeMaps, true);
|
||||
$orScopeMaps = json_decode($orScopeMaps, true);
|
||||
$moduleGroup = $this->dao->select('root,short,id')->from(TABLE_MODULE)->where('deleted')->eq('0')->andWhere('root')->in(array($rndScopeMaps['project'], $orScopeMaps['product']))->fetchGroup('root', 'short');
|
||||
foreach($templateList as $id => $template)
|
||||
{
|
||||
$template->lib = $scopeID;
|
||||
$template->module = zget($modulePairs, $template->templateType, 0);
|
||||
$templateVision = $template->vision;
|
||||
$templateType = $template->templateType;
|
||||
$templateScopeID = $templateVision == 'or' ? $orScopeMaps['product'] : $rndScopeMaps['project'];
|
||||
$template->lib = $templateScopeID;
|
||||
$template->module = $moduleGroup[$templateScopeID][$templateType]->id;
|
||||
$this->dao->update(TABLE_DOC)->data($template)->where('id')->eq($id)->exec();
|
||||
if(dao::isError()) return false;
|
||||
}
|
||||
@@ -4560,49 +4578,75 @@ class docModel extends model
|
||||
}
|
||||
|
||||
/**
|
||||
* 复制模板数据到OR界面。
|
||||
* Copy template to OR page.
|
||||
* 复制模板,将研发界面的除Wiki类型的模板复制到OR界面,将OR界面的所有文档模板复制到研发界面。
|
||||
* Copy templates of R&D interface, except for wiki type templates, to OR interface, and copy all templates of OR interface to R&D interface.
|
||||
*
|
||||
* @param array scopeIdList
|
||||
* @param array templateIdList
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function copyTemplate2OR(array $templateIdList = array())
|
||||
public function copyTemplate(array $templateIdList = array())
|
||||
{
|
||||
$this->loadModel('action');
|
||||
if(empty($templateIdList)) return array();
|
||||
|
||||
$scopeID = $this->dao->select('id')->from(TABLE_DOCLIB)
|
||||
->where('type')->eq('template')
|
||||
->andWhere('main')->eq('1')
|
||||
->andWhere('name')->eq($this->lang->docTemplate->builtInScopes['or']['product'])
|
||||
->andWhere('vision')->eq('or')
|
||||
->fetch('id');
|
||||
$oldTemplateList = $this->dao->select('*')->from(TABLE_DOC)->where('id')->in($templateIdList)->fetchAll('id');
|
||||
$oldContentList = $this->dao->select('*')->from(TABLE_DOCCONTENT)->where('doc')->in($templateIdList)->fetchGroup('doc', 'id');
|
||||
$oldChapterList = $this->dao->select('*')->from(TABLE_DOC)->where('template')->ne('')->andWhere('type')->in('chapter,article')->fetchGroup('template', 'id');
|
||||
$newTemplateList = array();
|
||||
|
||||
$modulePairs = $this->dao->select('short,id')->from(TABLE_MODULE)->where('deleted')->eq('0')->andWhere('root')->eq($scopeID)->fetchPairs();
|
||||
$templateList = $this->dao->select('*')->from(TABLE_DOC)->where('id')->in($templateIdList)->fetchAll('id');
|
||||
$contentList = $this->dao->select('*')->from(TABLE_DOCCONTENT)->where('doc')->in($templateIdList)->fetchGroup('doc', 'id');
|
||||
|
||||
foreach($templateList as $template)
|
||||
foreach($oldTemplateList as $oldTemplateID => $template)
|
||||
{
|
||||
if($template->type == 'book') continue;
|
||||
/* 研发界面的Wiki类型模板不复制到OR界面。*/
|
||||
/* The wiki type template of R&D interface is not copied to OR interface. */
|
||||
if($template->vision == 'rnd' && $template->type == 'book') continue;
|
||||
|
||||
$oldTemplateID = $template->id;
|
||||
/* 复制模板及模板内容。*/
|
||||
/* Copy template and content. */
|
||||
unset($template->id);
|
||||
$template->vision = 'or';
|
||||
$template->lib = $scopeID;
|
||||
$template->module = $modulePairs[$template->templateType];
|
||||
$templateVision = $template->vision == 'rnd' ? 'or' : 'rnd';
|
||||
$template->vision = $templateVision;
|
||||
$this->dao->insert(TABLE_DOC)->data($template)->exec();
|
||||
$newTemplateID = $this->dao->lastInsertID();
|
||||
|
||||
foreach($contentList[$oldTemplateID] as $content)
|
||||
foreach($oldContentList[$oldTemplateID] as $content)
|
||||
{
|
||||
unset($content->id);
|
||||
$content->doc = $newTemplateID;
|
||||
$this->dao->insert(TABLE_DOCCONTENT)->data($content)->exec();
|
||||
}
|
||||
|
||||
$comment = $template->version > 1 ? sprintf($this->lang->doc->docTemplateConvertComment, "#" . $template->version - 1) : '';
|
||||
$this->action->create('docTemplate', $newTemplateID, 'convertDocTemplate', $comment, '', 'system');
|
||||
/* OR界面的Wiki类型模板复制到研发界面。*/
|
||||
/* Copy the wiki type template of OR interface to R&D interface. */
|
||||
if($template->type == 'book' && isset($oldChapterList[$oldTemplateID]))
|
||||
{
|
||||
$chapterList = $oldChapterList[$oldTemplateID];
|
||||
$chapterContent = $this->dao->select('*')->from(TABLE_DOCCONTENT)->where('doc')->in(array_keys($chapterList))->fetchGroup('doc', 'id');
|
||||
foreach($chapterList as $oldChapterID => $chapter)
|
||||
{
|
||||
unset($chapter->id);
|
||||
$chapterVision = 'rnd';
|
||||
$chapter->vision = $chapterVision;
|
||||
$chapter->template = $newTemplateID;
|
||||
$this->dao->insert(TABLE_DOC)->data($chapter)->exec();
|
||||
$newChapterID = $this->dao->lastInsertID();
|
||||
|
||||
foreach($chapterContent[$oldChapterID] as $content)
|
||||
{
|
||||
unset($content->id);
|
||||
$content->doc = $newChapterID;
|
||||
$this->dao->insert(TABLE_DOCCONTENT)->data($content)->exec();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!isset($newTemplateList['all'])) $newTemplateList['all'] = array();
|
||||
if(!isset($newTemplateList['wiki'])) $newTemplateList['wiki'] = array();
|
||||
if(!isset($newTemplateList['html'])) $newTemplateList['html'] = array();
|
||||
$newTemplateList['all'][] = $newTemplateID;
|
||||
if($template->type == 'book') $newTemplateList['wiki'][] = $newTemplateID;
|
||||
if($template->type == 'html' || $template->type == 'markdown') $newTemplateList['html'][] = $newTemplateID;
|
||||
}
|
||||
|
||||
return $newTemplateList;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1804,9 +1804,8 @@ class docTest
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function copyTemplate2ORTest(array $templateIdList = array())
|
||||
public function copyTemplateTest(array $templateIdList = array())
|
||||
{
|
||||
$this->objectModel->copyTemplate2OR($templateIdList);
|
||||
return $this->objectModel->dao->select('*')->from(TABLE_DOC)->where('vision')->eq('or')->fetchAll('id');
|
||||
return $this->objectModel->copyTemplate($templateIdList);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 docModel->copyTemplate();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试复制文档模板1
|
||||
- 第all条的0属性 @6
|
||||
- 第html条的0属性 @6
|
||||
- 测试复制文档模板2
|
||||
- 第all条的0属性 @7
|
||||
- 第html条的0属性 @7
|
||||
- 测试复制文档模板3
|
||||
- 第all条的0属性 @8
|
||||
- 第wiki条的0属性 @8
|
||||
- 测试复制文档模板4
|
||||
- 第all条的0属性 @9
|
||||
- 第html条的0属性 @9
|
||||
- 测试复制文档模板5
|
||||
- 第all条的0属性 @10
|
||||
- 第html条的0属性 @10
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/doc.unittest.class.php';
|
||||
|
||||
$scope = zenData('doclib');
|
||||
$scope->id->range('1-10');
|
||||
$scope->type->range('template');
|
||||
$scope->vision->range('rnd{4},or{3},lite{2},rnd');
|
||||
$scope->name->range('产品,项目,执行,个人,市场,产品,个人,项目,个人,自定义范围');
|
||||
$scope->main->range('1{9},0');
|
||||
|
||||
$scope->gen(10);
|
||||
$doc = zenData('doc')->loadYaml('template');
|
||||
$doc->templateType->range('custom1,custom2,custom3,custom4,custom5');
|
||||
$doc->vision->range('rnd,rnd,or,or,or');
|
||||
$doc->type->range('html,markdown,book,html,markdown');
|
||||
$doc->gen(5);
|
||||
|
||||
$module = zenData('module')->loadYaml('templatemodule');
|
||||
$module->root->range('6');
|
||||
$module->gen(5);
|
||||
|
||||
zenData('doccontent')->gen(5);
|
||||
zenData('user')->gen(5);
|
||||
su('admin');
|
||||
|
||||
$docTester = new docTest();
|
||||
r($docTester->copyTemplateTest(array(1))) && p('all:0;html:0') && e('6,6'); // 测试复制文档模板1
|
||||
r($docTester->copyTemplateTest(array(2))) && p('all:0;html:0') && e('7,7'); // 测试复制文档模板2
|
||||
r($docTester->copyTemplateTest(array(3))) && p('all:0;wiki:0') && e('8,8'); // 测试复制文档模板3
|
||||
r($docTester->copyTemplateTest(array(4))) && p('all:0;html:0') && e('9,9'); // 测试复制文档模板4
|
||||
r($docTester->copyTemplateTest(array(5))) && p('all:0;html:0') && e('10,10'); // 测试复制文档模板5
|
||||
@@ -1,60 +0,0 @@
|
||||
#!/usr/bin/env php
|
||||
<?php
|
||||
/**
|
||||
|
||||
title=测试 docModel->copyTemplate2OR();
|
||||
timeout=0
|
||||
cid=1
|
||||
|
||||
- 测试复制文档模板1
|
||||
- 第6条的vision属性 @or
|
||||
- 第6条的lib属性 @6
|
||||
- 第6条的module属性 @1
|
||||
- 测试复制文档模板2
|
||||
- 第7条的vision属性 @or
|
||||
- 第7条的lib属性 @6
|
||||
- 第7条的module属性 @2
|
||||
- 测试复制文档模板3
|
||||
- 第8条的vision属性 @or
|
||||
- 第8条的lib属性 @6
|
||||
- 第8条的module属性 @3
|
||||
- 测试复制文档模板4
|
||||
- 第9条的vision属性 @or
|
||||
- 第9条的lib属性 @6
|
||||
- 第9条的module属性 @4
|
||||
- 测试复制文档模板5
|
||||
- 第10条的vision属性 @or
|
||||
- 第10条的lib属性 @6
|
||||
- 第10条的module属性 @5
|
||||
|
||||
*/
|
||||
|
||||
include dirname(__FILE__, 5) . '/test/lib/init.php';
|
||||
include dirname(__FILE__, 2) . '/lib/doc.unittest.class.php';
|
||||
|
||||
$scope = zenData('doclib');
|
||||
$scope->id->range('1-10');
|
||||
$scope->type->range('template');
|
||||
$scope->vision->range('rnd{4},or{3},lite{2},rnd');
|
||||
$scope->name->range('产品,项目,执行,个人,市场,产品,个人,项目,个人,自定义范围');
|
||||
$scope->main->range('1{9},0');
|
||||
|
||||
$scope->gen(10);
|
||||
$doc = zenData('doc')->loadYaml('template');
|
||||
$doc->templateType->range('custom1,custom2,custom3,custom4,custom5');
|
||||
$doc->gen(5);
|
||||
|
||||
$module = zenData('module')->loadYaml('templatemodule');
|
||||
$module->root->range('6');
|
||||
$module->gen(5);
|
||||
|
||||
zenData('doccontent')->gen(5);
|
||||
zenData('user')->gen(5);
|
||||
su('admin');
|
||||
|
||||
$docTester = new docTest();
|
||||
r($docTester->copyTemplate2ORTest(array(1))) && p('6:vision,lib,module') && e('or,6,1'); // 测试复制文档模板1
|
||||
r($docTester->copyTemplate2ORTest(array(2))) && p('7:vision,lib,module') && e('or,6,2'); // 测试复制文档模板2
|
||||
r($docTester->copyTemplate2ORTest(array(3))) && p('8:vision,lib,module') && e('or,6,3'); // 测试复制文档模板3
|
||||
r($docTester->copyTemplate2ORTest(array(4))) && p('9:vision,lib,module') && e('or,6,4'); // 测试复制文档模板4
|
||||
r($docTester->copyTemplate2ORTest(array(5))) && p('10:vision,lib,module') && e('or,6,5'); // 测试复制文档模板5
|
||||
@@ -581,12 +581,16 @@ class upgrade extends control
|
||||
/* If there are templates that need to be upgraded, display upgrade doc templates ui. */
|
||||
if($skipUpdateDocTemplates == 'no')
|
||||
{
|
||||
$upgradeDocTemplates = $this->upgrade->getUpgradeDocTemplates();
|
||||
$this->loadModel('doc')->addBuiltInScopes();
|
||||
$this->loadModel('doc');
|
||||
$this->doc->addBuiltInScopes();
|
||||
if(!$this->doc->checkIsTemplateUpgraded()) $this->doc->upgradeTemplateTypes();
|
||||
if(!empty($upgradeDocTemplates))
|
||||
|
||||
$upgradeDocTemplates = $this->upgrade->getUpgradeDocTemplates();
|
||||
$copiedTemplateList = $this->doc->copyTemplate(zget($upgradeDocTemplates, 'all', array()));
|
||||
$mergedTemplateList = array_merge_recursive($upgradeDocTemplates, $copiedTemplateList);
|
||||
if(!empty($mergedTemplateList))
|
||||
{
|
||||
$this->session->set('upgradeDocTemplates', $upgradeDocTemplates);
|
||||
$this->session->set('upgradeDocTemplates', $mergedTemplateList);
|
||||
return $this->locate(inlink('upgradeDocTemplates', "fromVersion={$fromVersion}"));
|
||||
}
|
||||
}
|
||||
@@ -973,7 +977,6 @@ class upgrade extends control
|
||||
{
|
||||
$this->session->set('upgradeDocTemplates', true);
|
||||
$this->doc->upgradeTemplateLibAndModule($upgradeDocTemplates['all']);
|
||||
$this->doc->copyTemplate2OR($upgradeDocTemplates['all']);
|
||||
}
|
||||
return $this->locate(inlink('afterExec', "fromVersion={$fromVersion}&processed=no&skipMoveFile=yes&skipUpdateDocs=yes&skipUpdateDocTemplates=yes"));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user