문서 이동 / 첨부 파일 삭제 기능 개선

This commit is contained in:
conory 2018-01-24 21:23:00 +09:00
parent b180270e08
commit 3d2ade4aa1
14 changed files with 253 additions and 234 deletions

View file

@ -114,6 +114,11 @@ class comment extends ModuleObject
return true; return true;
} }
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggeMoveDocumentModule', 'after'))
{
return true;
}
return FALSE; return FALSE;
} }
@ -204,6 +209,11 @@ class comment extends ModuleObject
{ {
$oDB->addIndex('comments', 'idx_nick_name', array('nick_name')); $oDB->addIndex('comments', 'idx_nick_name', array('nick_name'));
} }
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggeMoveDocumentModule', 'after'))
{
$oModuleController->insertTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggeMoveDocumentModule', 'after');
}
} }
/** /**

View file

@ -1726,7 +1726,13 @@ class commentController extends comment
$this->add('comment_list', $commentList); $this->add('comment_list', $commentList);
} }
function triggeMoveDocumentModule($obj)
{
executeQuery('comment.updateCommentModule', $obj);
executeQuery('comment.updateCommentListModule', $obj);
}
function triggerCopyModule(&$obj) function triggerCopyModule(&$obj)
{ {
$oModuleModel = getModel('module'); $oModuleModel = getModel('module');
@ -1741,7 +1747,6 @@ class commentController extends comment
} }
} }
} }
} }
/* End of file comment.controller.php */ /* End of file comment.controller.php */
/* Location: ./modules/comment/comment.controller.php */ /* Location: ./modules/comment/comment.controller.php */

View file

