Exemplo n.º 1
0
 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-');
             }
         }
     }
 }
Exemplo n.º 2
0
 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);
             }
         }
     }
 }
Exemplo n.º 3
0
 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);
                 }
             }
         }
     }
 }