/**
  * test to set container grants
  */
 public function testSetContainerGrants()
 {
     $this->markTestSkipped('FIXME: 0010343: fix some CLI tests');
     $out = $this->_cliHelper(array('containerId=' . $this->_container->getId(), 'accountId=' . Tinebase_Core::getUser()->getId(), 'grants=privateGrant'));
     $grants = Tinebase_Container::getInstance()->getGrantsOfContainer($this->_container);
     $this->assertTrue($grants->getFirstRecord()->privateGrant == 1);
 }
 /**
  * testNextScheduledImport
  */
 public function testNextScheduledImport()
 {
     $cc = Calendar_Controller_Event::getInstance();
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())));
     $all = $cc->search($filter);
     $this->assertEquals(0, $all->count());
     $now = Tinebase_DateTime::now()->subHour(1);
     $record = $this->createScheduledImport();
     // assert setting timestamp to start value
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $record = $this->_uit->runNextScheduledImport();
     // assert updating timestamp after successful run
     $now->addHour(1);
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $all = $cc->search($filter);
     $seq = $all->getFirstRecord()->seq;
     // assert all events have been imported
     $this->assertEquals(7, $all->count());
     // this must not be run, the interval is not exceed
     $ret = $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals($seq, $all->getFirstRecord()->seq);
     // setting manual timestamp to force run again
     $record->timestamp = $record->timestamp->subHour(1)->subSecond(1);
     $this->_uit->update($record);
     $ret = $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals(7, $all->count());
 }
