# Fix Android “bug” with UIDs/URIs on CardDav contacts

## Overview

I recently experienced a strange bug on Android 5.1, when trying to sync my owncloud contacts through DAVDroid. Only some of my contacts would get sync-ed… I finally figured it was because of the domain being included in the UIDs (or URIs) of the vCard in the DB. Example: `01234567-89ab-cdef-0123-456789abcdef@MY_OC_DOMAIN`. Manually changing the ID to `01234567-89ab-cdef-0123-456789abcdef` in the database would fix it.

I made a quick PHP script to update my DB.

## Fix

<note warning>Disclaimer: Although it worked fine for me, I can't be held responsible if it destroys your contact list…</note>

<pre><?php
define('__offStr','@YOUR_DOMAIN');;
mysql_connect('localhost','SQL_USER','SQL_PWD');
mysql_select_db('OC_DATABASE');
 
$rq = 'select id, carddata, uri from oc_contacts_cards';
$rx = mysql_query($rq) or die(mysql_error());
$t = mysql_num_rows($rx);
$n = 0;
while($rs = mysql_fetch_object($rx))
{
        #var_dump($rs);
        $a = !empty($rs->uri) && strpos($rs->uri,__offStr);
        $b = !empty($rs->carddata) && strpos($rs->carddata,__offStr);
        if($a || $b) 
        {
                $r = 'update oc_contacts_cards set';
                if($a)  
                        $r .= ' uri=\''.mysql_real_escape_string(str_replace(__offStr,'',$rs->uri)).'\',';
                if($b)
                        $r .= ' carddata=\''.mysql_real_escape_string(str_replace(__offStr,'',$rs->carddata)).'\',';
                $r .= ' id='.$rs->id.' where id='.$rs->id;      
                $rq = mysql_query($r) or die(mysql_error());
                #var_dump($rs->id);
                #var_dump($n_cd);
                #var_dump($n_uri);
                #var_dump($r);
                #echo '<hr />';
                $n++;
        }
}       
var_dump('Updated '.$n.' of '.$t.' contacts');
?>