/**
  * the singleton pattern
  *
  * @return Tinebase_Alarm
  */
 public static function getInstance()
 {
     if (self::$instance === NULL) {
         self::$instance = new Tinebase_Alarm();
     }
     return self::$instance;
 }
 /**
  * update to 8.1
  * - move ack & snooze time from attendee to alarm
  */
 public function update_0()
 {
     // find all events with ack or snooze times set
     $eventIds = $this->_db->query("SELECT DISTINCT " . $this->_db->quoteIdentifier('cal_event_id') . " FROM " . $this->_db->quoteIdentifier(SQL_TABLE_PREFIX . "cal_attendee") . " WHERE " . $this->_db->quoteIdentifier("alarm_ack_time") . " IS NOT NULL OR " . $this->_db->quoteIdentifier("alarm_snooze_time") . " IS NOT NULL")->fetchAll(Zend_Db::FETCH_ASSOC);
     $attendeeBE = new Calendar_Backend_Sql_Attendee();
     $alarmBE = Tinebase_Alarm::getInstance();
     foreach ($eventIds as $eventId) {
         $eventId = $eventId['cal_event_id'];
         $attendeeFilter = new Tinebase_Model_Filter_FilterGroup();
         $attendeeFilter->addFilter(new Tinebase_Model_Filter_Text('cal_event_id', 'equals', $eventId));
         $attendees = $attendeeBE->search($attendeeFilter);
         $alarms = $alarmBE->search(new Tinebase_Model_AlarmFilter(array(array('field' => 'model', 'operator' => 'equals', 'value' => 'Calendar_Model_Event'), array('field' => 'record_id', 'operator' => 'equals', 'value' => $eventId))));
         foreach ($alarms as $alarm) {
             foreach ($attendees as $attendee) {
                 if ($attendee->alarm_ack_time instanceof Tinebase_DateTime) {
                     $alarm->setOption("acknowledged-{$attendee->user_id}", $attendee->alarm_ack_time->format(Tinebase_Record_Abstract::ISO8601LONG));
                 }
                 if ($attendee->alarm_snooze_time instanceof Tinebase_DateTime) {
                     $alarm->setOption("snoozed-{$attendee->user_id}", $attendee->alarm_snooze_time->format(Tinebase_Record_Abstract::ISO8601LONG));
                 }
             }
             $alarmBE->update($alarm);
         }
     }
     // delte ack & snooze from attendee
     $this->_backend->dropCol('cal_attendee', 'alarm_ack_time');
     $this->_backend->dropCol('cal_attendee', 'alarm_snooze_time');
     $this->setTableVersion('cal_attendee', 5);
     $this->setApplicationVersion('Calendar', '8.1');
 }
 /**
  * tear down tests
  */
 public function tearDown()
 {
     parent::tearDown();
     Calendar_Controller_Event::getInstance()->sendNotifications(false);
     Tinebase_Acl_Roles::getInstance()->resetClassCache();
     if (!$this->_transactionId) {
         if ($this->_backend != NULL) {
             $events = $this->_backend->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_testCalendars->getId()))), new Tinebase_Model_Pagination(array()));
             // delete alarms
             Tinebase_Alarm::getInstance()->deleteAlarmsOfRecord('Calendar_Model_Event', $events->getArrayOfIds());
             foreach ($events as $event) {
                 $this->_backend->delete($event->getId());
             }
         }
         foreach ($this->_testCalendars as $cal) {
             Tinebase_Container::getInstance()->deleteContainer($cal, true);
         }
     }
     $this->_testUserContact = NULL;
     $this->_testCalendar = NULL;
     $this->_testCalendars = NULL;
     $this->_personas = NULL;
     $this->_personasContacts = array();
     $this->_personasDefaultCals = array();
 }
 /**
  * @see 0010449: allow to ignore data when importing ics
  */
 public function testImportWithOnlyBasicData()
 {
     $importEvents = $this->_importHelper('exchange2007_mail_anhang.ics', 1, false, array('onlyBasicData' => true));
     $event = $importEvents->getFirstRecord();
     Tinebase_Alarm::getInstance()->getAlarmsOfRecord('Calendar_Model_Event', $event);
     $emptyFields = array('alarms', 'attendee', 'uid');
     foreach ($emptyFields as $field) {
         $this->assertTrue(empty($event->alarms), 'field ' . $field . ' should be empty in event ' . print_r($event->toArray(), true));
     }
 }
 /**
  * save alarms
  * 
  * @param  Tinebase_Record_RecordSet $alarms
  * @param  string $recordId
  * @return Tinebase_Record_RecordSet
  */
 public function saveAlarms(Tinebase_Record_RecordSet $alarms, $recordId)
 {
     $createdAlarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm');
     $alarms->record_id = $recordId;
     $ac = Tinebase_Alarm::getInstance();
     foreach ($alarms as $alarm) {
         $createdAlarms->addRecord($ac->create($alarm));
     }
     return $createdAlarms;
 }
