6.0.0-beta1
7/9/25

[#9728] hook prefs_init
Summary hook prefs_init
Queue Turba
Queue Version Git master
Type Bug
State Not A Bug
Priority 1. Low
Owners mrubinsk (at) horde (dot) org, slusarz (at) horde (dot) org
Requester rsalmon (at) mbpgroup (dot) com
Created 03/28/2011 (5217 days ago)
Due
Updated 04/05/2011 (5209 days ago)
Assigned 03/28/2011 (5217 days ago)
Resolved 04/04/2011 (5210 days ago)
Github Issue Link
Github Pull Request
Milestone
Patch No

History
04/05/2011 07:27:04 AM Michael Slusarz Comment #20 Reply to this comment
Added documentation to reiterate that you can't access application
data in prefs_init.  To do what you are trying to do here, you should
instead use the postauthenticate hook and set the value manually with
$prefs->setValue(pref_name, pref_value, array('nosave' => true));
This means that the hook example for default_dir is wrong ?
Yes.  It has been removed.
04/05/2011 07:09:24 AM rsalmon (at) mbpgroup (dot) com Comment #19 Reply to this comment
Added documentation to reiterate that you can't access application 
data in prefs_init.  To do what you are trying to do here, you 
should instead use the postauthenticate hook and set the value 
manually with $prefs->setValue(pref_name, pref_value, array('nosave' 
=> true));
This means that the hook example for default_dir is wrong ?

04/04/2011 08:57:40 PM Michael Slusarz Comment #18
Assigned to Michael Slusarz
State ⇒ Not A Bug
Reply to this comment
Added documentation to reiterate that you can't access application 
data in prefs_init.  To do what you are trying to do here, you should 
instead use the postauthenticate hook and set the value manually with 
$prefs->setValue(pref_name, pref_value, array('nosave' => true));
04/04/2011 08:56:00 PM Git Commit Comment #17 Reply to this comment
Changes have been made in Git for this ticket:

Bug #9728: prefs_init does not have application data available to it

  2 files changed, 12 insertions(+), 2 deletions(-)
http://git.horde.org/horde-git/-/commit/3c1cd2ecf619fa54dca0f8ec55bdd79f09384c74
04/04/2011 07:23:36 PM Michael Slusarz Comment #16 Reply to this comment

[Show Quoted Text - 10 lines]
The session variable for the application won't be available in 
prefs_init since the preferences need to be initialized BEFORE the 
application is initialized.  Chicken-and-egg problem.

prefs_init code needs to be self-contained within the hook at the 
present time.
04/04/2011 03:54:25 PM rsalmon (at) mbpgroup (dot) com Comment #15
New Attachment: horde_debug_turba.txt Download
Reply to this comment
class Turba_Hooks
{        public function prefs_init($pref, $value, $username, $scope_ob)
        {
                Horde::debug(Turba::listShares());
                Horde::debug($_SESSION);
        }
}

Turba::listShares() always returns empty array and $_SESSION['turba'] 
is not set.



03/29/2011 07:55:38 PM rsalmon (at) mbpgroup (dot) com Comment #14 Reply to this comment
ok. I think there is some confusion here.  You say that you are 
setting the default_dir pref, right?  That pref only sets the value 
that specifies what address book is used for adding/importing 
contacts.  The setting that specifies what address books are 
*visible* is the "addressbooks" pref. Two different prefs.
Agreed, my issue can get confusing at some point. Two different prefs, 
but same issue, default_dir doesn't not set automatically using 
provided example (ie default_dir is set to null).
Also, the hook you posted does not contain the code I specified to 
you earlier that would be necessary to ensure the localsql source 
was properly initialized, this is why it is failing to find the 
default share, it hasn't been added to the cfgSources array yet. You 
need to run the sources through Turba::getConfigFromShares() as I 
mentioned on the mailing list (and you seem to have said you used in 
an earlier comment).
I am not following you there. If I open the file hooks.php attached to 
this ticket, I can clearly see a hook for 'addressbooks' using 
getConfigFromShares :

     return 
json_encode(array_keys(Turba::getConfigFromShares(Turba::availableSources())));

this is indeed inspired from our discussion on the mailing list.


More testing on hook for pref 'default_dir', the follwowing always 
return false in turba/config/hooks.php
$GLOBALS['session']->get('turba', 'has_share')

03/29/2011 05:13:00 PM Michael Rubinsky Comment #13 Reply to this comment
ok. I think there is some confusion here.  You say that you are 
setting the default_dir pref, right?  That pref only sets the value 
that specifies what address book is used for adding/importing 
contacts.  The setting that specifies what address books are *visible* 
is the "addressbooks" pref. Two different prefs.

Also, the hook you posted does not contain the code I specified to you 
earlier that would be necessary to ensure the localsql source was 
properly initialized, this is why it is failing to find the default 
share, it hasn't been added to the cfgSources array yet. You need to 
run the sources through Turba::getConfigFromShares() as I mentioned on 
the mailing list (and you seem to have said you used in an earlier 
comment).
03/29/2011 04:14:58 PM rsalmon (at) mbpgroup (dot) com Comment #12 Reply to this comment
..it's also in the other log file as well. I still don't understand 
the problem. You are saying the hook is not finding it, but it's 
listed. Is it, or is it not, listed if that user visits his prefs 
page?
Yes, the hook does not find it and I only get "addressbook 'localsql' 
does not exist." if hook is enabled on pref 'addressbooks'.

If I login, go to Preferences, "Address Books ", I can see my personal 
address book (ie localsql / t28kRogBqn9NgepUzGnnBqA) in the 
unselected_sources list, never in the selected_sources list.
And since pref 'addressbooks' is locked, users can't change it (this 
is the wanted behaviour).
If you query the user's prefs storage, what is the value of that pref?
I don't have any turba prefs. (ie : delete from horde_prefs where 
pref_scope='turba';)

