[horde] only first initialization of preferences via hooks

Steffen skhorde at smail.inf.fh-bonn-rhein-sieg.de
Wed Mar 5 10:07:23 UTC 2014


On Tue, 4 Mar 2014, Michael M Slusarz wrote:

> Quoting Steffen <skhorde at smail.inf.fh-bonn-rhein-sieg.de>:
>
>> how do I initialize preferences of users via hooks, but then keep my hands 
>> off them for later logins? I use: horde 5.1.5 stable
>
> Explicitly save the value to the prefs backend - $prefs->setValue() - before 
> returning the value from the hook.

Hmm, I seem to mis-understand the purpose prefs_init() actually. :-)

I want to provide user-depended start values. setValue() does not help me, 
because it does not save the value to the prefs DB and it does not prevent 
prefs_init() to be called again. Can I explicitly commit my changes to the 
prefs DB?

I now switched to kronolith/fb_cals for testing, in order to ensure the 
pref is found in one scope only.

class Kronolith_Hooks
{
     public function prefs_init($pref, $value, $username, $scope_ob)
     {
             if (is_null($username)) {	// not logged in
                 return $value;
             }

         switch ($pref) {
         case 'fb_cals':
 		$me = serialize(array('internal_fbz'));
 		$GLOBALS['prefs']->setValue('fb_cals', $me);
 		$scope_ob->set('fb_cals', $me);
 		if($fh = fopen('/tmp/hook.log', 'a')) {
 			fwrite($fh, print_r($GLOBALS['prefs'], true));
 			fwrite($fh, print_r($scope_ob, true)."\n");
 			fwrite($fh, "value=" . print_r($value, true)."\n");
 			fwrite($fh, "getValue()=" . print_r($GLOBALS['prefs']->getValue('fb_cals'), true)."\n");
 			fwrite($fh, "getDefault()=" . print_r($dflt, true)."\n");
 			fwrite($fh, "getDefault(scope)=" . print_r($scope_ob->getDefault('fb_cals'), true)."\n");
 			fclose($fh);
 		}
 		return $me;

I also added a logging statement into Horde_Prefs::setValue(), which shows
that my values are passed on and that the scope is kronolith.
The dump of $prefs shows:

 	[fb_cals] => Array
 		(
 			[v] => a:1:{i:0;s:12:"internal_fbz";}
 			[d] => a:2:{i:0;s:32:"internal_tlYSPxMIzwjT0YqX2fe5Tw4";i:1;s:16:"internal_fbz_eng";}
 		)

The [d] setting corresponds to the values I selected in the GUI.
The [v] setting corresponds to the value  I set in prefs_init().

After logoff the [d] value is storred in the prefs database still, but [v]
has gone.

value=a:2:{i:0;s:12:"internal_fbz";i:1;s:16:"internal_fbz_eng";}
getValue()=a:1:{i:0;s:12:"internal_fbz";}
getDefault()=a:0:{}
getDefault(scope)=a:2:{i:0;s:12:"internal_fbz";i:1;s:16:"internal_fbz_eng";}

The 1st getDefault() is the value from prefs.php, the getDefault(scope) is
the value from horde_prefs DB of the user, so is $value. getValue() is
the string passed to $prefs->setValue() / $scope_ob->set().

-- 
Steffen


More information about the horde mailing list