Replace $this->stop() with proper exceptions

This commit is contained in:
Kijin Sung 2018-09-06 00:19:47 +09:00
parent 5b7ce90a3d
commit d8a0773b97
26 changed files with 109 additions and 69 deletions

View file

@ -18,11 +18,9 @@ class adminAdminController extends admin
function init()
{
// forbit access if the user is not an administrator
$oMemberModel = getModel('member');
$logged_info = $oMemberModel->getLoggedInfo();
if($logged_info->is_admin != 'Y')
if (!$this->user->isAdmin())
{
return $this->stop("admin.msg_is_not_administrator");
throw new Rhymix\Framework\Exceptions\NotPermitted('admin.msg_is_not_administrator');
}
}

View file

@ -36,11 +36,9 @@ class adminAdminView extends admin
function init()
{
// forbit access if the user is not an administrator
$oMemberModel = getModel('member');
$logged_info = $oMemberModel->getLoggedInfo();
if($logged_info->is_admin != 'Y')
if (!$this->user->isAdmin())
{
return $this->stop("admin.msg_is_not_administrator");
throw new Rhymix\Framework\Exceptions\NotPermitted('admin.msg_is_not_administrator');
}
// change into administration layout

View file

@ -23,7 +23,7 @@ class adminloggingController extends adminlogging
$logged_info = $oMemberModel->getLoggedInfo();
if($logged_info->is_admin != 'Y')
{
return $this->stop("admin.msg_is_not_administrator");
throw new Rhymix\Framework\Exceptions\NotPermitted('admin.msg_is_not_administrator');
}
}

View file

@ -414,7 +414,7 @@ class autoinstallAdminView extends autoinstall
if(!$updateDate)
{
return $this->stop('msg_connection_fail');
throw new Rhymix\Framework\Exception('msg_connection_fail');
}
$oModel = getModel('autoinstall');
@ -535,13 +535,13 @@ class autoinstallAdminView extends autoinstall
if(!$type || $type == "core")
{
return $this->stop("msg_invalid_request");
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$config_file = $oModel->getConfigFilePath($type);
if(!$config_file)
{
return $this->stop("msg_invalid_request");
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$output = $oAdminModel->checkUseDirectModuleInstall($installedPackage);
@ -579,7 +579,7 @@ class autoinstallAdminView extends autoinstall
}
else
{
return $this->stop('msg_connection_fail');
throw new Rhymix\Framework\Exception('msg_connection_fail');
}
}

View file

@ -39,7 +39,10 @@ class boardAdminView extends board {
}
}
if($module_info && $module_info->module != 'board') return $this->stop("msg_invalid_request");
if($module_info && $module_info->module != 'board')
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// get the module category list
$module_category = $oModuleModel->getModuleCategories();

View file

@ -262,7 +262,7 @@ class boardView extends board
// if the module srl is not consistent
if($oDocument->get('module_srl')!=$this->module_info->module_srl )
{
return $this->stop('msg_invalid_request');
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// check the manage grant
@ -383,7 +383,11 @@ class boardView extends board
if(is_array($file_module_config->download_grant) && $downloadGrantCount>0)
{
if(!Context::get('is_logged')) return $this->stop('msg_not_permitted_download');
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted('msg_not_permitted_download');
}
$logged_info = Context::get('logged_info');
if($logged_info->is_admin != 'Y')
{
@ -406,7 +410,10 @@ class boardView extends board
break;
}
}
if(!$is_permitted) return $this->stop('msg_not_permitted_download');
if(!$is_permitted)
{
throw new Rhymix\Framework\Exceptions\NotPermitted('msg_not_permitted_download');
}
}
}
}

View file