示例#3
0
 /**
  * this function creates a Addressbook_Model_Contact and stores it in the database
  * 
  * @todo the header handling does not belong here. It should be moved to the DAV_Server class when supported
  * 
  * @param  Tinebase_Model_Container  $container
  * @param  stream|string           $vcardData
  */
 public static function create(Tinebase_Model_Container $container, $name, $vcardData)
 {
     list($backend, $version) = Addressbook_Convert_Contact_VCard_Factory::parseUserAgent($_SERVER['HTTP_USER_AGENT']);
     $converter = Addressbook_Convert_Contact_VCard_Factory::factory($backend, $version);
     $contact = $converter->toTine20Model($vcardData);
     $contact->container_id = $container->getId();
     $id = ($pos = strpos($name, '.')) === false ? $name : substr($name, 0, $pos);
     $contact->setId($id);
     $contact = Addressbook_Controller_Contact::getInstance()->create($contact, false);
     $card = new self($container, $contact);
     return $card;
 }
 /**
  * adds feast days to feast calendar
  *
  * @param array|Tinebase_DateTime $date
  */
 protected function _createFeastDay($date)
 {
     if (!$this->_feast_calendar) {
         $this->_getFeastCalendar();
     }
     $organizer = Addressbook_Controller_Contact::getInstance()->getContactByUserId(Tinebase_Core::getUser()->getId());
     if (is_array($date)) {
         $allDay = TRUE;
         if (count($date) == 1) {
             $dtstart = $date[0]->setTimezone(Tinebase_Core::getUserTimezone())->setTime(0, 0, 0);
             $dtend = clone $dtstart;
         } else {
             $dtstart = $date[0]->setTimezone(Tinebase_Core::getUserTimezone())->setTime(0, 0, 0);
             $dtend = clone $dtstart;
             $dtend = $dtend->addDay(count($date))->subHour(5);
         }
     } else {
         $allDay = FALSE;
         $dtstart = $date->setTimezone(Tinebase_Core::getUserTimezone())->setTime(6, 0, 0);
         $dtend = clone $dtstart;
         $dtend->addMinute(15);
     }
     $event = new Calendar_Model_Event(array('summary' => 'Feast Day', 'dtstart' => $dtstart->format('Y-m-d H:i:s'), 'dtend' => $dtend->format('Y-m-d H:i:s'), 'description' => Tinebase_Record_Abstract::generateUID(10), 'container_id' => $this->_feast_calendar->getId(), 'organizer' => $organizer->getId(), 'uid' => Calendar_Model_Event::generateUID(), 'is_all_day_event' => $allDay, 'attendee' => new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_id' => $organizer->getId(), 'user_type' => Calendar_Model_Attender::USERTYPE_USER, 'role' => Calendar_Model_Attender::ROLE_REQUIRED, 'status_authkey' => Tinebase_Record_Abstract::generateUID()))), Tinebase_Model_Grants::GRANT_READ => true, Tinebase_Model_Grants::GRANT_EDIT => true, Tinebase_Model_Grants::GRANT_DELETE => true));
     return Calendar_Controller_Event::getInstance()->create($event);
 }
示例#5
0
 /**
  * prepares iMIP component for client
  *  
  * @param  Calendar_Model_iMIP $_iMIP
  * @return Calendar_Model_iMIP
  */
 public function prepareComponent($_iMIP)
 {
     $this->_checkPreconditions($_iMIP);
     Calendar_Convert_Event_Json::resolveRelatedData($_iMIP->event);
     Tinebase_Model_Container::resolveContainerOfRecord($_iMIP->event);
     Tinebase_Model_Container::resolveContainerOfRecord($_iMIP->getExistingEvent());
     return $_iMIP;
 }
 /**
  * get other users container
  * 
  * @return Tinebase_Model_Container
  */
 protected function _getOtherUserContainer()
 {
     if (!$this->_otherUserContainer) {
         $sclever = Tinebase_Helper::array_value('sclever', Zend_Registry::get('personas'));
         $this->_otherUserContainer = Tinebase_Container::getInstance()->getDefaultContainer('Filemanager', $sclever->getId());
         Tinebase_Container::getInstance()->addGrants($this->_otherUserContainer->getId(), Tinebase_Acl_Rights::ACCOUNT_TYPE_ANYONE, NULL, array(Tinebase_Model_Grants::GRANT_READ), TRUE);
     }
     return $this->_otherUserContainer;
 }
示例#7
0
 /**
  * converts Tinebase_Record_Abstract to external format
  * 
  * @param  Tinebase_Record_Abstract $_record
  * @return mixed
  */
 public function fromTine20Model(Tinebase_Record_Abstract $_record)
 {
     if (!$_record) {
         return array();
     }
     $_record->setTimezone(Tinebase_Core::get(Tinebase_Core::USERTIMEZONE));
     $_record->bypassFilters = true;
     Tinebase_Model_Container::resolveContainerOfRecord($_record);
     return $_record->toArray();
 }
示例#8
0
 /**
  * testSetContainerInPathRecord
  * 
  * @todo move this to Tinebase?
  */
 public function testSetContainerInPathRecord()
 {
     $flatpath = Filemanager_Controller_Node::getInstance()->addBasePath('/' . Tinebase_Model_Container::TYPE_PERSONAL . '/' . Tinebase_Core::getUser()->accountLoginName . '/' . $this->_personalContainer->name);
     $path = Tinebase_Model_Tree_Node_Path::createFromPath($flatpath);
     $path->setContainer($this->_sharedContainer);
     $this->assertEquals('/' . $this->_application->getId() . '/folders/shared/' . $this->_sharedContainer->getId(), $path->statpath);
     // move it back
     $path->setContainer($this->_personalContainer);
     $this->assertEquals('/' . $this->_application->getId() . '/folders/personal/' . Tinebase_Core::getUser()->getId() . '/' . $this->_personalContainer->getId(), $path->statpath, 'wrong statpath: ' . print_r($path->toArray(), TRUE));
 }
 /**
  * testNextScheduledImport
  *
  * TODO this should run without the need for internet access to http://www.schulferien.org
  *      maybe we should put the file into the local filesystem
  */
 public function testNextScheduledImport()
 {
     $this->markTestSkipped('FIXME: use local ics file for this test / see TODO in doc block');
     $icsUri = 'http://www.schulferien.org/iCal/Ferien/icals/Ferien_Hamburg_2014.ics';
     $client = new Zend_Http_Client($icsUri);
     try {
         $client->request()->getBody();
     } catch (Exception $e) {
         $this->markTestSkipped('no access to ' . $icsUri);
     }
     $cc = Calendar_Controller_Event::getInstance();
     $filter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $this->_testCalendar->getId())));
     $all = $cc->search($filter);
     $this->assertEquals(0, $all->count());
     $now = Tinebase_DateTime::now()->subHour(1);
     $record = $this->createScheduledImport($icsUri);
     // assert setting timestamp to start value
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $record = $this->_uit->runNextScheduledImport();
     $this->assertTrue($record !== null, 'import did not run');
     // assert updating timestamp after successful run
     $now->addHour(1);
     $this->assertEquals($now->format('YMDHi'), $record->timestamp->format('YMDHi'));
     $all = $cc->search($filter);
     $seq = $all->getFirstRecord()->seq;
     // assert all events have been imported
     $this->assertEquals(7, $all->count());
     // this must not be run, the interval is not exceed
     $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals($seq, $all->getFirstRecord()->seq);
     // setting manual timestamp to force run again
     $record->timestamp = $record->timestamp->subHour(1)->subSecond(1);
     $this->_uit->update($record);
     $this->_uit->runNextScheduledImport();
     $all = $cc->search($filter);
     $this->assertEquals(7, $all->count());
 }
