0013292: customfield as duplicate check field does not work for empty values
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 3 Jul 2017 10:33:00 +0000 (12:33 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 3 Jul 2017 12:23:47 +0000 (14:23 +0200)
* do not search for duplicates if field of a group is empty
* also fixes problem with empty 'preferred_address' field

https://forge.tine20.org/view.php?id=13292

Change-Id: I347f3367dbb544740c8c35853953b49332551d07
Reviewed-on: http://gerrit.tine20.com/customers/4993
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Addressbook/Model/Contact.php
tine20/Tinebase/Controller/Record/Abstract.php

index 25c9a20..b2f42f8 100644 (file)
@@ -217,7 +217,7 @@ class Addressbook_Model_Contact extends Tinebase_Record_Abstract
         'tel_prefer_normalized'         => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'tz'                            => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'geo'                           => array(Zend_Filter_Input::ALLOW_EMPTY => true),
-        'preferred_address'             => array(Zend_Filter_Input::ALLOW_EMPTY => true),
+        'preferred_address'             => array(Zend_Filter_Input::ALLOW_EMPTY => true, Zend_Filter_Input::DEFAULT_VALUE => 0),
     // modlog fields
         'created_by'                    => array(Zend_Filter_Input::ALLOW_EMPTY => true),
         'creation_time'                 => array(Zend_Filter_Input::ALLOW_EMPTY => true),
@@ -308,6 +308,7 @@ class Addressbook_Model_Contact extends Tinebase_Record_Abstract
         foreach ($geoFields as $geoField) {
             $this->_filters[$geoField]        = new Zend_Filter_Empty(NULL);
         }
+        $this->_filters['preferred_address']        = new Zend_Filter_Empty(0);
     
         parent::__construct($_data, $_bypassFilters, $_convertDates);
     }
index ea26cba..4d8b8cb 100644 (file)
@@ -764,7 +764,7 @@ abstract class Tinebase_Controller_Record_Abstract
         
         if (Tinebase_Core::isLogLevel(Zend_Log::TRACE)) Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__
             . ' Duplicate check fields: ' . print_r($this->_duplicateCheckFields, TRUE));
-        
+
         $filters = array();
         foreach ($this->_duplicateCheckFields as $group) {
             $addFilter = array();
@@ -772,23 +772,45 @@ abstract class Tinebase_Controller_Record_Abstract
                 $group = array($group);
             }
             foreach ($group as $field) {
-                if (! empty($_record->{$field})) {
-                    if ($field === 'relations') {
-                        $relationFilter = $this->_getRelationDuplicateFilter($_record);
-                        if ($relationFilter) {
-                            $addFilter[] = $relationFilter;
-                        }
+                $customFieldConfig = Tinebase_CustomField::getInstance()->getCustomFieldByNameAndApplication(
+                    $this->_applicationName,
+                    $field,
+                    $this->_modelName
+                );
+
+                if ($customFieldConfig && isset($_record->customfields[$field])) {
+                    $value = $_record->customfields[$field];
+                    if (! empty($value)) {
+                        $addFilter[] = array(
+                            'field' => 'customfield',
+                            'operator' => 'equals',
+                            'value' => array(
+                                'value' => $value,
+                                'cfId' => $customFieldConfig->getId()
+                            )
+                        );
                     } else {
-                        $addFilter[] = array('field' => $field, 'operator' => 'equals', 'value' => $_record->{$field});
+                        // empty: go to next group
+                        continue 2;
                     }
-                    
-                } else if (isset($_record->customfields[$field])) {
-                    $customFieldConfig = Tinebase_CustomField::getInstance()->getCustomFieldByNameAndApplication($this->_applicationName, $field, $this->_modelName);
-                    if ($customFieldConfig) {
-                        $addFilter[] = array('field' => 'customfield', 'operator' => 'equals', 'value' => array(
-                            'value' => $_record->customfields[$field],
-                            'cfId'  => $customFieldConfig->getId()
-                        ));
+
+                } else {
+                    if (! empty($_record->{$field})) {
+                        if ($field === 'relations') {
+                            $relationFilter = $this->_getRelationDuplicateFilter($_record);
+                            if ($relationFilter) {
+                                $addFilter[] = $relationFilter;
+                            }
+                        } else {
+                            $addFilter[] = array(
+                                'field' => $field,
+                                'operator' => 'equals',
+                                'value' => $_record->{$field}
+                            );
+                        }
+                    } else {
+                        // empty: go to next group
+                        continue 2;
                     }
                 }
             }