mirror of
https://github.com/Lastorder-DC/rhymix.git
synced 2026-01-04 01:01:41 +09:00
Clean up trash handling logic
This commit is contained in:
parent
10123a86a8
commit
565cfad15f
4 changed files with 25 additions and 61 deletions
|
|
@ -1365,16 +1365,16 @@ class CommentController extends Comment
|
|||
}
|
||||
}
|
||||
|
||||
$oDB = DB::getInstance();
|
||||
$oDB->begin();
|
||||
|
||||
require_once(RX_BASEDIR.'modules/trash/model/TrashVO.php');
|
||||
$oTrashVO = new TrashVO();
|
||||
$oTrashVO->setTrashSrl(getNextSequence());
|
||||
$oTrashVO->setTitle(mb_substr($oComment->getContentText(100), 0, 250, 'UTF-8'));
|
||||
$oTrashVO->setOriginModule('comment');
|
||||
$oTrashVO->setSerializedObject(serialize($oComment->variables));
|
||||
$oTrashVO->setDescription($obj->description);
|
||||
$oTrashVO->setDescription($obj->description ?? '');
|
||||
|
||||
$oDB = DB::getInstance();
|
||||
$oDB->begin();
|
||||
|
||||
$oTrashAdminController = getAdminController('trash');
|
||||
$output = $oTrashAdminController->insertTrash($oTrashVO);
|
||||
|
|
@ -1437,7 +1437,6 @@ class CommentController extends Comment
|
|||
Rhymix\Framework\Storage::deleteDirectory(RX_BASEDIR . sprintf('files/thumbnails/%s', getNumberingPath($obj->comment_srl, 3)));
|
||||
|
||||
$output->add('document_srl', $oComment->document_srl);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1362,11 +1362,7 @@ class DocumentController extends Document
|
|||
*/
|
||||
function moveDocumentToTrash($obj)
|
||||
{
|
||||
$trash_args = new stdClass();
|
||||
// Get trash_srl if a given trash_srl doesn't exist
|
||||
if(!$obj->trash_srl) $trash_args->trash_srl = getNextSequence();
|
||||
else $trash_args->trash_srl = $obj->trash_srl;
|
||||
// Get its module_srl which the document belongs to
|
||||
// Check the document and grants
|
||||
$oDocument = DocumentModel::getDocument($obj->document_srl);
|
||||
if(!$oDocument->isExists())
|
||||
{
|
||||
|
|
@ -1384,48 +1380,23 @@ class DocumentController extends Document
|
|||
return new BaseObject(-1, 'msg_admin_document_no_move_to_trash');
|
||||
}
|
||||
}
|
||||
|
||||
$trash_args->module_srl = $oDocument->get('module_srl');
|
||||
$obj->module_srl = $oDocument->get('module_srl');
|
||||
// Cannot throw data from the trash to the trash
|
||||
if($trash_args->module_srl == 0)
|
||||
if($oDocument->get('module_srl') == 0)
|
||||
{
|
||||
return new BaseObject(-1, 'Cannot throw data from the trash to the trash');
|
||||
}
|
||||
// Data setting
|
||||
$trash_args->document_srl = $obj->document_srl;
|
||||
$trash_args->description = $obj->description;
|
||||
// Insert member's information only if the member is logged-in and not manually registered.
|
||||
if($this->user->isMember())
|
||||
{
|
||||
$trash_args->member_srl = $this->user->member_srl;
|
||||
$trash_args->user_id = htmlspecialchars_decode($this->user->user_id);
|
||||
$trash_args->user_name = htmlspecialchars_decode($this->user->user_name);
|
||||
$trash_args->nick_name = htmlspecialchars_decode($this->user->nick_name);
|
||||
}
|
||||
// Date setting for updating documents
|
||||
$document_args = new stdClass;
|
||||
$document_args->module_srl = 0;
|
||||
$document_args->document_srl = $obj->document_srl;
|
||||
|
||||
// begin transaction
|
||||
$oDB = DB::getInstance();
|
||||
$oDB->begin();
|
||||
|
||||
/*$output = executeQuery('document.insertTrash', $trash_args);
|
||||
if (!$output->toBool()) {
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}*/
|
||||
|
||||
// new trash module
|
||||
// Create trash object.
|
||||
require_once(RX_BASEDIR.'modules/trash/model/TrashVO.php');
|
||||
$oTrashVO = new TrashVO();
|
||||
$oTrashVO->setTrashSrl(getNextSequence());
|
||||
$oTrashVO->setTitle($oDocument->variables['title']);
|
||||
$oTrashVO->setOriginModule('document');
|
||||
$oTrashVO->setSerializedObject(serialize($oDocument->variables));
|
||||
$oTrashVO->setDescription($obj->description);
|
||||
$oTrashVO->setDescription($obj->description ?? '');
|
||||
|
||||
// begin transaction
|
||||
$oDB = DB::getInstance();
|
||||
$oDB->begin();
|
||||
|
||||
$oTrashAdminController = getAdminController('trash');
|
||||
$output = $oTrashAdminController->insertTrash($oTrashVO);
|
||||
|
|
@ -1435,24 +1406,18 @@ class DocumentController extends Document
|
|||
return $output;
|
||||
}
|
||||
|
||||
$output = executeQuery('document.deleteDocument', $trash_args);
|
||||
$output = executeQuery('document.deleteDocument', ['document_srl' => $oDocument->document_srl]);
|
||||
if(!$output->toBool())
|
||||
{
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/*$output = executeQuery('document.updateDocument', $document_args);
|
||||
if (!$output->toBool()) {
|
||||
$oDB->rollback();
|
||||
return $output;
|
||||
}*/
|
||||
|
||||
// update category
|
||||
if($oDocument->get('category_srl')) $this->updateCategoryCount($oDocument->get('module_srl'),$oDocument->get('category_srl'));
|
||||
|
||||
// remove thumbnails
|
||||
Rhymix\Framework\Storage::deleteDirectory(RX_BASEDIR . sprintf('files/thumbnails/%s', getNumberingPath($obj->document_srl, 3)));
|
||||
if ($oDocument->get('category_srl'))
|
||||
{
|
||||
$this->updateCategoryCount($oDocument->get('module_srl'), $oDocument->get('category_srl'));
|
||||
}
|
||||
|
||||
// Set the attachment to be invalid state
|
||||
if($oDocument->hasUploadedFiles())
|
||||
|
|
@ -1474,6 +1439,9 @@ class DocumentController extends Document
|
|||
// commit
|
||||
$oDB->commit();
|
||||
|
||||
// remove thumbnails
|
||||
Rhymix\Framework\Storage::deleteDirectory(RX_BASEDIR . sprintf('files/thumbnails/%s', getNumberingPath($obj->document_srl, 3)));
|
||||
|
||||
// Clear cache
|
||||
self::clearDocumentCache($oDocument->document_srl);
|
||||
return $output;
|
||||
|
|
|
|||
|
|
@ -24,8 +24,8 @@ class TrashVO
|
|||
}
|
||||
function getTitle()
|
||||
{
|
||||
if(empty($this->title)) return $lang->untitle;
|
||||
return htmlspecialchars($this->title, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
|
||||
if(empty($this->title)) return lang('untitle');
|
||||
return escape($this->title, false);
|
||||
}
|
||||
function setTitle($title)
|
||||
{
|
||||
|
|
@ -90,7 +90,7 @@ class TrashVO
|
|||
}
|
||||
function getNickName()
|
||||
{
|
||||
return htmlspecialchars($this->nickName, ENT_COMPAT | ENT_HTML401, 'UTF-8', false);
|
||||
return escape($this->nickName, false);
|
||||
}
|
||||
function setNickName($nickName)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,16 +12,13 @@ class trashAdminController extends trash
|
|||
{
|
||||
/**
|
||||
* object insert to trash
|
||||
* @param TrashVO $obj
|
||||
* @param TrashVO $oTrashVO
|
||||
* @return Object
|
||||
*/
|
||||
function insertTrash($obj)
|
||||
function insertTrash($oTrashVO)
|
||||
{
|
||||
$logged_info = Context::get('logged_info');
|
||||
|
||||
$oTrashVO = new TrashVO();
|
||||
$oTrashVO = &$obj;
|
||||
|
||||
if(!$oTrashVO->getTrashSrl()) $oTrashVO->setTrashSrl(getNextSequence());
|
||||
if(!is_string($oTrashVO->getSerializedObject())) $oTrashVO->setSerializedObject(serialize($oTrashVO->getSerializedObject()));
|
||||
$oTrashVO->setIpaddress(\RX_CLIENT_IP);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue