diff --git a/module/doc/control.php b/module/doc/control.php index 86e6551d34..1d211fa4be 100755 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -2317,7 +2317,7 @@ class doc extends control $doc->module = (int)$doc->module; $doc->privs = array('edit' => common::hasPriv('doc', 'edit', $doc) && $doc->acl == 'open'); $doc->editors = $this->doc->getEditors($docID); - $doc->draft = $this->doc->getDraft($docID); + $doc->draft = $doc->status == 'draft' ? $this->doc->getContent($docID, $version) : null; $lib = $this->doc->getLibByID((int)$doc->lib); $objectType = $lib->type; diff --git a/module/doc/model.php b/module/doc/model.php index 8fd918613d..6c77317352 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -1152,19 +1152,6 @@ class docModel extends model return null; } - /** - * 获取文档草稿。 - * Get doc draft. - * - * @param int $docID 文档ID - * @access public - * @return ?object - */ - public function getDraft(int $docID): ?object - { - return $this->getContent($docID, 0); - } - /** * 处理文档数据。 * Process doc data. diff --git a/module/doc/test/lib/doc.unittest.class.php b/module/doc/test/lib/doc.unittest.class.php index 2e6cdec7ca..f812c4416a 100644 --- a/module/doc/test/lib/doc.unittest.class.php +++ b/module/doc/test/lib/doc.unittest.class.php @@ -1883,4 +1883,18 @@ class docTest return $doc; } + + /** + * 获取文档内容。 + * Get document content test. + * + * @param int $docID + * @param int $version + * @access public + * @return object|null + */ + public function getContentTest(int $docID, int $version): object|null + { + return $this->objectModel->getContent($docID, $version); + } } diff --git a/module/doc/test/model/getcontent.php b/module/doc/test/model/getcontent.php new file mode 100755 index 0000000000..b8fe4bb7ae --- /dev/null +++ b/module/doc/test/model/getcontent.php @@ -0,0 +1,38 @@ +#!/usr/bin/env php +getContent(); +timeout=0 +cid=1 + +- 获取docID=1、版本为1的文档内容 + - 属性doc @1 + - 属性version @1 + - 属性title @文档标题1 +- 获取docID=2、版本为1的文档内容 + - 属性doc @2 + - 属性version @1 + - 属性title @文档标题2 +- 获取docID=1、版本为2的文档内容为空 @0 +- 获取docID=2、版本为2的文档内容为空 @0 +- 获取不存在的文档内容 @0 + +*/ + +include dirname(__FILE__, 5) . '/test/lib/init.php'; +include dirname(__FILE__, 2) . '/lib/doc.unittest.class.php'; + +zenData('doc')->loadYaml('doc')->gen(5); +zenData('doccontent')->loadYaml('doccontent')->gen(5); + +$docIDList = array('1', '2', '6'); +$versionList = array('1', '2'); + +$docTester = new docTest(); +r($docTester->getContentTest($docIDList[0], $versionList[0])) && p('doc,version,title') && e('1,1,文档标题1'); // 获取docID=1、版本为1的文档内容 +r($docTester->getContentTest($docIDList[1], $versionList[0])) && p('doc,version,title') && e('2,1,文档标题2'); // 获取docID=2、版本为1的文档内容 +r($docTester->getContentTest($docIDList[0], $versionList[1])) && p() && e(0); // 获取docID=1、版本为2的文档内容为空 +r($docTester->getContentTest($docIDList[1], $versionList[1])) && p() && e(0); // 获取docID=2、版本为2的文档内容为空 +r($docTester->getContentTest($docIDList[2], $versionList[0])) && p() && e(0); // 获取不存在的文档内容 \ No newline at end of file