From b67a611ca76a9665f87c1670a2d155dd23ef502a Mon Sep 17 00:00:00 2001 From: Mikael Nordfeldth Date: Sun, 13 Jul 2014 16:26:08 +0200 Subject: [PATCH] Allow default data from Profile_prefs::getData call --- classes/Profile_prefs.php | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/classes/Profile_prefs.php b/classes/Profile_prefs.php index 37ccf4fb96..32da3b11b8 100644 --- a/classes/Profile_prefs.php +++ b/classes/Profile_prefs.php @@ -112,8 +112,17 @@ class Profile_prefs extends Managed_DataObject return $pref; } - static function getData(Profile $profile, $namespace, $topic) { - $pref = self::getTopic($profile, $namespace, $topic); + static function getData(Profile $profile, $namespace, $topic, $def=null) { + try { + $pref = self::getTopic($profile, $namespace, $topic); + } catch (NoResultException $e) { + if ($def === null) { + // If no default value was set, continue the exception. + throw $e; + } + // If there was a default value, return that. + return $def; + } return $pref->data; } -- 2.39.5