diff --git a/module/doc/control.php b/module/doc/control.php index 51e83bd5d1..a5c5a5a170 100755 --- a/module/doc/control.php +++ b/module/doc/control.php @@ -1181,12 +1181,13 @@ class doc extends control $this->docZen->setAclForCreateLib(is_numeric($targetSpace) ? 'custom' : 'mine'); - $this->view->title = $this->lang->doc->moveLibAction; - $this->view->spaces = $this->docZen->getAllSpaces(); - $this->view->lib = $lib; - $this->view->targetSpace = $targetSpace; - $this->view->groups = $this->loadModel('group')->getPairs(); - $this->view->users = $this->loadModel('user')->getPairs('nocode|noclosed'); + $this->view->title = $this->lang->doc->moveLibAction; + $this->view->spaces = $this->docZen->getAllSpaces(); + $this->view->lib = $lib; + $this->view->targetSpace = $targetSpace; + $this->view->hasOthersDoc = $this->doc->hasOthersDoc($lib); + $this->view->groups = $this->loadModel('group')->getPairs(); + $this->view->users = $this->loadModel('user')->getPairs('nocode|noclosed'); $this->display(); } diff --git a/module/doc/js/movelib.ui.js b/module/doc/js/movelib.ui.js index 25154e710b..edb6c5017f 100644 --- a/module/doc/js/movelib.ui.js +++ b/module/doc/js/movelib.ui.js @@ -12,3 +12,18 @@ window.toggleLibAcl = function(e) $this = $(e.target); $this.closest('form').find('#whiteListBox').toggleClass('hidden', $(e.target).val() != 'private'); }; + +window.clickSubmit = function(e) +{ + zui.Modal.confirm({message: errorOthersCreated}).then((res) => + { + if(res) + { + const formUrl = $('form').attr('action'); + const formData = new FormData($("form")[0]); + $.ajaxSubmit({url: formUrl, data: formData}); + } + }); + + return false; +} diff --git a/module/doc/lang/de.php b/module/doc/lang/de.php index 134efcccb2..2161b950b8 100644 --- a/module/doc/lang/de.php +++ b/module/doc/lang/de.php @@ -357,6 +357,7 @@ $lang->doc->confirmUpdateContent = 'You have a document that is not saved from l $lang->doc->selectLibType = 'Please select a type of doc library.'; $lang->doc->noLibreOffice = 'You does not have access to office conversion settings!'; $lang->doc->errorParentChapter = 'The parent chapter cannot be its own chapter or sub chapter!'; +$lang->doc->errorOthersCreated = 'There are documents created by others in this library. You cannot move it.'; $lang->doc->noticeAcl['lib']['product']['default'] = "Users who can access the selected {$lang->productCommon} can access it."; $lang->doc->noticeAcl['lib']['product']['custom'] = "Users who can access the selected {$lang->productCommon} or users in the whiltelist can access it."; diff --git a/module/doc/lang/en.php b/module/doc/lang/en.php index ff2d2ce4cf..c680f86471 100644 --- a/module/doc/lang/en.php +++ b/module/doc/lang/en.php @@ -357,6 +357,7 @@ $lang->doc->confirmUpdateContent = 'You have a document that is not saved from l $lang->doc->selectLibType = 'Please select a type of doc library.'; $lang->doc->noLibreOffice = 'You does not have access to office conversion settings!'; $lang->doc->errorParentChapter = 'The parent chapter cannot be its own chapter or sub chapter!'; +$lang->doc->errorOthersCreated = 'There are documents created by others in this library. You cannot move it.'; $lang->doc->noticeAcl['lib']['product']['default'] = "Users who can access the selected {$lang->productCommon} can access it."; $lang->doc->noticeAcl['lib']['product']['custom'] = "Users who can access the selected {$lang->productCommon} or users in the whiltelist can access it."; diff --git a/module/doc/lang/fr.php b/module/doc/lang/fr.php index 32d5f2a257..2fc6b817db 100644 --- a/module/doc/lang/fr.php +++ b/module/doc/lang/fr.php @@ -357,6 +357,7 @@ $lang->doc->confirmUpdateContent = 'You have a document that is not saved from l $lang->doc->selectLibType = 'Please select a type of doc library.'; $lang->doc->noLibreOffice = 'You does not have access to office conversion settings!'; $lang->doc->errorParentChapter = 'The parent chapter cannot be its own chapter or sub chapter!'; +$lang->doc->errorOthersCreated = 'There are documents created by others in this library. You cannot move it.'; $lang->doc->noticeAcl['lib']['product']['default'] = "Users who can access the selected {$lang->productCommon} can access it."; $lang->doc->noticeAcl['lib']['product']['custom'] = "Users who can access the selected {$lang->productCommon} or users in the whiltelist can access it."; diff --git a/module/doc/lang/zh-cn.php b/module/doc/lang/zh-cn.php index 8e388da0bb..c575388b23 100644 --- a/module/doc/lang/zh-cn.php +++ b/module/doc/lang/zh-cn.php @@ -357,6 +357,7 @@ $lang->doc->confirmUpdateContent = '检查到您有未保存的文档内容, $lang->doc->selectLibType = '请选择文档库类型'; $lang->doc->noLibreOffice = '您还没有office转换设置访问权限!'; $lang->doc->errorParentChapter = '父章节不能是自身章节及子章节!'; +$lang->doc->errorOthersCreated = '该库下其他人创建的文档暂不支持移动,是否确认移动?'; $lang->doc->noticeAcl['lib']['product']['default'] = "有所选{$lang->productCommon}访问权限的用户可以访问。"; $lang->doc->noticeAcl['lib']['product']['custom'] = "有所选{$lang->productCommon}访问权限或白名单里的用户可以访问。"; diff --git a/module/doc/model.php b/module/doc/model.php index 97ecb4690f..77fa2dc934 100644 --- a/module/doc/model.php +++ b/module/doc/model.php @@ -2432,6 +2432,7 @@ class docModel extends model $item->main = zget($lib, 'main', 0); $item->objectType = $type; $item->objectID = $objectID; + $item->addedBy = $lib->addedBy; $item->active = $lib->id == $libID && $browseType != 'bysearch' ? 1 : 0; $item->children = $this->getModuleTree($lib->id, $moduleID, $lib->type == 'api' ? 'api' : 'doc', 0, $releaseModule, $docID); @@ -3002,8 +3003,9 @@ class docModel extends model } elseif($data->space == 'mine') { - $data->type = 'mine'; - $data->parent = 0; + $data->type = 'mine'; + $data->parent = 0; + $data->addedBy = $this->app->user->account; } else { @@ -3019,6 +3021,101 @@ class docModel extends model $actionID = $this->loadModel('action')->create('docLib', $libID, 'Moved', '', json_encode(array('from' => $lib->type == 'mine' ? 'mine' : $lib->parent, 'to' => $data->type == 'mine' ? 'mine' : $data->parent))); $this->action->logHistory($actionID, $changes); + + /* 从团队空间移动到我的空间,需要保留其他人创建的文档在团队空间。 */ + if($data->type == 'mine') $this->reserveOthersDoc($lib); + return true; } + + /** + * 迁移文档库时保留其他人创建的文档。 + * Reserve other people's documents when migrating document libraries. + * + * @param object $lib + * @access public + * @return void + */ + public function reserveOthersDoc(object $lib) + { + $othersDocList = $this->dao->select('id, module')->from(TABLE_DOC) + ->where('lib')->eq($lib->id) + ->andWhere('addedBy')->ne($this->app->user->account) + ->andWhere('deleted')->eq('0') + ->fetchPairs(); + + if($othersDocList) + { + unset($lib->id); + $this->dao->insert(TABLE_DOCLIB)->data($lib)->exec(); + $newLibID = $this->dao->lastInsertID(); + + $this->dao->update(TABLE_DOC)->set('lib')->eq($newLibID)->where('id')->in(array_keys($othersDocList))->exec(); + + $modulePairs = $this->dao->select('id, path')->from(TABLE_MODULE)->where('id')->in($othersDocList)->andWhere('deleted')->eq('0')->fetchPairs(); + $moduleIdList = array(); + foreach($modulePairs as $path) + { + $paths = explode(',', trim($path, ',')); + foreach($paths as $id) + { + if($id > 0) $moduleIdList[$id] = $id; + } + } + + $mapList = array(); + $idMap = array(); + $modules = $this->dao->select('*')->from(TABLE_MODULE)->where('id')->in($moduleIdList)->andWhere('deleted')->eq('0')->fetchAll('id'); + foreach($modules as $module) + { + $oldID = $module->id; + unset($module->id); + $module->root = $newLibID; + $this->dao->insert(TABLE_MODULE)->data($module)->exec(); + + $newID = $this->dao->lastInsertID(); + + $module->id = $newID; + $mapList[] = $module; + $idMap[$oldID] = $newID; + + $this->dao->update(TABLE_DOC)->set('module')->eq($newID)->where('module')->eq($oldID)->andWhere('lib')->eq($newLibID)->exec(); + } + + foreach($mapList as $module) + { + $parent = $module->parent ? $idMap[$module->parent] : 0; + $paths = explode(',', trim($module->path, ',')); + foreach($paths as $key => $path) + { + if($path) $paths[$key] = $idMap[$path]; + } + $path = implode(',', $paths); + $this->dao->update(TABLE_MODULE)->set('parent')->eq($parent)->set('path')->eq($path)->where('id')->eq($module->id)->exec(); + } + } + } + + /** + * 判断文档库下是否有其他人创建的文档。 + * Check if there are other documents created under the document library. + * + * @param object $lib + * @access public + * @return bool + */ + public function hasOthersDoc(object $lib): bool + { + if($lib->type != 'custom') return false; + + $docID = $this->dao->select('id')->from(TABLE_DOC) + ->where('vision')->eq($this->config->vision) + ->andWhere('templateType')->eq('') + ->andWhere('deleted')->eq(0) + ->andWhere('lib')->eq($lib->id) + ->andWhere('addedBy')->ne($this->app->user->account) + ->fetch('id'); + + return !empty($docID); + } } diff --git a/module/doc/ui/movelib.html.php b/module/doc/ui/movelib.html.php index 180d5c5113..39523d5768 100644 --- a/module/doc/ui/movelib.html.php +++ b/module/doc/ui/movelib.html.php @@ -21,9 +21,11 @@ if($libType == 'custom' && ($lib->type == 'mine' || $lib->parent != $targetSpace jsVar('targetSpace', $targetSpace); jsVar('libID', $lib->id); +jsVar('errorOthersCreated', $lang->doc->errorOthersCreated); formPanel ( on::change('[name=space]', 'changeSpace'), + $hasOthersDoc ? set::ajax(array('beforeSubmit' => jsRaw("clickSubmit"))) : null, formGroup ( set::width('5/6'), diff --git a/module/kanban/ui/view.html.php b/module/kanban/ui/view.html.php index 33c50ec240..e84da243e5 100644 --- a/module/kanban/ui/view.html.php +++ b/module/kanban/ui/view.html.php @@ -92,6 +92,7 @@ div zui::kanbanList ( set::key('kanban'), + set('$replace', false), set::items($kanbanList), set::height('calc(100vh - 120px)') ) diff --git a/module/story/model.php b/module/story/model.php index 86d3630e81..6096eec5d9 100644 --- a/module/story/model.php +++ b/module/story/model.php @@ -1778,6 +1778,10 @@ class storyModel extends model $story->parent = $parentID; $this->doChangeParent($story->id, $story, $oldStory); + + if($oldStory->parent > 0) $this->updateParentStatus($storyID, $oldStory->parent, false); + if($story->parent > 0) $this->updateParentStatus($storyID, $story->parent, false); + $this->setStage($story->id); }