/** * Test create a scheduled import */ public function createScheduledImport($source = 'http://localhost/test.ics') { $id = Tinebase_Record_Abstract::generateUID(); $import = new Tinebase_Model_Import(array('id' => $id, 'user_id' => $this->_originalTestUser->getId(), 'interval' => Tinebase_Model_Import::INTERVAL_HOURLY, 'model' => Calendar_Controller::getInstance()->getDefaultModel(), 'application_id' => Tinebase_Application::getInstance()->getApplicationByName('Calendar')->getId(), 'container_id' => $this->_testCalendar->getId(), 'sourcetype' => Tinebase_Model_Import::SOURCETYPE_REMOTE, 'source' => $source, 'options' => json_encode(array('forceUpdateExisting' => TRUE, 'import_defintion' => NULL, 'plugin' => 'Calendar_Import_Ical')))); $record = $this->_uit->create($import); $this->assertEquals(Calendar_Controller::getInstance()->getDefaultModel(), $this->_uit->get($id)->model); return $record; }
/** * inspect before create/update * * @TODO move stuff from other places here * @param Calendar_Model_Event $_record the record to inspect */ protected function _inspectEvent($_record) { $_record->uid = $_record->uid ? $_record->uid : Tinebase_Record_Abstract::generateUID(); $_record->organizer = $_record->organizer ? $_record->organizer : Tinebase_Core::getUser()->contact_id; $_record->transp = $_record->transp ? $_record->transp : Calendar_Model_Event::TRANSP_OPAQUE; $this->_inspectOriginatorTZ($_record); if ($_record->hasExternalOrganizer()) { // assert calendarUser as attendee. This is important to keep the event in the loop via its displaycontianer(s) try { $container = Tinebase_Container::getInstance()->getContainerById($_record->container_id); $owner = $container->getOwner(); $calendarUserId = Addressbook_Controller_Contact::getInstance()->getContactByUserId($owner, true)->getId(); } catch (Exception $e) { $container = NULL; $calendarUserId = Tinebase_Core::getUser()->contact_id; } $attendee = $_record->assertAttendee(new Calendar_Model_Attender(array('user_type' => Calendar_Model_Attender::USERTYPE_USER, 'user_id' => $calendarUserId)), false, false, true); if ($attendee && $container instanceof Tinebase_Model_Container) { $attendee->displaycontainer_id = $container->getId(); } if (!$container instanceof Tinebase_Model_Container || $container->type == Tinebase_Model_Container::TYPE_PERSONAL) { // move into special (external users) container $container = Calendar_Controller::getInstance()->getInvitationContainer($_record->resolveOrganizer()); if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Setting container_id to ' . $container->getId() . ' for external organizer ' . $_record->organizer->email); } $_record->container_id = $container->getId(); } } if ($_record->is_all_day_event) { // harmonize datetimes of all day events $_record->setTimezone($_record->originator_tz); if (!$_record->dtend) { $_record->dtend = clone $_record->dtstart; $_record->dtend->setTime(23, 59, 59); } $_record->dtstart->setTime(0, 0, 0); $_record->dtend->setTime(23, 59, 59); $_record->setTimezone('UTC'); } $_record->setRruleUntil(); if ($_record->rrule instanceof Calendar_Model_Rrule) { $_record->rrule->normalize($_record); } if ($_record->isRecurException()) { $baseEvent = $this->getRecurBaseEvent($_record); // remove invalid rrules if ($_record->rrule !== NULL) { if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) { Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' Removing invalid rrule from recur exception: ' . $_record->rrule); } $_record->rrule = NULL; } // // Maybe Later // // exdates needs to stay in baseEvents container // if($_record->container_id != $baseEvent->container_id) { // throw new Calendar_Exception_ExdateContainer(); // } } }