[dev] turba-git hooks

Michael Rubinsky mrubinsk at horde.org
Tue Mar 22 15:56:05 UTC 2011


Quoting Ronan SALMON <rsalmon at mbpgroup.com>:

> Michael Rubinsky <mrubinsk at horde.org> a écrit :
>
>> Quoting Ronan SALMON <rsalmon at mbpgroup.com>:
>>
>>> Hi all,
>>>
>>> I have 3 backends enabled : localsql, localldap, favourites
>>>
>>> I'm trying to setup a hook to automatically set pref  
>>> 'addressbooks'. So far, I've always been able to automatically set  
>>> backends 'localldap' and 'favourites', but not backend 'localsql'.
>>>
>>> Here is my hook :
>>>
>>> public function prefs_init($pref, $value, $username)
>>> {
>>>   switch ($pref) {
>>>   case 'addressbooks':
>>>       return json_encode(array_keys(Turba::availableSources()));
>>>   }
>>> }
>>>
>>> This returns the 3 backends just fine, but when I login and go to  
>>> turba's preferences, the 'localsql' backend is never in the  
>>> selected group.
>>
>> Probably because localsql is using shares. Try something like:
>>
>> return  
>> json_encode(array_keys(Turba:getConfigFromShares((Turba::availableSources()))));
>
> localsql and favourites are configured as defined in the default  
> configuration prefs.php.
>
> If I try to return  
> json_encode(array_keys(Turba::getConfigFromShares(Turba::availableSources())));
> I get the following errors :
>
> 2011-03-22T16:21:49+01:00 NOTICE: HORDE [turba] PHP ERROR: Undefined  
> variable: driver [pid 26971 on line 479 of  
> "/var/www/html/hordetest/turba/lib/Turba.php"]
> 2011-03-22T16:21:49+01:00 DEBUG:  1.  
> Horde_Core_Auth_Application->authenticate()  
> /var/www/html/hordetest/login.php:151
>  2. Horde_Core_Auth_Application->authenticate()  
> /var/www/html/hordetest/libs/Horde/Core/Auth/Application.php:128
>  3. Horde_Core_Auth_Application->_setAuth()  
> /var/www/html/hordetest/libs/Horde/Core/Auth/Application.php:140
>  4. Horde_Registry->callAppMethod()  
> /var/www/html/hordetest/libs/Horde/Core/Auth/Application.php:593
>  5. Horde_Registry->pushApp()  
> /var/www/html/hordetest/libs/Horde/Registry.php:1040
>  6. Horde_Registry->loadPrefs()  
> /var/www/html/hordetest/libs/Horde/Registry.php:1286
>  7. Horde_Prefs->retrieve()  
> /var/www/html/hordetest/libs/Horde/Registry.php:1437
>  8. Horde_Prefs->_loadScope()  
> /var/www/html/hordetest/libs/Horde/Prefs.php:336
>  9. Horde_Core_Prefs_Storage_Hooks->get()  
> /var/www/html/hordetest/libs/Horde/Prefs.php:368
> 10. Horde::callHook()  
> /var/www/html/hordetest/libs/Horde/Core/Prefs/Storage/Hooks.php:30
> 11. call_user_func_array() /var/www/html/hordetest/libs/Horde.php:1730
> 12. IMP_Hooks->prefs_init()
> 13. Horde_Registry->call() /var/www/html/hordetest/imp/config/hooks.php:74
> 14. Horde_Registry->callByPackage()  
> /var/www/html/hordetest/libs/Horde/Registry.php:955
> 15. Horde_Registry->pushApp()  
> /var/www/html/hordetest/libs/Horde/Registry.php:993
> 16. Horde_Registry->loadPrefs()  
> /var/www/html/hordetest/libs/Horde/Registry.php:1286
> 17. Horde_Prefs->retrieve()  
> /var/www/html/hordetest/libs/Horde/Registry.php:1437
> 18. Horde_Prefs->_loadScope()  
> /var/www/html/hordetest/libs/Horde/Prefs.php:336
> 19. Horde_Core_Prefs_Storage_Hooks->get()  
> /var/www/html/hordetest/libs/Horde/Prefs.php:368
> 20. Horde::callHook()  
> /var/www/html/hordetest/libs/Horde/Core/Prefs/Storage/Hooks.php:30
> 21. call_user_func_array() /var/www/html/hordetest/libs/Horde.php:1730
> 22. Turba_Hooks->prefs_init()
> 23. Turba::getConfigFromShares()  
> /var/www/html/hordetest/turba/config/hooks.php:60
> 24. Horde::errorHandler() /var/www/html/hordetest/turba/lib/Turba.php:479
>
> and it returns :
> Array
> (
>     [0] => localldap
>     [1] => favourites
> )
>
> Output of json_encode(array_keys(Turba::availableSources())) :
> Array
> (
>     [0] => localsql
>     [1] => localldap
>     [2] => favourites
> )
>
> So I guess using Turba::availableSources() is fine.

I just tested this and it works as expected for me:

<code>
echo  
json_encode(array_keys(Turba::getConfigFromShares(Turba::availableSources())));
</code>

<output>
["FgAPa5Iy92dNWcml68wCkJA","ThY6J5Iy92dNccTGDHvwU_A","favourites","facebook"]
</output>


I just pushed a change that fixed the undefined variable error (which  
would only be reached when an exception is thrown), so at least now  
you will be able to get a better error message... see what happens now.

http://github.com/horde/horde/commit/b777f5b66dec81d4f27d5c20b1ccd1ca9326bdf9

mike

The Horde Project (www.horde.org)
mrubinsk at horde.org


More information about the dev mailing list