Merge branch '2013.10' into 2014.11
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 1 Sep 2015 12:25:53 +0000 (14:25 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Tue, 1 Sep 2015 12:25:53 +0000 (14:25 +0200)
1  2 
tine20/Calendar/Controller/MSEventFacade.php

@@@ -55,7 -55,9 +55,9 @@@ class Calendar_Controller_MSEventFacad
      private static $_instance = NULL;
      
      protected static $_attendeeEmailCache = array();
-     
+     protected $_currentEventFacadeContainer;
      /**
       * the constructor
       *
          // if an id filter is set, we need to fetch exceptions in a second query
          if ($_filter->getFilter('id', true, true)) {
              $events->merge($this->_eventController->search(new Calendar_Model_EventFilter(array(
 -                array('field' => 'uid',     'operator' => 'in',      'value' => $events->uid),
 -                array('field' => 'id',      'operator' => 'notin',   'value' => $events->id),
 -                array('field' => 'recurid', 'operator' => 'notnull', 'value' => null)
 +                array('field' => 'base_event_id', 'operator' => 'in',      'value' => $events->id),
 +                array('field' => 'id',            'operator' => 'notin',   'value' => $events->id),
 +                array('field' => 'recurid',       'operator' => 'notnull', 'value' => null),
              )), NULL, FALSE, FALSE, $_action));
          }
  
          $this->_eventController->getAlarms($events);
          Tinebase_FileSystem_RecordAttachments::getInstance()->getMultipleAttachmentsOfRecords($events);
  
 -        $baseEventMap = array(); // uid => baseEvent
 -        $exceptionSets = array(); // uid => exceptions
 +        $baseEventMap = array(); // id => baseEvent
 +        $exceptionSets = array(); // id => exceptions
          $exceptionMap = array(); // idx => event
  
          foreach($events as $event) {
              if ($event->rrule) {
 -                $eventUid = $event->uid;
 -                $baseEventMap[$eventUid] = $event;
 -                $exceptionSets[$eventUid] = new Tinebase_Record_RecordSet('Calendar_Model_Event');
 +                $eventId = $event->id;
 +                $baseEventMap[$eventId] = $event;
 +                $exceptionSets[$eventId] = new Tinebase_Record_RecordSet('Calendar_Model_Event');
              } else if ($event->recurid) {
                  $exceptionMap[] = $event;
              }
          }
  
          foreach($exceptionMap as $exception) {
 -            $exceptionUid = $exception->uid;
 -            $baseEvent = array_key_exists($exceptionUid, $baseEventMap) ? $baseEventMap[$exceptionUid] : false;
 +            $baseEventId = $exception->base_event_id;
 +            $baseEvent = array_key_exists($baseEventId, $baseEventMap) ? $baseEventMap[$baseEventId] : false;
              if ($baseEvent) {
 -                $exceptionSet = $exceptionSets[$exceptionUid];
 +                $exceptionSet = $exceptionSets[$baseEventId];
                  $exceptionSet->addRecord($exception);
                  $events->removeRecord($exception);
              }
          }
  
 -        foreach($baseEventMap as $uid => $baseEvent) {
 -            $exceptionSet = $exceptionSets[$uid];
 +        foreach($baseEventMap as $id => $baseEvent) {
 +            $exceptionSet = $exceptionSets[$id];
              $this->_eventController->fakeDeletedExceptions($baseEvent, $exceptionSet);
              $baseEvent->exdate = $exceptionSet;
          }
  
          return $events;
      }
 -    
 -   /**
 -     * (non-PHPdoc)
 -     * @see Calendar_Controller_Event::lookupExistingEvent()
 -     */
 -    public function lookupExistingEvent($_event)
 -    {
 -        $event = $this->_eventController->lookupExistingEvent($_event);
  
 -        if ($event) {
 -            $this->_resolveData($event);
 -            return $this->_toiTIP($event);
 -        }
 -    }
 -    
      /*************** add / update / delete *****************/    
  
      /**
              }
          }
  
 -        $this->_resolveData($savedEvent);
 -        return $this->_toiTIP($savedEvent);
 +        // NOTE: exdate creation changes baseEvent, so we need to refetch it here
 +        return $this->get($savedEvent->getId());
      }
      
      /**
          }
          $currentOriginEvent = $this->_eventController->get($_event->getId());
          $this->_fromiTIP($_event, $currentOriginEvent);
 -        
 +
 +        // NOTE:  create an update must be handled equally as apple devices do not fetch events after creation.
 +        //        an update from the creating device would change defaults otherwise
 +        // NOTE2: Being organizer without attending is not possible when sync is in use as every update
 +        //        from a sync device of the organizer adds the organizer as attendee :-(
 +        //        -> in the sync world this is scenario is called delegation and handled differently
 +        //        -> it might be consequent to have the same behavior (organizer is always attendee with role chair)
 +        //           in tine20 in general. This is how Thunderbird handles it as well
          $_event->assertAttendee($this->getCalendarUser());
          
          $exceptions = $_event->exdate instanceof Tinebase_Record_RecordSet ? $_event->exdate : new Tinebase_Record_RecordSet('Calendar_Model_Event');
          $newPersistentExceptions = $exceptions->filter('is_deleted', 0);
          
          $migration = $this->_getExceptionsMigration($currentPersistentExceptions, $newPersistentExceptions);
 -        
 +
          $this->_eventController->delete($migration['toDelete']->getId());
          
          // NOTE: we need to exclude the toCreate exdates here to not confuse computations in createRecurException!
          if ($ownAttender) {
              $currentEvent = $this->_eventController->get($event->id);
              $currentAttender = Calendar_Model_Attender::getAttendee($currentEvent->attendee, $ownAttender);
-             $ownAttender->status_authkey = $currentAttender->status_authkey;
+             if ($currentAttender) {
+                 $ownAttender->status_authkey = $currentAttender->status_authkey;
+             } else {
+                 if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
+                     . ' currentAttender not found in currentEvent: ' . print_r($currentEvent->toArray(), true));
+             }
          }
      }
      
-     protected $_currentEventFacadeContainer;
-     
      /**
       * asserts correct event filter and calendar user in MSEventFacade
       * 
              $_exception->container_id = $_baseEvent->container_id;
          }
          $_exception->uid = $_baseEvent->uid;
 +        $_exception->base_event_id = $_baseEvent->getId();
          $_exception->recurid = $_baseEvent->uid . '-' . $_exception->getOriginalDtStart()->format(Tinebase_Record_Abstract::ISO8601LONG);
          
          // NOTE: we always refetch the base event as it might be touched in the meantime