Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6c79f5d

Browse files
committedOct 14, 2012
exceptions
1 parent 5718632 commit 6c79f5d

8 files changed

+208
-13
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* MantisBT - A PHP based bugtracking system
4+
*
5+
* MantisBT is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* MantisBT is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.
19+
* @link http://www.mantisbt.org
20+
* @package MantisBT
21+
*/
22+
23+
namespace MantisBT\Exception\Email;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* Email Address Invalid Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class AddressInvalid extends ExceptionAbstract
32+
{
33+
/**
34+
* Constructor
35+
* @param array $p_parameters parameters
36+
* @param \Exception previous exception
37+
*/
38+
public function __construct($p_parameters = null, \Exception $p_previous = null)
39+
{
40+
if ($p_parameters === null) {
41+
$t_message = lang_get('exception_email_invalid');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_email_invalid'), $p_parameters);
44+
}
45+
parent::__construct($t_message, 500, $p_previous);
46+
}
47+
}
48+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* MantisBT - A PHP based bugtracking system
4+
*
5+
* MantisBT is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* MantisBT is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.
19+
* @link http://www.mantisbt.org
20+
* @package MantisBT
21+
*/
22+
23+
namespace MantisBT\Exception\Email;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* Disposable Email Address Not Allowed Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class DisposableAddressNotAllowed extends ExceptionAbstract
32+
{
33+
/**
34+
* Constructor
35+
* @param array $p_parameters parameters
36+
* @param \Exception previous exception
37+
*/
38+
public function __construct($p_parameters = null, \Exception $p_previous = null)
39+
{
40+
if ($p_parameters === null) {
41+
$t_message = lang_get('exception_email_disposable');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_email_disposable'), $p_parameters);
44+
}
45+
parent::__construct($t_message, 500, $p_previous);
46+
}
47+
}
48+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* MantisBT - A PHP based bugtracking system
4+
*
5+
* MantisBT is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* MantisBT is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.
19+
* @link http://www.mantisbt.org
20+
* @package MantisBT
21+
*/
22+
23+
namespace MantisBT\Exception\PHP;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* Timezone Update Failed Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class TimezoneUpdateFailed extends ExceptionAbstract
32+
{
33+
/**
34+
* Constructor
35+
* @param array $p_parameters parameters
36+
* @param \Exception previous exception
37+
*/
38+
public function __construct($p_parameters = null, \Exception $p_previous = null)
39+
{
40+
if ($p_parameters === null) {
41+
$t_message = lang_get('exception_updating_timezone');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_updating_timezone'), $p_parameters);
44+
}
45+
parent::__construct($t_message, 500, $p_previous);
46+
}
47+
}
48+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
/**
3+
* MantisBT - A PHP based bugtracking system
4+
*
5+
* MantisBT is free software: you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, either version 2 of the License, or
8+
* (at your option) any later version.
9+
*
10+
* MantisBT is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
* GNU General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU General Public License
16+
* along with MantisBT. If not, see <http://www.gnu.org/licenses/>.
17+
*
18+
* @copyright Copyright (C) 2002 - 2012 MantisBT Team - mantisbt-dev@lists.sourceforge.
19+
* @link http://www.mantisbt.org
20+
* @package MantisBT
21+
*/
22+
23+
namespace MantisBT\Exception\User;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* User Preferences Not Found Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class UserPreferencesNotFound extends ExceptionAbstract
32+
{
33+
/**
34+
* Constructor
35+
* @param array $p_parameters parameters
36+
* @param \Exception previous exception
37+
*/
38+
public function __construct($p_parameters = null, \Exception $p_previous = null)
39+
{
40+
if ($p_parameters === null) {
41+
$t_message = lang_get('exception_user_prefs_not_found');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_user_prefs_not_found'), $p_parameters);
44+
}
45+
parent::__construct($t_message, 401, $p_previous);
46+
}
47+
}
48+
?>

‎core/classes/MantisBug.class.php

