Improved exception handling and other minor fixes

This commit is contained in:
Deon George 2013-05-10 00:42:54 +10:00
parent ce17247db6
commit 970b2ef4f0
11 changed files with 45 additions and 75 deletions

View File

@ -172,10 +172,7 @@ class Config extends Kohana_Config {
public static function theme() { public static function theme() {
// If we are using user admin pages (and login), we'll choose the admin theme. // If we are using user admin pages (and login), we'll choose the admin theme.
if (Request::current() AND (! empty(URL::$method_directory[strtolower(Request::current()->directory())]) OR in_array(strtolower(Request::current()->controller()),array('login')))) return URL::admin_url() ? 'theme/'.Kohana::$config->load('config')->theme_admin : 'theme/'.Kohana::$config->load('config')->theme;
return 'theme/'.Kohana::$config->load('config')->theme_admin;
else
return 'theme/'.Kohana::$config->load('config')->theme;
} }
public static function time($date) { public static function time($date) {

View File

@ -21,12 +21,12 @@ class Controller_User_Search extends Controller_Search {
$result = array(); $result = array();
if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) { if (isset($_REQUEST['term']) AND trim($_REQUEST['term'])) {
$result = array_merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'url','id',array('ACC %s: %s'=>array('id','name(TRUE)')),array(),array('urlprefix'=>'a/service/list/'))); $result = Arr::merge($result,ORM::factory('Account')->list_autocomplete($_REQUEST['term'],'url','id',array('ACC %s: %s'=>array('id','name(TRUE)')),array(),array('urlprefix'=>'a/service/list/')));
$result = array_merge($result,ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'url','id',array('INV %s: %s'=>array('id','account->name(TRUE)')),array(),array('urlprefix'=>'u/invoice/view/'))); $result = Arr::merge($result,ORM::factory('Invoice')->list_autocomplete($_REQUEST['term'],'url','id',array('INV %s: %s'=>array('id','account->name(TRUE)')),array(),array('urlprefix'=>'u/invoice/view/')));
$result = array_merge($result,ORM::factory('Service')->list_autocomplete($_REQUEST['term'],'url','id',array('SVC %s: %s'=>array('id','service_name()')),array(),array('urlprefix'=>'u/service/view/'))); $result = Arr::merge($result,ORM::factory('Service')->list_autocomplete($_REQUEST['term'],'url','id',array('SVC %s: %s'=>array('id','service_name()')),array(),array('urlprefix'=>'u/service/view/')));
foreach (array('Service_Plugin_Adsl','Service_Plugin_Domain','Service_Plugin_Host') as $o) foreach (array('Service_Plugin_Adsl','Service_Plugin_Domain','Service_Plugin_Host') as $o)
$result = array_merge($result,ORM::factory($o)->list_autocomplete($_REQUEST['term'],'url','service_id',array('SVC %s: %s'=>array('service_id','service_name()')),array(),array('urlprefix'=>'u/service/view/'))); $result = Arr::merge($result,ORM::factory($o)->list_autocomplete($_REQUEST['term'],'url','service_id',array('SVC %s: %s'=>array('service_id','service_name()')),array(),array('urlprefix'=>'u/service/view/')));
} }
$this->auto_render = FALSE; $this->auto_render = FALSE;

View File

@ -0,0 +1,15 @@
<?php defined('SYSPATH') or die('No direct access allowed.');
/**
* This class overrides Kohana's 403 Exception
*
* @package OSB
* @category Exceptions
* @author Deon George
* @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html
*/
class HTTP_Exception_403 extends HTTP_Exception {
protected $_code = 403;
}
?>

View File

@ -9,17 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing * @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class HTTP_Exception_404 extends Kohana_HTTP_Exception_404 { class HTTP_Exception_404 extends HTTP_Exception {
public function get_response() { protected $_code = 404;
$response = Response::factory();
$response->status($this->_code);
$view = View::factory('errors/404');
$view->message = $this->getMessage();
$response->body($view->render());
return $response;
}
} }
?> ?>

View File