@ -56,7 +56,7 @@ class commentAdminController extends comment
$cart = Context::get('cart');
if(!$cart)
{
return $this->stop('msg_cart_is_null');
throw new Rhymix\Framework\Exception('msg_cart_is_null');
}
if(!is_array($cart))
{
@ -171,7 +171,7 @@ class commentAdminController extends comment
$cart = Context::get('cart');
if(!$cart)
{
return $this->stop('msg_cart_is_null');
throw new Rhymix\Framework\Exception('msg_cart_is_null');
}
if(!is_array($cart))
{
@ -184,7 +184,7 @@ class commentAdminController extends comment
$comment_count = count($comment_srl_list);
if(!$comment_count)
{
return $this->stop('msg_cart_is_null');
throw new Rhymix\Framework\Exception('msg_cart_is_null');
}
$oCommentController = getController('comment');
@ -329,7 +329,7 @@ class commentAdminController extends comment
$oCommentController = getController('comment');
$oComment = $oCommentModel->getComment($comment_srl, false);
if(!$oComment->isGranted()) return $this->stop('msg_not_permitted');
if(!$oComment->isGranted()) throw new Rhymix\Framework\Exceptions\NotPermitted;
$message_content = "";
$this->_moveCommentToTrash(array($comment_srl), $oCommentController, $oDB, $message_content);

View file

@ -27,10 +27,10 @@ class documentAdminController extends document
{
// error appears if no doc is selected
$cart = Context::get('cart');
if(!$cart) return $this->stop('msg_cart_is_null');
if(!$cart) throw new Rhymix\Framework\Exception('msg_cart_is_null');
$document_srl_list= explode('|@|', $cart);
$document_count = count($document_srl_list);
if(!$document_count) return $this->stop('msg_cart_is_null');
if(!$document_count) throw new Rhymix\Framework\Exception('msg_cart_is_null');
// Delete a doc
$oDocumentController = getController('document');
for($i=0;$i<$document_count;$i++)
@ -314,7 +314,10 @@ class documentAdminController extends document
$oDocumentModel = getModel('document');
$oDocumentController = getController('document');
$oDocument = $oDocumentModel->getDocument($document_srl, false, false);
if(!$oDocument->isGranted()) return $this->stop('msg_not_permitted');
if(!$oDocument->isGranted())
{
throw new Rhymix\Framework\Exceptions\NotPermitted;
}
$oMemberModel = getModel('member');
$member_info = $oMemberModel->getMemberInfoByMemberSrl($oDocument->get('member_srl'));

View file

@ -172,7 +172,10 @@ class documentView extends document
$oMemberModel = getModel('member');
// A message appears if the user is not logged-in
if(!$oMemberModel->isLogged()) return $this->stop('msg_not_logged');
if(!$oMemberModel->isLogged())
{
throw new Rhymix\Framework\Exceptions\MustLogin;
}
// Get the saved document (module_srl is set to member_srl instead)
$logged_info = Context::get('logged_info');
$args = new stdClass();

View file

@ -106,9 +106,9 @@ class editorAdminView extends editor
$oEditorModel = getModel('editor');
$component = $oEditorModel->getComponent($component_name,$site_srl);
if(!$component->component_name) {
$this->stop('msg_invalid_request');
return;
if(!$component->component_name)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
Context::set('component', $component);

View file

@ -97,9 +97,9 @@ class editorView extends editor
$oEditorModel = getModel('editor');
$component = $oEditorModel->getComponent($component_name, $site_srl);
if(!$component->component_name) {
$this->stop('msg_invalid_request');
return;
if(!$component->component_name)
{
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
Context::set('component', $component);

View file

@ -32,11 +32,11 @@ class fileAdminController extends file
{
// An error appears if no document is selected
$cart = Context::get('cart');
if(!$cart) return $this->stop('msg_file_cart_is_null');
if(!$cart) throw new Rhymix\Framework\Exception('msg_file_cart_is_null');
if(!is_array($cart)) $file_srl_list= explode('|@|', $cart);
else $file_srl_list = $cart;
$file_count = count($file_srl_list);
if(!$file_count) return $this->stop('msg_file_cart_is_null');
if(!$file_count) throw new Rhymix\Framework\Exception('msg_file_cart_is_null');
$oFileController = getController('file');
// Delete the post

View file

@ -145,7 +145,10 @@ class fileController extends file
$this->add('upload_target_srl', $output->get('upload_target_srl'));
$this->add('download_url', $oFileModel->getDirectFileUrl($output->get('uploaded_filename')));
if($output->error != '0') $this->stop($output->message);
if($output->error != '0')
{
throw new Rhymix\Framework\Exception($output->message);
}
}
/**
@ -283,9 +286,15 @@ class fileController extends file
$columnList = array('file_srl', 'sid', 'isvalid', 'source_filename', 'module_srl', 'uploaded_filename', 'file_size', 'member_srl', 'upload_target_srl', 'upload_target_type');
$file_obj = $oFileModel->getFile($file_srl, $columnList);
// If the requested file information is incorrect, an error that file cannot be found appears
if($file_obj->file_srl!=$file_srl || $file_obj->sid!=$sid) return $this->stop('msg_file_not_found');
if($file_obj->file_srl != $file_srl || $file_obj->sid !== $sid)
{
throw new Rhymix\Framework\Exceptions\TargetNotFound('msg_file_not_found');
}
// Notify that file download is not allowed when standing-by(Only a top-administrator is permitted)
if($logged_info->is_admin != 'Y' && $file_obj->isvalid!='Y') return $this->stop('msg_not_permitted_download');
if($logged_info->is_admin != 'Y' && $file_obj->isvalid != 'Y')
{
throw new Rhymix\Framework\Exceptions\NotPermitted('msg_not_permitted_download');
}
// File name
$filename = $file_obj->source_filename;
$file_module_config = $oFileModel->getFileModuleConfig($file_obj->module_srl);
@ -334,7 +343,10 @@ class fileController extends file
}
else $file_module_config->allow_outlink = 'Y';
}
if($file_module_config->allow_outlink != 'Y') return $this->stop('msg_not_allowed_outlink');
if($file_module_config->allow_outlink != 'Y')
{
throw new Rhymix\Framework\Exceptions\NotPermitted('msg_not_allowed_outlink');
}
}
// Check if a permission for file download is granted
@ -347,7 +359,11 @@ class fileController extends file
if(is_array($file_module_config->download_grant) && $downloadGrantCount>0)
{
if(!Context::get('is_logged')) return $this->stop('msg_not_permitted_download');
if(!Context::get('is_logged'))
{
throw new Rhymix\Framework\Exceptions\NotPermitted('msg_not_permitted_download');
}
$logged_info = Context::get('logged_info');
if($logged_info->is_admin != 'Y')
{
@ -370,14 +386,27 @@ class fileController extends file
break;
}
}
if(!$is_permitted) return $this->stop('msg_not_permitted_download');
if(!$is_permitted)
{
throw new Rhymix\Framework\Exceptions\NotPermitted('msg_not_permitted_download');
}
}
}
}
// Call a trigger (before)
$output = ModuleHandler::triggerCall('file.downloadFile', 'before', $file_obj);
if(!$output->toBool()) return $this->stop(($output->message)?$output->message:'msg_not_permitted_download');
if(!$output->toBool())
{
if ($output->message)
{
throw new Rhymix\Framework\Exception($output->message);
}
else
{
throw new Rhymix\Framework\Exceptions\NotPermitted('msg_not_permitted_download');
}
}
// Increase download_count
$args = new stdClass();
@ -416,20 +445,20 @@ class fileController extends file
// Check file key
if(strlen($file_key) != 32 || !isset($_SESSION['__XE_FILE_KEY__']) || !is_string($_SESSION['__XE_FILE_KEY__']))
{
return $this->stop('msg_invalid_request');
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$file_key_data = $file_srl . $file_obj->file_size . $file_obj->uploaded_filename . $_SERVER['REMOTE_ADDR'];
$file_key_compare = substr(hash_hmac('sha256', $file_key_data, $_SESSION['__XE_FILE_KEY__']), 0, 32);
if($file_key !== $file_key_compare)
{
return $this->stop('msg_invalid_request');
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Check if file exists
$uploaded_filename = $file_obj->uploaded_filename;
if(!file_exists($uploaded_filename))
{
return $this->stop('msg_file_not_found');
throw new Rhymix\Framework\Exceptions\TargetNotFound('msg_file_not_found');
}
// If client sent an If-None-Match header with the correct ETag, do not download again
@ -456,7 +485,7 @@ class fileController extends file
$fp = fopen($uploaded_filename, 'rb');
if(!$fp)
{
return $this->stop('msg_file_not_found');
throw new Rhymix\Framework\Exceptions\TargetNotFound('msg_file_not_found');
}
// Take care of pause and resume
@ -842,7 +871,7 @@ class fileController extends file
if(!in_array($uploaded_ext, $ext))
{
return $this->stop('msg_not_allowed_filetype');
throw new Rhymix\Framework\Exception('msg_not_allowed_filetype');
}
}

View file

@ -17,7 +17,7 @@ class installController extends install
// Stop if already installed.
if (Context::isInstalled())
{
$this->stop('msg_already_installed');
throw new Rhymix\Framework\Exception('msg_already_installed');
}
// Increase time limit.

View file

@ -19,7 +19,7 @@ class installView extends install
// Stop if already installed.
if (Context::isInstalled())
{
return $this->stop('msg_already_installed');
throw new Rhymix\Framework\Exception('msg_already_installed');
}
// Set the browser title.

View file

@ -104,7 +104,7 @@ class krzipModel extends krzip
$query = trim(strval($query));
if($query === '')
{
return $this->stop('msg_krzip_no_query');
return $this->setError('msg_krzip_no_query');
}
$output = $this->getEpostapiSearch($query);

View file

@ -23,7 +23,7 @@ class layoutAdminController extends layout
*/
function procLayoutAdminInsert()
{
if(Context::get('layout') == 'faceoff') return $this->stop('not supported');
if(Context::get('layout') == 'faceoff') throw new Rhymix\Framework\Exception('not supported');
// Get information to create a layout
$site_module_info = Context::get('site_module_info');
@ -683,7 +683,7 @@ class layoutAdminController extends layout
*/
function procLayoutAdminUserLayoutImport()
{
return $this->stop('not supported');
throw new Rhymix\Framework\Exception('not supported');
// check upload
if(!Context::isUploaded()) exit();
@ -713,12 +713,12 @@ class layoutAdminController extends layout
$sourceArgs = Context::getRequestVars();
if($sourceArgs->layout == 'faceoff')
{
return $this->stop('not supported');
throw new Rhymix\Framework\Exception('not supported');
}
if(!$sourceArgs->layout_srl)
{
return $this->stop('msg_empty_origin_layout');
throw new Rhymix\Framework\Exception('msg_empty_origin_layout');
}
$oLayoutModel = getModel('layout');
@ -731,7 +731,7 @@ class layoutAdminController extends layout
if(!is_array($sourceArgs->title) || count($sourceArgs->title) == 0)
{
return $this->stop('msg_empty_target_layout');
throw new Rhymix\Framework\Exception('msg_empty_target_layout');
}
$output = $oLayoutModel->getLayoutRawData($sourceArgs->layout_srl, array('extra_vars'));

View file

@ -67,7 +67,7 @@ class layoutAdminModel extends layout
// Error appears if there is no layout information is registered
if(!$layout_info)
{
return $this->stop('msg_invalid_request');
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
// Get a menu list

View file

@ -140,11 +140,11 @@ class layoutAdminView extends layout
$layout = Context::get('layout');
if(!in_array($type, array('P', 'M'))) $type = 'P';
if(!$layout) return $this->stop('msg_invalid_request');
if(!$layout) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$oLayoutModel = getModel('layout');
$layout_info = $oLayoutModel->getLayoutInfo($layout, null, $type);
if(!$layout_info) return $this->stop('msg_invalid_request');
if(!$layout_info) throw new Rhymix\Framework\Exceptions\InvalidRequest;
Context::set('layout_info', $layout_info);
@ -175,10 +175,10 @@ class layoutAdminView extends layout
// Get layout info
$layout = Context::get('layout');
if($layout == 'faceoff') return $this->stop('not supported');
if($layout == 'faceoff') throw new Rhymix\Framework\Exception('not supported');
$layout_info = $oModel->getLayoutInfo($layout, null, $type);
if(!$layout_info) return $this->stop('msg_invalid_request');
if(!$layout_info) throw new Rhymix\Framework\Exceptions\InvalidRequest;
// get Menu list
$oMenuAdminModel = getAdminModel('menu');

View file

@ -867,7 +867,7 @@ class menuAdminController extends menu
$oAdmin = getClass('admin');
if($menu_title == $oAdmin->getAdminMenuName() && $itemInfo->parent_srl == 0)
{
return $this->stop('msg_cannot_delete_for_admin_topmenu');
return new BaseObject(-1002, 'msg_cannot_delete_for_admin_topmenu');
}
if($itemInfo->parent_srl) $parent_srl = $itemInfo->parent_srl;
@ -892,7 +892,7 @@ class menuAdminController extends menu
$this->_checkHomeMenuInOriginMenu($originMenu, $siteInfo->mid, $isStartmenuInclude);
if($isStartmenuInclude)
{
throw new Rhymix\Framework\Exception('msg_cannot_delete_homemenu');
return new BaseObject(-1003, 'msg_cannot_delete_homemenu');
}
$oDB = DB::getInstance();

View file

@ -267,8 +267,7 @@ class moduleModel extends module
if(!$menuItemSrl)
{
$this->stop(-1, 'msg_invalid_request');
return;
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
$args = new stdClass();

View file

@ -25,10 +25,10 @@ class moduleView extends module
$skin = Context::get('skin');
// Get modules/skin information
$module_path = sprintf("./modules/%s/", $selected_module);
if(!is_dir($module_path)) $this->stop("msg_invalid_request");
if(!is_dir($module_path)) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$skin_info_xml = sprintf("%sskins/%s/skin.xml", $module_path, $skin);
if(!file_exists($skin_info_xml)) $this->stop("msg_invalid_request");
if(!file_exists($skin_info_xml)) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$oModuleModel = getModel('module');
$skin_info = $oModuleModel->loadSkinInfo($module_path, $skin);

View file

@ -163,7 +163,7 @@ class pageAdminView extends page
{
if($this->module_info->page_type == 'OUTSIDE')
{
return $this->stop(-1, 'msg_invalid_request');
throw new Rhymix\Framework\Exceptions\InvalidRequest;
}
if($this->module_srl)

View file

@ -44,7 +44,7 @@ class pollAdminController extends poll
else $poll_srl_list= explode('|@|', $cart);
$poll_count = count($poll_srl_list);
if(!$poll_count) return $this->stop('msg_cart_is_null');
if(!$poll_count) throw new Rhymix\Framework\Exception('msg_cart_is_null');
// Delete the post
for($i=0;$i<$poll_count;$i++)
{

View file

@ -139,7 +139,7 @@ class pollAdminView extends poll
$args->poll_index_srl = Context::get('poll_index_srl');
$output = executeQuery('poll.getPoll', $args);
if(!$output->data) return $this->stop('msg_poll_not_exists');
if(!$output->data) throw new Rhymix\Framework\Exception('msg_poll_not_exists');
$poll = new stdClass();
$poll->stop_date = $output->data->stop_date;
@ -148,7 +148,7 @@ class pollAdminView extends poll
$output = executeQuery('poll.getPollTitle', $args);
if(!$output->data)
{
return $this->stop('msg_poll_not_exists');
throw new Rhymix\Framework\Exception('msg_poll_not_exists');
}
$tmp = &$poll->poll[$args->poll_index_srl];

View file

@ -59,7 +59,7 @@ class widgetAdminView extends widget
function dispWidgetAdminAddContent()
{
$module_srl = Context::get('module_srl');
if(!$module_srl) return $this->stop("msg_invalid_request");
if(!$module_srl) throw new Rhymix\Framework\Exceptions\InvalidRequest;
$document_srl = Context::get('document_srl');
$oDocumentModel = getModel('document');