[dev] Littles questions for using API's methods

Gerard Breiner gerard.breiner at ias.u-psud.fr
Mon Aug 6 15:27:41 UTC 2012


Le 6 août 2012 à 09:28, Jan Schneider a écrit :

> 
> Zitat von Gerard Breiner <gerard.breiner at ias.u-psud.fr>:
> 
>> Hello,
>> 
>> At this time I can export/import all main calendars kronolith to davical but it seems there is an issue about permission. In fact each of all ics files ì get has a SUMMARY:busy...
>> I found it is due to kronolith/lib/Event.php getTitle method in which it seems the current user has not permissions.
>> [CODE]
>> // We explicitly allow admin access here for the alarms notifications.
>>        if (!$GLOBALS['registry']->isAdmin() && $this->private && $this->creator != $user) {
>>              return _("busy");
>>             } elseif ($GLOBALS['registry']->isAdmin() || $this->hasPermission(Horde_Perms::READ, $user)) {
>>                   return strlen($this->title) ? $this->title : _("[Unnamed event]");
>>             }  else {
>>                        return _("busy");
>>             }
>> [/CODE]
>> 
>> Could you please indicate me  how to set up the permissions in my script :
>> 
>> [CODE]
>> #!/usr/bin/env php
>> <?php
>> set_include_path('/www/horde4/pear/php' . PATH_SEPARATOR . get_include_path());
>> if (file_exists(dirname(__FILE__) . '/../../kronolith/lib/Application.php')) {
>>    $baseDir = dirname(__FILE__) . '/../';
>> } else {
>>    require_once 'PEAR/Config.php';
>>    $baseDir = PEAR_Config::singleton()
>>        ->get('horde_dir', null, 'pear.horde.org') . '/kronolith/';
>> }
>> 
>> require_once dirname(__FILE__) . '/../lib/Application.php';
>> Horde_Registry::appInit('kronolith', array(
>>    'cli' => true
>> ));
>> // Call a Registry method.
>> // Retrieve a list of users associated with each calendar, and
>>    // thus a list of users who have used kronolith and
>>    // potentially have an agenda preference set.
>>    $calendars = $GLOBALS['kronolith_shares']->listAllShares();
>>    $users = array();
>>    foreach (array_keys($calendars) as $calendarId) {
>>        try {
>>            $calendar = $GLOBALS['kronolith_shares']->getShare($calendarId);
>>        } catch (Exception $e) {
>>            die($e->getMessage());
>>        }
>>        $users = array_merge($users, $calendar->listUsers(Horde_Perms::READ));
>>    }
>> // Remove duplicates.
>>    $users = array_unique($users);
>> natcasesort($users);
>> // Tell the registry that we are doing authentication ourselves.
>> define('AUTH_HANDLER', true);
> 
>  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> This is H3 code.
So, what is the H4 code ?
Something like this for getting users ? :

[CODE]
$db = $injector->getInstance('Horde_Db_Adapter');
if (!empty($options['debug'])) {
    $logger = new Horde_Log_Logger(new Horde_Log_Handler_Stream(STDOUT));
    $db->setLogger($logger);
$sql2 = 'SELECT DISTINCT share_owner  FROM kronolith_shares';

 try {
    $useruids = $db->selectValues($sql2);
} catch (Horde_Db_Exception $e) {
    die($e->getMessage());
}
natcasesort($useruids);}
[/CODE]
That works but I suppose it is still H3…. ?


> 
>> $contentType = 'text/calendar';
>> foreach ($users as $user) {
>>   $registry->setAuth($user, array('password' => ''));
> 
>     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> You are explicitely setting a user here that is *not* an admin.

Yes, but if I do understand,  the user may be other than admin if he has permission on the current event.
this is checked in kronolith/lib/Event.php getTitle()  line : [CODE] } elseif ($GLOBALS['registry']->isAdmin() || $this->hasPermission(Horde_Perms::READ, $user)) [/CODE]. If I put a negation on the "hasPermission" it works. It is this condition that put a "busy" for SUMMARY. Yet in my code I specified "Horde_Perms::READ"….

Best regards.

Gérard Breiner



