Exemplo n.º 1
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.º 2
0
 /**
  * @param IFile $node
  * @return resource
  */
 private function getStream(IFile $node)
 {
     $data = $node->get();
     if (is_resource($data)) {
         return $data;
     }
     return fopen('data://text/plain,' . $data, 'r');
 }
Exemplo n.º 3
0
 public function afterWriteContent($uri, \Sabre\DAV\IFile $node)
 {
     $this->updateReminder($uri, $node->get(), $this->getUser());
 }
Exemplo n.º 4
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.º 5
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);
                 }
             }
         }
     }
 }
Exemplo n.º 6
0
 /**
  * This method is triggered before a file gets updated with new content.
  *
  * We use this event to process any changes to scheduling objects.
  *
  * @param string $path
  * @param IFile $node
  * @param resource|string $data
  * @param bool $modified
  * @return void
  */
 function beforeWriteContent($path, IFile $node, &$data, &$modified)
 {
     if (!$node instanceof ICalendarObject || $node instanceof ISchedulingObject) {
         return;
     }
     if (!$this->scheduleReply($this->server->httpRequest)) {
         return;
     }
     // It's a calendar, so the contents are most likely an iCalendar
     // object. It's time to start processing this.
     //
     // This step also ensures that $data is re-propagated with a string
     // version of the object.
     if (is_resource($data)) {
         $data = stream_get_contents($data);
     }
     $vObj = Reader::read($data);
     $addresses = $this->getAddressesForPrincipal($node->getOwner());
     $oldObj = Reader::read($node->get());
     $this->processICalendarChange($oldObj, $vObj, $addresses);
     // After all this exciting action we set $data to the updated event
     // that contains all the new status information (if any).
     $newData = $vObj->serialize();
     if ($newData !== $data) {
         $data = $newData;
         // Setting $modified tells sabredav that the object has changed,
         // and that no ETag must be sent back.
         $modified = true;
     }
 }