示例#10
0
 /**
  * import helper
  *
  * @param array $_additionalOptions
  * @param array $_clientRecords
  * @return array
  */
 protected function _importHelper($_additionalOptions = array('dryrun' => 1), $_clientRecords = array())
 {
     $definition = Tinebase_ImportExportDefinition::getInstance()->getByName('adb_tine_import_csv');
     $definitionOptions = Tinebase_ImportExportDefinition::getOptionsAsZendConfigXml($definition);
     $tempFileBackend = new Tinebase_TempFile();
     $tempFile = $tempFileBackend->createTempFile(dirname(dirname(dirname(dirname(__FILE__)))) . '/tine20/' . $definitionOptions->example);
     $options = array_merge($_additionalOptions, array('container_id' => $this->container->getId()));
     $result = $this->_instance->importContacts($tempFile->getId(), $definition->getId(), $options, $_clientRecords);
     if (isset($_additionalOptions['dryrun']) && $_additionalOptions['dryrun'] === 0) {
         foreach ($result['results'] as $contact) {
             $this->_contactIdsToDelete[] = $contact['id'];
         }
     }
     return $result;
 }
 /**
  * Deletes the card
  *
  * @return void
  * 
  * @see Calendar_Frontend_WebDAV_Event::delete()
  */
 public function delete()
 {
     // when a move occurs, thunderbird first sends to delete command and immediately a put command
     // we must delay the delete command, otherwise the put command fails
     sleep(1);
     // (re) fetch contact as tree move does not refresh src node before delete
     // check if we are still in the same container, if not -> it is a MOVE
     try {
         $contact = Addressbook_Controller_Contact::getInstance()->get($this->_contact);
         if ($contact->container_id == $this->_container->getId()) {
             Addressbook_Controller_Contact::getInstance()->delete($contact);
         }
     } catch (Tinebase_Exception_AccessDenied $tead) {
         Tinebase_Exception::log($tead);
         throw new DAV\Exception\Forbidden('Access denied');
     }
 }
 /**
  * return vcard and convert Calendar_Model_Event to vcard if needed
  * 
  * @return string
  */
 protected function _getVEvent()
 {
     if ($this->_vevent == null) {
         $this->_vevent = $this->_getConverter()->fromTine20Model($this->getRecord());
         foreach ($this->_vevent->children() as $component) {
             if ($component->name == 'VEVENT') {
                 // NOTE: we store the requested container here to have an origin when the event is moved
                 $component->add('X-TINE20-CONTAINER', $this->_container->getId());
                 if (isset($component->{'VALARM'}) && !$this->_container->isPersonalOf(Tinebase_Core::getUser())) {
                     // prevent duplicate alarms
                     $component->add('X-MOZ-LASTACK', Tinebase_DateTime::now()->addYear(100)->setTimezone('UTC'), array('VALUE' => 'DATE-TIME'));
                 }
             }
         }
     }
     return $this->_vevent->serialize();
 }