+6-6
Original file line numberDiff line numberDiff line change
@@ -300,22 +300,22 @@ function bug_get_row( $p_bug_id ) {
300300
function bug_cache_row( $p_bug_id, $p_trigger_errors = false ) {
301301
global $g_cache_bug;
302302

303+
$p_bug_id = (int) $p_bug_id;
304+
303305
if( isset( $g_cache_bug[$p_bug_id] ) ) {
304306
return $g_cache_bug[$p_bug_id];
305307
}
306308

307-
$c_bug_id = (int) $p_bug_id;
308-
309309
$t_query = 'SELECT * FROM {bug} WHERE id=%d';
310-
$t_result = db_query( $t_query, array( $c_bug_id ) );
310+
$t_result = db_query( $t_query, array( $p_bug_id ) );
311311

312312
$t_row = db_fetch_array( $t_result );
313313

314314
if( !$t_row ) {
315-
$g_cache_bug[$c_bug_id] = false;
315+
$g_cache_bug[$p_bug_id] = false;
316316

317317
if( $p_trigger_errors ) {
318-
throw new MantisBT\Exception\Issue\IssueNotFound( $p_bug_id );
318+
throw new MantisBT\Exception\Issue\IssueNotFound( array( $p_bug_id ) );
319319
} else {
320320
return false;
321321
}
@@ -766,7 +766,7 @@ function delete() {
766766
helper_call_custom_function( 'issue_delete_validate', array( $this->id ) );
767767

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

771771
# log deletion of bug - removed later on in this function by history_delete
772772
history_log_event_special( $this->id, BUG_DELETED, bug_format_id( $this->id ) );

‎core/date_api.php

+4-4
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,23 @@ function date_get_null() {
7070
* @param string $p_timezone PHP timezone to set
7171
* @return null
7272
* @access public
73+
* @throws MantisBT\Exception\PHP\TimezoneUpdateFailed
7374
*/
7475
function date_set_timezone( $p_timezone ) {
7576
global $g_cache_timezone;
7677

7778
array_push( $g_cache_timezone, date_default_timezone_get() );
7879

7980
if( !date_default_timezone_set( $p_timezone ) ) {
80-
// unable to set timezone
81-
throw new MantisBT\Exception\Updating_Timezone();
81+
throw new MantisBT\Exception\PHP\TimezoneUpdateFailed();
8282
}
8383
}
8484

8585
/**
8686
* restore previous timezone
8787
* @return null
8888
* @access public
89+
* @throws MantisBT\Exception\PHP\TimezoneUpdateFailed
8990
*/
9091
function date_restore_timezone( ) {
9192
global $g_cache_timezone;
@@ -97,8 +98,7 @@ function date_restore_timezone( ) {
9798
}
9899

99100
if( !date_default_timezone_set( $t_timezone ) ) {
100-
// unable to set timezone
101-
throw new MantisBT\Exception\Updating_Timezone();
101+
throw new MantisBT\Exception\PHP\TimezoneUpdateFailed();
102102
}
103103
}
104104

‎core/email_api.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,11 @@ function email_is_valid( $p_email ) {
153153
* throw an exception otherwise
154154
* @param string $p_email
155155
* @return null
156+
* @throws MantisBT\Exception\Email\AddressInvalid
156157
*/
157158
function email_ensure_valid( $p_email ) {
158159
if( !email_is_valid( $p_email ) ) {
159-
throw new MantisBT\Exception\Email_Invalid();
160+
throw new MantisBT\Exception\Email\AddressInvalid();
160161
}
161162
}
162163

@@ -178,10 +179,11 @@ function email_is_disposable( $p_email ) {
178179
* trigger an ERROR if it isn't
179180
* @param string $p_email
180181
* @return null
182+
* @throws MantisBT\Exception\Email\DisposableAddressNotAllowed
181183
*/
182184
function email_ensure_not_disposable( $p_email ) {
183185
if( email_is_disposable( $p_email ) ) {
184-
throw new MantisBT\Exception\Email_Disposable();
186+
throw new MantisBT\Exception\Email\DisposableAddressNotAllowed();
185187
}
186188
}
187189

‎core/user_pref_api.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,7 @@ function Get( $p_string ) {
294294
* @param int $p_project_id
295295
* @param bool $p_trigger_errors
296296
* @return bool|array
297+
* @throws MantisBT\Exception\User\UserPreferencesNotFound
297298
*/
298299
function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS, $p_trigger_errors = true ) {
299300
global $g_cache_user_pref;
@@ -309,7 +310,7 @@ function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS, $p_trigg
309310

310311
if( !$t_row ) {
311312
if( $p_trigger_errors ) {
312-
throw new MantisBT\Exception\User_Prefs_Not_Found();
313+
throw new MantisBT\Exception\User\UserPreferencesNotFound();
313314
} else {
314315
$g_cache_user_pref[(int)$p_user_id][(int)$p_project_id] = false;
315316
return false;

0 commit comments

Comments
 (0)
Please sign in to comment.