Skip to content

Commit

Permalink
exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
mantis committed Oct 14, 2012
1 parent 5718632 commit 6c79f5d
Show file tree
Hide file tree
Showing 8 changed files with 208 additions and 13 deletions.
48 changes: 48 additions & 0 deletions core/classes/Exception/Email/AddressInvalid.class.php
@@ -0,0 +1,48 @@
<?php
/**
* MantisBT - A PHP based bugtracking system
*
* MantisBT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MantisBT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.
* @link http://www.mantisbt.org
* @package MantisBT
*/

namespace MantisBT\Exception\Email;
use MantisBT\Exception\ExceptionAbstract;

/**
* Email Address Invalid Exception
* @package MantisBT
* @subpackage classes
*/
class AddressInvalid extends ExceptionAbstract
{
/**
* Constructor
* @param array $p_parameters parameters
* @param \Exception previous exception
*/
public function __construct($p_parameters = null, \Exception $p_previous = null)
{
if ($p_parameters === null) {
$t_message = lang_get('exception_email_invalid');
} else {
$t_message = vsprintf( lang_get('exception_email_invalid'), $p_parameters);
}
parent::__construct($t_message, 500, $p_previous);
}
}
?>
48 changes: 48 additions & 0 deletions core/classes/Exception/Email/DisposableAddressNotAllowed.class.php
@@ -0,0 +1,48 @@
<?php
/**
* MantisBT - A PHP based bugtracking system
*
* MantisBT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MantisBT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.
* @link http://www.mantisbt.org
* @package MantisBT
*/

namespace MantisBT\Exception\Email;
use MantisBT\Exception\ExceptionAbstract;

/**
* Disposable Email Address Not Allowed Exception
* @package MantisBT
* @subpackage classes
*/
class DisposableAddressNotAllowed extends ExceptionAbstract
{
/**
* Constructor
* @param array $p_parameters parameters
* @param \Exception previous exception
*/
public function __construct($p_parameters = null, \Exception $p_previous = null)
{
if ($p_parameters === null) {
$t_message = lang_get('exception_email_disposable');
} else {
$t_message = vsprintf( lang_get('exception_email_disposable'), $p_parameters);
}
parent::__construct($t_message, 500, $p_previous);
}
}
?>
48 changes: 48 additions & 0 deletions core/classes/Exception/PHP/TimezoneUpdateFailed.class.php
@@ -0,0 +1,48 @@
<?php
/**
* MantisBT - A PHP based bugtracking system
*
* MantisBT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MantisBT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.
* @link http://www.mantisbt.org
* @package MantisBT
*/

namespace MantisBT\Exception\PHP;
use MantisBT\Exception\ExceptionAbstract;

/**
* Timezone Update Failed Exception
* @package MantisBT
* @subpackage classes
*/
class TimezoneUpdateFailed extends ExceptionAbstract
{
/**
* Constructor
* @param array $p_parameters parameters
* @param \Exception previous exception
*/
public function __construct($p_parameters = null, \Exception $p_previous = null)
{
if ($p_parameters === null) {
$t_message = lang_get('exception_updating_timezone');
} else {
$t_message = vsprintf( lang_get('exception_updating_timezone'), $p_parameters);
}
parent::__construct($t_message, 500, $p_previous);
}
}
?>
48 changes: 48 additions & 0 deletions core/classes/Exception/User/UserPreferencesNotFound.class.php
@@ -0,0 +1,48 @@
<?php
/**
* MantisBT - A PHP based bugtracking system
*
* MantisBT is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 2 of the License, or
* (at your option) any later version.
*
* MantisBT is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
*
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.
* @link http://www.mantisbt.org
* @package MantisBT
*/

namespace MantisBT\Exception\User;
use MantisBT\Exception\ExceptionAbstract;

