<?xml version="1.0" encoding="UTF-8"?> 
<?xml-stylesheet href="https://dev.horde.org/themes/horde//default/feed-rss.xsl" type="text/xsl"?> 
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"> 
 <channel> 
  <title>hook prefs_init</title> 
  <pubDate>Sun, 05 Apr 2026 09:00:15 +0000</pubDate> 
  <link>https://bugs.horde.org/ticket/9728</link> 
  <atom:link rel="self" type="application/rss+xml" title="hook prefs_init" href="https://bugs.horde.org/ticket/9728/rss" /> 
  <description>hook prefs_init</description> 
 
   
   
  <item> 
   <title>First, hook public function default_dir($username = null) sh</title> 
   <description>First, hook public function default_dir($username = null) should probably be merged in a prefs_init function since hooks changed in Horde.

Secondly,
I&#039;m trying to setup a hook to automatically set pref &#039;addressbooks&#039;. So far, I&#039;ve always been able to automatically set backends &#039;localldap&#039; and &#039;favourites&#039;, but not backend &#039;localsql&#039;.

Here is my hook :

public function prefs_init($pref, $value, $username, $scope_ob )
{
   switch ($pref) {
	case &#039;addressbooks&#039;:
		 $shares = Turba::listShares(true);
		return json_encode(array_keys(Turba::getConfigFromShares(Turba::availableSources())));
   }
}

When I login I get a : addressbook &#039;localsql&#039; does not exist.

I&#039;ve added the following line right before the return call of getConfigFromShares (turba/lib/Turba.php:523)
Attached is the output.

Looks like backend &#039;localsql&#039; doesn&#039;t not get initialize properly during login process.


</description> 
   <pubDate>Mon, 28 Mar 2011 09:36:33 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62697</link> 
  </item> 
   
  <item> 
   <title>Changes have been made in Git for this ticket:

Bug #9728: d</title> 
   <description>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</description> 
   <pubDate>Mon, 28 Mar 2011 20:27:22 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62732</link> 
  </item> 
   
  <item> 
   <title>&gt; First, hook public function default_dir($username = null) </title> 
   <description>&gt; First, hook public function default_dir($username = null) should 
&gt; probably be merged in a prefs_init function since hooks changed in 
&gt; Horde.

This has been done.</description> 
   <pubDate>Mon, 28 Mar 2011 20:27:39 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62733</link> 
  </item> 
   
  <item> 
   <title>&gt; I&#039;ve added the following line right before the return call</title> 
   <description>&gt; I&#039;ve added the following line right before the return call of 
&gt; getConfigFromShares (turba/lib/Turba.php:523)

Horde::debug($newSources);
</description> 
   <pubDate>Mon, 28 Mar 2011 21:23:49 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62744</link> 
  </item> 
   
  <item> 
   <title>From your log:

2011-03-28T11:21:33+02:00 DEBUG: Variable </title> 
   <description>From your log:

2011-03-28T11:21:33+02:00 DEBUG: Variable information:
array(3) {
  [0]=&gt;
  string(23) &quot;t28kRogBqn9NgepUzGnnBqA&quot;
  [1]=&gt;
  string(9) &quot;localldap&quot;
  [2]=&gt;
  string(10) &quot;favourites&quot;
}

What source is [0]? That looks like a share id. You won&#039;t see &quot;localsql&quot; in this list if it is using shares, it is replaced with the share ids of all shares the user has access to.</description> 
   <pubDate>Mon, 28 Mar 2011 21:46:32 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62747</link> 
  </item> 
   
  <item> 
   <title>&gt; What source is [0]? That looks like a share id. You won&#039;t </title> 
   <description>&gt; What source is [0]? That looks like a share id. You won&#039;t see 
&gt; &quot;localsql&quot; in this list if it is using shares, it is replaced with 
&gt; 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 &#039;localsql&#039;  (turba/config/backend.php)

