@@ -291,11 +291,10 @@ function Get( $p_string ) {
291
291
*
292
292
* @param int $p_user_id
293
293
* @param int $p_project_id
294
- * @param bool $p_trigger_errors
295
294
* @return bool|array
296
295
* @throws MantisBT\Exception\User\UserPreferencesNotFound
297
296
*/
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 ) {
299
298
global $ g_cache_user_pref ;
300
299
301
300
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
308
307
$ t_row = db_fetch_array ( $ t_result );
309
308
310
309
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 ();
317
311
}
318
312
319
313
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 ) {
397
391
* @return bool
398
392
*/
399
393
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 ) {
401
399
return false ;
402
- } else {
403
- return true ;
404
400
}
401
+ return false ;
405
402
}
406
403
407
404
/**
@@ -554,34 +551,34 @@ function user_pref_get( $p_user_id, $p_project_id = ALL_PROJECTS ) {
554
551
555
552
$ t_prefs = new UserPreferences ( $ p_user_id , $ p_project_id );
556
553
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
561
558
if ( ALL_PROJECTS != $ p_project_id ) {
562
559
# 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 );
564
561
}
565
562
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 ) {
568
565
# We use an empty array
569
- $ row = array ();
570
- }
566
+ $ t_row = array ();
567
+ }
571
568
}
572
569
573
570
if ($ t_vars == null ) {
574
571
$ t_vars = getClassProperties ( 'UserPreferences ' , 'protected ' );
575
572
}
576
573
577
- $ t_row_keys = array_keys ( $ row );
574
+ $ t_row_keys = array_keys ( $ t_row );
578
575
579
576
# Check each variable in the class
580
577
foreach ( $ t_vars as $ var => $ val ) {
581
578
# If we got a field from the DB with the same name
582
579
if ( in_array ( $ var , $ t_row_keys , true ) ) {
583
580
# Store that value in the object
584
- $ t_prefs ->$ var = $ row [$ var ];
581
+ $ t_prefs ->$ var = $ t_row [$ var ];
585
582
}
586
583
}
587
584
if ( auth_is_user_authenticated () && auth_get_current_user_id () == $ p_user_id ) {
0 commit comments