Skip to content

Commit

Permalink
profile_get_row_direct() now throws exception
Browse files Browse the repository at this point in the history
If the given Profile does not exist, throw an exception to trigger an
error, instead of silently returning false.

Adapt MC API to catch the exception instead of the return value.

Fixes #27258
  • Loading branch information
dregad committed Sep 18, 2020
1 parent 1078148 commit fc5ad9a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 3 deletions.
5 changes: 3 additions & 2 deletions api/soap/mc_api.php
Expand Up @@ -647,8 +647,9 @@ function mci_profile_as_array_by_id( $p_profile_id ) {
return null;
}

$t_profile = profile_get_row_direct( $t_profile_id );
if( $t_profile === false ) {
try {
$t_profile = profile_get_row_direct( $t_profile_id );
} catch (ClientException $e) {
return null;
}

Expand Down
14 changes: 13 additions & 1 deletion core/profile_api.php
Expand Up @@ -42,6 +42,8 @@
require_api( 'user_api.php' );
require_api( 'utility_api.php' );

use Mantis\Exceptions\ClientException;

/**
* Create a new profile for the user, return the ID of the new profile
* @param integer $p_user_id A valid user identifier.
Expand Down Expand Up @@ -170,14 +172,24 @@ function profile_get_row( $p_user_id, $p_profile_id ) {
* Return a profile row from the database
* @param integer $p_profile_id A profile identifier.
* @return array
* @throws ClientException if the profile ID does not exist
* @todo relationship of this function to profile_get_row?
*/
function profile_get_row_direct( $p_profile_id ) {
db_param_push();
$t_query = 'SELECT * FROM {user_profile} WHERE id=' . db_param();
$t_result = db_query( $t_query, array( $p_profile_id ) );

return db_fetch_array( $t_result );
$t_row = db_fetch_array( $t_result );
if( !$t_row ) {
throw new ClientException(
"Profile #$p_profile_id not found",
ERROR_USER_PROFILE_NOT_FOUND,
array( $p_profile_id )
);
}

return $t_row;
}

/**
Expand Down

0 comments on commit fc5ad9a

Please sign in to comment.