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 6f476eb

Browse files
committedOct 13, 2012
Additional Exceptions
1 parent e1c487d commit 6f476eb

11 files changed

+307
-12
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\CustomField;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* Custom Field Not Found Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class FieldNotFound 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_custom_field_not_found');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_custom_field_not_found'), $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\CustomField;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* Invalid Definition Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class InvalidDefinition 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_custom_field_invalid_definition');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_custom_field_invalid_definition'), $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\CustomField;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* Name Not Unique Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class NameNotUnique 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_custom_field_name_not_unique');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_custom_field_name_not_unique'), $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\Issue\Relationship;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* Revision Not Found Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class RelationshipNotFound 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_relationship_not_found');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_relationship_not_found'), $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 Name Not Unique Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class UserNameNotUnique 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_name_not_unique');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_user_name_not_unique'), $p_parameters);
44+
}
45+
parent::__construct($t_message, 401, $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\Validation;
24+
use MantisBT\Exception\ExceptionAbstract;
25+
26+
/**
27+
* GPC Not Found Exception
28+
* @package MantisBT
29+
* @subpackage classes
30+
*/
31+
class GPCNotFound 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_gpc_var_not_found');
42+
} else {
43+
$t_message = vsprintf( lang_get('exception_gpc_var_not_found'), $p_parameters);
44+
}
45+
parent::__construct($t_message, 500, $p_previous);
46+
}
47+
}
48+
?>