示例#6
0
 /**
  * tear down tests
  *
  */
 public function tearDown()
 {
     if ($this->_transactionId) {
         Tinebase_TransactionManager::getInstance()->rollBack();
     } else {
         $events = $this->_backend->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'in', 'value' => $this->_testCalendars->getId()))), new Tinebase_Model_Pagination(array()));
         // delete alarms
         Tinebase_Alarm::getInstance()->deleteAlarmsOfRecord('Calendar_Model_Event', $events->getArrayOfIds());
         foreach ($events as $event) {
             $this->_backend->delete($event->getId());
         }
         foreach ($this->_testCalendars as $cal) {
             Tinebase_Container::getInstance()->deleteContainer($cal, true);
         }
     }
 }
 /**
  * testUpdatePreserveAlarmProperties
  * 
  * @see #7430: Calendar sends too much alarms for recurring events
  */
 public function testUpdatePreserveAlarmProperties()
 {
     $alarm30 = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm', array(array('minutes_before' => 30)), TRUE);
     $event = $this->_getEvent();
     $event->dtstart = Tinebase_DateTime::now()->subDay(1)->addMinute(15);
     $event->dtend = clone $event->dtstart;
     $event->dtend->addHour(2);
     $event->rrule = 'FREQ=DAILY;INTERVAL=1;COUNT=3';
     $event->alarms = clone $alarm30;
     $event->organizer = Tinebase_Core::getUser()->contact_id;
     $event = Calendar_Controller_Event::getInstance()->create($event);
     $exceptions = new Tinebase_Record_RecordSet('Calendar_Model_Event');
     $recurSet = Calendar_Model_Rrule::computeRecurrenceSet($event, $exceptions, $event->dtstart, Tinebase_DateTime::now()->addDay(1));
     $exceptionEvent = Calendar_Controller_Event::getInstance()->createRecurException($recurSet->getFirstRecord());
     Tinebase_Alarm::getInstance()->sendPendingAlarms("Tinebase_Event_Async_Minutely");
     Calendar_Controller_EventNotificationsTests::flushMailer();
     $event = $this->_uit->get($event->getId());
     $persistentAlarm = $event->exdate[0]->alarms->getFirstRecord();
     $event->alarms = $event->alarms = clone $alarm30;
     Calendar_Controller_Alarm::setAcknowledgeTime($event->alarms, Tinebase_DateTime::now());
     foreach ($event->exdate as $exdate) {
         $exdate->alarms = clone $alarm30;
     }
     $updatedEvent = $this->_uit->update($event);
     $updatedAlarm = $updatedEvent->exdate[0]->alarms->getFirstRecord();
     $this->assertNotNull($persistentAlarm);
     $diff = $persistentAlarm->diff($updatedAlarm);
     $this->assertTrue($diff->isEmpty(), 'no diff');
     $this->assertTrue(Calendar_Controller_Alarm::getAcknowledgeTime($updatedEvent->alarms->getFirstRecord()) instanceof Tinebase_DateTime, 'ack time missing');
 }
 /**
  * testAdoptAlarmDSTBoundaryAllDayEvent
  * 
  * @see 0009820: Infinite loop in adoptAlarmTime / computeNextOccurrence (DST Boundary)
  */
 public function testAdoptAlarmDSTBoundaryAllDayEvent()
 {
     $event = $this->_getEvent();
     $event->is_all_day_event = 1;
     $event->dtstart = new Tinebase_DateTime('2014-03-03 23:00:00');
     $event->dtend = new Tinebase_DateTime('2014-03-04 22:59:59');
     $event->originator_tz = 'Europe/Berlin';
     $event->rrule = 'FREQ=DAILY';
     $event->alarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm', array(new Tinebase_Model_Alarm(array('minutes_before' => 15), TRUE)));
     $savedEvent = Calendar_Controller_Event::getInstance()->create($event);
     $alarm = $savedEvent->alarms->getFirstRecord();
     $alarm->sent_time = new Tinebase_DateTime('2014-03-29 22:46:01');
     $alarm->alarm_time = new Tinebase_DateTime('2014-03-29 22:45:00');
     $alarm->setOption('recurid', $savedEvent->uid . '-2014-03-29 23:00:00');
     Tinebase_Alarm::getInstance()->update($alarm);
     $alarm = $this->_eventController->get($savedEvent->getId())->alarms->getFirstRecord();
     Calendar_Controller_Event::getInstance()->adoptAlarmTime($savedEvent, $alarm, 'instance');
     $this->assertEquals('2014-03-30 21:45:00', $alarm->alarm_time->toString());
 }
 /**
  * resets all grants of personas calendars and deletes events from it
  */
 protected function cleanupTestCalendars()
 {
     foreach ($this->_getAllPersonasDefaultCals() as $loginName => $calendar) {
         Tinebase_Container::getInstance()->setGrants($calendar, new Tinebase_Record_RecordSet('Tinebase_Model_Grants', array(array('account_id' => $this->_getPersona($loginName)->getId(), 'account_type' => 'user', Tinebase_Model_Grants::GRANT_READ => true, Tinebase_Model_Grants::GRANT_ADD => true, Tinebase_Model_Grants::GRANT_EDIT => true, Tinebase_Model_Grants::GRANT_DELETE => true, Tinebase_Model_Grants::GRANT_PRIVATE => true, Tinebase_Model_Grants::GRANT_ADMIN => true))), true);
         $events = $this->_backend->search(new Calendar_Model_EventFilter(array(array('field' => 'container_id', 'operator' => 'equals', 'value' => $calendar->getId()))), new Tinebase_Model_Pagination(array()));
         // delete alarms
         Tinebase_Alarm::getInstance()->deleteAlarmsOfRecord('Calendar_Model_Event', $events->getArrayOfIds());
         // delete events
         foreach ($events as $event) {
             $this->_backend->delete($event->getId());
         }
     }
 }
 /**
  * delete alarms for records
  *
  * @param array $_recordIds
  */
 protected function _deleteAlarmsForIds($_recordIds)
 {
     if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
         Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " Deleting alarms for records " . print_r($_recordIds, TRUE));
     }
     Tinebase_Alarm::getInstance()->deleteAlarmsOfRecord($this->_modelName, $_recordIds);
 }
 /**
  * updates an attender status of a event
  * 
  * @param  Calendar_Model_Event    $_event
  * @param  Calendar_Model_Attender $_attender
  * @param  string                  $_authKey
  * @return Calendar_Model_Attender updated attender
  */
 public function attenderStatusUpdate(Calendar_Model_Event $_event, Calendar_Model_Attender $_attender, $_authKey)
 {
     try {
         $event = $this->get($_event->getId());
         if (!$event->attendee) {
             throw new Tinebase_Exception_NotFound('Could not find any attendee of event.');
         }
         if (($currentAttender = Calendar_Model_Attender::getAttendee($event->attendee, $_attender)) == null) {
             throw new Tinebase_Exception_NotFound('Could not find attender in event.');
         }
         $updatedAttender = clone $currentAttender;
         if ($currentAttender->status_authkey !== $_authKey) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " no permissions to update status for {$currentAttender->user_type} {$currentAttender->user_id}");
             }
             return $updatedAttender;
         }
         Calendar_Controller_Alarm::enforceACL($_event, $event);
         $currentAttenderDisplayContainerId = $currentAttender->displaycontainer_id instanceof Tinebase_Model_Container ? $currentAttender->displaycontainer_id->getId() : $currentAttender->displaycontainer_id;
         $attenderDisplayContainerId = $_attender->displaycontainer_id instanceof Tinebase_Model_Container ? $_attender->displaycontainer_id->getId() : $_attender->displaycontainer_id;
         // check if something what can be set as user has changed
         if ($currentAttender->status == $_attender->status && $currentAttenderDisplayContainerId == $attenderDisplayContainerId && $currentAttender->transp == $_attender->transp && !Calendar_Controller_Alarm::hasUpdates($_event, $event)) {
             if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
                 Tinebase_Core::getLogger()->DEBUG(__METHOD__ . '::' . __LINE__ . "no status change -> do nothing");
             }
             return $updatedAttender;
         }
         $updatedAttender->status = $_attender->status;
         $updatedAttender->displaycontainer_id = isset($_attender->displaycontainer_id) ? $_attender->displaycontainer_id : $updatedAttender->displaycontainer_id;
         $updatedAttender->transp = isset($_attender->transp) ? $_attender->transp : Calendar_Model_Event::TRANSP_OPAQUE;
         if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) {
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " update attender status to {$_attender->status} for {$currentAttender->user_type} {$currentAttender->user_id}");
             Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . ' set alarm_ack_time / alarm_snooze_time: ' . $updatedAttender->alarm_ack_time . ' / ' . $updatedAttender->alarm_snooze_time);
         }
         $transactionId = Tinebase_TransactionManager::getInstance()->startTransaction(Tinebase_Core::getDb());
         $updatedAttender = $this->_backend->updateAttendee($updatedAttender);
         if ($_event->alarms instanceof Tinebase_Record_RecordSet) {
             foreach ($_event->alarms as $alarm) {
                 $this->_inspectAlarmSet($event, $alarm);
             }
             Tinebase_Alarm::getInstance()->setAlarmsOfRecord($_event);
         }
         $this->_increaseDisplayContainerContentSequence($updatedAttender, $event);
         if ($currentAttender->status != $updatedAttender->status) {
             $this->_touch($event, TRUE);
         }
         Tinebase_TransactionManager::getInstance()->commitTransaction($transactionId);
     } catch (Exception $e) {
         Tinebase_TransactionManager::getInstance()->rollBack();
         throw $e;
     }
     // send notifications
     if ($currentAttender->status != $updatedAttender->status && $this->_sendNotifications && $_event->mute != 1) {
         $updatedEvent = $this->get($event->getId());
         $this->doSendNotifications($updatedEvent, Tinebase_Core::getUser(), 'changed', $event);
     }
     return $updatedAttender;
 }
