[horde] question on horde identities on_change hook

Michael Menge michael.menge at zdv.uni-tuebingen.de
Wed Mar 29 13:19:29 UTC 2017


Quoting Jan Schneider <jan at horde.org>:

> Zitat von Michael Menge <michael.menge at zdv.uni-tuebingen.de>:
>
>> Quoting Jan Schneider <jan at horde.org>:
>>
>>> Zitat von Michael Menge <michael.menge at zdv.uni-tuebingen.de>:
>>>
>>>> Hi,
>>>>
>>>> I try to write an on_change hook for horde identities/from_addr.  
>>>> My goal is to restrict the
>>>> addresses our users can configure in horde/imp to their own  
>>>> addresses and variants (plus-addressing).
>>>> The address verification feature ($conf[user][verify_from_addr])  
>>>> could work but we don't want to
>>>> allow external addresses and it should be unnecessary to send an  
>>>> email as we already know the
>>>> allowed addresses.
>>>>
>>>>
>>>>
>>>> In horde/config/prefs.local.php I have the following function.
>>>>
>>>> $_prefs['from_addr']['on_change'] = function() {
>>>>  global $prefs, $registry;
>>>>  $data = $GLOBALS['registry']->getAuthInfo();
>>>>  $userID=$data['authId'];
>>>>  $value=$GLOBALS['prefs']->getValue('identities');
>>>>  $value2=$prefs->getValue('from_addr');
>>>>  Horde::logMessage("Horde Prefs call on_change for identities:  
>>>> ".$userID." value: ".$value." value2: ".$value2);
>>>>  myVerifyFunction($userID, $value);
>>>> }
>>>>
>>>> This function is call every time the Identity UI/form is saved.
>>>> But the value retrieved by getValue('identities') still contain  
>>>> the old value before the change.
>>>> This is different then the other on_change calls in horde/imp  
>>>> prefs.php (e.g. language, use_trash, trash_folder)
>>>> how can I retrieve the new value.
>>>
>>> This is because the from_addr preference, as being a part of the  
>>> identities preference, won't really get stored. You need to use  
>>> on_change hook for the identities preference instead.
>>
>> I tried that before, but if i use  
>> $_prefs['identities']['on_change'] = function() { ....
>> the hook is not called at all. I guess that is because 'identities'  
>> is a prefGroup?
>
> It's both, but on_change is only set on prefs. Without looking at  
> the code, just to the description of on_change in prefs.php, it  
> seems to be tied to changing prefs through the *UI*. That would  
> explain why it isn't called on 'identities' that's updated  
> implicitely. And it would also explain why you cannot update the  
> identites pref inside this callback: it's updated *after* the form  
> submission and thus also after the on_change callback.
>

Should i open a bug ticket?

One interesting thing to note on_change is called for from_addr
when the form is saved even if no from_addr is changed.

--------------------------------------------------------------------------------
M.Menge                                Tel.: (49) 7071/29-70316
Universität Tübingen                   Fax.: (49) 7071/29-5912
Zentrum für Datenverarbeitung          mail:  
michael.menge at zdv.uni-tuebingen.de
Wächterstraße 76
72074 Tübingen



More information about the horde mailing list