‎core/classes/MantisDatabase/PDO/PDO.class.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public function __construct() {
5252
* @param string $p_database_name database name
5353
* @param array $p_database_options database options
5454
* @throws MantisBT\Exception\PHP\ExtensionNotLoaded
55-
* @throws MantisBT\Exception\Database\QueryFailed
55+
* @throws MantisBT\Exception\Database\ConnectionFailed
5656
* @return bool
5757
*/
5858
public function connect($p_dsn, $p_database_host, $p_database_user, $p_database_password, $p_database_name, array $p_database_options=null) {

‎core/classes/MantisUser.class.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,7 @@ function delete() {
422422
* Return true if it is, false otherwise
423423
* @param string $p_username username
424424
* @return bool
425+
* @throws MantisBT\Exception\User\UserNameNotUnique
425426
*/
426427
private function validate_username($p_username) {
427428
# The DB field is hard-coded. USERLEN should not be modified.
@@ -443,7 +444,7 @@ private function validate_username($p_username) {
443444
$t_result = db_query( $t_query, array( $p_username ), 1 );
444445

445446
if( db_result( $t_result ) ) {
446-
throw new MantisBT\Exception\User_Name_Not_Unique();
447+
throw new MantisBT\Exception\User\UserNameNotUnique();
447448
} else {
448449
return true;
449450
}

‎core/custom_field_api.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ function custom_field_allow_manage_display( $p_type, $p_display ) {
106106
* @param bool $p_trigger_errors indicates whether to trigger an error if the field is not found
107107
* @return array array representing custom field
108108
* @access public
109+
* @throws MantisBT\Exception\CustomField\FieldNotFound
109110
*/
110111
function custom_field_cache_row( $p_field_id, $p_trigger_errors = true ) {
111112
global $g_cache_custom_field, $g_cache_name_to_id_map;
@@ -121,7 +122,7 @@ function custom_field_cache_row( $p_field_id, $p_trigger_errors = true ) {
121122

122123
if( !$t_row ) {
123124
if( $p_trigger_errors ) {
124-
throw new MantisBT\Exception\Custom_Field_Not_Found( 'Custom ' . $p_field_id );
125+
throw new MantisBT\Exception\CustomField\FieldNotFound( 'Custom ' . $p_field_id );
125126
} else {
126127
return false;
127128
}
@@ -411,6 +412,8 @@ function custom_field_create( $p_name ) {
411412
* @return bool
412413
* @access public
413414
* @throws MantisBT\Exception\Field\EmptyField
415+
* @throws MantisBT\Exception\CustomField\NameNotUnique
416+
* @throws MantisBT\Exception\CustomField\InvalidDefinition
414417
*/
415418
function custom_field_update( $p_field_id, $p_def_array ) {
416419
$c_field_id = (int)$p_field_id;
@@ -438,11 +441,11 @@ function custom_field_update( $p_field_id, $p_def_array ) {
438441
}
439442

440443
if(( $c_access_level_rw < $c_access_level_r ) || ( $c_length_min < 0 ) || (( $c_length_max != 0 ) && ( $c_length_min > $c_length_max ) ) ) {
441-
throw new MantisBT\Exception\Custom_Field_Invalid_Definition();
444+
throw new MantisBT\Exception\CustomField\InvalidDefinition();
442445
}
443446

444447
if( !custom_field_is_name_unique( $c_name, $c_field_id ) ) {
445-
throw new MantisBT\Exception\Custom_Field_Name_Not_Unique();
448+
throw new MantisBT\Exception\CustomField\NameNotUnique();
446449
}
447450

448451
$t_update_something = false;
@@ -619,11 +622,9 @@ function custom_field_update( $p_field_id, $p_def_array ) {
619622
custom_field_clear_cache( $p_field_id );
620623
} else {
621624
return false;
622-
623625
# there is nothing to update...
624626
}
625627

626-
# db_query errors on failure so:
627628
return true;
628629
}
629630

@@ -1319,6 +1320,7 @@ function custom_field_set_sequence( $p_field_id, $p_project_id, $p_sequence ) {
13191320
* @param array $p_field_def custom field definition
13201321
* @param int $p_bug_id bug id
13211322
* @access public
1323+
* @throws MantisBT\Exception\CustomField\InvalidDefinition
13221324
*/
13231325
function print_custom_field_input( $p_field_def, $p_bug_id = null ) {
13241326
if( null === $p_bug_id ) {
@@ -1339,7 +1341,7 @@ function print_custom_field_input( $p_field_def, $p_bug_id = null ) {
13391341
if( isset( $g_custom_field_type_definition[$p_field_def['type']]['#function_print_input'] ) ) {
13401342
call_user_func( $g_custom_field_type_definition[$p_field_def['type']]['#function_print_input'], $p_field_def, $t_custom_field_value );
13411343
} else {
1342-
throw new MantisBT\Exception\Custom_Field_Invalid_Definition();
1344+
throw new MantisBT\Exception\CustomField\InvalidDefinition();
13431345
}
13441346
}
13451347

‎core/gpc_api.php

+2-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@
5252
* @param string $p_var_name Variable name
5353
* @param mixed $p_default Default value
5454
* @return null
55+
* @throws MantisBT\Exception\Validation\GPCNotFound
5556
*/
5657
function gpc_get( $p_var_name, $p_default = null ) {
5758
if( isset( $_POST[$p_var_name] ) ) {
@@ -63,7 +64,7 @@ function gpc_get( $p_var_name, $p_default = null ) {
6364
# check for a default passed in (allowing null)
6465
$t_result = $p_default;
6566
} else {
66-
throw new MantisBT\Exception\GPC_Var_Not_Found( $p_var_name );
67+
throw new MantisBT\Exception\Validation\GPCNotFound( $p_var_name );
6768
}
6869

6970
return $t_result;

‎core/relationship_api.php

+6-3
Original file line numberDiff line numberDiff line change
@@ -461,6 +461,7 @@ function relationship_same_type_exists( $p_src_bug_id, $p_dest_bug_id, $p_rel_ty
461461
* @param int $p_relationship_id Relationship id
462462
* @param int $p_bug_id Bug Id
463463
* @return int Complementary bug id
464+
* @throws MantisBT\Exception\Issue\Relationship\RelationshipNotFound
464465
*/
465466
function relationship_get_linked_bug_id( $p_relationship_id, $p_bug_id ) {
466467

@@ -474,18 +475,19 @@ function relationship_get_linked_bug_id( $p_relationship_id, $p_bug_id ) {
474475
return $t_bug_relationship_data->src_bug_id;
475476
}
476477

477-
throw new MantisBT\Exception\Relationship_Not_Found();
478+
throw new MantisBT\Exception\Issue\Relationship\RelationshipNotFound();
478479
}
479480

480481
/**
481482
* get class description of a relationship (source side)
482483
* @param int $p_relationship_type Relationship type
483484
* @return string Relationship description
485+
* @throws MantisBT\Exception\Issue\Relationship\RelationshipNotFound
484486
*/
485487
function relationship_get_description_src_side( $p_relationship_type ) {
486488
global $g_relationships;
487489
if( !isset( $g_relationships[$p_relationship_type] ) ) {
488-
throw new MantisBT\Exception\Relationship_Not_Found();
490+
throw new MantisBT\Exception\Issue\Relationship\RelationshipNotFound();
489491
}
490492
return lang_get( $g_relationships[$p_relationship_type]['#description'] );
491493
}
@@ -494,11 +496,12 @@ function relationship_get_description_src_side( $p_relationship_type ) {
494496
* get class description of a relationship (destination side)
495497
* @param int $p_relationship_type Relationship type
496498
* @return string Relationship description
499+
* @throws MantisBT\Exception\Issue\Relationship\RelationshipNotFound
497500
*/
498501
function relationship_get_description_dest_side( $p_relationship_type ) {
499502
global $g_relationships;
500503
if( !isset( $g_relationships[$p_relationship_type] ) || !isset( $g_relationships[$g_relationships[$p_relationship_type]['#complementary']] ) ) {
501-
throw new MantisBT\Exception\Relationship_Not_Found();
504+
throw new MantisBT\Exception\Issue\Relationship\RelationshipNotFound();
502505
}
503506
return lang_get( $g_relationships[$g_relationships[$p_relationship_type]['#complementary']]['#description'] );
504507
}

0 commit comments

Comments
 (0)
Please sign in to comment.