示例#12
0
 /**
  * saves an event to tine db
  * 
  * @param Calendar_Model_Event $_event
  * @return void
  */
 protected function _saveTineEvent($_event)
 {
     $savedEvent = $this->_calEventBackend->create($_event);
     $_event->attendee->cal_event_id = $savedEvent->getId();
     foreach ($_event->attendee as $attender) {
         $this->_calEventBackend->createAttendee($attender);
     }
     // handle alarms
     foreach ($_event->alarms as $alarm) {
         $alarm->record_id = $savedEvent->getId();
         $alarm->model = 'Calendar_Model_Event';
         $alarm->options = Zend_Json::encode(array('minutes_before' => $alarm->minutes_before, 'recurid' => $_event->recurid));
         // NOTE: alarm_time for recur base events is already set at this point
         if (!$alarm->alarm_time instanceof DateTime) {
             $alarm->setTime($_event->dtstart);
         }
         if ($alarm->alarm_time->isEarlier($this->_migrationStartTime)) {
             $this->_log->debug('skipping alarm for event ' . $_event->getId() . ' at ' . $alarm->alarm_time . ' as it is in the past');
             continue;
         }
         // save alarm
         Tinebase_Alarm::getInstance()->create($alarm);
     }
 }
 public function testAdoptAlarmDSTBoundary()
 {
     $event = $this->_getEvent();
     $event->rrule = 'FREQ=DAILY;INTERVAL=1';
     $event->alarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm', array(new Tinebase_Model_Alarm(array('minutes_before' => 30), TRUE)));
     $persistentEvent = $this->_eventController->create($event);
     // prepare alarm for last non DST instance
     $exceptions = new Tinebase_Record_RecordSet('Calendar_Model_Event');
     $from = new Tinebase_DateTime('2012-03-24 00:00:00');
     $until = new Tinebase_DateTime('2012-03-24 23:59:59');
     $recurSet = Calendar_Model_Rrule::computeRecurrenceSet($persistentEvent, $exceptions, $from, $until);
     $alarm = $persistentEvent->alarms->getFirstRecord();
     $alarm->setOption('recurid', $recurSet[0]->recurid);
     Tinebase_Alarm::getInstance()->update($alarm);
     $loadedBaseEvent = $this->_eventController->get($persistentEvent->getId());
     $alarm = $loadedBaseEvent->alarms->getFirstRecord();
     $this->assertEquals('2012-03-24', substr($alarm->getOption('recurid'), -19, -9), 'precondition failed');
     // adopt alarm
     $this->_eventController->adoptAlarmTime($loadedBaseEvent, $alarm, 'instance');
     $this->assertEquals('2012-03-25', substr($alarm->getOption('recurid'), -19, -9), 'alarm adoption failed');
 }