Skip to content

Commit

Permalink
Fix synchronizing tags with Kolab categories.
Browse files Browse the repository at this point in the history
  • Loading branch information
yunosh committed Mar 5, 2014
1 parent 9928591 commit def59ce
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 17 deletions.
1 change: 1 addition & 0 deletions turba/config/backends.php
Expand Up @@ -607,6 +607,7 @@
'__uid' => 'uid',
'__type' => '__type',
'__members' => '__members',
'__internaltags' => 'categories',
/* Personal */
'name' => array(
'fields' => array(
Expand Down
12 changes: 4 additions & 8 deletions turba/lib/Driver/Kolab.php
Expand Up @@ -223,10 +223,6 @@ public function toTurbaKeys(array $entry)
$entry['last-name'] = $entry['display-name'];
}

if (!empty($entry['categories'])) {
$entry['categories'] = $entry['categories'][0];
}

return parent::toTurbaKeys($entry);
}

Expand Down Expand Up @@ -367,10 +363,6 @@ public function connect()
unset($contact['address']);
}

if (isset($contact['categories'])) {
$contact['__internaltags'] = $contact['categories'];
}

if (!empty($contact['birthday'])) {
$contact['birthday'] = $contact['birthday']->format('Y-m-d');
}
Expand Down Expand Up @@ -630,6 +622,10 @@ protected function _read($key, $ids, $owner, array $fields,
}
$object = $this->_contacts_cache[$id];

if (isset($object['categories'])) {
$object['categories'] = serialize($object['categories']);
}

if (!isset($object['__type']) || $object['__type'] == 'Object') {
if ($count) {
$result = array();
Expand Down
9 changes: 1 addition & 8 deletions turba/lib/Form/EditContact.php
Expand Up @@ -50,20 +50,13 @@ public function __construct($vars, Turba_Object $contact)

$object_values = $vars->get('object');
$object_keys = array_keys($contact->attributes);
$object_keys[] = '__tags';
foreach ($object_keys as $info_key) {
if (!isset($object_values[$info_key])) {
$object_values[$info_key] = $contact->getValue($info_key);
}
}

/* Get tags. */
if (!isset($object_values['__tags']) &&
($tagger = $injector->getInstance('Turba_Tagger')) &&
!($tagger instanceof Horde_Core_Tagger_Null) &&
($uid = $contact->getValue('__uid'))) {
$object_values['__tags'] = implode(', ', $tagger->getTags($uid, 'contact'));
}

$vars->set('object', $object_values);
$vars->set('source', $contact->getSource());
}
Expand Down
3 changes: 2 additions & 1 deletion turba/lib/Object.php
Expand Up @@ -214,13 +214,14 @@ public function hasValue($attribute)
public function synchronizeTags(array $tags)
{
if (!is_null($internaltags = $this->getValue('__internaltags'))) {
$internaltags = unserialize($internaltags);
usort($tags, 'strcoll');
if (array_diff($internaltags, $tags)) {
$GLOBALS['injector']->getInstance('Turba_Tagger')->replaceTags(
$this->getValue('__uid'),
$internaltags,
$this->driver->getContactOwner(),
'task'
'contact'
);
}
$this->setValue('__tags', implode(', ', $internaltags));
Expand Down

0 comments on commit def59ce

Please sign in to comment.