3 commits - plugins/calendar plugins/libcalendaring

Thomas Brüderli bruederli at kolabsys.com
Sun Aug 25 12:38:17 CEST 2013


 plugins/calendar/drivers/kolab/kolab_driver.php     |   21 +++++------
 plugins/libcalendaring/libvcalendar.php             |   10 +++--
 plugins/libcalendaring/tests/libvcalendar.php       |    4 +-
 plugins/libcalendaring/tests/resources/freebusy.ifb |   36 --------------------
 4 files changed, 18 insertions(+), 53 deletions(-)

New commits:
commit 3f62bf917fd80ab6e41ed9dbe64ae848339986c8
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Sun Aug 25 12:37:07 2013 +0200

    Adapt freebusy parser to new ical parser from libcalendaring plugin (#2146)

diff --git a/plugins/calendar/drivers/kolab/kolab_driver.php b/plugins/calendar/drivers/kolab/kolab_driver.php
index 516452f..7ae8026 100644
--- a/plugins/calendar/drivers/kolab/kolab_driver.php
+++ b/plugins/calendar/drivers/kolab/kolab_driver.php
@@ -935,28 +935,25 @@ class kolab_driver extends calendar_driver
 
     // parse free-busy information using Horde classes
     if ($fbdata) {
-      $fbcal = $this->cal->get_ical()->get_parser();
-      $fbcal->parsevCalendar($fbdata);
-      if ($fb = $fbcal->findComponent('vfreebusy')) {
+      $ical = $this->cal->get_ical();
+      $ical->import($fbdata);
+      if ($fb = $ical->freebusy) {
         $result = array();
-        $params = $fb->getExtraParams();
-        foreach ($fb->getBusyPeriods() as $from => $to) {
-          if ($to == null)  // no information, assume free
-            break;
-          $type = $params[$from]['FBTYPE'];
-          $result[] = array($from, $to, isset($fbtypemap[$type]) ? $fbtypemap[$type] : calendar::FREEBUSY_BUSY);
+        foreach ($fb['periods'] as $tuple) {
+          list($from, $to, $type) = $tuple;
+          $result[] = array($from->format('U'), $to->format('U'), isset($fbtypemap[$type]) ? $fbtypemap[$type] : calendar::FREEBUSY_BUSY);
         }
 
         // we take 'dummy' free-busy lists as "unknown"
-        if (empty($result) && ($comment = $fb->getAttribute('COMMENT')) && stripos($comment, 'dummy'))
+        if (empty($result) && !empty($fb['comment']) && stripos($fb['comment'], 'dummy'))
           return false;
 
         // set period from $start till the begin of the free-busy information as 'unknown'
-        if (($fbstart = $fb->getStart()) && $start < $fbstart) {
+        if ($fb['start'] && ($fbstart = $fb['start']->format('U')) && $start < $fbstart) {
           array_unshift($result, array($start, $fbstart, calendar::FREEBUSY_UNKNOWN));
         }
         // pad period till $end with status 'unknown'
-        if (($fbend = $fb->getEnd()) && $fbend < $end) {
+        if ($fb['end'] && ($fbend = $fb['end']->format('U')) && $fbend < $end) {
           $result[] = array($fbend, $end, calendar::FREEBUSY_UNKNOWN);
         }
 


commit ec42d07053322ef9b2285d921eb48b041880e02c
Merge: 0c1c275 f4554e2
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Sun Aug 25 12:35:57 2013 +0200

    Merge branch 'master' of ssh://git.kolab.org/git/roundcubemail-plugins-kolab



commit 0c1c2757efd8890944f155d142f58ce712371575
Author: Thomas Bruederli <bruederli at kolabsys.com>
Date:   Sun Aug 25 12:35:41 2013 +0200

    Skip dupes in freebusy list

diff --git a/plugins/libcalendaring/libvcalendar.php b/plugins/libcalendaring/libvcalendar.php
index 271f331..998ed13 100644
--- a/plugins/libcalendaring/libvcalendar.php
+++ b/plugins/libcalendaring/libvcalendar.php
@@ -172,8 +172,7 @@ class libvcalendar
                     }
                 }
                 else if ($ve->name == 'VFREEBUSY') {
-                    $this->_parse_freebusy($ve);
-                    break;
+                    $this->objects[] = $this->_parse_freebusy($ve);
                 }
             }
         }
@@ -454,7 +453,8 @@ class libvcalendar
      */
     private function _parse_freebusy($ve)
     {
-        $this->freebusy = array('periods' => array());
+        $this->freebusy = array('_type' => 'freebusy', 'periods' => array());
+        $seen = array();
 
         foreach ($ve->children as $prop) {
             if (!($prop instanceof VObject\Property))
@@ -476,6 +476,10 @@ class libvcalendar
                 $periods = explode(',', $prop->value);
                 $fbtype = strval($prop['FBTYPE']) ?: 'BUSY';
 
+                // skip dupes
+                if ($seen[$prop->value.':'.$fbtype]++)
+                    continue;
+
                 foreach ($periods as $period) {
                     // Every period is formatted as [start]/[end]. The start is an
                     // absolute UTC time, the end may be an absolute UTC time, or
diff --git a/plugins/libcalendaring/tests/libvcalendar.php b/plugins/libcalendaring/tests/libvcalendar.php
index bc93bab..a204338 100644
--- a/plugins/libcalendaring/tests/libvcalendar.php
+++ b/plugins/libcalendaring/tests/libvcalendar.php
@@ -138,8 +138,8 @@ class libvcalendar_test extends PHPUnit_Framework_TestCase
 
         $this->assertInstanceOf('DateTime', $freebusy['start'], "'start' property is DateTime object");
         $this->assertInstanceOf('DateTime', $freebusy['end'], "'end' property is DateTime object");
-        $this->assertEquals(50, count($freebusy['periods']), "Number of freebusy periods defined");
-        $this->assertEquals(48, count($ical->get_busy_periods()), "Number of busy periods found");
+        $this->assertEquals(11, count($freebusy['periods']), "Number of freebusy periods defined");
+        $this->assertEquals(9, count($ical->get_busy_periods()), "Number of busy periods found");
     }
 
     /**
diff --git a/plugins/libcalendaring/tests/resources/freebusy.ifb b/plugins/libcalendaring/tests/resources/freebusy.ifb
index 07476b2..4491942 100644
--- a/plugins/libcalendaring/tests/resources/freebusy.ifb
+++ b/plugins/libcalendaring/tests/resources/freebusy.ifb
@@ -10,48 +10,12 @@ DTEND:20131122T140026Z
 FREEBUSY;FBTYPE=FREE:20130826T110000Z/20130826T150000Z
 FREEBUSY:20130826T110000Z/20130826T150000Z
 FREEBUSY:20130826T110000Z/20130826T150000Z
-FREEBUSY:20130826T110000Z/20130826T150000Z
-FREEBUSY:20130826T110000Z/20130826T150000Z
-FREEBUSY:20130826T110000Z/20130826T150000Z
-FREEBUSY:20130826T110000Z/20130826T150000Z
-FREEBUSY:20130827T100000Z/20130827T160000Z
-FREEBUSY:20130827T100000Z/20130827T160000Z
-FREEBUSY:20130827T100000Z/20130827T160000Z
-FREEBUSY:20130827T100000Z/20130827T160000Z
-FREEBUSY:20130827T100000Z/20130827T160000Z
 FREEBUSY:20130827T100000Z/20130827T160000Z
-FREEBUSY:20130827T100000Z/20130827T160000Z
-FREEBUSY:20130828T100000Z/20130828T120000Z
-FREEBUSY:20130828T100000Z/20130828T120000Z
-FREEBUSY:20130828T100000Z/20130828T120000Z
-FREEBUSY:20130828T100000Z/20130828T120000Z
 FREEBUSY:20130828T100000Z/20130828T120000Z
 FREEBUSY:20130828T100000Z/20130828T120000Z
-FREEBUSY:20130828T100000Z/20130828T120000Z
-FREEBUSY:20130830T090000Z/20130830T093000Z
-FREEBUSY:20130830T090000Z/20130830T093000Z
-FREEBUSY:20130830T090000Z/20130830T093000Z
 FREEBUSY:20130830T090000Z/20130830T093000Z
-FREEBUSY:20130830T090000Z/20130830T093000Z
-FREEBUSY:20130830T090000Z/20130830T093000Z
-FREEBUSY:20130830T090000Z/20130830T093000Z
-FREEBUSY:20130830T093000Z/20130830T100000Z
-FREEBUSY:20130830T093000Z/20130830T100000Z
-FREEBUSY:20130830T093000Z/20130830T100000Z
-FREEBUSY:20130830T093000Z/20130830T100000Z
-FREEBUSY:20130830T093000Z/20130830T100000Z
-FREEBUSY:20130830T093000Z/20130830T100000Z
 FREEBUSY:20130830T093000Z/20130830T100000Z
 FREEBUSY:20130930T070000Z/20130930T160000Z
-FREEBUSY:20130930T070000Z/20130930T160000Z
-FREEBUSY:20130930T070000Z/20130930T160000Z
-FREEBUSY:20130930T070000Z/20130930T160000Z
-FREEBUSY:20130930T070000Z/20130930T160000Z
-FREEBUSY:20130930T070000Z/20130930T160000Z
-FREEBUSY:20130930T070000Z/20130930T160000Z
-FREEBUSY:20131104T113000Z/20131104T160000Z
-FREEBUSY:20131104T113000Z/20131104T160000Z
-FREEBUSY:20131104T113000Z/20131104T160000Z
 FREEBUSY:20131104T113000Z/20131104T160000Z
 FREEBUSY;FBTYPE=OOF:20131104T113000Z/20131104T160000Z
 FREEBUSY;FBTYPE=BUSY-TENTATIVE:20131104T113000Z/20131104T160000Z




More information about the commits mailing list