public function getUser() { if (!isset($this->iUserId) && isset($this->server)) { $this->iUserId = $this->server->getUser(); } return $this->iUserId; }
function afterWriteContent($path, \Sabre\DAV\IFile $node) { if ($node instanceof \Sabre\CardDAV\ICard) { $iUserId = $this->server->getUser(); if (isset($iUserId)) { $iTenantId = $node instanceof \Afterlogic\DAV\CardDAV\SharedCard ? 0 : null; $sContactFileName = $node->getName(); $oContactDb = $this->oApiContactsManager->getContactByStrId($iUserId, $sContactFileName, $iTenantId); if (!isset($oContactDb)) { $oVCard = \Sabre\VObject\Reader::read($node->get(), \Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES); if ($oVCard && $oVCard->UID) { $oContactDb = $this->oApiContactsManager->getContactByStrId($iUserId, (string) $oVCard->UID . '.vcf', $iTenantId); } } $oContact = new \CContact(); $oContact->InitFromVCardStr($iUserId, $node->get()); $oContact->IdContactStr = $sContactFileName; $oContact->IdTenant = $iTenantId; if (isset($oContactDb)) { $oContact->IdContact = $oContactDb->IdContact; $oContact->IdDomain = $oContactDb->IdDomain; $oContact->SharedToAll = !!$oContactDb->SharedToAll; $this->oApiContactsManager->updateContact($oContact); } else { $this->oApiContactsManager->createContact($oContact); } } } }