@ -47,150 +47,92 @@ class documentAdminController extends document
/** /**
* Change the module to move a specific article * Change the module to move a specific article
* @param array $document_srl_list * @param array $document_srl_list
* @param int $module_srl * @param int $target_module_srl
* @param int $category_srl * @param int $target_category_srl
* @return Object * @return Object
*/ */
function moveDocumentModule($document_srl_list, $module_srl, $category_srl) function moveDocumentModule($document_srl_list, $target_module_srl, $target_category_srl)
{ {
if(!count($document_srl_list)) return; if(empty($document_srl_list))
{
$oDocumentModel = getModel('document'); return;
$oDocumentController = getController('document'); }
$oDB = &DB::getInstance(); $obj = new stdClass;
$obj->document_srls = implode(',', $document_srl_list);
$obj->list_count = count($document_srl_list);
$obj->document_list = executeQueryArray('document.getDocuments', $obj)->data;
$obj->module_srl = $target_module_srl;
$obj->category_srl = $target_category_srl;
$oDB = DB::getInstance();
$oDB->begin(); $oDB->begin();
$triggerObj = new stdClass();
$triggerObj->document_srls = implode(',',$document_srl_list);
$triggerObj->module_srl = $module_srl;
$triggerObj->category_srl = $category_srl;
// Call a trigger (before) // Call a trigger (before)
$output = ModuleHandler::triggerCall('document.moveDocumentModule', 'before', $triggerObj); $output = ModuleHandler::triggerCall('document.moveDocumentModule', 'before', $obj);
if(!$output->toBool())
{
$oDB->rollback();
return $output;
}
for($i=count($document_srl_list)-1;$i>=0;$i--)
{
$document_srl = $document_srl_list[$i];
$oDocument = $oDocumentModel->getDocument($document_srl);
if(!$oDocument->isExists()) continue;
$source_category_srl = $oDocument->get('category_srl');
unset($obj);
$obj = $oDocument->getObjectVars();
// ISSUE https://github.com/xpressengine/xe-core/issues/32
$args_doc_origin = new stdClass();
$args_doc_origin->document_srl = $document_srl;
$output_ori = executeQuery('document.getDocument', $args_doc_origin, array('content'));
$obj->content = $output_ori->data->content;
// Move the attached file if the target module is different
if($module_srl != $obj->module_srl && $oDocument->hasUploadedFiles())
{
$args = new stdClass;
$args->module_srl = $module_srl;
$args->upload_target_srl = $oDocument->get('document_srl');
$output = executeQuery('file.updateFileModule', $args);
if(!$output->toBool())
{
$oDB->rollback();
return $output;
}
}
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;
$output = executeQuery('document.updateDocumentModule', $obj);
if(!$output->toBool())
{
$oDB->rollback();
return $output;
}
else
{
$update_output = $oDocumentController->insertDocumentUpdateLog($obj);
if(!$update_output->toBool())
{
$oDB->rollback();
return $update_output;
}
}
// 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)
{
if($source_category_srl) $oDocumentController->updateCategoryCount($oDocument->get('module_srl'), $source_category_srl);
if($category_srl) $oDocumentController->updateCategoryCount($module_srl, $category_srl);
}
}
$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())
{
$oDB->rollback();
return $output;
}
$output = executeQuery('comment.updateCommentListModule', $args);
if(!$output->toBool()) if(!$output->toBool())
{ {
$oDB->rollback(); $oDB->rollback();
return $output; return $output;
} }
// move the trackback $origin_category = array();
if(getClass('trackback')) $oDocumentController = getController('document');
foreach($obj->document_list as $document)
{ {
$output = executeQuery('trackback.updateTrackbackModule', $args); // If the target module is different
if(!$output->toBool()) if($document->module_srl != $obj->module_srl)
{ {
$oDB->rollback(); $oDocumentController->deleteDocumentAliasByDocument($document->document_srl);
return $output;
} }
// If the target category is different
if($document->category_srl != $obj->category_srl && $document->category_srl)
{
$origin_category[$document->category_srl] = $document->module_srl;
}
$oDocumentController->insertDocumentUpdateLog($document);
} }
// Tags // Move a module of the article
$output = executeQuery('tag.updateTagModule', $args); $output = executeQuery('document.updateDocumentsModule', $obj);
if(!$output->toBool()) if(!$output->toBool())
{ {
$oDB->rollback(); $oDB->rollback();
return $output; return $output;
} }
// Move a module of the extra vars
$output = executeQuery('document.updateDocumentExtraVarsModule', $obj);
if(!$output->toBool())
{
$oDB->rollback();
return $output;
}
$oDB->commit();
// Call a trigger (after) // Call a trigger (after)
ModuleHandler::triggerCall('document.moveDocumentModule', 'after', $triggerObj); ModuleHandler::triggerCall('document.moveDocumentModule', 'after', $obj);
$oDB->commit(); // update category count
foreach($origin_category as $category_srl => $module_srl)
{
$oDocumentController->updateCategoryCount($module_srl, $category_srl);
}
if($obj->category_srl)
{
$oDocumentController->updateCategoryCount($obj->module_srl, $obj->category_srl);
}
//remove from cache //remove from cache
foreach ($document_srl_list as $document_srl) foreach ($document_srl_list as $document_srl)
{ {
Rhymix\Framework\Cache::delete('document_item:'. getNumberingPath($document_srl) . $document_srl); Rhymix\Framework\Cache::delete('document_item:'. getNumberingPath($document_srl) . $document_srl);
} }
return new BaseObject(); return new BaseObject();
} }

View file

