rhymix/modules/trash/trash.admin.controller.php
Kijin Sung 84e5542d77 Remove unnecessary use of BaseObject
- 트리거 등 반환값이 필요하지 않은 곳에서 new BaseObject()를 반환하는 것 삭제
- 모듈 설치, 업데이트 후 무의미한 new BaseObject()를 반환하는 것 삭제
- 사용자에게 에러 메시지를 돌려주는 용도로 new BaseObject(-1, '에러메시지')를
  사용하는 경우는 대부분 $this->setError()로 변경함. 언어 변환과 sprintf()
  처리까지 한 번에 이루어지므로 이쪽이 더 편리함.
2017-12-01 00:54:51 +09:00

237 lines
6.4 KiB
PHP

<?php
/* Copyright (C) NAVER <http://www.navercorp.com> */
/**
* trashAdminController class
* trash admin the module's controller class
*
* @author NAVER (developers@xpressengine.com)
* @package /modules/trash
* @version 0.1
*/
class trashAdminController extends trash
{
/**
* object insert to trash
* @param TrashVO $obj
* @return Object
*/
function insertTrash($obj)
{
$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($_SERVER['REMOTE_ADDR']);
$oTrashVO->setRemoverSrl($logged_info->member_srl);
$oTrashVO->setRegdate(date('YmdHis'));
return executeQuery('trash.insertTrash', $oTrashVO);
}
/**
* Empty trash
* @param array trashSrls
* @return Object
*/
function procTrashAdminEmptyTrash()
{
global $lang;
$isAll = Context::get('is_all');
$originModule = Context::get('origin_module');
$tmpTrashSrls = Context::get('cart');
$is_type = Context::get('is_type');
$trashSrls = array();
if($isAll != 'true')
{
if(is_array($tmpTrashSrls))
{
$trashSrls = $tmpTrashSrls;
}
else
{
$trashSrls = explode('|@|', $tmpTrashSrls);
}
}
//module relation data delete...
$output = $this->_relationDataDelete($isAll, $is_type, $trashSrls);
if(!$output->toBool()) return $this->setError($output->message);
if(!$this->_emptyTrash($trashSrls)) return $this->setError($lang->fail_empty);
$this->setMessage('success_deleted', 'info');
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispTrashAdminList', 'origin_module', $originModule);
$this->setRedirectUrl($returnUrl, $output);
}
/**
* Empty trash - private method
* @param string $isAll
* @param string $is_type
* @param array trashSrls
* @return Object
*/
function _relationDataDelete($isAll, $is_type, &$trashSrls)
{
$oTrashModel = getModel('trash');
if($isAll == 'true')
{
$args = new stdClass();
$args->originModule = $is_type;
$output = $oTrashModel->getTrashAllList($args);
if(!$output->toBool())
{
return $output;
}
if(is_array($output->data))
{
foreach($output->data as $value)
{
$trashSrls[] = $value->getTrashSrl();
}
}
}
else
{
$args = new stdClass();
$args->trashSrl = $trashSrls;
$output = $oTrashModel->getTrashList($args);
if(!$output->toBool())
{
return $output;
}
}
if(is_array($output->data))
{
foreach($output->data as $oTrashVO)
{
//class file check
$classPath = ModuleHandler::getModulePath($oTrashVO->getOriginModule());
if(!is_dir(FileHandler::getRealPath($classPath))) return $this->setError('not exist restore module directory');
$classFile = sprintf('%s%s.admin.controller.php', $classPath, $oTrashVO->getOriginModule());
$classFile = FileHandler::getRealPath($classFile);
if(!file_exists($classFile)) return $this->setError('not exist restore module class file');
$oAdminController = getAdminController($oTrashVO->getOriginModule());
if(!method_exists($oAdminController, 'emptyTrash')) return $this->setError('not exist restore method in module class file');
$output2 = $oAdminController->emptyTrash($oTrashVO->getSerializedObject());
if(!$output2->toBool()) return $output;
}
}
return new BaseObject(0, 'success_deleted');
}
/**
* Restore content object
* @return void|Object
*/
function procTrashAdminRestore()
{
global $lang;
$trashSrlList = Context::get('cart');
if(is_array($trashSrlList))
{
// begin transaction
$oDB = &DB::getInstance();
$oDB->begin();
// eache restore method call in each classfile
foreach($trashSrlList as $value)
{
$oTrashModel = getModel('trash');
$output = $oTrashModel->getTrash($value);
if(!$output->toBool()) return $output;
//class file check
$classPath = ModuleHandler::getModulePath($output->data->getOriginModule());
if(!is_dir(FileHandler::getRealPath($classPath))) return $this->setError('not exist restore module directory');
$classFile = sprintf('%s%s.admin.controller.php', $classPath, $output->data->getOriginModule());
$classFile = FileHandler::getRealPath($classFile);
if(!file_exists($classFile)) return $this->setError('not exist restore module class file');
$oAdminController = getAdminController($output->data->getOriginModule());
if(!method_exists($oAdminController, 'restoreTrash')) return $this->setError('not exist restore method in module class file');
$originObject = unserialize($output->data->getSerializedObject());
$output = $oAdminController->restoreTrash($originObject);
if(!$output->toBool())
{
$oDB->rollback();
return $output;
}
}
// restore object delete in trash box
if(!$this->_emptyTrash($trashSrlList)) {
$oDB->rollback();
return $this->setError($lang->fail_empty);
}
$oDB->commit();
}
$this->setMessage('success_restore', 'info');
$returnUrl = Context::get('success_return_url') ? Context::get('success_return_url') : getNotEncodedUrl('', 'module', 'admin', 'act', 'dispTrashAdminList');
$this->setRedirectUrl($returnUrl);
}
/**
* Set trash list to Context
* @return void|Object
*/
function procTrashAdminGetList()
{
if(!Context::get('is_logged')) return $this->setError('msg_not_permitted');
$trashSrls = Context::get('trash_srls');
if($trashSrls) $trashSrlList = explode(',', $trashSrls);
if(count($trashSrlList) > 0)
{
$oTrashModel = getModel('trash');
$args = new stdClass();
$args->trashSrl = $trashSrlList;
$output = $oTrashModel->getTrashList($args);
$trashList = $output->data;
}
else
{
global $lang;
$trashList = array();
$this->setMessage($lang->no_documents);
}
$oSecurity = new Security($trashList);
$oSecurity->encodeHTML('..');
$this->add('trash_list', $trashList);
}
/**
* empty trash
* @param array trashSrls
* @return bool
*/
function _emptyTrash($trashSrls)
{
if(!is_array($trashSrls)) return false;
$args = new stdClass();
$args->trashSrls = $trashSrls;
$output = executeQuery('trash.deleteTrash', $args);
if(!$output->toBool()) return false;
return true;
}
}
/* End of file trash.admin.controller.php */
/* Location: ./modules/trash/trash.admin.controller.php */