Looks like something does not initialize properly during the login 
process (by the way : $conf['auth']['params']['app'] = 'imp'). I don't 
mind debugging, but I don't know where to start.


03/29/2011 03:57:32 PM Michael Rubinsky Comment #11 Reply to this comment
..it's also in the other log file as well. I still don't understand 
the problem. You are saying the hook is not finding it, but it's 
listed. Is it, or is it not, listed if that user visits his prefs 
page?  If you query the user's prefs storage, what is the value of 
that pref?
03/29/2011 03:42:24 PM rsalmon (at) mbpgroup (dot) com Comment #10 Reply to this comment
What source is [0]?
You can see that in the horde_debug.txt : localsql
not in horde_debug.txt but horde_debug[1].txt


03/29/2011 03:09:23 PM rsalmon (at) mbpgroup (dot) com Comment #9 Reply to this comment
What source is [0]?
You can see that in the horde_debug.txt : localsql

it doesn't not appear in the first Horde::debug($newSources) call, but 
it does in the following ones.


03/29/2011 01:22:15 PM Michael Rubinsky Comment #8 Reply to this comment
What source is [0]? That looks like a share id. You won't see
"localsql" in this list if it is using shares, it is replaced with
the share ids of all shares the user has access to.
attached is the ouput of Horde::debug($newSources);
I have not changed configuration of backend 'localsql'   
(turba/config/backend.php)
OK, but my question still stands, I still see the localsql shared 
address book in the list.
prefs.local.php :
$_prefs['addressbooks']['locked'] = true;
$_prefs['addressbooks']['hook'] = true;
03/29/2011 07:41:00 AM rsalmon (at) mbpgroup (dot) com Comment #7
New Attachment: hooks.php Download
Reply to this comment
I modify prefs.local.php and hooks.php (attached) to use Michael 
recent changes.

prefs.local.php :
$_prefs['addressbooks']['locked'] = true;
$_prefs['addressbooks']['hook'] = true;
$_prefs['default_dir']['locked'] = true;
$_prefs['default_dir']['hook'] = true;




03/29/2011 07:16:08 AM rsalmon (at) mbpgroup (dot) com Comment #6
New Attachment: horde_debug[1].txt Download
Reply to this comment
What source is [0]? That looks like a share id. You won't see 
"localsql" in this list if it is using shares, it is replaced with 
the share ids of all shares the user has access to.
attached is the ouput of Horde::debug($newSources);
I have not changed configuration of backend 'localsql'   
(turba/config/backend.php)

prefs.local.php :
$_prefs['addressbooks']['locked'] = true;
$_prefs['addressbooks']['hook'] = true;



03/28/2011 09:46:32 PM Michael Rubinsky Comment #5
State ⇒ Feedback
Reply to this comment
From your log:

2011-03-28T11:21:33+02:00 DEBUG: Variable information:
array(3) {
   [0]=>
   string(23) "t28kRogBqn9NgepUzGnnBqA"
   [1]=>
   string(9) "localldap"
   [2]=>
   string(10) "favourites"
}

What source is [0]? That looks like a share id. You won't see 
"localsql" in this list if it is using shares, it is replaced with the 
share ids of all shares the user has access to.
03/28/2011 09:23:49 PM rsalmon (at) mbpgroup (dot) com Comment #4 Reply to this comment
I've added the following line right before the return call of 
getConfigFromShares (turba/lib/Turba.php:523)
Horde::debug($newSources);

03/28/2011 09:13:17 PM Jan Schneider Assigned to Michael Rubinsky
State ⇒ Assigned
 
03/28/2011 08:27:39 PM Michael Slusarz Comment #3 Reply to this comment
First, hook public function default_dir($username = null) should 
probably be merged in a prefs_init function since hooks changed in 
Horde.
This has been done.
03/28/2011 08:27:22 PM Git Commit Comment #2 Reply to this comment
Changes have been made in Git for this ticket:

Bug #9728: default_dir is no longer called as hook - move to prefs_init hook

  1 files changed, 28 insertions(+), 25 deletions(-)
http://git.horde.org/horde-git/-/commit/07445b77b221c5b1301817fb35a81cde62e79393
03/28/2011 09:36:33 AM rsalmon (at) mbpgroup (dot) com Comment #1
Priority ⇒ 1. Low
State ⇒ Unconfirmed
New Attachment: horde_debug.txt Download
Patch ⇒ No
Milestone ⇒
Queue ⇒ Turba
Summary ⇒ hook prefs_init
Type ⇒ Bug
Reply to this comment
First, hook public function default_dir($username = null) should 
probably be merged in a prefs_init function since hooks changed in 
Horde.

Secondly,
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, $scope_ob )
{
    switch ($pref) {
        case 'addressbooks':
                 $shares = Turba::listShares(true);
                return 
json_encode(array_keys(Turba::getConfigFromShares(Turba::availableSources())));
    }
}

When I login I get a : addressbook 'localsql' does not exist.

I've added the following line right before the return call of 
getConfigFromShares (turba/lib/Turba.php:523)
Attached is the output.

Looks like backend 'localsql' doesn't not get initialize properly 
during login process.



Saved Queries