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 2f87420

Browse files
committedApr 6, 2013
use exceptions instead of $trigger_errors
1 parent ca388c2 commit 2f87420

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed
 

‎core/user_pref_api.php

+19-22
Original file line numberDiff line numberDiff line change
@@ -291,11 +291,10 @@ function Get( $p_string ) {
291291
*
292292
* @param int $p_user_id
293293
* @param int $p_project_id
294-
* @param bool $p_trigger_errors
295294
* @return bool|array
296295
* @throws MantisBT\Exception\User\UserPreferencesNotFound
297296
*/
298-
function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS, $p_trigger_errors = true ) {
297+
function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS ) {
299298
global $g_cache_user_pref;
300299

301300
if( isset( $g_cache_user_pref[(int)$p_user_id][(int)$p_project_id] ) ) {
@@ -308,12 +307,7 @@ function user_pref_cache_row( $p_user_id, $p_project_id = ALL_PROJECTS, $p_trigg
308307
$t_row = db_fetch_array( $t_result );
309308

310309
if( !$t_row ) {
311-
if( $p_trigger_errors ) {
312-
throw new MantisBT\Exception\User\UserPreferencesNotFound();
313-
} else {
314-
$g_cache_user_pref[(int)$p_user_id][(int)$p_project_id] = false;
315-
return false;
316-
}
310+
throw new MantisBT\Exception\User\UserPreferencesNotFound();
317311
}
318312

319313
if( !isset( $g_cache_user_pref[(int)$p_user_id] ) ) {
@@ -397,11 +391,14 @@ function user_pref_clear_cache( $p_user_id = null, $p_project_id = null ) {
397391
* @return bool
398392
*/
399393
function user_pref_exists( $p_user_id, $p_project_id = ALL_PROJECTS ) {
400-
if( false === user_pref_cache_row( $p_user_id, $p_project_id, false ) ) {
394+
try {
395+
if( user_pref_cache_row( $p_user_id, $p_project_id ) !== false ) {
396+
return true;
397+
}
398+
} catch ( MantisBT\Exception\User\UserPreferencesNotFound $e) {
401399
return false;
402-
} else {
403-
return true;
404400
}
401+
return false;
405402
}
406403

407404
/**
@@ -554,34 +551,34 @@ function user_pref_get( $p_user_id, $p_project_id = ALL_PROJECTS ) {
554551

555552
$t_prefs = new UserPreferences( $p_user_id, $p_project_id );
556553

557-
$row = user_pref_cache_row( $p_user_id, $p_project_id, false );
558-
559-
# If the user has no preferences for the given project
560-
if( false === $row ) {
554+
try {
555+
$t_row = user_pref_cache_row( $p_user_id, $p_project_id );
556+
} catch ( MantisBT\Exception\User\UserPreferencesNotFound $e ) {
557+
# If the user has no preferences for the given project
561558
if( ALL_PROJECTS != $p_project_id ) {
562559
# Try to get the prefs for ALL_PROJECTS (the defaults)
563-
$row = user_pref_cache_row( $p_user_id, ALL_PROJECTS, false );
560+
$t_row = user_pref_cache_row( $p_user_id, ALL_PROJECTS, false );
564561
}
565562

566-
# If $row is still false (the user doesn't have default preferences)
567-
if( false === $row ) {
563+
# If $t_row is still false (the user doesn't have default preferences)
564+
if( false === $t_row ) {
568565
# We use an empty array
569-
$row = array();
570-
}
566+
$t_row = array();
567+
}
571568
}
572569

573570
if ($t_vars == null ) {
574571
$t_vars = getClassProperties( 'UserPreferences', 'protected');
575572
}
576573

577-
$t_row_keys = array_keys( $row );
574+
$t_row_keys = array_keys( $t_row );
578575

579576
# Check each variable in the class
580577
foreach( $t_vars as $var => $val ) {
581578
# If we got a field from the DB with the same name
582579
if( in_array( $var, $t_row_keys, true ) ) {
583580
# Store that value in the object
584-
$t_prefs->$var = $row[$var];
581+
$t_prefs->$var = $t_row[$var];
585582
}
586583
}
587584
if ( auth_is_user_authenticated() && auth_get_current_user_id() == $p_user_id ) {

0 commit comments

Comments
 (0)
Please sign in to comment.