[kronolith] Default fb_cals on first user login via hooks doesn't work right

Michael J Rubinsky mrubinsk at horde.org
Fri Jun 14 18:08:32 UTC 2019


Quoting winnertako <fabiojsousa at gmail.com>:

> Michael J Rubinsky wrote
>> Quoting winnertako <
>
>> fabiojsousa@
>
>> >:
>>
>>> Hello,
>>>
>>> I'm trying to initialize the free-busy information on users first login
>>> via
>>> hooks. My hook:
>>>
>>> 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':
>>>          		$cals =
>>> @unserialize($GLOBALS['prefs']->getValue('display_cals'));
>>>          		$fb_url = 'a:1:{i:0;s:32:"internal_' . $cals[0] . '";}';
>>>          		$GLOBALS['prefs']->setValue('fb_cals', $fb_url);
>>>                 $scope_ob->set($pref, $fb_url);
>>>                 $scope_ob->setDirty($pref, true);
>>>
>>>  		}
>>>  		return $fb_url;
>>>  	}
>>>  }
>>>
>>>
>>> I've one strange problem, when the user get is first login the free-busy
>>> link is wrong *a:1:{i:0;s:32:"internal_";}*
>>> but when the user do the second login the free-busy information get the
>>> correct syntax  *a:1:{i:0;s:32:"internal_pZFqfLNIZnq_4Rm6je1d_aE";}*
>>>
>>> What I'm missing ?
>>
>> The prefs_init method is called before the application is fully
>> initialized. The VERY FIRST time a user logs in, there are no
>> calendars for that user (and they are not created until during app
>> initialization), so there are therefore no calendars in that user's
>> preferences yet...therefore, there is no existing calendar id to
>> populate the fb_url with.
>>
>>
>> You should look at the appauthenticated hook instead, as suggested by
>> the comments in hooks.php.dist.
>>
>>
>>> Thank you
>>>
>>>
>>>
>>>
>>>
>>> --
>>> Sent from: http://horde.690.n7.nabble.com/Horde-Kronolith-f87467.html
>>> --
>>> kronolith mailing list
>>> Frequently Asked Questions: http://wiki.horde.org/FAQ
>>> To unsubscribe, mail:
>
>> kronolith-unsubscribe at .horde
>
>>
>>
>>
>> --
>> mike
>> The Horde Project
>> http://www.horde.org
>> https://www.facebook.com/hordeproject
>> https://www.twitter.com/hordeproject
>>
>> --
>> kronolith mailing list
>> Frequently Asked Questions: http://wiki.horde.org/FAQ
>> To unsubscribe, mail:
>
>> kronolith-unsubscribe at .horde
>
>>
>>
>> attachment0 (9K)
>> <http://horde.690.n7.nabble.com/attachment/144221/0/attachment0>
>> attachment1 (838 bytes)
>> <http://horde.690.n7.nabble.com/attachment/144221/1/attachment1>
>
> I've tried to do the same but inside the *function appauthenticated()* but
> without success.  The user  fb_cal only appears after the second login.

Try creating a Kronolith_Calendars_Manager object first, the first  
time it's instantiated it checks for and creates the user's default  
share.:

  $calendar_manager = $injector->createInstance('Kronolith_CalendarsManager');

You're also always assuming that the first entry in the list of  
displayed calendars is the one that fb should be using. It would be  
more correct to use Kronolith::getDefaultCalendar();

So:


      $calendar_manager =  
$injector->createInstance('Kronolith_CalendarsManager');
      $default_calendar = Kronolith::getDefaultCalendar();

should get you the user's default calendar.

>     public function appauthenticated()
>     {
>           $fb_cals = $GLOBALS['prefs']->getValue('fb_cals');
>
>           if ($fb_cals == 'a:0:{}' || $fb_cals ==
> 'a:1:{i:0;s:32:"internal_";}' || empty($fb_cals)) {
>               $display_calendars =
> @unserialize($GLOBALS['prefs']->getValue('display_cals'));
>               $fb_url = 'a:1:{i:0;s:32:"internal_' . $display_calendars[0] .
> '";}';
>               $GLOBALS['prefs']->setValue('fb_cals', $fb_url);
>               $scope_ob->set($pref, $fb_url);
>               $scope_ob->setDirty($pref, true);
>           }
>     }
>
>
>
> --
> Sent from: http://horde.690.n7.nabble.com/Horde-Kronolith-f87467.html
> --
> kronolith mailing list
> Frequently Asked Questions: http://wiki.horde.org/FAQ
> To unsubscribe, mail: kronolith-unsubscribe at lists.horde.org



-- 
mike
The Horde Project
http://www.horde.org
https://www.facebook.com/hordeproject
https://www.twitter.com/hordeproject
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-keys
Size: 9272 bytes
Desc: PGP Public Key
URL: <https://lists.horde.org/archives/kronolith/attachments/20190614/38f5f3c8/attachment-0002.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 821 bytes
Desc: PGP Digital Signature
URL: <https://lists.horde.org/archives/kronolith/attachments/20190614/38f5f3c8/attachment-0003.bin>


More information about the kronolith mailing list