0009710: bysetpos unknown in rrule.php
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 6 Aug 2014 11:33:21 +0000 (13:33 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 4 Sep 2014 09:26:38 +0000 (11:26 +0200)
* map bysetpos to bymonthday (and remove byday) rrule part

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

Change-Id: I2b83445ffedc80bc339bb31cec909c4a151656ba
Reviewed-on: http://gerrit.tine20.com/customers/938
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tests/tine20/Calendar/Convert/Event/VCalendar/GenericTest.php
tests/tine20/Calendar/Import/files/outlook_bysetpos.ics [new file with mode: 0644]
tine20/Calendar/Model/Rrule.php

index c3985f6..d727fab 100644 (file)
@@ -638,16 +638,38 @@ class Calendar_Convert_Event_VCalendar_GenericTest extends PHPUnit_Framework_Tes
      */
     public function testConvertWithInvalidAlarmTime()
     {
-        $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/invalid_alarm_time.ics', 'r');
+        $savedEvent = $this->_saveIcsEvent('invalid_alarm_time.ics');
+        $this->assertEquals(104, count($savedEvent->exdate), print_r($savedEvent->toArray(), true));
+        $this->assertEquals(2, count($savedEvent->alarms), print_r($savedEvent->toArray(), true));
+    }
+    
+    /**
+     * save ics test event
+     * 
+     * @param string $filename
+     * @return Calendar_Model_Event
+     */
+    protected function _saveIcsEvent($filename)
+    {
+        $vcalendarStream = Calendar_Frontend_WebDAV_EventTest::getVCalendar(dirname(__FILE__) . '/../../../Import/files/' . $filename, 'r');
         
         $this->_converter = Calendar_Convert_Event_VCalendar_Factory::factory(Calendar_Convert_Event_VCalendar_Factory::CLIENT_GENERIC);
         
         $event = $this->_converter->toTine20Model($vcalendarStream);
         
-        // try to save event
-        $savedEvent = Calendar_Controller_MSEventFacade::getInstance()->create($event);
+        return Calendar_Controller_MSEventFacade::getInstance()->create($event);
+    }
+
+    /**
+     * testRruleWithBysetpos
+     * 
+     * @see 0010058: vevent with lots of exdates leads alarm saving failure
+     */
+    public function testRruleWithBysetpos()
+    {
+        $savedEvent = $this->_saveIcsEvent('outlook_bysetpos.ics');
         
-        $this->assertEquals(104, count($savedEvent->exdate), print_r($savedEvent->toArray(), true));
-        $this->assertEquals(2, count($savedEvent->alarms), print_r($savedEvent->toArray(), true));
+        $this->assertEquals(1, $savedEvent->rrule->bymonthday, print_r($savedEvent->toArray(), true));
+        $this->assertTrue(! isset($savedEvent->rrule->byday), print_r($savedEvent->toArray(), true));
     }
 }
diff --git a/tests/tine20/Calendar/Import/files/outlook_bysetpos.ics b/tests/tine20/Calendar/Import/files/outlook_bysetpos.ics
new file mode 100644 (file)
index 0000000..bf3472e
--- /dev/null
@@ -0,0 +1,30 @@
+BEGIN:VCALENDAR
+PRODID:-//Microsoft Corporation//Outlook 12.0 MIMEDIR//EN
+VERSION:2.0
+METHOD:PUBLISH
+X-MS-OLK-FORCEINSPECTOROPEN:TRUE
+BEGIN:VEVENT
+CLASS:PUBLIC
+CREATED:20111019T073153Z
+DTSTART:20131027T030000
+DTEND:20131027T050000
+LAST-MODIFIED:20111019T073153Z
+PRIORITY:5
+SEQUENCE:0
+RRULE:FREQ=YEARLY;INTERVAL=1;BYMONTH=10;BYSETPOS=1;BYDAY=MO,TU,WE,TH,FR
+SUMMARY;LANGUAGE=de:summary
+TRANSP:TRANSPARENT
+UID:040000008200E00074C5B7101A82E0080000000000465FCFA940CC01000000000000000
+    010000000D581BE011ABF35418FBE154EDCEA07A7
+X-ALT-DESC;FMTTYPE=text/html:<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//E
+    N">\n<HTML>\n<HEAD>\n<META NAME="Generator" CONTENT="MS Exchange Server ve
+    rsion 08.00.0681.000">\n<TITLE></TITLE>\n</HEAD>\n<BODY>\n<!-- Converted f
+    rom text/rtf format -->\n\n<P DIR=LTR><SPAN LANG="de"></SPAN></P>\n\n</BOD
+    Y>\n</HTML>
+X-MICROSOFT-CDO-BUSYSTATUS:FREE
+X-MICROSOFT-CDO-IMPORTANCE:1
+X-MICROSOFT-DISALLOW-COUNTER:FALSE
+X-MS-OLK-ALLOWEXTERNCHECK:TRUE
+X-MS-OLK-CONFTYPE:0
+END:VEVENT
+END:VCALENDAR
\ No newline at end of file
index 651cdd4..ee9242d 100644 (file)
@@ -147,11 +147,23 @@ class Calendar_Model_Rrule extends Tinebase_Record_Abstract
     {
         if ($_rrule) {
             $parts = explode(';', $_rrule);
+            $skipParts = array();
             foreach ($parts as $part) {
                 list($key, $value) = explode('=', $part);
                 $part = strtolower($key);
+                if (in_array($part, $skipParts)) {
+                    continue;
+                }
                 if (! in_array($part, $this->_rruleParts)) {
-                    throw new Tinebase_Exception_UnexpectedValue("$part is not a known rrule part");
+                    if ($part === 'bysetpos') {
+                        if (Tinebase_Core::isLogLevel(Zend_Log::NOTICE)) Tinebase_Core::getLogger()->notice(__METHOD__ . '::' . __LINE__
+                            . " Map bysetpos to a supported RRULE part: bymonthday");
+                        $part = 'bymonthday';
+                        $this->byday = null;
+                        $skipParts[] = 'byday';
+                    } else {
+                        throw new Tinebase_Exception_UnexpectedValue("$part is not a known rrule part");
+                    }
                 }
                 $this->$part = $value;
             }
@@ -485,7 +497,8 @@ class Calendar_Model_Rrule extends Tinebase_Record_Abstract
                 }
                 
             } catch (Exception $e) {
-               if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ . " could not compute recurSet of event: {$candidate->getId()} ");
+               if (Tinebase_Core::isLogLevel(Zend_Log::DEBUG)) Tinebase_Core::getLogger()->debug(__METHOD__ . '::' . __LINE__ 
+                       . " Could not compute recurSet of event: {$candidate->getId()} ");
                continue;
             }
         }