示例#13
0
 /**
  * return vcard and convert Calendar_Model_Event to vcard if needed
  * 
  * @return string
  */
 protected function _getVEvent()
 {
     if ($this->_vevent == null) {
         $this->_vevent = $this->_converter->fromTine20Model($this->getRecord());
         foreach ($this->_vevent->children() as $component) {
             if ($component->name == 'VEVENT') {
                 // NOTE: we store the requested container here to have an origin when the event is moved
                 $component->{'X-TINE20-CONTAINER'} = $this->_container->getId();
                 if (isset($component->{'VALARM'}) && !$this->_container->isPersonalOf(Tinebase_Core::getUser())) {
                     // prevent duplicate alarms
                     $component->{'X-MOZ-LASTACK'} = new Sabre_VObject_Element_DateTime('X-MOZ-LASTACK');
                     $component->{'X-MOZ-LASTACK'}->setDateTime(Tinebase_DateTime::now()->addYear(100), Sabre_VObject_Element_DateTime::UTC);
                 }
             }
         }
     }
     return $this->_vevent->serialize();
 }
 /**
  * Updates properties on this node,
  *
  * The properties array uses the propertyName in clark-notation as key,
  * and the array value for the property value. In the case a property
  * should be deleted, the property value will be null.
  *
  * This method must be atomic. If one property cannot be changed, the
  * entire operation must fail.
  *
  * If the operation was successful, true can be returned.
  * If the operation failed, false can be returned.
  *
  * Deletion of a non-existant property is always succesful.
  *
  * Lastly, it is optional to return detailed information about any
  * failures. In this case an array should be returned with the following
  * structure:
  *
  * array(
  *   403 => array(
  *      '{DAV:}displayname' => null,
  *   ),
  *   424 => array(
  *      '{DAV:}owner' => null,
  *   )
  * )
  *
  * In this example it was forbidden to update {DAV:}displayname. 
  * (403 Forbidden), which in turn also caused {DAV:}owner to fail
  * (424 Failed Dependency) because the request needs to be atomic.
  *
  * @param array $mutations 
  * @return bool|array 
  */
 public function updateProperties($mutations)
 {
     if (!Tinebase_Core::getUser()->hasGrant($this->_container, Tinebase_Model_Grants::GRANT_ADMIN)) {
         throw new \Sabre\DAV\Exception\Forbidden('permission to update container denied');
     }
     $result = array(200 => array(), 403 => array());
     foreach ($mutations as $key => $value) {
         switch ($key) {
             case '{DAV:}displayname':
                 if ($value === $this->_container->uuid || $value === $this->_container->getId()) {
                     if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) {
                         Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__ . ' It is not allowed to overwrite the name with the uuid/id');
                     }
                     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' ' . print_r(array('useIdAsName' => $this->_useIdAsName, 'container' => $this->_container->toArray(), 'new value' => $value), true));
                     }
                 } else {
                     $this->_container->name = $value;
                 }
                 $result['200'][$key] = null;
                 break;
             case '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}calendar-description':
             case '{' . \Sabre\CalDAV\Plugin::NS_CALDAV . '}calendar-timezone':
                 // fake success
                 $result['200'][$key] = null;
                 break;
             case '{http://apple.com/ns/ical/}calendar-color':
                 $this->_container->color = substr($value, 0, 7);
                 $result['200'][$key] = null;
                 break;
             default:
                 $result['403'][$key] = null;
         }
     }
     Tinebase_Container::getInstance()->update($this->_container);
     return $result;
 }
示例#15
0
 /**
  * returns a simple event
  *
  * @return Calendar_Model_Event
  */
 protected function _getEvent()
 {
     return new Calendar_Model_Event(array('summary' => 'Mittagspause', 'dtstart' => '2009-04-06 13:00:00', 'dtend' => '2009-04-06 13:30:00', 'description' => 'Wieslaw Brudzinski: Das Gesetz garantiert zwar die Mittagspause, aber nicht das Mittagessen...', 'container_id' => $this->_testCalendar->getId(), Tinebase_Model_Grants::GRANT_EDIT => true));
 }
