[sync] Turba and Syncml patch proposal

Karsten Fourmont fourmont at gmx.de
Tue Nov 30 12:13:05 PST 2004


OK, here's my proposed patch for Turba. It contains the following changes

lib/Driver.php:
-fixes history to use logging guid  'turba:source:uid' rather than guid 
only.
-adds support for a few additional fields ("URL", "PAGER", name prefix) 
to turba/lib/Driver.php: tohash and tovcard

lib/api.php
-adds contenttype text/x-vcard support to turba_replace. Currently it 
supports only array.
-turba_[replace|delete|export] now accept a guid as turba:source:guid 
string or as
  $uid= array('addressbook' => 'source , 'contactId' => guid) array
  Currently they do nothing (or just raise an pear_error)
-turba_[replace|delete|export] now all use __uid rather than __key for 
identifying the object
-turba_import now uses the default address book from the prefs if no 
source is specified.
  If this doesn't work the first user writeable address book is used.
-turba_import returns a guid in turba:source:guid format

What I don't know is if the api is supposed to use the keys or the uids 
  and if the turba:source:uid form is still valid.
My patch goes in the direction of using uids (not keys) in the format 
"turba:source:uid". I think that's consistent with the api.php of the 
other modules, only with the addition of the :source part to specify the 
address book.

I haven't found anyhting in the archive about the reasons for 
introducing seperate keys and uids and the "disabling" of turba_export. 
So if there's anything I missed, a few pointers would be great.

Is it Ok to commit this patch?

Once this is done, syncing addresses should be working. All you need is 
a matching source.php/attributes.php/database. I'll post a seperate 
message about this.


  Karsten

-------------- next part --------------
Index: lib/Driver.php
===================================================================
RCS file: /repository/turba/lib/Driver.php,v
retrieving revision 1.55
diff -r1.55 Driver.php
431,432c431,432
<         $history->log($uid, array('action' => 'add'), true);
< 
---
>         $history->log('turba:' . $this->name . ':' . $uid,
>                         array('action' => 'add'), true); 
463,464c463,464
<         $history->log($object->getValue('__uid'), array('action' => 'delete'), true);
< 
---
>         $history->log('turba:' . $this->name . ':' . $object->getValue('__uid'),
>                       array('action' => 'delete'), true);
505c505,506
<         $history->log($object->getValue('__uid'), array('action' => 'modify'), true);
---
>         $history->log('turba:' . $this->name . ':' . $object->getValue('__uid'), 
>                       array('action' => 'modify'), true);
587a589,592
>             case 'pager':
>                 $vcard->setAttribute('TEL', $val, array('TYPE'=>'PAGER'));
>                 break;
> 
591a597,600
>             case 'website':
>                 $vcard->setAttribute('URL', $val);
>                 break;
> 
615c624
<                 VCARD_N_PREFIX      => '',
---
>                 VCARD_N_PREFIX      => isset($hash['name_prefix']) ? $hash['name_prefix'] : '',
679a689
>                 $hash['name_prefix'] = $name[VCARD_N_PREFIX];
739a750,751
>                 } elseif (isset($item['params']['PAGER'])) {
>                     $hash['pager'] = $item['value'];
753a766,767
>                         } elseif (String::upper($tel) == 'PAGER') {
>                             $hash['pager'] = $item['value'];
762a777,778
>                     } elseif (isset($item['params']['Pager'])) {
>                         $hash['pager'] = $item['value'];
774a791,794
>             case 'URL':
>                 $hash['website'] = $item['value'];
>                 break;
> 
Index: lib/api.php
===================================================================
RCS file: /repository/turba/lib/api.php,v
retrieving revision 1.118
diff -r1.118 api.php
312c312
<     global $cfgSources;
---
>     global $cfgSources,$prefs;
313a314,331
>     // get default address book from prefs
>     if(empty($source)) {
>         $source = $prefs->getValue('default_dir');
>     }
>     // check if source is writeable
>     if (!empty($source) && !empty($cfgSources[$source]['readonly'])) {
>         $source = false;
>     }
>     // search for first writable source:
>     if(empty($source)) {
>         foreach ($cfgSources as $key => $curSource) {
>             if (empty($curSource['readonly'])) {
>                 $source = $key;
>                 break;
>             }
>         }
>     }
>     
381c399
<     return $object->getValue('__key');
---
>     return 'turba:' . $source . ':' . $object->getValue('__uid');
407,412c425,433
<     // Need to reference some sort of mapping here to turn the UID
<     // into a source id and contact id:
<     //
<     // $source = $uid['addressbook'];
<     // $objectId = $uid['contactId'];
<     return PEAR::raiseError('Turba needs a UID map');
---
>     if (is_array($uid)) {
>         $source = $uid['addressbook'];
>         $objectId = $uid['contactId'];
>     } else {
>         if (substr($uid,0,6) == 'turba:') {
>             $uid = substr($uid,6);
>         }
>         list($source, $objectId) = explode(':', $uid, 2);
>     }
432c453
<     $result = $driver->search(array('__key' => $objectId));
---
>     $result = $driver->search(array('__uid' => $objectId));
498,501c519,527
<     //
<     // $source = $uid['addressbook'];
<     // $objectId = $uid['contactId'];
<     return PEAR::raiseError('Turba needs a UID map');
---
>     if (is_array($uid)) {
>         $source = $uid['addressbook'];
>         $objectId = $uid['contactId'];
>     } else {
>         if (substr($uid,0,6) == 'turba:') {
>             $uid = substr($uid,6);
>         }
>         list($source, $objectId) = explode(':', $uid, 2);
>     }
521c547
<     $result = $driver->search(array('__key' => $objectId));
---
>     $result = $driver->search(array('__uid' => $objectId));
548,553c574,582
<     // Need to reference some sort of mapping here to turn the UID
<     // into a source id and contact id:
<     //
<     // $source = $uid['addressbook'];
<     // $objectId = $uid['contactId'];
<     return PEAR::raiseError('Turba needs a UID map');
---
>     if (is_array($uid)) {
>         $source = $uid['addressbook'];
>         $objectId = $uid['contactId'];
>     } else {
>         if (substr($uid,0,6) == 'turba:') {
>             $uid = substr($uid,6);
>         }
>         list($source, $objectId) = explode(':', $uid, 2);
>     }
565,569c594,601
<     $object = $driver->getObject($objectId);
<     if (is_a($object, 'PEAR_Error')) {
<         return $object;
<     } elseif (!Turba::hasPermission($object, 'object', PERMS_EDIT)) {
<         return PEAR::raiseError(_("Permission Denied"), 'horde.warning');
---
>     $result = $driver->search(array('__uid' => $objectId));
>     if (is_a($result, 'PEAR_Error')) {
>         return $result;
>     } elseif ($result->count() == 0) {
>         return PEAR::raiseError(_("Object not found"), 'horde.error', null, null, $source);
>         return true;
>     } elseif ($result->count() > 1) {
>         return PEAR::raiseError("Internal Horde Error: multiple turba objects with same objectId.", 'horde.error', null, null, $source);
570a603
>     $object = $result->objects[0];
574a608,624
>     case 'text/x-vcard':
>         require_once 'Horde/iCalendar.php';
>         $iCal = &new Horde_iCalendar();
>         if (!$iCal->parsevCalendar($content)) {
>             return PEAR::raiseError(_("There was an error importing the iCalendar data."));
>         }
>         switch ($iCal->getComponentCount()) {
>         case 0:
>             return PEAR::raiseError(_("No vCard data was found."));
>         case 1:
>             $content = $iCal->getComponent(0);
>             $content = $driver->toHash($content);
>             break;
>         default:
>             return PEAR::raiseError(_("Only one vcard supported."));
>         }
>         break;


More information about the sync mailing list