2 commits - lib/kolab_sync_backend.php lib/kolab_sync_data_calendar.php lib/kolab_sync_data.php lib/kolab_sync_data_tasks.php tests/data.php tests/phpunit.xml
Aleksander Machniak
machniak at kolabsys.com
Sun Oct 7 12:44:54 CEST 2012
lib/kolab_sync_backend.php | 4 +
lib/kolab_sync_data.php | 39 +++++++++----------
lib/kolab_sync_data_calendar.php | 2
lib/kolab_sync_data_tasks.php | 2
tests/data.php | 79 +++++++++++++++++++++++++++++++++++++++
tests/phpunit.xml | 1
6 files changed, 105 insertions(+), 22 deletions(-)
New commits:
commit 17679cbe642b7ff6ef779e485e0e5121a921a4e1
Author: Aleksander Machniak <alec at alec.pl>
Date: Sun Oct 7 12:44:22 2012 +0200
Fix event/task recurrences handling (Bug #1035)
diff --git a/lib/kolab_sync_data.php b/lib/kolab_sync_data.php
index e413f84..c238a91 100644
--- a/lib/kolab_sync_data.php
+++ b/lib/kolab_sync_data.php
@@ -1060,31 +1060,29 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
/**
* Convert ActiveSync event/task recurrence into Kolab
*/
- protected function recurrence_to_kolab($data, $timezone = null)
+ protected function recurrence_to_kolab($recurrence, $timezone = null)
{
- if (!isset($data->recurrence) || isset($data->recurrence->type)) {
+ if (!($recurrence instanceof Syncroton_Model_EventRecurrence) || !isset($recurrence->type)) {
return null;
}
- $type = $data->recurrence->type;
-
- $rrule['FREQ'] = array_search($type, $this->recurTypeMap);
+ $type = $recurrence->type;
switch ($type) {
case self::RECUR_TYPE_DAILY:
break;
case self::RECUR_TYPE_WEEKLY:
- $rrule['BYDAY'] = $this->bitmask2day($data->recurrence->dayOfWeek);
+ $rrule['BYDAY'] = $this->bitmask2day($recurrence->dayOfWeek);
break;
case self::RECUR_TYPE_MONTHLY:
- $rrule['BYMONTHDAY'] = $data->recurrence->dayOfMonth;
+ $rrule['BYMONTHDAY'] = $recurrence->dayOfMonth;
break;
case self::RECUR_TYPE_MONTHLY_DAYN:
- $week = $data->recurrence->weekOfMonth;
- $day = $data->recurrence->dayOfWeek;
+ $week = $recurrence->weekOfMonth;
+ $day = $recurrence->dayOfWeek;
$byDay = $week == 5 ? -1 : $week;
$byDay .= $this->bitmask2day($day);
@@ -1092,15 +1090,15 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
break;
case self::RECUR_TYPE_YEARLY:
- $rrule['BYMONTH'] = $data->recurrence->monthOfYear;
- $rrule['BYMONTHDAY'] = $data->recurrence->dayOfMonth;
+ $rrule['BYMONTH'] = $recurrence->monthOfYear;
+ $rrule['BYMONTHDAY'] = $recurrence->dayOfMonth;
break;
case self::RECUR_TYPE_YEARLY_DAYN:
- $rrule['BYMONTH'] = $data->recurrence->monthOfYear;
+ $rrule['BYMONTH'] = $recurrence->monthOfYear;
- $week = $data->recurrence->weekOfMonth;
- $day = $data->recurrence->dayOfWeek;
+ $week = $recurrence->weekOfMonth;
+ $day = $recurrence->dayOfWeek;
$byDay = $week == 5 ? -1 : $week;
$byDay .= $this->bitmask2day($day);
@@ -1108,16 +1106,17 @@ abstract class kolab_sync_data implements Syncroton_Data_IData
break;
}
- $rrule['INTERVAL'] = isset($data->recurrence->interval) ? $data->recurrence->interval : 1;
+ $rrule['FREQ'] = array_search($type, $this->recurTypeMap);
+ $rrule['INTERVAL'] = isset($recurrence->interval) ? $recurrence->interval : 1;
- if (isset($data->recurrence->until)) {
+ if (isset($recurrence->until)) {
if ($timezone) {
- $data->recurrence->until->setTimezone($timezone);
+ $recurrence->until->setTimezone($timezone);
}
- $rrule['UNTIL'] = $data->recurrence->until;
+ $rrule['UNTIL'] = $recurrence->until;
}
- else if (!empty($data->recurrence->occurrences)) {
- $rrule['COUNT'] = $data->recurrence->occurrences;
+ else if (!empty($recurrence->occurrences)) {
+ $rrule['COUNT'] = $recurrence->occurrences;
}
return $rrule;
diff --git a/lib/kolab_sync_data_calendar.php b/lib/kolab_sync_data_calendar.php
index e886a57..5c66557 100644
--- a/lib/kolab_sync_data_calendar.php
+++ b/lib/kolab_sync_data_calendar.php
@@ -447,7 +447,7 @@ class kolab_sync_data_calendar extends kolab_sync_data
}
// recurrence
- $event['recurrence'] = $this->recurrence_to_kolab($data, $timezone);
+ $event['recurrence'] = $this->recurrence_to_kolab($data->recurrence, $timezone);
return $event;
}
diff --git a/lib/kolab_sync_data_tasks.php b/lib/kolab_sync_data_tasks.php
index d94caf0..2dfc642 100644
--- a/lib/kolab_sync_data_tasks.php
+++ b/lib/kolab_sync_data_tasks.php
@@ -216,7 +216,7 @@ class kolab_sync_data_tasks extends kolab_sync_data
}
// recurrence
- $task['recurrence'] = $this->recurrence_to_kolab($data);
+ $task['recurrence'] = $this->recurrence_to_kolab($data->recurrence);
return $task;
}
diff --git a/tests/data.php b/tests/data.php
new file mode 100644
index 0000000..0c44932
--- /dev/null
+++ b/tests/data.php
@@ -0,0 +1,79 @@
+<?php
+
+class data extends PHPUnit_Framework_TestCase
+{
+ function setUp()
+ {
+ }
+
+
+ /**
+ * Test for kolab_sync_data::recurrence_to_kolab()
+ */
+ function test_recurrence_to_kolab()
+ {
+ $xml = '<!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
+ <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase" xmlns:Calendar="uri:Calendar">
+ <ApplicationData>
+ <Calendar:Recurrence>
+ <Calendar:Type>0</Calendar:Type>
+ <Calendar:Interval>1</Calendar:Interval>
+ <Calendar:Until>20101128T225959Z</Calendar:Until>
+ </Calendar:Recurrence>
+ </ApplicationData>
+ </Sync>';
+
+ $xml = new SimpleXMLElement($xml);
+ $event = new Syncroton_Model_Event($xml->ApplicationData);
+ $data = new kolab_sync_data_test;
+
+ $result = $data->recurrence_to_kolab($event->recurrence);
+
+ $this->assertEquals('DAILY', $result['FREQ']);
+ $this->assertEquals(1, $result['INTERVAL']);
+ $this->assertEquals('20101128T225959Z', $result['UNTIL']->format("Ymd\THis\Z"));
+
+ $xml = '<!DOCTYPE AirSync PUBLIC "-//AIRSYNC//DTD AirSync//EN" "http://www.microsoft.com/">
+ <Sync xmlns="uri:AirSync" xmlns:AirSyncBase="uri:AirSyncBase" xmlns:Calendar="uri:Calendar">
+ <ApplicationData>
+ <Calendar:Recurrence>
+ <Calendar:Type>1</Calendar:Type>
+ <Calendar:Interval>1</Calendar:Interval>
+ <Calendar:DayOfWeek>8</Calendar:DayOfWeek>
+ </Calendar:Recurrence>
+ </ApplicationData>
+ </Sync>';
+
+ $xml = new SimpleXMLElement($xml);
+ $event = new Syncroton_Model_Event($xml->ApplicationData);
+
+ $result = $data->recurrence_to_kolab($event->recurrence);
+
+ $this->assertEquals('WEEKLY', $result['FREQ']);
+ $this->assertEquals(1, $result['INTERVAL']);
+ $this->assertEquals('WE', $result['BYDAY']);
+ }
+}
+
+/**
+ * kolab_sync_data wrapper, so we can test preotected methods too
+ */
+class kolab_sync_data_test extends kolab_sync_data
+{
+ function __construct()
+ {
+ }
+
+ public function recurrence_to_kolab($data, $timezone = null)
+ {
+ return parent::recurrence_to_kolab($data, $timezone);
+ }
+
+ function toKolab(Syncroton_Model_IEntry $data, $folderId, $entry = null)
+ {
+ }
+
+ function getEntry(Syncroton_Model_SyncCollection $collection, $serverId)
+ {
+ }
+}
diff --git a/tests/phpunit.xml b/tests/phpunit.xml
index 337c0eb..34fab9a 100644
--- a/tests/phpunit.xml
+++ b/tests/phpunit.xml
@@ -4,6 +4,7 @@
<testsuites>
<testsuite name="All Tests">
<file>body_converter.php</file>
+ <file>data.php</file>
</testsuite>
</testsuites>
</phpunit>
commit f7c62344b6c829761df05fd8d9dad45437e2c0fa
Author: Aleksander Machniak <alec at alec.pl>
Date: Fri Oct 5 13:52:40 2012 +0200
Fix PHP Warning: Invalid argument supplied for foreach() when connection to IMAP fails
diff --git a/lib/kolab_sync_backend.php b/lib/kolab_sync_backend.php
index 3ecfdae..659fe6e 100644
--- a/lib/kolab_sync_backend.php
+++ b/lib/kolab_sync_backend.php
@@ -187,6 +187,10 @@ class kolab_sync_backend
// get folders activesync config
$folderdata = $this->storage->get_metadata("*", self::ASYNC_KEY);
+ if (empty($folderdata)) {
+ return $this->folder_meta;
+ }
+
foreach ($folderdata as $folder => $meta) {
if ($asyncdata = $meta[self::ASYNC_KEY]) {
if ($metadata = $this->unserialize_metadata($asyncdata)) {
More information about the commits
mailing list