> 
>>   $cals[$user] = $registry->call('calendar/listCalendars', array(true, HORDE_PERMS::READ));
>>   if ($cals[$user]['0'] != '') {
>>      if (strpbrk($user, '*') != true) {
>>       if ($user != 'mmiville')  {
>>           $export[$user] = $registry->call('calendar/exportCalendar', array($cals[$user]['0'], $contentType, Horde_Perms::READ));
>>           $file = '/home/webadm/exported_calendars/' . $user . '.ics';
>>           $hdl = fopen ($file, a);
>>           fwrite($hdl,($export[$user]));
>> 
>> }
>> }
>> } //end of foreach
>> fclose($hdl);
>> [/CODE]
>> 
>> Any help would be appreciated.
>> 
>> Best regards.
>> 
>> Gérard Breiner
>> 
>> Le 15 juin 2012 à 22:05, Gerard Breiner a écrit :
>> 
>>> Many thanks again Jan? I read the doc?  No doubt that Xdebug is a very suitable tool for debugging?
>>> However for this time  I finally chose to debug  by adding temporarily a var_dump(events) at the line 845 in kronolith/lib/Api.php... I found a event_recurtype field  set to 1 which I replace by the NULL value and afterwards the calendar has been exported without another error.
>>> 
>>> Best regards.
>>> 
>>> Gérard
>>> 
>>> 
>>> Le 14 juin 2012 à 14:29, Jan Schneider a écrit :
>>> 
>>>> 
>>>> Zitat von Gerard Breiner <gerard.breiner at ias.u-psud.fr>:
>>>> 
>>>>> Many thanks Jan for your fast answer?. However, I Installed Xdebug  but I'm trying to use it without result?
>>>>> Yet it is installed? php -m list :  [
>>>>> Zend Modules]
>>>>> Xdebug
>>>>> 
>>>>> In my Cli php.ini I added  :
>>>>> 
>>>>> [CODE]
>>>>> error_reporting = E_ALL & E_NOTICE
>>>>> 
>>>>> [xdebug]
>>>>> zend_extension="/usr/lib64/php5/20090626/xdebug.so"
>>>>> ;xdebug.default_enable=Off
>>>>> xdebug.default_enable=1
>>>>> xdebug.show_local_vars=1
>>>>> xdebug.trace_format=2
>>>>> xdebug.trace_output_dir="/www/horde4/log"
>>>>> xdebug.trace_output_name="xdebug.log"
>>>>> 
>>>>> [/CODE]
>>>>> 
>>>>> When I run my script "exportCalendars.phpt" for the calendars which has a bad event I get :
>>>>> 
>>>>> PHP Notice:  Undefined index: SERVER_NAME in /www/horde4/config/horde.local.php on line 12
>>>>> PHP Stack trace:
>>>>> PHP   1. {main}() /www/horde4/pear/exportcals.php:0
>>>>> PHP   2. require_once() /www/horde4/pear/exportcals.php:12
>>>>> PHP   3. require_once() /www/horde4/lib/Application.php:18
>>>>> PHP   4. include_once() /www/horde4/lib/core.php:40
>>>>> PHP Notice:  Undefined index: SERVER_PORT in /www/horde4/config/horde.local.php on line 13
>>>>> PHP Stack trace:
>>>>> PHP   1. {main}() /www/horde4/pear/exportcals.php:0
>>>>> PHP   2. require_once() /www/horde4/pear/exportcals.php:12
>>>>> PHP   3. require_once() /www/horde4/lib/Application.php:18
>>>>> PHP   4. include_once() /www/horde4/lib/core.php:40
>>>>> PHP Notice:  Undefined index: SERVER_NAME in /www/horde4/config/horde.local.php on line 22
>>>>> PHP Stack trace:
>>>>> PHP   1. {main}() /www/horde4/pear/exportcals.php:0
>>>>> PHP   2. require_once() /www/horde4/pear/exportcals.php:12
>>>>> PHP   3. require_once() /www/horde4/lib/Application.php:18
>>>>> PHP   4. include_once() /www/horde4/lib/core.php:40
>>>>> 
>>>>> ====================
>>>>> 
>>>>> Fatal Error:
>>>>> DateTime::__construct(): Failed to parse time string (-001-11-01) at position 7 (-): Double timezone specification
>>>>> 
>>>>> 1. Horde_Registry->call() /www/horde4/pear/exportcals.php:68
>>>>> 2. Horde_Registry->callByPackage() /www/horde4/pear/php/Horde/Registry.php:979
>>>>> 3. call_user_func_array() /www/horde4/pear/php/Horde/Registry.php:1020
>>>>> 4. Kronolith_Api->exportCalendar()
>>>>> 5. Kronolith_Event->toiCalendar() /www/horde4/kronolith/lib/Api.php:846
>>>>> 6. Horde_Date->__construct() /www/horde4/kronolith/lib/Event.php:842
>>>>> 7. Horde_Date->_initializeFromArgs() /www/horde4/pear/php/Horde/Date.php:201
>>>>> 8. Horde_Date->_initializeFromArray() /www/horde4/pear/php/Horde/Date.php:1045
>>>>> 9. Horde_Date->_correct() /www/horde4/pear/php/Horde/Date.php:1076
>>>>> 10. Horde_Date_Utils::daysInMonth() /www/horde4/pear/php/Horde/Date.php:1009
>>>>> 11. DateTime->__construct() /www/horde4/pear/php/Horde/Date/Utils.php:58
>>>>> 
>>>>> I wonder what else I have to configure for Xdebug  works.
>>>> 
>>>> See http://xdebug.org/docs/stack_trace especially xdebug.collect_params
>>>> 
>>>>> 
>>>>> Best regards.
>>>>> 
>>>>> Gérard
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> 
>>>>> Le 11 juin 2012 à 16:58, Jan Schneider a écrit :
>>>>> 
>>>>>> Install Xdebug and you should get a backtrace with function call parameter that would help identifying the broken event.
>>>>>> 
>>>>>> Zitat von Gerard Breiner <gerard.breiner at ias.u-psud.fr>:
>>>>>> 
>>>>>>> Hello,
>>>>>>> 
>>>>>>> I come here back for saying my script works and do what he is supposed to do? I think to have identified the calendar for which "calendar/exportCalendars" rise the error  "Double timezone specification".
>>>>>>> Is there a way for identifying what is not clean inside this calendar ?
>>>>>>> 
>>>>>>> Many thanks in advance.
>>>>>>> 
>>>>>>> Best regards.
>>>>>>> 
>>>>>>> Gérard
>>>>>>> 
>>>>>>> 
>>>>>>> Le 6 juin 2012 à 17:08, Gerard Breiner a écrit :
>>>>>>> 
>>>>>>>> Many thanks Jan, Mike?.
>>>>>>>> 
>>>>>>>> I picked up a few pieces of code and now I might expect  to get an export of all the calendar but I'm facing an error when I run 'calendar/exportCalendars' method :
>>>>>>>> It seems this error occurs for calendars whose owners has never create an event.
>>>>>>>> 
>>>>>>>> Fatal Error:
>>>>>>>> DateTime::__construct(): Failed to parse time string (-001-11-01) at position 7 (-): Double timezone specification
>>>>>>>> 
>>>>>>>> It seems this error is raised at :
>>>>>>>> DateTime->__construct() /www/horde4/pear/php/Horde/Date/Utils.php:58
>>>>>>>> 
>>>>>>>> At this time my code is :
>>>>>>>> 
>>>>>>>> [CODE]
>>>>>>>> #!/usr/bin/env php
>>>>>>>> <?php
>>>>>>>> set_include_path('/www/horde4/pear/php' . PATH_SEPARATOR . get_include_path());
>>>>>>>> if (file_exists(dirname(__FILE__) . '/../../kronolith/lib/Application.php')) {
>>>>>>>> $baseDir = dirname(__FILE__) . '/../';
>>>>>>>> } else {
>>>>>>>> require_once 'PEAR/Config.php';
>>>>>>>> $baseDir = PEAR_Config::singleton()
>>>>>>>>    ->get('horde_dir', null, 'pear.horde.org') . '/kronolith/';
>>>>>>>> }
>>>>>>>> 
>>>>>>>> require_once dirname(__FILE__) . '/../lib/Application.php';
>>>>>>>> Horde_Registry::appInit('kronolith', array(
>>>>>>>> 'cli' => true
>>>>>>>> ));
>>>>>>>> // Call a Registry method.
>>>>>>>> // Retrieve a list of users associated with each calendar, and
>>>>>>>> // thus a list of users who have used kronolith and
>>>>>>>> // potentially have an agenda preference set.
>>>>>>>> $calendars = $GLOBALS['kronolith_shares']->listAllShares();
>>>>>>>> $users = array();
>>>>>>>> foreach (array_keys($calendars) as $calendarId) {
>>>>>>>>    try {
>>>>>>>>        $calendar = $GLOBALS['kronolith_shares']->getShare($calendarId);
>>>>>>>>    } catch (Exception $e) {
>>>>>>>>        continue;
>>>>>>>>    }
>>>>>>>>    $users = array_merge($users, $calendar->listUsers(Horde_Perms::READ));
>>>>>>>> }
>>>>>>>> // Remove duplicates.
>>>>>>>> $users = array_unique($users);
>>>>>>>> 
>>>>>>>> // Tell the registry that we are doing authentication ourselves.
>>>>>>>> define('AUTH_HANDLER', true);
>>>>>>>> 
>>>>>>>> $contentType = 'text/calendar';
>>>>>>>> foreach ($users as $user) {
>>>>>>>> $registry->setAuth($user, array('password' => ''));
>>>>>>>> $cals[$user] = $registry->call('calendar/listCalendars', array('true', 'HORDE_PERMS::READ'));
>>>>>>>> if ($cals[$user]['0'] != '') {
>>>>>>>>   $export[$user] = $registry->call('calendar/exportCalendar', array($cals[$user]['0'], $contentType, 'Horde_Perms::READ'));
>>>>>>>>   $file = '/home/webadm/exportCalendars/' . $user . '.ics';
>>>>>>>>   $hdl = fopen($file, a);
>>>>>>>>   fwrite($hdl, $export[$user]);
>>>>>>>> }
>>>>>>>> 
>>>>>>>> }
>>>>>>>> fclose($hdl);
>>>>>>>> [/CODE]
>>>>>>>> 
>>>>>>>> Best regards.
>>>>>>>> 
>>>>>>>> Gérard
>>>>>>>> 
>>>>>>>> 
>>>>>>>> Le 4 juin 2012 à 17:20, Michael J Rubinsky a écrit :
>>>>>>>> 
>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> Quoting Gerard Breiner <gerard.breiner at ias.u-psud.fr>:
>>>>>>>>> 
>>>>>>>>>> Hello Mike,
>>>>>>>>>> 
>>>>>>>>>> Thanks for these precisions? It make me understand what Jan meant?
>>>>>>>>>> I will try soon to reduce registry.local.php and kept only what is necessary.
>>>>>>>>>> 
>>>>>>>>>> I have another question about calendar permissions and listCalendars.
>>>>>>>>>> In the admin interface admin/perms I have assigned the permissions 'show' and 'read' to allow the user webadm access to all agendas.
>>>>>>>>>> I dont understand why with the below code I do not list all the calendars but only the others users shares with "webadm" user? It is like the perms I setup has not been validated.
>>>>>>>>> 
>>>>>>>>> Permissions for calendars are set by the owner of the calendar, from within Kronolith - not from the administrative interface. Look on the calendar's property view.
>>>>>>>>> 
>>>>>>>>> 
>>>>>>>>> --
>>>>>>>>> mike
>>>>>>>>> 
>>>>>>>>> The Horde Project (www.horde.org)
>>>>>>>>> mrubinsk at horde.org
>>>>>>>> 
>>>>>>>> --
>>>>>>>> dev mailing list
>>>>>>>> Frequently Asked Questions: http://wiki.horde.org/FAQ
>>>>>>>> To unsubscribe, mail: dev-unsubscribe at lists.horde.org
>>>>>>> 
>>>>>>> --
>>>>>>> dev mailing list
>>>>>>> Frequently Asked Questions: http://wiki.horde.org/FAQ
>>>>>>> To unsubscribe, mail: dev-unsubscribe at lists.horde.org
>>>>>> 
>>>>>> --
>>>>>> Jan Schneider
>>>>>> The Horde Project
>>>>>> http://www.horde.org/
>>>>>> 
>>>>>> 
>>>>>> --
>>>>>> dev mailing list
>>>>>> Frequently Asked Questions: http://wiki.horde.org/FAQ
>>>>>> To unsubscribe, mail: dev-unsubscribe at lists.horde.org
>>>> 
>>>> --
>>>> Jan Schneider
>>>> The Horde Project
>>>> http://www.horde.org/
>>>> 
>>>> 
>>> 
>>> --
>>> dev mailing list
>>> Frequently Asked Questions: http://wiki.horde.org/FAQ
>>> To unsubscribe, mail: dev-unsubscribe at lists.horde.org
> 
> 
> -- 
> Jan Schneider
> The Horde Project
> http://www.horde.org/
> 



More information about the dev mailing list