From 155c9f7dc29ec134ecab0649330993d9fa30f2f0 Mon Sep 17 00:00:00 2001 From: xieqiyu Date: Fri, 23 May 2025 15:27:11 +0800 Subject: [PATCH] * [task#143975,doing,2h] Copy template to OR. --- module/doc/model.php | 59 ++++++++++++++++++++-- module/doc/test/lib/doc.unittest.class.php | 14 +++++ module/tree/control.php | 2 +- module/upgrade/control.php | 1 + 4 files changed, 72 insertions(+), 4 deletions(-) diff --git a/module/doc/model.php b/module/doc/model.php index 915b0301d3..dbae914464 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -4091,11 +4091,17 @@ class docModel extends model $templateList = $this->dao->select('*')->from(TABLE_DOC)->where('id')->in($templateIdList)->fetchAll('id'); if(empty($templateList)) return true; - $scopeMaps = array_flip($this->config->doc->scopeMaps); - $modulePairs = $this->dao->select('short,id')->from(TABLE_MODULE)->where('deleted')->eq('0')->andWhere('type')->eq('docTemplate')->fetchPairs(); + $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(); foreach($templateList as $id => $template) { - $template->lib = $scopeMaps['project']; + $template->lib = $scopeID; $template->module = zget($modulePairs, $template->templateType, 0); $this->dao->update(TABLE_DOC)->data($template)->where('id')->eq($id)->exec(); if(dao::isError()) return false; @@ -4554,4 +4560,51 @@ class docModel extends model { $this->dao->update(TABLE_DOCLIB)->set('deleted')->eq('1')->where('id')->in($scopeIdList)->exec(); } + + /** + * 复制模板数据到OR界面。 + * Copy template to OR page. + * + * @param array scopeIdList + * @access public + * @return void + */ + public function copyTemplate2OR(array $templateIdList = array()) + { + $this->loadModel('action'); + + $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'); + + $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) + { + if($template->type == 'book') continue; + + $oldTemplateID = $template->id; + unset($template->id); + $template->vision = 'or'; + $template->lib = $scopeID; + $template->module = $modulePairs[$template->templateType]; + $this->dao->insert(TABLE_DOC)->data($template)->exec(); + $newTemplateID = $this->dao->lastInsertID(); + + foreach($contentList[$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'); + } + } } diff --git a/module/doc/test/lib/doc.unittest.class.php b/module/doc/test/lib/doc.unittest.class.php index 130cb49074..7aa1ebd410 100644 --- a/module/doc/test/lib/doc.unittest.class.php +++ b/module/doc/test/lib/doc.unittest.class.php @@ -1795,4 +1795,18 @@ class docTest $this->objectModel->addBuiltInScopes(); return $this->objectModel->dao->select('*')->from(TABLE_DOCLIB)->fetchAll('id'); } + + /** + * 复制模板数据到OR界面。 + * Copy template to OR page. + * + * @param array scopeIdList + * @access public + * @return void + */ + public function copyTemplate2ORTest(array $templateIdList = array()) + { + $this->objectModel->copyTemplate2OR($templateIdList); + return $this->objectModel->dao->select('*')->from(TABLE_DOC)->where('vision')->eq('or')->fetchAll('id'); + } } diff --git a/module/tree/control.php b/module/tree/control.php index 059ffbb582..c0d32e3596 100644 --- a/module/tree/control.php +++ b/module/tree/control.php @@ -205,7 +205,7 @@ class tree extends control $parentLabel = $this->lang->docTemplate->parentModule; $scopes = array(); - $scopeList = $this->doc->getTemplateScopes(); + $scopeList = $this->loadModel('doc')->getTemplateScopes(); foreach($scopeList as $scope) $scopes[$scope->id] = $scope->name; $this->view->scopes = $scopes; } diff --git a/module/upgrade/control.php b/module/upgrade/control.php index 65367b1655..b8a88e5ce3 100644 --- a/module/upgrade/control.php +++ b/module/upgrade/control.php @@ -973,6 +973,7 @@ 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")); }