mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 17:21:39 +09:00
copyDocumentModule(), deleteModuleDocument() 정리, 성능 개선
This commit is contained in:
parent
3d2ade4aa1
commit
54401ea28f
10 changed files with 366 additions and 417 deletions
|
|
@ -114,7 +114,11 @@ class comment extends ModuleObject
|
|||
return true;
|
||||
}
|
||||
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggeMoveDocumentModule', 'after'))
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggerMoveDocument', 'after'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!$oModuleModel->getTrigger('document.copyDocumentModule', 'comment', 'controller', 'triggerAddCopyDocument', 'add'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -210,9 +214,13 @@ class comment extends ModuleObject
|
|||
$oDB->addIndex('comments', 'idx_nick_name', array('nick_name'));
|
||||
}
|
||||
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggeMoveDocumentModule', 'after'))
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggerMoveDocument', 'after'))
|
||||
{
|
||||
$oModuleController->insertTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggeMoveDocumentModule', 'after');
|
||||
$oModuleController->insertTrigger('document.moveDocumentModule', 'comment', 'controller', 'triggerMoveDocument', 'after');
|
||||
}
|
||||
if(!$oModuleModel->getTrigger('document.copyDocumentModule', 'comment', 'controller', 'triggerAddCopyDocument', 'add'))
|
||||
{
|
||||
$oModuleController->insertTrigger('document.copyDocumentModule', 'comment', 'controller', 'triggerAddCopyDocument', 'add');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1727,12 +1727,44 @@ class commentController extends comment
|
|||
$this->add('comment_list', $commentList);
|
||||
}
|
||||
|
||||
function triggeMoveDocumentModule($obj)
|
||||
function triggerMoveDocument($obj)
|
||||
{
|
||||
executeQuery('comment.updateCommentModule', $obj);
|
||||
executeQuery('comment.updateCommentListModule', $obj);
|
||||
}
|
||||
|
||||
function triggerAddCopyDocument(&$obj)
|
||||
{
|
||||
$args = new stdClass;
|
||||
$args->document_srls = $obj->source->document_srl;
|
||||
$comment_list = executeQueryArray('comment.getCommentsByDocumentSrls', $args)->data;
|
||||
|
||||
$copied_comments = array();
|
||||
foreach($comment_list as $comment)
|
||||
{
|
||||
$copy = clone $comment;
|
||||
$copy->comment_srl = getNextSequence();
|
||||
$copy->module_srl = $obj->copied->module_srl;
|
||||
$copy->document_srl = $obj->copied->document_srl;
|
||||
$copy->parent_srl = $comment->parent_srl ? $copied_comments[$comment->parent_srl] : 0;
|
||||
|
||||
// call a trigger (add)
|
||||
$args = new stdClass;
|
||||
$args->source = $comment;
|
||||
$args->copied = $copy;
|
||||
ModuleHandler::triggerCall('comment.copyCommentByDocument', 'add', $args);
|
||||
|
||||
// insert a copied comment
|
||||
$this->insertComment($copy, true);
|
||||
|
||||
$copied_comments[$comment->comment_srl] = $copy->comment_srl;
|
||||
}
|
||||
|
||||
// update
|
||||
$obj->copied->last_updater = $copy->nick_name;
|
||||
$obj->copied->comment_count = count($copied_comments);
|
||||
}
|
||||
|
||||
function triggerCopyModule(&$obj)
|
||||
{
|
||||
$oModuleModel = getModel('module');
|
||||
|
|
|
|||
14
modules/comment/queries/getCommentsByDocumentSrls.xml
Normal file
14
modules/comment/queries/getCommentsByDocumentSrls.xml
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<query id="getCommentsByDocumentSrls" action="select">
|
||||
<tables>
|
||||
<table name="comments" />
|
||||
</tables>
|
||||
<columns>
|
||||
<column name="*" />
|
||||
</columns>
|
||||
<conditions>
|
||||
<condition operation="in" column="document_srl" var="document_srls" filter="number" notnull="notnull" />
|
||||
</conditions>
|
||||
<navigation>
|
||||
<index var="sort_index" default="comment_srl" order="asc" />
|
||||
</navigation>
|
||||
</query>
|
||||
|
|
@ -43,344 +43,7 @@ class documentAdminController extends document
|
|||
|
||||
$this->setMessage(sprintf(lang('msg_checked_document_is_deleted'), $document_count) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Change the module to move a specific article
|
||||
* @param array $document_srl_list
|
||||
* @param int $target_module_srl
|
||||
* @param int $target_category_srl
|
||||
* @return Object
|
||||
*/
|
||||
function moveDocumentModule($document_srl_list, $target_module_srl, $target_category_srl)
|
||||
{
|
||||
if(empty($document_srl_list))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$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();
|
||||
|
||||
// Call a trigger (before)
|
||||
$output = ModuleHandler::triggerCall('document.moveDocumentModule', 'before', $obj);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
$origin_category = array();
|
||||
$oDocumentController = getController('document');
|
||||
|
||||
foreach($obj->document_list as $document)
|
||||
{
|
||||
// If the target module is different
|
||||
if($document->module_srl != $obj->module_srl)
|
||||
{
|
||||
$oDocumentController->deleteDocumentAliasByDocument($document->document_srl);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// Move a module of the article
|
||||
$output = executeQuery('document.updateDocumentsModule', $obj);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
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)
|
||||
ModuleHandler::triggerCall('document.moveDocumentModule', 'after', $obj);
|
||||
|
||||
// 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
|
||||
foreach ($document_srl_list as $document_srl)
|
||||
{
|
||||
Rhymix\Framework\Cache::delete('document_item:'. getNumberingPath($document_srl) . $document_srl);
|
||||
}
|
||||
|
||||
return new BaseObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the post
|
||||
* @param array $document_srl_list
|
||||
* @param int $module_srl
|
||||
* @param int $category_srl
|
||||
* @return object
|
||||
*/
|
||||
function copyDocumentModule($document_srl_list, $module_srl, $category_srl)
|
||||
{
|
||||
if(count($document_srl_list) < 1) return;
|
||||
|
||||
$oDocumentModel = getModel('document');
|
||||
$oDocumentController = getController('document');
|
||||
|
||||
$oFileModel = getModel('file');
|
||||
|
||||
$oDB = &DB::getInstance();
|
||||
$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)
|
||||
$output = ModuleHandler::triggerCall('document.copyDocumentModule', 'before', $triggerObj);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
$extraVarsList = $oDocumentModel->getDocumentExtraVarsFromDB($document_srl_list);
|
||||
$extraVarsListByDocumentSrl = array();
|
||||
if(is_array($extraVarsList->data))
|
||||
{
|
||||
foreach($extraVarsList->data as $value)
|
||||
{
|
||||
if(!isset($extraVarsListByDocumentSrl[$value->document_srl]))
|
||||
{
|
||||
$extraVarsListByDocumentSrl[$value->document_srl] = array();
|
||||
}
|
||||
|
||||
$extraVarsListByDocumentSrl[$value->document_srl][] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
|
||||
$obj = $oDocument->getObjectVars();
|
||||
|
||||
$extraVars = $extraVarsListByDocumentSrl[$document_srl];
|
||||
if($module_srl == $obj->module_srl)
|
||||
{
|
||||
if(is_array($extraVars))
|
||||
{
|
||||
foreach($extraVars as $extraItem)
|
||||
{
|
||||
if($extraItem->var_idx >= 0) $obj->{'extra_vars'.$extraItem->var_idx} = $extraItem->value;
|
||||
}
|
||||
}
|
||||
}
|
||||
$obj->module_srl = $module_srl;
|
||||
$obj->document_srl = getNextSequence();
|
||||
$obj->category_srl = $category_srl;
|
||||
$obj->password_is_hashed = true;
|
||||
$obj->comment_count = 0;
|
||||
$obj->trackback_count = 0;
|
||||
|
||||
// Pre-register the attachment
|
||||
if($oDocument->hasUploadedFiles())
|
||||
{
|
||||
$files = $oDocument->getUploadedFiles();
|
||||
foreach($files as $val)
|
||||
{
|
||||
$file_info = array();
|
||||
$file_info['tmp_name'] = $val->uploaded_filename;
|
||||
$file_info['name'] = $val->source_filename;
|
||||
$oFileController = getController('file');
|
||||
$inserted_file = $oFileController->insertFile($file_info, $module_srl, $obj->document_srl, 0, true);
|
||||
// if 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);
|
||||
// If binary file
|
||||
}
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Write a post
|
||||
$output = $oDocumentController->insertDocument($obj, true, true);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
// copy multi language contents
|
||||
if(is_array($extraVars))
|
||||
{
|
||||
foreach($extraVars as $value)
|
||||
{
|
||||
if($value->idx >= 0 && $value->lang_code == Context::getLangType())
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if( $value->var_idx < 0 || ($module_srl == $value->module_srl && $value->var_idx >= 0) )
|
||||
{
|
||||
$oDocumentController->insertDocumentExtraVar($value->module_srl, $obj->document_srl, $value->var_idx, $value->value, $value->eid, $value->lang_code);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Move the comments
|
||||
if($oDocument->getCommentCount())
|
||||
{
|
||||
$oCommentModel = getModel('comment');
|
||||
$comment_output = $oCommentModel->getCommentList($document_srl, 0, true, 99999999);
|
||||
$comments = $comment_output->data;
|
||||
if(count($comments) > 0)
|
||||
{
|
||||
$oCommentController = getController('comment');
|
||||
$success_count = 0;
|
||||
$p_comment_srl = array();
|
||||
foreach($comments as $comment_obj)
|
||||
{
|
||||
$comment_srl = getNextSequence();
|
||||
$p_comment_srl[$comment_obj->comment_srl] = $comment_srl;
|
||||
|
||||
// Pre-register the attachment
|
||||
if($comment_obj->uploaded_count)
|
||||
{
|
||||
$files = $oFileModel->getFiles($comment_obj->comment_srl, true);
|
||||
foreach($files as $val)
|
||||
{
|
||||
$file_info = array();
|
||||
$file_info['tmp_name'] = $val->uploaded_filename;
|
||||
$file_info['name'] = $val->source_filename;
|
||||
$oFileController = getController('file');
|
||||
$inserted_file = $oFileController->insertFile($file_info, $module_srl, $comment_srl, 0, true);
|
||||
// if image/video files
|
||||
if($val->direct_download == 'Y')
|
||||
{
|
||||
$source_filename = substr($val->uploaded_filename,2);
|
||||
$target_filename = substr($inserted_file->get('uploaded_filename'),2);
|
||||
$comment_obj->content = str_replace($source_filename, $target_filename, $comment_obj->content);
|
||||
// If binary file
|
||||
}
|
||||
else
|
||||
{
|
||||
$comment_obj->content = str_replace('file_srl='.$val->file_srl, 'file_srl='.$inserted_file->get('file_srl'), $comment_obj->content);
|
||||
$comment_obj->content = str_replace('sid='.$val->sid, 'sid='.$inserted_file->get('sid'), $comment_obj->content);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$comment_obj->module_srl = $obj->module_srl;
|
||||
$comment_obj->document_srl = $obj->document_srl;
|
||||
$comment_obj->comment_srl = $comment_srl;
|
||||
|
||||
if($comment_obj->parent_srl) $comment_obj->parent_srl = $p_comment_srl[$comment_obj->parent_srl];
|
||||
|
||||
$output = $oCommentController->insertComment($comment_obj, true);
|
||||
if($output->toBool()) $success_count ++;
|
||||
}
|
||||
$oDocumentController->updateCommentCount($obj->document_srl, $success_count, $comment_obj->nick_name, true);
|
||||
}
|
||||
}
|
||||
|
||||
// Move the trackbacks
|
||||
$oTrackbackModel = getModel('trackback');
|
||||
if($oTrackbackModel && $oDocument->getTrackbackCount())
|
||||
{
|
||||
$trackbacks = $oTrackbackModel->getTrackbackList($oDocument->document_srl);
|
||||
if(count($trackbacks))
|
||||
{
|
||||
$success_count = 0;
|
||||
foreach($trackbacks as $trackback_obj)
|
||||
{
|
||||
$trackback_obj->trackback_srl = getNextSequence();
|
||||
$trackback_obj->module_srl = $obj->module_srl;
|
||||
$trackback_obj->document_srl = $obj->document_srl;
|
||||
$output = executeQuery('trackback.insertTrackback', $trackback_obj);
|
||||
if($output->toBool()) $success_count++;
|
||||
}
|
||||
// Update the number of trackbacks
|
||||
$oDocumentController->updateTrackbackCount($obj->document_srl, $success_count);
|
||||
}
|
||||
}
|
||||
|
||||
$copied_srls[$document_srl] = $obj->document_srl;
|
||||
}
|
||||
|
||||
// Call a trigger (before)
|
||||
$triggerObj->copied_srls = $copied_srls;
|
||||
ModuleHandler::triggerCall('document.copyDocumentModule', 'after', $triggerObj);
|
||||
|
||||
$oDB->commit();
|
||||
|
||||
$output = new BaseObject();
|
||||
$output->add('copied_srls', $copied_srls);
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all documents of the module
|
||||
* @param int $module_srl
|
||||
* @return object
|
||||
*/
|
||||
function deleteModuleDocument($module_srl)
|
||||
{
|
||||
$args = new stdClass();
|
||||
$args->module_srl = $module_srl;
|
||||
$oDocumentModel = getModel('document');
|
||||
$args->module_srl = $module_srl;
|
||||
$document_list = $oDocumentModel->getDocumentList($args);
|
||||
$documents = $document_list->data;
|
||||
$output = executeQuery('document.deleteModuleDocument', $args);
|
||||
if(is_array($documents))
|
||||
{
|
||||
foreach ($documents as $oDocument)
|
||||
{
|
||||
$document_srl_list[] = $oDocument->document_srl;
|
||||
}
|
||||
}
|
||||
|
||||
//remove from cache
|
||||
foreach ($document_srl_list as $document_srl)
|
||||
{
|
||||
Rhymix\Framework\Cache::delete('document_item:'. getNumberingPath($document_srl) . $document_srl);
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Save the default settings of the document module
|
||||
* @return object
|
||||
|
|
@ -730,60 +393,222 @@ class documentAdminController extends document
|
|||
$trash_srl = Context::get('trash_srl');
|
||||
$this->restoreTrash($trash_srl);
|
||||
}
|
||||
|
||||
/*function restoreTrash($trash_srl){
|
||||
$oDB = &DB::getInstance();
|
||||
$oDocumentModel = getModel('document');
|
||||
|
||||
$trash_args->trash_srl = $trash_srl;
|
||||
|
||||
$output = executeQuery('document.getTrash', $trash_args);
|
||||
if (!$output->toBool()) {
|
||||
return $output;
|
||||
}
|
||||
|
||||
$document_args->document_srl = $output->data->document_srl;
|
||||
$document_args->module_srl = $output->data->module_srl;
|
||||
$document_args->member_srl = $output->data->member_srl;
|
||||
$document_args->ipaddress = $output->data->ipaddress;
|
||||
$document_args->update_order = $output->data->update_order;
|
||||
|
||||
$oDocument = $oDocumentModel->getDocument($document_args->document_srl);
|
||||
|
||||
// begin transaction
|
||||
$oDB->begin();
|
||||
|
||||
$output = executeQuery('document.updateDocument', $document_args);
|
||||
if (!$output->toBool()) {
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
|
||||
/**
|
||||
* Move module of the documents
|
||||
* @param array $document_srl_list
|
||||
* @param int $target_module_srl
|
||||
* @param int $target_category_srl
|
||||
* @return Object
|
||||
*/
|
||||
function moveDocumentModule($document_srl_list, $target_module_srl, $target_category_srl)
|
||||
{
|
||||
if(empty($document_srl_list))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$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();
|
||||
|
||||
// call a trigger (before)
|
||||
$output = ModuleHandler::triggerCall('document.moveDocumentModule', 'before', $obj);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
$origin_category = array();
|
||||
$oDocumentController = getController('document');
|
||||
|
||||
foreach($obj->document_list as $document)
|
||||
{
|
||||
// if the target module is different
|
||||
if($document->module_srl != $obj->module_srl)
|
||||
{
|
||||
$oDocumentController->deleteDocumentAliasByDocument($document->document_srl);
|
||||
}
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
// update documents
|
||||
$output = executeQuery('document.updateDocumentsModule', $obj);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
// update extra vars
|
||||
$output = executeQuery('document.updateDocumentExtraVarsModule', $obj);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
// call a trigger (after)
|
||||
ModuleHandler::triggerCall('document.moveDocumentModule', 'after', $obj);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
$oDB->commit();
|
||||
|
||||
// remove from cache
|
||||
foreach ($document_srl_list as $document_srl)
|
||||
{
|
||||
Rhymix\Framework\Cache::delete('document_item:'. getNumberingPath($document_srl) . $document_srl);
|
||||
}
|
||||
|
||||
return new BaseObject();
|
||||
}
|
||||
|
||||
$output = executeQuery('document.deleteTrash', $trash_args);
|
||||
if (!$output->toBool()) {
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
/**
|
||||
* Copy the documents
|
||||
* @param array $document_srl_list
|
||||
* @param int $target_module_srl
|
||||
* @param int $target_category_srl
|
||||
* @return object
|
||||
*/
|
||||
function copyDocumentModule($document_srl_list, $target_module_srl, $target_category_srl)
|
||||
{
|
||||
if(empty($document_srl_list))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$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();
|
||||
|
||||
// call a trigger (before)
|
||||
$output = ModuleHandler::triggerCall('document.copyDocumentModule', 'before', $obj);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
$oDocumentController = getController('document');
|
||||
$extra_vars_list = getModel('document')->getDocumentExtraVarsFromDB($document_srl_list)->data;
|
||||
|
||||
$extra_vars = array();
|
||||
foreach($extra_vars_list as $extra)
|
||||
{
|
||||
if(!isset($extra_vars[$extra->document_srl]))
|
||||
{
|
||||
$extra_vars[$extra->document_srl] = array();
|
||||
}
|
||||
|
||||
$extra_vars[$extra->document_srl][] = $extra;
|
||||
}
|
||||
|
||||
$copied_srls = array();
|
||||
foreach($obj->document_list as $document)
|
||||
{
|
||||
$copy = clone $document;
|
||||
$copy->document_srl = getNextSequence();
|
||||
$copy->module_srl = $obj->module_srl;
|
||||
$copy->category_srl = $obj->category_srl;
|
||||
$copy->comment_count = 0;
|
||||
$copy->trackback_count = 0;
|
||||
$copy->password_is_hashed = true;
|
||||
|
||||
// call a trigger (add)
|
||||
$args = new stdClass;
|
||||
$args->source = $document;
|
||||
$args->copied = $copy;
|
||||
ModuleHandler::triggerCall('document.copyDocumentModule', 'add', $args);
|
||||
|
||||
// insert a copied document
|
||||
$output = $oDocumentController->insertDocument($copy, true, true);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
// insert copied extra vars of the document
|
||||
if(isset($extra_vars[$document->document_srl]))
|
||||
{
|
||||
foreach($extra_vars[$document->document_srl] as $extra)
|
||||
{
|
||||
$oDocumentController->insertDocumentExtraVar($copy->module_srl, $copy->document_srl, $extra->var_idx, $extra->value, $extra->eid, $extra->lang_code);
|
||||
}
|
||||
}
|
||||
|
||||
$copied_srls[$document->document_srl] = $copy->document_srl;
|
||||
}
|
||||
|
||||
// call a trigger (after)
|
||||
$obj->copied_srls = $copied_srls;
|
||||
ModuleHandler::triggerCall('document.copyDocumentModule', 'after', $obj);
|
||||
|
||||
$oDB->commit();
|
||||
|
||||
// return copied document_srls
|
||||
$output = new BaseObject();
|
||||
$output->add('copied_srls', $copied_srls);
|
||||
return $output;
|
||||
}
|
||||
// If the post was not temorarily saved, set the attachment's status to be valid
|
||||
if($oDocument->hasUploadedFiles() && $document_args->member_srl != $document_args->module_srl) {
|
||||
$args->upload_target_srl = $oDocument->document_srl;
|
||||
$args->isvalid = 'Y';
|
||||
executeQuery('file.updateFileValid', $args);
|
||||
|
||||
/**
|
||||
* Delete all documents of the module
|
||||
* @param int $module_srl
|
||||
* @return object
|
||||
*/
|
||||
function deleteModuleDocument($module_srl)
|
||||
{
|
||||
$args = new stdClass;
|
||||
$args->page = 0;
|
||||
$args->module_srl = $module_srl;
|
||||
$document_list = executeQueryArray('document.getDocumentList', $args, array('document_srl'))->data;
|
||||
|
||||
// delete documents
|
||||
$output = executeQuery('document.deleteModuleDocument', $args);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
return $output;
|
||||
}
|
||||
|
||||
// remove from cache
|
||||
foreach ($document_list as $document)
|
||||
{
|
||||
Rhymix\Framework\Cache::delete('document_item:'. getNumberingPath($document->document_srl) . $document->document_srl);
|
||||
}
|
||||
|
||||
return new BaseObject();
|
||||
}
|
||||
// call a trigger (after)
|
||||
if($output->toBool()) {
|
||||
$trigger_output = ModuleHandler::triggerCall('document.restoreTrash', 'after', $document_args);
|
||||
if(!$trigger_output->toBool()) {
|
||||
$oDB->rollback();
|
||||
return $trigger_output;
|
||||
}
|
||||
}
|
||||
|
||||
// commit
|
||||
$oDB->commit();
|
||||
return $output;
|
||||
}*/
|
||||
|
||||
|
||||
/**
|
||||
* Restore document from trash module, called by trash module
|
||||
* This method is passived
|
||||
|
|
|
|||
|
|
@ -2904,7 +2904,7 @@ class documentController extends document
|
|||
$oDocument = getModel('document')->getDocument($file->upload_target_srl, false, false);
|
||||
if(!$oDocument->isExists())
|
||||
{
|
||||
return new BaseObject();
|
||||
return;
|
||||
}
|
||||
|
||||
$this->updateUploaedCount($file->upload_target_srl);
|
||||
|
|
|
|||
|
|
@ -29,25 +29,19 @@ class documentModel extends document
|
|||
{
|
||||
return $_SESSION['granted_document'][$document_srl];
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return document extra information from database
|
||||
* @param array $documentSrls
|
||||
* @param array $document_srls
|
||||
* @return object
|
||||
*/
|
||||
function getDocumentExtraVarsFromDB($documentSrls)
|
||||
function getDocumentExtraVarsFromDB($document_srls)
|
||||
{
|
||||
if(!is_array($documentSrls) || count($documentSrls) == 0)
|
||||
{
|
||||
return $this->setError('msg_invalid_request');
|
||||
}
|
||||
|
||||
$args = new stdClass();
|
||||
$args->document_srl = $documentSrls;
|
||||
$output = executeQueryArray('document.getDocumentExtraVars', $args);
|
||||
return $output;
|
||||
$args = new stdClass;
|
||||
$args->document_srl = $document_srls;
|
||||
return executeQueryArray('document.getDocumentExtraVars', $args);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Extra variables for each article will not be processed bulk select and apply the macro city
|
||||
* @return void
|
||||
|
|
|
|||
|
|
@ -78,7 +78,15 @@ class file extends ModuleObject
|
|||
|
||||
if(!$oDB->isColumnExists('files', 'cover_image')) return true;
|
||||
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'file', 'controller', 'triggeMoveDocumentModule', 'after'))
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'file', 'controller', 'triggerMoveDocument', 'after'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!$oModuleModel->getTrigger('document.copyDocumentModule', 'file', 'controller', 'triggerAddCopyDocument', 'add'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if(!$oModuleModel->getTrigger('comment.copyCommentByDocument', 'file', 'controller', 'triggerAddCopyCommentByDocument', 'add'))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
|
@ -146,9 +154,17 @@ class file extends ModuleObject
|
|||
|
||||
if(!$oDB->isColumnExists('files', 'cover_image')) $oDB->addColumn('files', 'cover_image', 'char', '1', 'N');
|
||||
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'file', 'controller', 'triggeMoveDocumentModule', 'after'))
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'file', 'controller', 'triggerMoveDocument', 'after'))
|
||||
{
|
||||
$oModuleController->insertTrigger('document.moveDocumentModule', 'file', 'controller', 'triggeMoveDocumentModule', 'after');
|
||||
$oModuleController->insertTrigger('document.moveDocumentModule', 'file', 'controller', 'triggerMoveDocument', 'after');
|
||||
}
|
||||
if(!$oModuleModel->getTrigger('document.copyDocumentModule', 'file', 'controller', 'triggerAddCopyDocument', 'add'))
|
||||
{
|
||||
$oModuleController->insertTrigger('document.copyDocumentModule', 'file', 'controller', 'triggerAddCopyDocument', 'add');
|
||||
}
|
||||
if(!$oModuleModel->getTrigger('comment.copyCommentByDocument', 'file', 'controller', 'triggerAddCopyCommentByDocument', 'add'))
|
||||
{
|
||||
$oModuleController->insertTrigger('comment.copyCommentByDocument', 'file', 'controller', 'triggerAddCopyCommentByDocument', 'add');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1095,7 +1095,47 @@ class fileController extends file
|
|||
executeQuery('file.updateFile', $args);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
function copyFile($source_file, $module_srl, $upload_target_srl, &$content = null)
|
||||
{
|
||||
$file_info = array();
|
||||
$file_info['name'] = $source_file->source_filename;
|
||||
$file_info['tmp_name'] = $source_file->uploaded_filename;
|
||||
$copied_file = $this->insertFile($file_info, $module_srl, $upload_target_srl, 0, true);
|
||||
|
||||
if($content)
|
||||
{
|
||||
// if image/video files
|
||||
if($source_file->direct_download == 'Y')
|
||||
{
|
||||
$source_filename = substr($source_file->uploaded_filename, 2);
|
||||
$copied_filename = substr($copied_file->get('uploaded_filename'), 2);
|
||||
$content = str_replace($source_filename, $copied_filename, $content);
|
||||
}
|
||||
// if binary file
|
||||
else
|
||||
{
|
||||
$content = str_replace('file_srl=' . $source_file->file_srl, 'file_srl=' . $copied_file->get('file_srl'), $content);
|
||||
$content = str_replace('sid=' . $source_file->sid, 'sid=' . $copied_file->get('sid'), $content);
|
||||
}
|
||||
}
|
||||
|
||||
return $copied_file;
|
||||
}
|
||||
|
||||
function copyFiles($source_file_list, $module_srl, $upload_target_srl, &$content = null)
|
||||
{
|
||||
if(!is_array($source_file_list))
|
||||
{
|
||||
$source_file_list = getModel('file')->getFiles($source_file_list, array(), 'file_srl', true);
|
||||
}
|
||||
|
||||
foreach($source_file_list as $source_file)
|
||||
{
|
||||
$this->copyFile($source_file, $module_srl, $upload_target_srl, $content);
|
||||
}
|
||||
}
|
||||
|
||||
public function procFileSetCoverImage()
|
||||
{
|
||||
$vars = Context::getRequestVars();
|
||||
|
|
@ -1123,8 +1163,8 @@ class fileController extends file
|
|||
$output = executeQuery('file.updateClearCoverImage', $args);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
if($file_info->cover_image != 'Y')
|
||||
|
|
@ -1162,13 +1202,33 @@ class fileController extends file
|
|||
return;
|
||||
}
|
||||
|
||||
function triggeMoveDocumentModule($obj)
|
||||
function triggerMoveDocument($obj)
|
||||
{
|
||||
$obj->upload_target_srls = $obj->document_srls;
|
||||
executeQuery('file.updateFileModule', $obj);
|
||||
executeQuery('file.updateFileModuleComment', $obj);
|
||||
}
|
||||
|
||||
function triggerAddCopyDocument(&$obj)
|
||||
{
|
||||
if(!$obj->source->uploaded_count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->copyFiles($obj->source->document_srl, $obj->copied->module_srl, $obj->copied->document_srl, $obj->copied->content);
|
||||
}
|
||||
|
||||
function triggerAddCopyCommentByDocument(&$obj)
|
||||
{
|
||||
if(!$obj->source->uploaded_count)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
$this->copyFiles($obj->source->comment_srl, $obj->copied->module_srl, $obj->copied->comment_srl, $obj->copied->content);
|
||||
}
|
||||
|
||||
function triggerCopyModule(&$obj)
|
||||
{
|
||||
$oModuleModel = getModel('module');
|
||||
|
|
|
|||
|
|
@ -43,7 +43,7 @@ class tag extends ModuleObject
|
|||
if(!$oModuleModel->getTrigger('module.deleteModule', 'tag', 'controller', 'triggerDeleteModuleTags', 'after')) return true;
|
||||
// tag in the index column of the table tag
|
||||
if(!$oDB->isIndexExists("tags","idx_tag")) return true;
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggeMoveDocumentModule', 'after')) return true;
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggerMoveDocument', 'after')) return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
@ -78,9 +78,9 @@ class tag extends ModuleObject
|
|||
if(!$oDB->isIndexExists("tags","idx_tag"))
|
||||
$oDB->addIndex("tags","idx_tag", array("document_srl","tag"));
|
||||
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggeMoveDocumentModule', 'after'))
|
||||
if(!$oModuleModel->getTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggerMoveDocument', 'after'))
|
||||
{
|
||||
$oModuleController->insertTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggeMoveDocumentModule', 'after');
|
||||
$oModuleController->insertTrigger('document.moveDocumentModule', 'tag', 'controller', 'triggerMoveDocument', 'after');
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ class tagController extends tag
|
|||
return $oTagController->deleteModuleTags($module_srl);
|
||||
}
|
||||
|
||||
function triggeMoveDocumentModule($obj)
|
||||
function triggerMoveDocument($obj)
|
||||
{
|
||||
executeQuery('tag.updateTagModule', $obj);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue