mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-18 07:52:21 +01:00
fix bug in ldap->vcard translation that caused the remote update not to work (was hard to find this one !)
This commit is contained in:
parent
98fa8e0b00
commit
ac16864059
@ -473,7 +473,7 @@ class Database extends AbstractBackend {
|
||||
return null;
|
||||
}
|
||||
$row['permissions'] = \OCP\PERMISSION_ALL;
|
||||
return $row;
|
||||
$end = microtime(true);
|
||||
}
|
||||
|
||||
public function hasContact($addressbookid, $id) {
|
||||
@ -648,7 +648,7 @@ class Database extends AbstractBackend {
|
||||
)
|
||||
);
|
||||
}
|
||||
return true;
|
||||
$end = microtime(true);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -213,12 +213,7 @@ class Ldap extends AbstractBackend {
|
||||
*/
|
||||
public function ldapUpdate($ldapDN, $ldapValues) {
|
||||
if (self::ldapIsConnected()) {
|
||||
$result = @ldap_modify($this->ldapConnection, $ldapDN, $ldapValues);
|
||||
if (!$result) {
|
||||
self::ldapDelete($ldapDN);
|
||||
return self::ldapAdd($ldapDN, $ldapValues);
|
||||
}
|
||||
return true;
|
||||
return @ldap_modify($this->ldapConnection, $ldapDN, $ldapValues);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
@ -262,7 +257,6 @@ class Ldap extends AbstractBackend {
|
||||
$this->addressbooks[] = self::getAddressBook($addressbookid);
|
||||
}
|
||||
return $this->addressbooks;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
@ -529,12 +523,14 @@ class Ldap extends AbstractBackend {
|
||||
|
||||
$uri = isset($options['uri']) ? $options['uri'] : null;
|
||||
|
||||
$contact->REV = (new \DateTime)->format(\DateTime::W3C);
|
||||
|
||||
// 2014/02/13 Sometimes, a card is created without a name (I don't like that)...
|
||||
if (!isset($contact->N)) {
|
||||
$generated = "gruik".rand(0, 65535);
|
||||
$generated = "nocn-".rand(0, 65535);
|
||||
$contact->N = $generated;
|
||||
$contact->FN = $generated;
|
||||
error_log("Generated name: $generated");
|
||||
//error_log("Generated name: $generated");
|
||||
}
|
||||
|
||||
if(!$contact instanceof VCard) {
|
||||
@ -545,7 +541,7 @@ class Ldap extends AbstractBackend {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
error_log("adding ".$contact->serialize());
|
||||
//error_log("adding ".$contact->serialize());
|
||||
|
||||
try {
|
||||
$contact->validate(VCard::REPAIR|VCard::UPGRADE);
|
||||
@ -588,16 +584,7 @@ class Ldap extends AbstractBackend {
|
||||
* @return bool
|
||||
*/
|
||||
public function updateContact($addressbookid, $id, $carddata, array $options = array()) {
|
||||
$backtrace = debug_backtrace();
|
||||
$trace=array();
|
||||
foreach ($backtrace as $elt) {
|
||||
foreach ($elt as $key => $line) {
|
||||
if ($key == "file" || $key == "line") {
|
||||
$trace[] = $line;
|
||||
}
|
||||
}
|
||||
}
|
||||
//error_log("stay modified ".print_r($trace,1));
|
||||
error_log(__FUNCTION__." call : ".$begin);
|
||||
if(!$carddata instanceof VCard) {
|
||||
try {
|
||||
$vcard = \Sabre\VObject\Reader::read($carddata);
|
||||
@ -609,7 +596,14 @@ class Ldap extends AbstractBackend {
|
||||
$vcard = $carddata;
|
||||
}
|
||||
|
||||
//error_log("updating ".$vcard->serialize());
|
||||
try {
|
||||
$vcard->validate(VCard::REPAIR|VCard::UPGRADE);
|
||||
} catch (\Exception $e) {
|
||||
OCP\Util::writeLog('contacts', __METHOD__ . ' ' .
|
||||
'Error validating vcard: ' . $e->getMessage(), \OCP\Util::ERROR);
|
||||
return false;
|
||||
}
|
||||
//$vcard->REV = (new \DateTime)->format(\DateTime::W3C);
|
||||
|
||||
if (!is_array($id)) {
|
||||
$a_ids = array($id);
|
||||
@ -631,9 +625,12 @@ class Ldap extends AbstractBackend {
|
||||
$dn = base64_decode($tmpVCard->{'X-LDAP-DN'});
|
||||
}
|
||||
// Updates the existing card
|
||||
$ldifSource = self::ldapFindOne($dn, $this->ldapParams['ldapfilter'], $this->connector->getLdapEntries());
|
||||
$this->connector->insertEmptyEntries($ldifSource, $ldifEntries);
|
||||
$result = self::ldapUpdate($dn, $ldifEntries);
|
||||
}
|
||||
self::ldapCloseConnection();
|
||||
error_log(__FUNCTION__." end call : ".$end.", duration: ".($end-$begin));
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
@ -33,7 +33,14 @@ class LdapConnector {
|
||||
\OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.', error in setting xml config', \OCP\Util::DEBUG);
|
||||
}
|
||||
}
|
||||
|
||||
private function convertDate ($ldapDate) {
|
||||
|
||||
$tstamp = strtotime($ldapDate);
|
||||
$theDate = new \DateTime;
|
||||
$theDate->setTimestamp($tstamp);
|
||||
|
||||
return $theDate;
|
||||
}
|
||||
/**
|
||||
* @brief transform a ldap entry into an VCard object
|
||||
* for each ldap entry which is like "property: value"
|
||||
@ -43,7 +50,8 @@ class LdapConnector {
|
||||
*/
|
||||
public function ldapToVCard($ldapEntry) {
|
||||
$vcard = \Sabre\VObject\Component::create('VCARD');
|
||||
$vcard->REV = $ldapEntry['modifytimestamp'][0];
|
||||
$vcard->REV = $this->convertDate($ldapEntry['modifytimestamp'][0])->format(\DateTime::W3C);
|
||||
//error_log("modifytimestamp: ".$vcard->REV);
|
||||
$vcard->{'X-LDAP-DN'} = base64_encode($ldapEntry['dn']);
|
||||
// OCP\Util::writeLog('ldap_vcard_connector', __METHOD__.' vcard is '.$vcard->serialize(), \OCP\Util::DEBUG);
|
||||
|
||||
@ -86,7 +94,6 @@ class LdapConnector {
|
||||
if (!isset($vcard->UID)) {
|
||||
$vcard->UID = base64_encode($ldapEntry['dn']);
|
||||
}
|
||||
$vcard->validate(\Sabre\VObject\Component\VCard::REPAIR);
|
||||
return $vcard;
|
||||
}
|
||||
|
||||
@ -421,6 +428,22 @@ class LdapConnector {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief adds empty entries in $dest if $dest doesn't have those entries and if $source has
|
||||
* otherwise, I couldn't find how to remove attributes
|
||||
* @param $source the source ldap entry as model
|
||||
* @param $dest the destination entry to add empty params if we have to
|
||||
*/
|
||||
public function insertEmptyEntries($source, &$dest) {
|
||||
for ($i=0; $i<$source["count"]; $i++) {
|
||||
|
||||
$l_property = $source[$i];
|
||||
if (!isset($dest[$l_property]) && $l_property != 'modifytimestamp') {
|
||||
$dest[$l_property] = array();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
|
Loading…
x
Reference in New Issue
Block a user