public function getAccount() { if (!isset($this->oAccount) && isset($this->server)) { $this->oAccount = $this->server->getAccount(); } return $this->oAccount; }
function afterWriteContent($path, \Sabre\DAV\IFile $node) { if ('sabredav' !== \CApi::GetManager()->GetStorageByType('contacts')) { if ($node instanceof \Sabre\CardDAV\ICard) { $oAccount = $this->server->getAccount(); if (isset($oAccount)) { $iUserId = $oAccount->IdUser; $iTenantId = $node instanceof \afterlogic\DAV\CardDAV\SharedCard ? $oAccount->IdTenant : null; $sContactFileName = $node->getName(); $oContactDb = $this->oApiContactsManager->GetContactByStrId($iUserId, $sContactFileName, $iTenantId); if (!isset($oContactDb)) { $oDavManager = \CApi::Manager('dav'); $oVCard = $oDavManager ? $oDavManager->VObjectReaderRead($node->get()) : null; 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); } } } } }
function afterWriteContent($path, \Sabre\DAV\IFile $node) { if ('sabredav' !== \CApi::GetManager()->GetStorageByType('contacts')) { if ($node instanceof \Sabre\CardDAV\ICard) { $oAccount = $this->server->getAccount(); if (isset($oAccount)) { $iUserId = $oAccount->IdUser; $iTenantId = $node instanceof \afterlogic\DAV\CardDAV\SharedCard ? $oAccount->IdTenant : null; $sFileName = $node->getName(); $oContactDb = $this->oApiContactsManager->GetContactByStrId($iUserId, $sFileName, $iTenantId); $oContact = new \CContact(); $oContact->InitFromVCardStr($iUserId, $node->get()); $oContact->IdContact = $oContactDb->IdContact; $oContact->SharedToAll = !!$oContactDb->SharedToAll; $bResult = $this->oApiContactsManager->UpdateContact($oContact); // \CApi::LogObject($bResult, \ELogLevel::Full, 'contacts-'); } } } }