[#14753] Doubled name at importing a vcf-file or synchronizing with CardDAV
Summary Doubled name at importing a vcf-file or synchronizing with CardDAV
Queue Turba
Queue Version 4.2.21
Type Bug
State Feedback
Priority 2. Medium
Owners
Requester softload@justmail.de
Created 2017-12-15 (839 days ago)
Due
Updated 2018-01-22 (801 days ago)
Assigned 2018-01-22 (801 days ago)
Resolved
Milestone
Patch No

Comments
softload@justmail.de 2017-12-15 19:27:48
When importing the attached vcf-file or synchronized it with CardDAV, 
the contact Test2, which has only a last-name, gets the last-name as 
additional first-name. So the name is doubled. The reason is the name 
in the FN-field of the vcf-file and the parsing at importing. The user 
could be patched this by shut-off the parsing. This could be done with 
a local-setupfile backends.local.php in /etc/horde/turba. Following 
entry has to be in the file:

<?php
$cfgSources['localsql']['map']['name']['parse'] = array('none');

Because of another bug the array must have an entry. Otherwise nothing 
can be imported.

softload@justmail.de 2018-01-01 16:11:01
The Problem is in class Turba_Driver in function toDriverKeys in file 
horde/turba/lib/Driver.php. This function use the settings 
$cfgSources['localsql']['map']['name']['parse'] in 
horde/turba/config/backends.php. The first array is array('fields' => 
array('firstname', 'middlenames', 'lastname'), 'format' => '%s %s 
%s'). Is there only a lastname in FN-field of the vcf-file, this entry 
is read as firstname. The middlenames isn't set, if nothing else is in 
FN-field. In line 330 of Driver.php it is then checked, that lastname 
already is set, because of the N-field of the vcf-file. Then both 
for-loops are break. But the Problem is in Line 342. The variable 
$tmp_fields isn't empty and now the fault mapping of the FN-field is 
merge to the existing $fields. The correct way would be to clean the 
array $tmp_fields before breaking the loops.

But i think it is not good to break all loops, because there can be 
additional entrys in FN-field, which wouldn't be set of the N-field. 
So the break in line 333 should be only one break.  But then the 
setting of $tmp_fields in line 335 should be before the break, because 
of a break, the counter isn't correct.

The second bug is the array_merge in line 342. If the parsing-Array is 
empty, $tmp_fields isn't set and array_merge return nothing. So 
$fields is erased. There are two solutions. Set $tmp_fields to an 
empty Array additional before the loop or check $tmp_fields if it is 
set. I prefer the last one.

I made all changes in the appended file "Driver new.php"

softload@justmail.de 2018-01-01 16:13:31
And there should another parsing-entry in backends.php.
array('fields' => array('lastname'), 'format' => '%s')

I made this change in the appended file "backends new.php"

Jan Schneider <jan@horde.org> 2018-01-22 16:48:44
Can you provide patches against those files instead? This way your 
changes are much easier to read and don't depend on the release version.

softload@justmail.de 2018-01-22 17:26:54
> Can you provide patches against those files instead? This way your 
> changes are much easier to read and don't depend on the release 
> version.

  Sorry, but i don't know, how patches can be done with php. That's 
the reason i tried to explain the changes with the line numbers and 
comments in the provided files.

Jan Schneider <jan@horde.org> 2018-01-22 17:31:23
You do this like with any files. Compare the old and the new versions with:
diff -u old.php new.php

softload@justmail.de 2018-01-22 19:39:58
> You do this like with any files. Compare the old and the new versions with:
> diff -u old.php new.php

Here are the patches now. The first for turba/lib/Driver.php

softload@justmail.de 2018-01-22 19:40:57
>> You do this like with any files. Compare the old and the new versions with:
>> diff -u old.php new.php
>
> Here are the patches now. The first for turba/lib/Driver.php

And the next for turba/config/backends.php