}
/**
- * Obtain all calendar server chages that occured in the specified time
- * interval.
- *
- * @param integer $from_ts Starting timestamp
- * @param integer $to_ts Ending timestamp
- *
- * @return array Hash of add, modify, and delete arrays
- */
- public function calendar_getChanges($from_ts, $to_ts)
- {
- try {
- return $this->_registry->calendar->getChanges($from_ts, $to_ts);
- } catch (Exception $e) {
- return array('add' => array(),
- 'modify' => array(),
- 'delete' => array());
- }
- }
-
- /**
* Export the specified event as an ActiveSync message
*
* @param string $uid The calendar id
return $this->_registry->hasInterface($api);
}
+ /**
+ * Get all server changes for the specified collection
+ * @param string $collection The collection type (calendar, contacts, tasks)
+ * @param integer $from_ts Starting timestamp
+ * @param integer $to_ts Ending timestamp
+ *
+ * @return array A hash of add, modify, and delete uids
+ * @throws InvalidArgumentException
+ */
+ public function getChanges($collection, $from_ts, $to_ts)
+ {
+ if (!in_array($collection, array('calendar', 'contacts', 'tasks'))) {
+ throw new InvalidArgumentException('collection must be one of calendar, contacts, or tasks');
+ }
+ try {
+ return $this->_registry->{$collection}->getChanges($from_ts, $to_ts);
+ } catch (Exception $e) {
+ return array('add' => array(),
+ 'modify' => array(),
+ 'delete' => array());
+ }
+ }
+
}
\ No newline at end of file
public function getMessageList($folderid, $cutoffdate)
{
$this->_logger->debug('Horde::getMessageList(' . $folderid . ', ' . $cutoffdate . ')');
+
ob_start();
$messages = array();
-
switch ($folderid) {
case self::APPOINTMENTS_FOLDER:
$startstamp = (int)$cutoffdate;
$this->_endBuffer();
return array();
}
-
$this->_endBuffer();
+
return $messages;
}
* Get a list of server changes that occured during the specified time
* period.
*
- * @param string $folderId The server id of the collection to check.
- * @param integer $from_ts The starting timestamp
- * @param integer $to_ts The ending timestamp
+ * @param string $folderId The server id of the collection to check.
+ * @param integer $from_ts The starting timestamp
+ * @param integer $to_ts The ending timestamp
+ * @param integer $cutoffdate The earliest date to retrieve back to
*
* @return array A list of messge uids that have chnaged in the specified
* time period.
public function getServerChanges($folderId, $from_ts, $to_ts, $cutoffdate)
{
$this->_logger->debug("Horde_ActiveSync_Driver_Horde::getServerChanges($folderId, $from_ts, $to_ts, $cutoffdate)");
- $adds = array();
+ $changes = array();
ob_start();
switch ($folderId) {
case self::APPOINTMENTS_FOLDER:
$startstamp = (int)$cutoffdate;
$endstamp = time() + 32140800; //60 * 60 * 24 * 31 * 12 == one year
try {
- $adds = $this->_connector->calendar_listUids($startstamp, $endstamp);
+ $changes['add'] = $this->_connector->calendar_listUids($startstamp, $endstamp);
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
$this->_endBuffer();
return array();
}
- $edits = $deletes = array();
} else {
try {
- $changes = $this->_connector->calendar_getChanges($from_ts, $to_ts);
- // @TODO: these assignments are just until all collections are refactored.
- $adds = $changes['add'];
- $edits = $changes['modify'];
- $deletes = $changes['delete'];
+ $changes = $this->_connector->getChanges('calendar', $from_ts, $to_ts);
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
$this->_endBuffer();
}
}
break;
+
case self::CONTACTS_FOLDER:
/* Can't use History for first sync */
if ($from_ts == 0) {
try {
- $adds = $this->_connector->contacts_listUids();
+ $changes['add'] = $this->_connector->contacts_listUids();
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
$this->_endBuffer();
$edits = $deletes = array();
} else {
try {
- $adds = $this->_connector->contacts_listBy('add', $from_ts, $to_ts);
- $edits = $this->_connector->contacts_listBy('modify', $from_ts, $to_ts);
- $deletes = $this->_connector->contacts_listBy('delete', $from_ts, $to_ts);
+ $changes = $this->_connector->getChanges('contacts', $from_ts, $to_ts);
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
$this->_endBuffer();
}
}
break;
+
case self::TASKS_FOLDER:
/* Can't use History for first sync */
if ($from_ts == 0) {
try {
- $adds = $this->_connector->tasks_listUids();
+ $changes['add'] = $this->_connector->tasks_listUids();
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
$this->_endBuffer();
return array();
}
- $edits = $deletes = array();
} else {
try {
- $adds = $this->_connector->tasks_listBy('add', $from_ts, $to_ts);
- $edits = $this->_connector->tasks_listBy('modify', $from_ts, $to_ts);
- $deletes = $this->_connector->tasks_listBy('delete', $from_ts, $to_ts);
+ $changes = $this->_connector->getChanges('tasks', $from_ts, $to_ts);
} catch (Horde_Exception $e) {
$this->_logger->err($e->getMessage());
$this->_endBuffer();
break;
}
- /* Build the changes array */
- $changes = array();
+ $results = array();
/* Server additions */
- foreach ($adds as $add) {
- $changes[] = array(
+ foreach ($changes['add'] as $add) {
+ $results[] = array(
'id' => $add,
'type' => 'change',
'flags' => Horde_ActiveSync::FLAG_NEWMESSAGE);
}
/* Server changes */
- foreach ($edits as $change) {
- $changes[] = array(
+ foreach ($changes['modify'] as $change) {
+ $results[] = array(
'id' => $change,
'type' => 'change');
}
/* Server Deletions */
- foreach ($deletes as $deleted) {
- $changes[] = array(
+ foreach ($changes['delete'] as $deleted) {
+ $results[] = array(
'id' => $deleted,
'type' => 'delete');
}
-
$this->_endBuffer();
- return $changes;
+
+ return $results;
}
/**
}
/**
+ * Method for obtaining all server changes between two timestamps. Basically
+ * a wrapper around listBy(), but returns an array containing all adds,
+ * edits and deletions.
+ *
+ * @param integer $start The starting timestamp
+ * @param integer $end The ending timestamp.
+ *
+ * @return array An hash with 'add', 'modify' and 'delete' arrays.
+ */
+ public function getChanges($start, $end)
+ {
+ return array('add' => $this->listBy('add', $start, null, $end),
+ 'modify' => $this->listBy('modify', $start, null, $end),
+ 'delete' => $this->listBy('delete', $start, null, $end));
+ }
+
+ /**
* Returns the timestamp of an operation for a given uid an action.
*
* @param string $uid The uid to look for.
}
/**
+ * Method for obtaining all server changes between two timestamps. Basically
+ * a wrapper around listBy(), but returns an array containing all adds,
+ * edits and deletions.
+ *
+ * @param integer $start The starting timestamp
+ * @param integer $end The ending timestamp.
+ *
+ * @return array An hash with 'add', 'modify' and 'delete' arrays.
+ */
+ public function getChanges($start, $end)
+ {
+ return array('add' => $this->listBy('add', $start, null, $end),
+ 'modify' => $this->listBy('modify', $start, null, $end),
+ 'delete' => $this->listBy('delete', $start, null, $end));
+ }
+
+ /**
* Returns the timestamp of an operation for a given uid an action.
*
* @param string $uid The uid to look for.