From: Jan Schneider Date: Mon, 5 Jul 2010 10:34:25 +0000 (+0200) Subject: Implement contact merging. X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a85e65cacb497253afbf558a31e439fc8d265ae4;p=horde.git Implement contact merging. --- diff --git a/turba/docs/CHANGES b/turba/docs/CHANGES index 16ef1ff46..3479ab4b5 100644 --- a/turba/docs/CHANGES +++ b/turba/docs/CHANGES @@ -2,6 +2,7 @@ v3.0-git -------- +[jan] Add duplicate search and merging. [mjr] The listTimeObjects API now returns categories for each source individually instead of returning only the categories available (Request #8504). diff --git a/turba/edit.php b/turba/edit.php index e9e2019c8..dc4a71030 100644 --- a/turba/edit.php +++ b/turba/edit.php @@ -81,7 +81,12 @@ if ($groupedit) { $edited = $form->execute(); if (!is_a($edited, 'PEAR_Error')) { $url = Horde_Util::getFormData('url'); - header('Location: ' . (empty($url) ? $contact->url('Contact', true) : $url)); + if (empty($url)) { + $url = $contact->url('Contact', true); + } else { + $url = new Horde_Url($url, true); + } + header('Location: ' . $url->add('unique', hash('md5', microtime()))); exit; } diff --git a/turba/lib/Object.php b/turba/lib/Object.php index f651afc40..268eb10d1 100644 --- a/turba/lib/Object.php +++ b/turba/lib/Object.php @@ -224,6 +224,21 @@ class Turba_Object { } /** + * Merges another contact into this one by filling empty fields of this + * contact with values from the other. + * + * @param Turba_Object $contact Another contact. + */ + function merge(Turba_Object $contact) + { + foreach (array_keys($contact->attributes) as $attribute) { + if (!$this->hasValue($attribute) && $contact->hasValue($attribute)) { + $this->setValue($attribute, $contact->getValue($attribute)); + } + } + } + + /** * Returns history information about this contact. * * @return array A hash with the optional entries 'created' and 'modified' diff --git a/turba/lib/View/Duplicates.php b/turba/lib/View/Duplicates.php index 2f357f557..e2d00a76e 100644 --- a/turba/lib/View/Duplicates.php +++ b/turba/lib/View/Duplicates.php @@ -73,7 +73,9 @@ class Turba_View_Duplicates $view = new Horde_View(array('templatePath' => TURBA_TEMPLATES . '/search/duplicate')); new Horde_View_Helper_Text($view); - $hasDuplicate = $this->_type && $this->_duplicate; + $hasDuplicate = $this->_type && $this->_duplicate && + isset($this->_duplicates[$this->_type]) && + isset($this->_duplicates[$this->_type][$this->_duplicate]); if ($hasDuplicate) { $vars = new Horde_Variables(); $view->type = $attributes[$this->_type]['label']; @@ -81,13 +83,14 @@ class Turba_View_Duplicates echo $view->render('header'); $view->contactUrl = Horde::applicationUrl('contact.php'); + $view->mergeUrl = Horde::applicationUrl('merge.php'); $view->first = true; $duplicate = $this->_duplicates[$this->_type][$this->_duplicate]; while ($contact = $duplicate->next()) { $contact->lastModification(); } $duplicate->sort(array(array('field' => '__modified', 'ascending' => false))); - $view->mergeInto = $duplicate->reset()->getValue('__key'); + $view->mergeTarget = $duplicate->reset()->getValue('__key'); while ($contact = $duplicate->next()) { $view->source = $contact->getSource(); $view->id = $contact->getValue('__key'); diff --git a/turba/merge.php b/turba/merge.php new file mode 100644 index 000000000..4449b8537 --- /dev/null +++ b/turba/merge.php @@ -0,0 +1,50 @@ + + */ + +require_once dirname(__FILE__) . '/lib/Application.php'; +Horde_Registry::appInit('turba'); + +$source = Horde_Util::getFormData('source'); +$key = Horde_Util::getFormData('key'); +$mergeInto = Horde_Util::getFormData('merge_into'); +$driver = Turba_Driver::singleton($source); + +if ($url = Horde_Util::getFormData('url')) { + $url = new Horde_Url($url, true); + $url->add('unique', hash('md5', microtime())); +} + +$contact = $driver->getObject($mergeInto); +if (is_a($contact, 'PEAR_Error')) { + $notification->push($contact); + header('Location: ' . $url); + exit; +} +$toMerge = $driver->getObject($key); +if (is_a($toMerge, 'PEAR_Error')) { + $notification->push($toMerge); + header('Location: ' . $url); + exit; +} + +$contact->merge($toMerge); +if (is_a($result = $contact->store(), 'PEAR_Error')) { + $notification->push($result); + header('Location: ' . $url); + exit; +} +if (is_a($result = $driver->delete($key), 'PEAR_Error')) { + $notification->push($result); +} + +header('Location: ' . $url); +exit; diff --git a/turba/templates/search/duplicate/contact_header.html.php b/turba/templates/search/duplicate/contact_header.html.php index 65d8c4e8c..314ccb85b 100644 --- a/turba/templates/search/duplicate/contact_header.html.php +++ b/turba/templates/search/duplicate/contact_header.html.php @@ -6,14 +6,13 @@
first): ?> -
+ - " /> -
+