From c431855bbf09cd80c4f2e53a3a6d082028fdd47d Mon Sep 17 00:00:00 2001 From: Kijin Sung Date: Fri, 12 Jan 2018 19:51:45 +0900 Subject: [PATCH] Fix #975 do not move file when moving document MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 문서를 다른 게시판으로 이동할 때 첨부파일 경로를 변경하지 않도록 하여 아래와 같은 문제 발생을 사전에 차단합니다. - 본문에 삽입한 이미지 경로와 실제 파일이 저장된 경로가 달라지는 문제 - 경로 변경에 실패하여 파일이 증발하는 문제 단, files/attach/(images|binaries)/(기존 게시판의 module_srl) 폴더에 파일이 그대로 남아 있게 되므로, 게시판 삭제 후 해당 폴더를 수동으로 삭제하면 문제가 될 수 있습니다. 더이상 게시판의 module_srl과 해당 폴더에 저장된 파일들의 소속 모듈이 일치하지 않을 수 있다는 뜻입니다. --- .../document/document.admin.controller.php | 46 +++++-------------- modules/file/queries/updateFileModule.xml | 11 +++++ 2 files changed, 23 insertions(+), 34 deletions(-) create mode 100644 modules/file/queries/updateFileModule.xml diff --git a/modules/document/document.admin.controller.php b/modules/document/document.admin.controller.php index 70ca56fc8..3393896ee 100644 --- a/modules/document/document.admin.controller.php +++ b/modules/document/document.admin.controller.php @@ -93,47 +93,22 @@ class documentAdminController extends document // Move the attached file if the target module is different if($module_srl != $obj->module_srl && $oDocument->hasUploadedFiles()) { - $oFileController = getController('file'); - - $files = $oDocument->getUploadedFiles(); - $delete_file_srls = array(); - if(is_array($files)) + $args = new stdClass; + $args->module_srl = $module_srl; + $args->upload_target_srl = $oDocument->get('document_srl'); + $output = executeQuery('file.updateFileModule', $args); + if(!$output->toBool()) { - foreach($files as $val) - { - $file_info = array(); - $file_info['tmp_name'] = $val->uploaded_filename; - $file_info['name'] = $val->source_filename; - $inserted_file = $oFileController->insertFile($file_info, $module_srl, $obj->document_srl, $val->download_count, true); - if($inserted_file && $inserted_file->toBool()) - { - // for image/video files - if($val->direct_download == 'Y') - { - $source_filename = substr($val->uploaded_filename,2); - $target_filename = substr($inserted_file->get('uploaded_filename'),2); - $obj->content = str_replace($source_filename, $target_filename, $obj->content); - // For binary files - } - else - { - $obj->content = str_replace('file_srl='.$val->file_srl, 'file_srl='.$inserted_file->get('file_srl'), $obj->content); - $obj->content = str_replace('sid='.$val->sid, 'sid='.$inserted_file->get('sid'), $obj->content); - } - } - $delete_file_srls[] = $val->file_srl; - } - // Delete an existing file - $oFileController->deleteFile($delete_file_srls); + $oDB->rollback(); + return $output; } - // Set the all files to be valid - $oFileController->setFilesValid($obj->document_srl); } if($module_srl != $obj->module_srl) { $oDocumentController->deleteDocumentAliasByDocument($obj->document_srl); } + // Move a module of the article $obj->module_srl = $module_srl; $obj->category_srl = $category_srl; @@ -152,12 +127,14 @@ class documentAdminController extends document return $update_output; } } - //Move a module of the extra vars + + // Move a module of the extra vars $output = executeQuery('document.moveDocumentExtraVars', $obj); if(!$output->toBool()) { $oDB->rollback(); return $output; } + // Set 0 if a new category doesn't exist after catergory change if($source_category_srl != $category_srl) { @@ -169,6 +146,7 @@ class documentAdminController extends document $args = new stdClass(); $args->document_srls = implode(',',$document_srl_list); $args->module_srl = $module_srl; + // move the comment $output = executeQuery('comment.updateCommentModule', $args); if(!$output->toBool()) diff --git a/modules/file/queries/updateFileModule.xml b/modules/file/queries/updateFileModule.xml new file mode 100644 index 000000000..e33ff3d9f --- /dev/null +++ b/modules/file/queries/updateFileModule.xml @@ -0,0 +1,11 @@ + + + + + + + + + + +