/**
* User Preferences Not Found Exception
* @package MantisBT
* @subpackage classes
*/
class UserPreferencesNotFound extends ExceptionAbstract
{
/**
* Constructor
* @param array $p_parameters parameters
* @param \Exception previous exception
*/
public function __construct($p_parameters = null, \Exception $p_previous = null)
{
if ($p_parameters === null) {
$t_message = lang_get('exception_user_prefs_not_found');
} else {
$t_message = vsprintf( lang_get('exception_user_prefs_not_found'), $p_parameters);
}
parent::__construct($t_message, 401, $p_previous);
}
}
?>
12 changes: 6 additions & 6 deletions core/classes/MantisBug.class.php
Expand Up @@ -300,22 +300,22 @@ function bug_get_row( $p_bug_id ) {
function bug_cache_row( $p_bug_id, $p_trigger_errors = false ) {
global $g_cache_bug;

$p_bug_id = (int) $p_bug_id;

if( isset( $g_cache_bug[$p_bug_id] ) ) {
return $g_cache_bug[$p_bug_id];
}

$c_bug_id = (int) $p_bug_id;

$t_query = 'SELECT * FROM {bug} WHERE id=%d';
$t_result = db_query( $t_query, array( $c_bug_id ) );
$t_result = db_query( $t_query, array( $p_bug_id ) );

$t_row = db_fetch_array( $t_result );

if( !$t_row ) {
$g_cache_bug[$c_bug_id] = false;
$g_cache_bug[$p_bug_id] = false;

if( $p_trigger_errors ) {
throw new MantisBT\Exception\Issue\IssueNotFound( $p_bug_id );
throw new MantisBT\Exception\Issue\IssueNotFound( array( $p_bug_id ) );
} else {
return false;
}
Expand Down Expand Up @@ -766,7 +766,7 @@ function delete() {
helper_call_custom_function( 'issue_delete_validate', array( $this->id ) );

# signal bug delete event
event_signal( 'EVENT_BUG_DELETED', array( $t_bug_id ) );
event_signal( 'EVENT_BUG_DELETED', array( $this->id ) );

# log deletion of bug - removed later on in this function by history_delete
history_log_event_special( $this->id, BUG_DELETED, bug_format_id( $this->id ) );
Expand Down
8 changes: 4 additions & 4 deletions core/date_api.php
Expand Up @@ -70,22 +70,23 @@ function date_get_null() {
* @param string $p_timezone PHP timezone to set
* @return null
* @access public
* @throws MantisBT\Exception\PHP\TimezoneUpdateFailed
*/
function date_set_timezone( $p_timezone ) {
global $g_cache_timezone;

array_push( $g_cache_timezone, date_default_timezone_get() );

if( !date_default_timezone_set( $p_timezone ) ) {
// unable to set timezone
throw new MantisBT\Exception\Updating_Timezone();
throw new MantisBT\Exception\PHP\TimezoneUpdateFailed();
}
}

/**
* restore previous timezone
* @return null
* @access public
* @throws MantisBT\Exception\PHP\TimezoneUpdateFailed
*/
function date_restore_timezone( ) {
global $g_cache_timezone;
Expand All @@ -97,8 +98,7 @@ function date_restore_timezone( ) {
}

if( !date_default_timezone_set( $t_timezone ) ) {
// unable to set timezone
throw new MantisBT\Exception\Updating_Timezone();
throw new MantisBT\Exception\PHP\TimezoneUpdateFailed();
}
}

Expand Down
6 changes: 4 additions & 2 deletions core/email_api.php
Expand Up @@ -153,10 +153,11 @@ function email_is_valid( $p_email ) {
* throw an exception otherwise
* @param string $p_email
* @return null
* @throws MantisBT\Exception\Email\AddressInvalid
*/
function email_ensure_valid( $p_email ) {
if( !email_is_valid( $p_email ) ) {
throw new MantisBT\Exception\Email_Invalid();
throw new MantisBT\Exception\Email\AddressInvalid();
}
}

Expand All @@ -178,10 +179,11 @@ function email_is_disposable( $p_email ) {
* trigger an ERROR if it isn't
* @param string $p_email
* @return null
* @throws MantisBT\Exception\Email\DisposableAddressNotAllowed
*/
function email_ensure_not_disposable( $p_email ) {
if( email_is_disposable( $p_email ) ) {
throw new MantisBT\Exception\Email_Disposable();
throw new MantisBT\Exception\Email\DisposableAddressNotAllowed();
}
}

Expand Down
3 changes: 2 additions & 1 deletion core/user_pref_api.php
Expand Up @@ -294,6 +294,7 @@ function Get( $p_string ) {
* @param int $p_project_id
* @param bool $p_trigger_errors
* @return bool|array
* @throws MantisBT\Exception\User\UserPreferencesNotFound
*/
function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS, $p_trigger_errors = true ) {
global $g_cache_user_pref;
Expand All @@ -309,7 +310,7 @@ function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS, $p_trigg

if( !$t_row ) {
if( $p_trigger_errors ) {
throw new MantisBT\Exception\User_Prefs_Not_Found();
throw new MantisBT\Exception\User\UserPreferencesNotFound();
} else {
$g_cache_user_pref[(int)$p_user_id][(int)$p_project_id] = false;
return false;
Expand Down

0 comments on commit 6c79f5d

Please sign in to comment.