prefs.local.php :
$_prefs[&#039;addressbooks&#039;][&#039;locked&#039;] = true;
$_prefs[&#039;addressbooks&#039;][&#039;hook&#039;] = true;


</description> 
   <pubDate>Tue, 29 Mar 2011 07:16:08 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62764</link> 
  </item> 
   
  <item> 
   <title>I modify prefs.local.php and hooks.php (attached) to use Mic</title> 
   <description>I modify prefs.local.php and hooks.php (attached) to use Michael recent changes.

prefs.local.php :
$_prefs[&#039;addressbooks&#039;][&#039;locked&#039;] = true;
$_prefs[&#039;addressbooks&#039;][&#039;hook&#039;] = true;
$_prefs[&#039;default_dir&#039;][&#039;locked&#039;] = true;
$_prefs[&#039;default_dir&#039;][&#039;hook&#039;] = true;



</description> 
   <pubDate>Tue, 29 Mar 2011 07:41:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62766</link> 
  </item> 
   
  <item> 
   <title>&gt;&gt; What source is [0]? That looks like a share id. You won&#039;t</title> 
   <description>&gt;&gt; What source is [0]? That looks like a share id. You won&#039;t see
&gt;&gt; &quot;localsql&quot; in this list if it is using shares, it is replaced with
&gt;&gt; the share ids of all shares the user has access to.
&gt;
&gt; attached is the ouput of Horde::debug($newSources);
&gt; I have not changed configuration of backend &#039;localsql&#039;  
&gt; (turba/config/backend.php)

OK, but my question still stands, I still see the localsql shared address book in the list.



&gt;
&gt; prefs.local.php :
&gt; $_prefs[&#039;addressbooks&#039;][&#039;locked&#039;] = true;
&gt; $_prefs[&#039;addressbooks&#039;][&#039;hook&#039;] = true;
&gt;
&gt;
&gt;
</description> 
   <pubDate>Tue, 29 Mar 2011 13:22:15 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62785</link> 
  </item> 
   
  <item> 
   <title>&gt; What source is [0]?

You can see that in the horde_debug</title> 
   <description>&gt; What source is [0]?

You can see that in the horde_debug.txt : localsql

it doesn&#039;t not appear in the first Horde::debug($newSources) call, but it does in the following ones.

</description> 
   <pubDate>Tue, 29 Mar 2011 15:09:23 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62799</link> 
  </item> 
   
  <item> 
   <title>&gt;&gt; What source is [0]?
&gt;
&gt; You can see that in the horde_d</title> 
   <description>&gt;&gt; What source is [0]?
&gt;
&gt; You can see that in the horde_debug.txt : localsql

not in horde_debug.txt but horde_debug[1].txt

</description> 
   <pubDate>Tue, 29 Mar 2011 15:42:24 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62800</link> 
  </item> 
   
  <item> 
   <title>..it&#039;s also in the other log file as well. I still don&#039;t und</title> 
   <description>..it&#039;s also in the other log file as well. I still don&#039;t understand the problem. You are saying the hook is not finding it, but it&#039;s listed. Is it, or is it not, listed if that user visits his prefs page?  If you query the user&#039;s prefs storage, what is the value of that pref?</description> 
   <pubDate>Tue, 29 Mar 2011 15:57:32 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62801</link> 
  </item> 
   
  <item> 
   <title>&gt; ..it&#039;s also in the other log file as well. I still don&#039;t u</title> 
   <description>&gt; ..it&#039;s also in the other log file as well. I still don&#039;t understand 
&gt; the problem. You are saying the hook is not finding it, but it&#039;s 
&gt; listed. Is it, or is it not, listed if that user visits his prefs 
&gt; page? 

Yes, the hook does not find it and I only get &quot;addressbook &#039;localsql&#039; does not exist.&quot; if hook is enabled on pref &#039;addressbooks&#039;.

If I login, go to Preferences, &quot;Address Books &quot;, I can see my personal address book (ie localsql / t28kRogBqn9NgepUzGnnBqA) in the unselected_sources list, never in the selected_sources list. 
And since pref &#039;addressbooks&#039; is locked, users can&#039;t change it (this is the wanted behaviour).

&gt; If you query the user&#039;s prefs storage, what is the value of 
&gt; that pref?

I don&#039;t have any turba prefs. (ie : delete from horde_prefs where pref_scope=&#039;turba&#039;;)

Looks like something does not initialize properly during the login process (by the way : $conf[&#039;auth&#039;][&#039;params&#039;][&#039;app&#039;] = &#039;imp&#039;). I don&#039;t mind debugging, but I don&#039;t know where to start. 

</description> 
   <pubDate>Tue, 29 Mar 2011 16:14:58 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62802</link> 
  </item> 
   
  <item> 
   <title>ok. I think there is some confusion here.  You say that you </title> 
   <description>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 &quot;addressbooks&quot; 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&#039;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).</description> 
   <pubDate>Tue, 29 Mar 2011 17:13:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62803</link> 
  </item> 
   
  <item> 
   <title>&gt; ok. I think there is some confusion here.  You say that yo</title> 
   <description>&gt; ok. I think there is some confusion here.  You say that you are 
&gt; setting the default_dir pref, right?  That pref only sets the value 
&gt; that specifies what address book is used for adding/importing 
&gt; contacts.  The setting that specifies what address books are 
&gt; *visible* is the &quot;addressbooks&quot; pref. Two different prefs.

Agreed, my issue can get confusing at some point. Two different prefs, but same issue, default_dir doesn&#039;t not set automatically using provided example (ie default_dir is set to null).

&gt; Also, the hook you posted does not contain the code I specified to 
&gt; you earlier that would be necessary to ensure the localsql source was 
&gt; properly initialized, this is why it is failing to find the default 
&gt; share, it hasn&#039;t been added to the cfgSources array yet. You need to 
&gt; run the sources through Turba::getConfigFromShares() as I mentioned 
&gt; on the mailing list (and you seem to have said you used in an earlier 
&gt; 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 &#039;addressbooks&#039; 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 &#039;default_dir&#039;, the follwowing always return false in turba/config/hooks.php
$GLOBALS[&#039;session&#039;]-&gt;get(&#039;turba&#039;, &#039;has_share&#039;) 
</description> 
   <pubDate>Tue, 29 Mar 2011 19:55:38 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t62815</link> 
  </item> 
   
  <item> 
   <title>class Turba_Hooks
{	public function prefs_init($pref, $valu</title> 
   <description>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[&#039;turba&#039;] is not set.


</description> 
   <pubDate>Mon, 04 Apr 2011 15:54:25 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t63107</link> 
  </item> 
   
  <item> 
   <title>&gt; class Turba_Hooks
&gt; {	public function prefs_init($pref, $</title> 
   <description>&gt; class Turba_Hooks
&gt; {	public function prefs_init($pref, $value, $username, $scope_ob)
&gt; 	{
&gt; 		Horde::debug(Turba::listShares());
&gt; 		Horde::debug($_SESSION);
&gt; 	}
&gt; }
&gt;
&gt; Turba::listShares() always returns empty array and $_SESSION[&#039;turba&#039;] 
&gt; is not set.

The session variable for the application won&#039;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.</description> 
   <pubDate>Mon, 04 Apr 2011 19:23:36 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t63124</link> 
  </item> 
   
  <item> 
   <title>Changes have been made in Git for this ticket:

Bug #9728: p</title> 
   <description>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</description> 
   <pubDate>Mon, 04 Apr 2011 20:56:00 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t63135</link> 
  </item> 
   
  <item> 
   <title>Added documentation to reiterate that you can&#039;t access appli</title> 
   <description>Added documentation to reiterate that you can&#039;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-&gt;setValue(pref_name, pref_value, array(&#039;nosave&#039; =&gt; true));</description> 
   <pubDate>Mon, 04 Apr 2011 20:57:40 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t63136</link> 
  </item> 
   
  <item> 
   <title>&gt; Added documentation to reiterate that you can&#039;t access app</title> 
   <description>&gt; Added documentation to reiterate that you can&#039;t access application 
&gt; data in prefs_init.  To do what you are trying to do here, you should 
&gt; instead use the postauthenticate hook and set the value manually with 
&gt; $prefs-&gt;setValue(pref_name, pref_value, array(&#039;nosave&#039; =&gt; true));

This means that the hook example for default_dir is wrong ?
</description> 
   <pubDate>Tue, 05 Apr 2011 07:09:24 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t63150</link> 
  </item> 
   
  <item> 
   <title>&gt;&gt; Added documentation to reiterate that you can&#039;t access ap</title> 
   <description>&gt;&gt; Added documentation to reiterate that you can&#039;t access application
&gt;&gt; data in prefs_init.  To do what you are trying to do here, you should
&gt;&gt; instead use the postauthenticate hook and set the value manually with
&gt;&gt; $prefs-&gt;setValue(pref_name, pref_value, array(&#039;nosave&#039; =&gt; true));
&gt;
&gt; This means that the hook example for default_dir is wrong ?

Yes.  It has been removed.</description> 
   <pubDate>Tue, 05 Apr 2011 07:27:04 +0000</pubDate> 
   <link>https://bugs.horde.org/ticket/9728#t63151</link> 
  </item> 
   
   
 
 </channel> 
</rss> 
