0010048: config for notifications for past events
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 9 Jul 2014 15:41:24 +0000 (17:41 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 18 Jul 2014 08:22:59 +0000 (10:22 +0200)
* configure timeslot for notifications (DEFAULT: 1 week in the past)

https://forge.tine20.org/mantisbt/view.php?id=10048

Change-Id: I533e12294715a4d720bc0732a870b9bcaaa433d8
Reviewed-on: http://gerrit.tine20.com/customers/840
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Controller/EventNotificationsTests.php
tine20/Calendar/Config.php
tine20/Calendar/Controller/EventNotifications.php

index 4fb0fda..988d423 100644 (file)
@@ -56,6 +56,8 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         $this->_notificationController = Calendar_Controller_EventNotifications::getInstance();
         
         $this->_setupPreferences();
+        
+        Calendar_Config::getInstance()->set(Calendar_Config::MAX_NOTIFICATION_PERIOD_FROM, /* last 10 years */ 52 * 10);
     }
     
     /**
@@ -71,6 +73,8 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         if ($this->_emailTestClass instanceof Felamimail_Controller_MessageTest) {
             $this->_emailTestClass->tearDown();
         }
+        
+        Calendar_Config::getInstance()->set(Calendar_Config::MAX_NOTIFICATION_PERIOD_FROM, /* last week */ 1);
     }
     
     /**
@@ -350,7 +354,7 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         $this->_eventController->createRecurException($recurSet[6], FALSE, FALSE); //2012-03-21
         $this->_assertMail('jmcblack', 'reschedule');
         
-        // cancle thisandfuture
+        // cancel thisandfuture
         // @TODO check RANGE in ics
         // @TODO add RANGE text to message
         self::flushMailer();
@@ -365,13 +369,8 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
         $updatedBaseEvent->summary = 'update first occurence';
         $this->_eventController->createRecurException($updatedBaseEvent, FALSE, FALSE); // 2012-03-14
         $this->_assertMail('jmcblack', 'has been updated');
-        
-        // update thisandfuture
-        
-        // reschedule thisandfuture
-        
-        
     }
+    
     public function testAttendeeAlarmSkip()
     {
         $event = $this->_getEvent();
@@ -974,14 +973,7 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
      */
     public function testPutEventExceptionAlarmReminder()
     {
-        $_SERVER['HTTP_USER_AGENT'] = 'Mac_OS_X/10.9 (13A603) CalendarAgent/174';
-    
-        // create recurring event
-        self::flushMailer();
-        $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../Import/files/apple_ical_remind_part1.ics');
-        $id = Tinebase_Record_Abstract::generateUID();
-        $event = Calendar_Frontend_WebDAV_Event::create($this->_testCalendar, "$id.ics", $vcalendar);
-    
+        $event = $this->_createRecurringCalDavEvent();
         $messages = self::getMessages();
         $this->assertEquals(1, count($messages), 'one invitation should be send to sclever');
         $this->_assertMail('sclever', 'invitation');
@@ -997,6 +989,36 @@ class Calendar_Controller_EventNotificationsTests extends Calendar_TestCase
     }
     
     /**
+     * createRecurringCalDavEvent
+     * 
+     * @return Calendar_Frontend_WebDAV_Event
+     */
+    protected function _createRecurringCalDavEvent()
+    {
+        $_SERVER['HTTP_USER_AGENT'] = 'Mac_OS_X/10.9 (13A603) CalendarAgent/174';
+        
+        self::flushMailer();
+        $vcalendar = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../Import/files/apple_ical_remind_part1.ics');
+        $id = Tinebase_Record_Abstract::generateUID();
+        $event = Calendar_Frontend_WebDAV_Event::create($this->_testCalendar, "$id.ics", $vcalendar);
+        
+        return $event;
+    }
+    
+    /**
+     * testNotificationPeriodConfig
+     * 
+     * @see 0010048: config for notifications for past events
+     */
+    public function testNotificationPeriodConfig()
+    {
+        Calendar_Config::getInstance()->set(Calendar_Config::MAX_NOTIFICATION_PERIOD_FROM, /* last week */ 1);
+        $event = $this->_createRecurringCalDavEvent();
+        $messages = self::getMessages();
+        $this->assertEquals(0, count($messages), 'no invitation should be send to sclever');
+    }
+    
+    /**
      * get test alarm emails
      * 
      * @param boolean $deleteThem
index 2b9d99b..f357404 100644 (file)
@@ -44,6 +44,13 @@ class Calendar_Config extends Tinebase_Config_Abstract
     const MAX_FILTER_PERIOD_CALDAV = 'maxfilterperiodcaldav';
     
     /**
+     * MAX_NOTIFICATION_PERIOD_FROM
+     * 
+     * @var string
+     */
+    const MAX_NOTIFICATION_PERIOD_FROM = 'maxnotificationperiodfrom';
+    
+    /**
      * MAX_JSON_DEFAULT_FILTER_PERIOD_FROM
      * 
      * @var string
@@ -103,6 +110,17 @@ class Calendar_Config extends Tinebase_Config_Abstract
             'setBySetupModule'      => TRUE,
             'default'               => 2,
         ),
+        self::MAX_NOTIFICATION_PERIOD_FROM => array(
+        //_('Timeslot for event notifications')
+            'label'                 => 'Timeslot for event notifications',
+        //_('For how long in the past (in weeks) event notifications should be sent.')
+            'description'           => 'For how long in the past (in weeks) event notifications should be sent.',
+            'type'                  => Tinebase_Config_Abstract::TYPE_INT,
+            'clientRegistryInclude' => FALSE,
+            'setByAdminModule'      => FALSE,
+            'setBySetupModule'      => TRUE,
+            'default'               => 1, // 1 week is default
+        ),
         self::MAX_JSON_DEFAULT_FILTER_PERIOD_FROM => array(
         //_('Default filter period (from) for events fetched via JSON API')
             'label'                 => 'Default filter period (from) for events fetched via JSON API',
index 826bf25..676a72b 100644 (file)
             }
         }
         
+        $notificationPeriodConfig = Calendar_Config::getInstance()->get(Calendar_Config::MAX_NOTIFICATION_PERIOD_FROM);
+        if (Tinebase_DateTime::now()->subWeek($notificationPeriodConfig)->isLater($_event->dtend)) {
+            if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__
+                . " Skip notifications to past events (MAX_NOTIFICATION_PERIOD_FROM: " . $notificationPeriodConfig . " week(s))");
+            return;
+        }
+        
         // lets resolve attendee once as batch to fill cache
         $attendee = clone $_event->attendee;
         Calendar_Model_Attender::resolveAttendee($attendee);