@ -131,7 +131,9 @@ class document extends ModuleObject
// 2017.12.21 Add an index for nick_name // 2017.12.21 Add an index for nick_name
if(!$oDB->isIndexExists('documents', 'idx_nick_name')) return true; if(!$oDB->isIndexExists('documents', 'idx_nick_name')) return true;
if(!$oModuleModel->getTrigger('file.deleteFile', 'document', 'controller', 'triggerAfterDeleteFile', 'after')) return true;
return false; return false;
} }
@ -356,6 +358,11 @@ class document extends ModuleObject
{ {
$oDB->addIndex('documents', 'idx_nick_name', array('nick_name')); $oDB->addIndex('documents', 'idx_nick_name', array('nick_name'));
} }
if(!$oModuleModel->getTrigger('file.deleteFile', 'document', 'controller', 'triggerAfterDeleteFile', 'after'))
{
$oModuleController->insertTrigger('file.deleteFile', 'document', 'controller', 'triggerAfterDeleteFile', 'after');
}
} }
/** /**

View file

@ -2869,26 +2869,47 @@ class documentController extends document
} }
} }
} }
public function updateUploaedCount($documentSrlList) public function updateUploaedCount($document_srl_list)
{ {
$oDocumentModel = getModel('document'); if(!is_array($document_srl_list))
$oFileModel = getModel('file');
if(is_array($documentSrlList))
{ {
$documentSrlList = array_unique($documentSrlList); $document_srl_list = array($document_srl_list);
foreach($documentSrlList AS $key => $documentSrl) }
if(empty($document_srl_list))
{
return;
}
$oFileModel = getModel('file');
$document_srl_list = array_unique($document_srl_list);
foreach($document_srl_list as $document_srl)
{
if(!$document_srl = (int) $document_srl)
{ {
$fileCount = $oFileModel->getFilesCount($documentSrl); continue;
$args = new stdClass();
$args->document_srl = $documentSrl;
$args->uploaded_count = $fileCount;
executeQuery('document.updateUploadedCount', $args);
} }
$args = new stdClass;
$args->document_srl = $document_srl;
$args->uploaded_count = $oFileModel->getFilesCount($document_srl);
executeQuery('document.updateUploadedCount', $args);
} }
} }
function triggerAfterDeleteFile($file)
{
$oDocument = getModel('document')->getDocument($file->upload_target_srl, false, false);
if(!$oDocument->isExists())
{
return new BaseObject();
}
$this->updateUploaedCount($file->upload_target_srl);
}
/** /**
* Copy extra keys when module copied * Copy extra keys when module copied
* @param object $obj * @param object $obj

View file

@ -0,0 +1,11 @@
<query id="updateDocumentExtraVarsModule" action="update">
<tables>
<table name="document_extra_vars" />
</tables>
<columns>
<column name="module_srl" var="module_srl" filter="number" />
</columns>
<conditions>
<condition operation="in" column="document_srl" var="document_srls" notnull="notnull" />
</conditions>
</query>

View file

@ -0,0 +1,12 @@
<query id="updateDocumentsModule" action="update">
<tables>
<table name="documents" />
</tables>
<columns>
<column name="module_srl" var="module_srl" filter="number" default="0" />
<column name="category_srl" var="category_srl" filter="number" default="0" />
</columns>
<conditions>
<condition operation="in" column="document_srl" var="document_srls" notnull="notnull" />
</conditions>
</query>

View file

@ -15,42 +15,12 @@ class fileAdminController extends file
} }
/** /**
* Delete the attachment of a particular module * @deprecated move to fileController
*
* @param int $module_srl Sequence of module to delete files
* @return Object * @return Object
*/ */
function deleteModuleFiles($module_srl) function deleteModuleFiles($module_srl)
{ {
// Get a full list of attachments return getController('file')->deleteModuleFiles($module_srl);
$args = new stdClass();
$args->module_srl = $module_srl;
$columnList = array('file_srl', 'uploaded_filename');
$output = executeQueryArray('file.getModuleFiles',$args, $columnList);
if(!$output) return $output;
$files = $output->data;
// Remove from the DB
$args->module_srl = $module_srl;
$output = executeQuery('file.deleteModuleFiles', $args);
if(!$output->toBool()) return $output;
// Remove the file
FileHandler::removeDir( sprintf("./files/attach/images/%s/", $module_srl) ) ;
FileHandler::removeDir( sprintf("./files/attach/binaries/%s/", $module_srl) );
// Remove the file list obtained from the DB
$path = array();
$cnt = count($files);
for($i=0;$i<$cnt;$i++)
{
$uploaded_filename = $files[$i]->uploaded_filename;
FileHandler::removeFile($uploaded_filename);
$path_info = pathinfo($uploaded_filename);
if(!in_array($path_info['dirname'], $path)) $path[] = $path_info['dirname'];
}
// Remove a file directory of the document
for($i=0;$i<count($path);$i++) FileHandler::removeBlankDir($path[$i]);
return $output;
} }
/** /**

View file

@ -77,7 +77,12 @@ class file extends ModuleObject
if(!$oModuleModel->getTrigger('module.procModuleAdminCopyModule', 'file', 'controller', 'triggerCopyModule', 'after')) return true; if(!$oModuleModel->getTrigger('module.procModuleAdminCopyModule', 'file', 'controller', 'triggerCopyModule', 'after')) return true;
if(!$oDB->isColumnExists('files', 'cover_image')) return true; if(!$oDB->isColumnExists('files', 'cover_image')) return true;
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'file', 'controller', 'triggeMoveDocumentModule', 'after'))
{
return true;
}
return false; return false;
} }
@ -140,6 +145,11 @@ class file extends ModuleObject
} }
if(!$oDB->isColumnExists('files', 'cover_image')) $oDB->addColumn('files', 'cover_image', 'char', '1', 'N'); if(!$oDB->isColumnExists('files', 'cover_image')) $oDB->addColumn('files', 'cover_image', 'char', '1', 'N');
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'file', 'controller', 'triggeMoveDocumentModule', 'after'))
{
$oModuleController->insertTrigger('document.moveDocumentModule', 'file', 'controller', 'triggeMoveDocumentModule', 'after');
}
} }
/** /**

View file

@ -694,9 +694,8 @@ class fileController extends file
{ {
$module_srl = $obj->module_srl; $module_srl = $obj->module_srl;
if(!$module_srl) return; if(!$module_srl) return;
$oFileController = getAdminController('file'); return $this->deleteModuleFiles($module_srl);
return $oFileController->deleteModuleFiles($module_srl);
} }
/** /**
@ -950,70 +949,58 @@ class fileController extends file
* - ipaddress * - ipaddress
* </pre> * </pre>
* *
* @param int $file_srl Sequence of file to delete * @param array|int $file_list or $file_srl
* @return Object * @return Object
*/ */
function deleteFile($file_srl) function deleteFile($file_list)
{ {
if(!$file_srl) return; if(!is_array($file_list))
$srls = (is_array($file_srl)) ? $file_srl : explode(',', $file_srl);
if(!count($srls)) return;
$oDocumentController = getController('document');
$documentSrlList = array();
foreach($srls as $srl)
{ {
$srl = (int)$srl; $file_list = explode(',', $file_list);
if(!$srl) }
if(empty($file_list))
{
return new BaseObject();
}
foreach($file_list as $file)
{
if(!is_object($file))
{
if(!$file_srl = (int) $file)
{
continue;
}
$file = getModel('file')->getFile($file_srl);
}
if(empty($file->file_srl))
{ {
continue; continue;
} }
$args = new stdClass();
$args->file_srl = $srl;
$output = executeQuery('file.getFile', $args);
if(!$output->toBool() || !$output->data)
{
continue;
}
$file_info = $output->data;
if($file_info->upload_target_srl)
{
$documentSrlList[] = $file_info->upload_target_srl;
}
$source_filename = $output->data->source_filename;
$uploaded_filename = $output->data->uploaded_filename;
// Call a trigger (before) // Call a trigger (before)
$trigger_obj = $output->data; $output = ModuleHandler::triggerCall('file.deleteFile', 'before', $file);
$output = ModuleHandler::triggerCall('file.deleteFile', 'before', $trigger_obj);
if(!$output->toBool()) return $output; if(!$output->toBool()) return $output;
// Remove from the DB // Remove from the DB
$output = executeQuery('file.deleteFile', $args); $output = executeQuery('file.deleteFile', $file);
if(!$output->toBool()) return $output; if(!$output->toBool()) return $output;
// If successfully deleted, remove the file // If successfully deleted, remove the file
Rhymix\Framework\Storage::delete(FileHandler::getRealPath($uploaded_filename)); Rhymix\Framework\Storage::delete(FileHandler::getRealPath($file->uploaded_filename));
// Call a trigger (after) // Call a trigger (after)
ModuleHandler::triggerCall('file.deleteFile', 'after', $trigger_obj); ModuleHandler::triggerCall('file.deleteFile', 'after', $file);
// Remove empty directories // Remove empty directories
Rhymix\Framework\Storage::deleteEmptyDirectory(dirname(FileHandler::getRealPath($uploaded_filename)), true); Rhymix\Framework\Storage::deleteEmptyDirectory(dirname(FileHandler::getRealPath($file->uploaded_filename)), true);
} }
$oDocumentController->updateUploaedCount($documentSrlList); return new BaseObject();
return $output;
} }
/** /**
* Delete all attachments of a particular document * Delete all attachments of a particular document
* *
@ -1024,26 +1011,39 @@ class fileController extends file
{ {
// Get a list of attachements // Get a list of attachements
$oFileModel = getModel('file'); $oFileModel = getModel('file');
$columnList = array('file_srl', 'uploaded_filename', 'module_srl'); $file_list = $oFileModel->getFiles($upload_target_srl);
$file_list = $oFileModel->getFiles($upload_target_srl, $columnList);
// Success returned if no attachement exists // Success returned if no attachement exists
if(!is_array($file_list)||!count($file_list)) return new BaseObject(); if(empty($file_list))
// Delete the file
foreach ($file_list as $file)
{ {
$this->deleteFile($file->file_srl); return new BaseObject();
} }
// Remove from the DB // Delete the file
$args = new stdClass(); return $this->deleteFile($file_list);
$args->upload_target_srl = $upload_target_srl;
$output = executeQuery('file.deleteFiles', $args);
if(!$output->toBool()) return $output;
return $output;
} }
/**
* Delete the attachment of a particular module
*
* @param int $module_srl Sequence of module to delete files
* @return Object
*/
function deleteModuleFiles($module_srl)
{
// Get a full list of attachments
$args = new stdClass;
$args->module_srl = $module_srl;
$output = executeQueryArray('file.getModuleFiles', $args);
if(!$output->toBool() || empty($file_list = $output->data))
{
return $output;
}
// Delete the file
return $this->deleteFile($file_list);
}
/** /**
* Move an attachement to the other document * Move an attachement to the other document
* *
@ -1161,7 +1161,14 @@ class fileController extends file
{ {
return; return;
} }
function triggeMoveDocumentModule($obj)
{
$obj->upload_target_srls = $obj->document_srls;
executeQuery('file.updateFileModule', $obj);
executeQuery('file.updateFileModuleComment', $obj);
}
function triggerCopyModule(&$obj) function triggerCopyModule(&$obj)
{ {
$oModuleModel = getModel('module'); $oModuleModel = getModel('module');

View file

@ -6,6 +6,6 @@
<column name="module_srl" var="module_srl" filter="number" notnull="notnull" /> <column name="module_srl" var="module_srl" filter="number" notnull="notnull" />
</columns> </columns>
<conditions> <conditions>
<condition operation="equal" column="upload_target_srl" var="upload_target_srl" filter="number" notnull="notnull" /> <condition operation="in" column="upload_target_srl" var="upload_target_srls" filter="number" notnull="notnull" />
</conditions> </conditions>
</query> </query>

View file

@ -0,0 +1,13 @@
<query id="updateFileModuleComment" action="update">
<tables>
<table name="files" />
<table name="comments" />
</tables>
<columns>
<column name="files.module_srl" var="module_srl" filter="number" notnull="notnull" />
</columns>
<conditions>
<condition operation="equal" column="files.upload_target_srl" default="comments.comment_srl" />
<condition operation="in" column="comments.document_srl" var="upload_target_srls" filter="number" notnull="notnull" pipe="and" />
</conditions>
</query>

View file

@ -43,6 +43,7 @@ class tag extends ModuleObject
if(!$oModuleModel->getTrigger('module.deleteModule', 'tag', 'controller', 'triggerDeleteModuleTags', 'after')) return true; if(!$oModuleModel->getTrigger('module.deleteModule', 'tag', 'controller', 'triggerDeleteModuleTags', 'after')) return true;
// tag in the index column of the table tag // tag in the index column of the table tag
if(!$oDB->isIndexExists("tags","idx_tag")) return true; if(!$oDB->isIndexExists("tags","idx_tag")) return true;
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggeMoveDocumentModule', 'after')) return true;
return false; return false;
} }
@ -76,6 +77,11 @@ class tag extends ModuleObject
// tag in the index column of the table tag // tag in the index column of the table tag
if(!$oDB->isIndexExists("tags","idx_tag")) if(!$oDB->isIndexExists("tags","idx_tag"))
$oDB->addIndex("tags","idx_tag", array("document_srl","tag")); $oDB->addIndex("tags","idx_tag", array("document_srl","tag"));
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggeMoveDocumentModule', 'after'))
{
$oModuleController->insertTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggeMoveDocumentModule', 'after');
}
} }
/** /**

View file

@ -94,6 +94,11 @@ class tagController extends tag
$oTagController = getAdminController('tag'); $oTagController = getAdminController('tag');
return $oTagController->deleteModuleTags($module_srl); return $oTagController->deleteModuleTags($module_srl);
} }
function triggeMoveDocumentModule($obj)
{
executeQuery('tag.updateTagModule', $obj);
}
} }
/* End of file tag.controller.php */ /* End of file tag.controller.php */
/* Location: ./modules/tag/tag.controller.php */ /* Location: ./modules/tag/tag.controller.php */