@ -1,7 +1,7 @@
<?php defined('SYSPATH') or die('No direct access allowed.'); <?php defined('SYSPATH') or die('No direct access allowed.');
/** /**
* This class provides a custom 501 Exception to catch OSB specific errors. * This class overrides Kohana's 501 Exception to catch OSB specific errors
* *
* @package OSB * @package OSB
* @category Exceptions * @category Exceptions
@ -9,26 +9,7 @@
* @copyright (c) 2009-2013 Open Source Billing * @copyright (c) 2009-2013 Open Source Billing
* @license http://dev.osbill.net/license.html * @license http://dev.osbill.net/license.html
*/ */
class HTTP_Exception_501 extends Kohana_HTTP_Exception { class HTTP_Exception_501 extends HTTP_Exception {
protected $_code = 501; protected $_code = 501;
public function __construct($message='',array $variables=NULL,$code=0) {
parent::__construct($message,$variables,$code);
$response = Response::factory();
$response->status($this->_code);
// @todo This is not working as cleanly as I would like - ie: we shouldnt need to publish the headers ourselves?
header(':', true, 501);
if (Kohana::$config->load('debug')->show_errors)
$response->body(View::factory('errors/501')->set('message',$this->getMessage())->render());
else
$response->body('Dang, something went wrong, tell us how we got here...');
echo $response->render();
exit (501);
}
} }
?> ?>

View File

@ -27,7 +27,7 @@ class Model_RTM extends ORM_OSB {
$result = array(); $result = array();
foreach ($rtmo->agents_direct() as $artmo) foreach ($rtmo->agents_direct() as $artmo)
$result = $result+$rtmo->customers($artmo); $result = Arr::merge($result,$rtmo->customers($artmo));
foreach ($rtmo->customers_direct() as $ao) foreach ($rtmo->customers_direct() as $ao)
array_push($result,$ao); array_push($result,$ao);

View File

@ -18,6 +18,10 @@ class URL extends Kohana_URL {
'task'=>'task', 'task'=>'task',
); );
public static function admin_url() {
return (Request::current() AND ((Auth::instance()->logged_in() AND ! empty(URL::$method_directory[strtolower(Request::current()->directory())])) OR in_array(strtolower(Request::current()->controller()),array('login'))));
}
/** /**
* Wrapper to provide a URL::site() link based on function * Wrapper to provide a URL::site() link based on function
*/ */

View File

@ -0,0 +1,5 @@
<h1>Oops!</h1>
<h2>403 Not Found or Not Authorised?</h2>
<div class="error-details">
Sorry, either the item doesnt exist, or you are not authorised to see it.
</div>

View File

@ -1,27 +1,5 @@
<?php
Style::factory()
->type('file')
->data('media/css/pages/error.css');
echo View::factory('theme/focusbusiness/page')
->set('meta',new Meta)
->set('navbar','')
->set('content','
<div class="container">
<div class="row">
<div class="span8">
<div class="error-container">
<h1>Oops!</h1> <h1>Oops!</h1>
<h2>404 Not Found?</h2> <h2>404 Not Found?</h2>
<div class="error-details"> <div class="error-details">
Sorry, an error has occured, requested page not found? Sorry, an error has occured, requested page not found?
</div> </div>
<div class="error-actions">
'.HTML::anchor('/','<i class="icon-chevron-left"></i> Back to Home',array('class'=>'btn btn-large btn-primary')).'
</div>
</div>
</div>
</div>
</div>
');
?>

View File

@ -1,4 +1,6 @@
Bother, something went wrong - 501. <h1>Oops!</h1>
<h2>501 Bother, something went wrong.</h2>
<?php echo $message; ?> <?php echo $message; ?>
<hr/> <div class="error-details">
<?php echo Debug::vars(array('cookie'=>$_COOKIE,'request'=>$_REQUEST,'session'=>$_SESSION,'server'=>$_SERVER)); ?> If this keeps happening, please let us know.
</div>

View File

@ -15,10 +15,8 @@ class Controller_Reseller_Invoice extends Controller_Invoice {
$ao = ORM::factory('Account',$id); $ao = ORM::factory('Account',$id);
if (! $ao->loaded() OR ! Auth::instance()->authorised($ao)) { if (! $ao->loaded() OR ! Auth::instance()->authorised($ao))
$this->template->content = 'Unauthorised or doesnt exist?'; throw HTTP_Exception::factory(403,'Unauthorised or doesnt exist?');
return FALSE;
}
Block::add(array( Block::add(array(
'body'=>$output, 'body'=>$output,