示例#16
0
 /**
  * create container node
  * 
  * @param Tinebase_Model_Container $_container
  */
 public function createContainerNode(Tinebase_Model_Container $_container)
 {
     $application = Tinebase_Application::getInstance()->getApplicationById($_container->application_id);
     $path = '/' . $application->getId() . '/' . $_container->type . '/' . $_container->getId();
     if (!$this->fileExists($path)) {
         $this->mkdir($path);
     }
 }
 /**
  * @param Tinebase_Model_Container $sourceContainer
  * @param Tinebase_Model_Container $destinationContainer
  */
 public function moveEventsToContainer(Tinebase_Model_Container $sourceContainer, Tinebase_Model_Container $destinationContainer)
 {
     $this->_db->update($this->_tablePrefix . $this->_tableName, array('container_id' => $destinationContainer->getId()), $this->_db->quoteInto($this->_db->quoteIdentifier('container_id') . ' = ?', $sourceContainer->getId()));
     $attendeeBackend = new Calendar_Backend_Sql_Attendee();
     $attendeeBackend->moveEventsToContainer($sourceContainer, $destinationContainer);
 }
 /**
  * converts a int, string or Tinebase_Model_Container to a containerid
  *
  * @param   int|string|Tinebase_Model_Container $_containerId the containerid to convert
  * @return  int
  * @throws  Tinebase_Exception_InvalidArgument
  */
 public static function convertContainerIdToInt($_containerId)
 {
     if ($_containerId instanceof Tinebase_Model_Container) {
         if ($_containerId->getId() === NULL) {
             throw new Tinebase_Exception_InvalidArgument('No container id set.');
         }
         $id = (int) $_containerId->getId();
     } else {
         $id = (int) $_containerId;
     }
     if ($id === 0) {
         throw new Tinebase_Exception_InvalidArgument('Container id can not be 0 (' . $_containerId . ').');
     }
     return $id;
 }
 /**
  * resolves a single path
  * 
  * @param  String $_path
  * @return array of container ids
  */
 protected function _resolvePath($_path)
 {
     $containerIds = array();
     if ($containerId = Tinebase_Model_Container::pathIsContainer($_path)) {
         if ($this->_options['ignoreAcl'] == TRUE) {
             $containerIds[] = $containerId;
         } else {
             if (Tinebase_Core::getUser()->hasGrant($containerId, $this->_requiredGrants)) {
                 $containerIds[] = $containerId;
             }
         }
     } else {
         if ($ownerId = Tinebase_Model_Container::pathIsPersonalNode($_path)) {
             $containerIds = $this->_resolveContainerNode('personal', $ownerId);
         } else {
             $node = $_path == '/' ? 'all' : substr($_path, 1);
             $node = $node === 'personal' ? Tinebase_Model_Container::TYPE_OTHERUSERS : $node;
             $containerIds = $this->_resolveContainerNode($node);
         }
     }
     return $containerIds;
 }
 /**
  * request inital synckey
  * 
  * @param Tinebase_Model_Container $container
  */
 protected function _requestInitialSynckey($container)
 {
     $doc = new DOMDocument();
     $doc->loadXML('<?xml version="1.0" encoding="utf-8"?>
         <!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
         <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase"><Collections><Collection><Class>Contacts</Class><SyncKey>0</SyncKey><CollectionId>' . $container->getId() . '</CollectionId><DeletesAsMoves/><GetChanges/><WindowSize>100</WindowSize><Options>' . '<AirSyncBase:BodyPreference><AirSyncBase:Type>1</AirSyncBase:Type><AirSyncBase:TruncationSize>5120</AirSyncBase:TruncationSize>' . '</AirSyncBase:BodyPreference><Conflict>1</Conflict></Options></Collection></Collections></Sync>');
     $sync = new Syncroton_Command_Sync($doc, $this->_device, $this->_device->policykey);
     $sync->handle();
     $syncDoc = $sync->getResponse();
     #$syncDoc->formatOutput = true; echo $syncDoc->saveXML();
     $xpath = new DomXPath($syncDoc);
     $xpath->registerNamespace('AirSync', 'uri:AirSync');
     $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:Class');
     $this->assertEquals(1, $nodes->length, $syncDoc->saveXML());
     $this->assertEquals('Contacts', $nodes->item(0)->nodeValue, $syncDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:SyncKey');
     $this->assertEquals(1, $nodes->length, $syncDoc->saveXML());
     $this->assertEquals(1, $nodes->item(0)->nodeValue, $syncDoc->saveXML());
     $nodes = $xpath->query('//AirSync:Sync/AirSync:Collections/AirSync:Collection/AirSync:Status');
     $this->assertEquals(1, $nodes->length, $syncDoc->saveXML());
     $this->assertEquals(Syncroton_Command_Sync::STATUS_SUCCESS, $nodes->item(0)->nodeValue, $syncDoc->saveXML());
 }
 /**
  * get content sequences for single container or array of ids
  * 
  * @param array|integer|Tinebase_Model_Container $containerIds
  * @return array with key = container id / value = content seq number | integer
  */
 public function getContentSequence($containerIds)
 {
     if (empty($containerIds)) {
         return NULL;
     }
     $containerIds = !is_array($containerIds) ? Tinebase_Model_Container::convertContainerIdToInt($containerIds) : $containerIds;
     $select = $this->_getSelect(array('id', 'content_seq'), TRUE);
     $select->where($this->_db->quoteInto($this->_db->quoteIdentifier('id') . ' IN (?)', (array) $containerIds));
     $stmt = $this->_db->query('/*' . __FUNCTION__ . '*/' . $select);
     $result = $stmt->fetchAll();
     foreach ($result as $key => $value) {
         $result[$value['id']] = $value['content_seq'];
     }
     $result = is_array($containerIds) ? $result : (isset($result[$containerIds]) ? $result[$containerIds] : NULL);
     return $result;
 }
 /**
  * @param Tinebase_Model_Container $sourceContainer
  * @param Tinebase_Model_Container $destinationContainer
  */
 public function moveEventsToContainer(Tinebase_Model_Container $sourceContainer, Tinebase_Model_Container $destinationContainer)
 {
     $this->_db->update($this->_tablePrefix . $this->_tableName, array('displaycontainer_id' => $destinationContainer->getId()), $this->_db->quoteInto($this->_db->quoteIdentifier('displaycontainer_id') . ' = ?', $sourceContainer->getId()));
 }
示例#23
0
 /**
  * returns a simple event
  *
  * @return Calendar_Model_Event
  */
 protected function _getEvent()
 {
     return new Calendar_Model_Event(array('summary' => 'Wakeup', 'dtstart' => '2009-03-25 06:00:00', 'dtend' => '2009-03-25 06:15:00', 'description' => 'Early to bed and early to rise, makes a men healthy, wealthy and wise', 'attendee' => $this->_getAttendee(), 'container_id' => $this->_testCalendar->getId(), 'organizer' => $this->_testUserContact->getId(), 'uid' => Calendar_Model_Event::generateUID(), Tinebase_Model_Grants::GRANT_READ => true, Tinebase_Model_Grants::GRANT_EDIT => true, Tinebase_Model_Grants::GRANT_DELETE => true));
 }
 /**
  * asserts correct event filter and calendar user in MSEventFacade
  * 
  * NOTE: this is nessesary as MSEventFacade is a singleton and in some operations (e.g. move) there are 
  *       multiple instances of self
  */
 public function assertEventFacadeParams(Tinebase_Model_Container $container, $setEventFilter = true)
 {
     if (!$this->_currentEventFacadeContainer || $this->_currentEventFacadeContainer->getId() !== $container->getId()) {
         $this->_currentEventFacadeContainer = $container;
         try {
             $calendarUserId = $container->type == Tinebase_Model_Container::TYPE_PERSONAL ? Addressbook_Controller_Contact::getInstance()->getContactByUserId($container->getOwner(), true)->getId() : Tinebase_Core::getUser()->contact_id;
         } catch (Exception $e) {
             $calendarUserId = Calendar_Controller_MSEventFacade::getCurrentUserContactId();
         }
         $calendarUser = new Calendar_Model_Attender(array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $calendarUserId));
         $this->setCalendarUser($calendarUser);
         if ($setEventFilter) {
             $eventFilter = new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $container->getId())));
             $this->setEventFilter($eventFilter);
         }
     }
 }
 /**
  *  create some events to compare
  *  
  * - event1: in calendar 1
  * - event2: only in calendar 2
  * - event3+4: in both calendars
  * - event5: slightly different from event1 (same summary) / in cal2
  * - event6: only in cal1 (next week)
  * - event7: only in displaycontainer
  * - event8+9: in both calendars (whole day)
  * 
  * @param Tinebase_Model_Container $cal1
  * @param Tinebase_Model_Container $cal2
  */
 protected function _buildCompareCalendarsFixture($cal1, $cal2)
 {
     $event1 = $this->_getEvent(true);
     $event1->summary = 'event 1';
     $this->_controller->create($event1);
     $event2 = $this->_getEvent(true);
     $event2->dtstart->addDay(1);
     $event2->dtend->addDay(1);
     $event2->summary = 'event 2';
     $event2->container_id = $cal2->getId();
     $this->_controller->create($event2);
     $event3 = $this->_getEvent(true);
     $event3->dtstart->addDay(2);
     $event3->dtend->addDay(2);
     $event3->summary = 'event 3';
     $event4 = clone $event3;
     $this->_controller->create($event3);
     $event4->container_id = $cal2->getId();
     $this->_controller->create($event4);
     $event5 = $this->_getEvent(true);
     $event5->summary = 'event 1';
     $event5->dtstart->addMinute(30);
     $event5->container_id = $cal2->getId();
     $this->_controller->create($event5);
     // this tests weekly processing, too
     $event6 = $this->_getEvent(true);
     $event6->summary = 'event 6';
     $event6->dtstart->addDay(8);
     $event6->dtend->addDay(8);
     $this->_controller->create($event6);
     // add event that is only in displaycontainer (should not appear in report)
     $currentDefault = Tinebase_Core::getPreference('Calendar')->getValueForUser(Calendar_Preference::DEFAULTCALENDAR, Tinebase_Core::getUser()->getId());
     Tinebase_Core::getPreference('Calendar')->setValue(Calendar_Preference::DEFAULTCALENDAR, $cal1->getId());
     $event7 = $this->_getEvent(true);
     $event7->summary = 'event 7';
     $event7->attendee = new Tinebase_Record_RecordSet('Calendar_Model_Attender', array(array('user_id' => Tinebase_Core::getUser()->contact_id, 'user_type' => Calendar_Model_Attender::USERTYPE_USER, 'role' => Calendar_Model_Attender::ROLE_REQUIRED)));
     Tinebase_Core::set(Tinebase_Core::USER, $this->_personas['sclever']);
     $cal3 = $this->_getTestContainer('Calendar');
     $event7->container_id = $cal3->getId();
     $this->_controller->create($event7);
     Tinebase_Core::set(Tinebase_Core::USER, $this->_originalTestUser);
     Tinebase_Core::getPreference('Calendar')->setValue(Calendar_Preference::DEFAULTCALENDAR, $currentDefault);
     $event8 = $this->_getEvent(true);
     $event8->summary = 'event 8';
     $event8->is_all_day_event = true;
     $event9 = clone $event8;
     $this->_controller->create($event8);
     $event9->container_id = $cal2->getId();
     $this->_controller->create($event9);
 }
 /**
  * validate path
  * 
  * @param Tinebase_Model_Container $_container
  */
 protected function _validatePath(Tinebase_Model_Container $_container)
 {
     if ($_container->type == Tinebase_Model_Container::TYPE_SHARED) {
         $this->assertEquals("/{$_container->type}/{$_container->getId()}", $_container->path);
     } else {
         $this->assertEquals("/{$_container->type}/{$_container->owner_id}/{$_container->getId()}", $_container->path);
     }
 }
 /**
  * remove container sync grant if empty
  *
  * @param Tinebase_Model_Container $container
  * @param Tinebase_Record_RecordSet $grants
  */
 protected function _removeSyncGrantIfContainerEmpty($container, $grants)
 {
     if ($container->creation_time->addHour(1)->compare(Tinebase_DateTime::now()) === 1) {
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . ' ' . __LINE__ . ' Do not remove sync grant on initial import - ignore new calendars');
         }
         return;
     }
     $etags = $this->_recordBackend->getEtagsForContainerId($container->getId());
     if (count($etags)) {
         // we found records - container not empty
         return;
     }
     foreach ($grants as $grant) {
         if ($grant->{Tinebase_Model_Grants::GRANT_SYNC}) {
             if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
                 Tinebase_Core::getLogger()->info(__METHOD__ . ' ' . __LINE__ . ' Removing SYNC grant for empty ' . $this->appName . ' container ' . $container->name . ' (account: ' . $grant->account_id . ')');
             }
             $grant->{Tinebase_Model_Grants::GRANT_SYNC} = false;
         }
     }
 }