0010120: shorten long event summaries
authorPhilipp Schüle <p.schuele@metaways.de>
Wed, 6 Aug 2014 10:51:43 +0000 (12:51 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 4 Sep 2014 09:26:38 +0000 (11:26 +0200)
* adds full summary string to description
* truncates summary at first linebreak or 255 chars

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

Change-Id: Icfc26370e9c090cbae2a66c373f0d86ca58f0226
Reviewed-on: http://gerrit.tine20.com/customers/937
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/iphone_longsummary.ics [new file with mode: 0644]
tine20/Calendar/Convert/Event/VCalendar/Abstract.php

index d727fab..072f507 100644 (file)
@@ -672,4 +672,17 @@ class Calendar_Convert_Event_VCalendar_GenericTest extends PHPUnit_Framework_Tes
         $this->assertEquals(1, $savedEvent->rrule->bymonthday, print_r($savedEvent->toArray(), true));
         $this->assertTrue(! isset($savedEvent->rrule->byday), print_r($savedEvent->toArray(), true));
     }
+
+    /**
+     * testLongSummary
+     * 
+     * @see 0010120: shorten long event summaries
+     */
+    public function testLongSummary()
+    {
+        $savedEvent = $this->_saveIcsEvent('iphone_longsummary.ics');
+        
+        $this->assertEquals('Finanz-IT anrufen, xxxxxxxxxxxh', $savedEvent->summary, print_r($savedEvent->toArray(), true));
+        $this->assertContains("Finanz-IT anrufen, xxxxxxxxxxxh\nFestgelegt für 25. Juli 2012", $savedEvent->description, print_r($savedEvent->toArray(), true));
+    }
 }
diff --git a/tests/tine20/Calendar/Import/files/iphone_longsummary.ics b/tests/tine20/Calendar/Import/files/iphone_longsummary.ics
new file mode 100644 (file)
index 0000000..4866799
--- /dev/null
@@ -0,0 +1,39 @@
+BEGIN:VCALENDAR
+CALSCALE:GREGORIAN
+PRODID:-//Apple Inc.//iCal 3.0m//EN
+VERSION:2.0
+BEGIN:VTIMEZONE
+TZID:Europe/Berlin
+BEGIN:DAYLIGHT
+DTSTART:19810329T020000
+RRULE:FREQ=YEARLY;BYMONTH=3;BYDAY=-1SU
+TZNAME:CEST
+TZOFFSETFROM:+0100
+TZOFFSETTO:+0200
+END:DAYLIGHT
+BEGIN:STANDARD
+DTSTART:19961027T030000
+RRULE:FREQ=YEARLY;BYMONTH=10;BYDAY=-1SU
+TZNAME:CET
+TZOFFSETFROM:+0200
+TZOFFSETTO:+0100
+END:STANDARD
+END:VTIMEZONE
+BEGIN:VEVENT
+DTEND;TZID=Europe/Berlin:20111020T100000
+DTSTAMP:20111020T064721Z
+DTSTART;TZID=Europe/Berlin:20111020T090000
+LOCATION:Ortrud
+SEQUENCE:0
+SUMMARY:Finanz-IT anrufen\, xxxxxxxxxxxh\nFestgelegt für 25. Juli 2012\nH
+ allo xxxxxx\,\n\nHerr xxxxxxxxxxxhvon der F-I hatte mich heute versucht 
+ zu erreichen\, leider habe ich ihn jetzt verpasst. Kannst du versuchen I
+ hn diese Woche noch anzurufen?\n\nWie es aussieht möchte er jetzt doch n
+ och mal über die Abschlagszahlungen handeln. Aussage auf der Mailbox war
+  das er die Datierung und die Summe klären möchte.\nIch befürchte das xx
+ x und xxx soweit noch nicht sind und deshalb die Bitte an dich\, bevor w
+ ieder was falsch läuft.\n\nVertraglich haben wir Zahlung in zwei Summen 
+ (Halbjahr) immer im Voraus vereinbart.\nBezahlt haben sie letztes mal xx
+UID:631C01AB-0FE0-4E37-B774-56F05DDAD1E6
+END:VEVENT
+END:VCALENDAR
index 5734461..f31d714 100644 (file)
@@ -764,6 +764,7 @@ class Calendar_Convert_Event_VCalendar_Abstract implements Tinebase_Convert_Inte
             Tinebase_Core::getLogger()->trace(__METHOD__ . '::' . __LINE__ . ' vevent ' . $vevent->serialize());
         
         $newAttendees = array();
+        $shortenedFields = array();
         $attachments = new Tinebase_Record_RecordSet('Tinebase_Model_Tree_Node');
         $event->alarms = new Tinebase_Record_RecordSet('Tinebase_Model_Alarm');
         
@@ -848,7 +849,18 @@ class Calendar_Convert_Event_VCalendar_Abstract implements Tinebase_Convert_Inte
                 case 'UID':
                 case 'SUMMARY':
                     $key = strtolower($property->name);
-                    $event->$key = $property->getValue();
+                    $value = $property->getValue();
+                    switch ($key) {
+                        case 'summary':
+                            if (strlen($value) > 255) {
+                                $shortenedFields[$key] = $value;
+                                $endPos = strpos($value, "\n") < 255 ? strpos($value, "\n") : 255;
+                                $value = substr($value, 0, $endPos);
+                            }
+                            break;
+                    }
+                    $event->$key = $value;
+                    
                     break;
                     
                 case 'ORGANIZER':
@@ -1065,6 +1077,10 @@ class Calendar_Convert_Event_VCalendar_Abstract implements Tinebase_Convert_Inte
             }
         }
         
+        foreach ($shortenedFields as $key => $value) {
+            $event->description = "--------\n$key: $value";
+        }
+        
         if (isset($lastAck)) {
             Calendar_Controller_Alarm::setAcknowledgeTime($event->alarms, $lastAck);
         }