Skip to content

Commit

Permalink
Trigger Kolab synchronization on API access.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Aug 14, 2015
1 parent 103079d commit dfd5d79
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
7 changes: 7 additions & 0 deletions nag/lib/Api.php
Expand Up @@ -907,6 +907,13 @@ public function listBy($action, $timestamp, $tasklist = null, $end = null, $isMo
*/
public function getChanges($start, $end, $isModSeq = false, $tasklist = null)
{
if (empty($tasklist)) {
Nag::getDefaultTasklist();
}
$GLOBALS['injector']->getInstance('Nag_Factory_Driver')
->create($tasklist)
->synchronize($end);

return array(
'add' => $this->listBy('add', $start, $tasklist, $end, $isModSeq),
'modify' => $this->listBy('modify', $start, $tasklist, $end, $isModSeq),
Expand Down
10 changes: 10 additions & 0 deletions nag/lib/Driver.php
Expand Up @@ -513,6 +513,16 @@ public function getByUID($uids, array $tasklists = null, $getall = true)
throw new Nag_Exception($this->_errormsg);
}

/**
* Synchronize with the Kolab backend.
*
* @param mixed $token A value indicating the last synchronization point,
* if available.
*/
public function synchronize($token = false)
{
}

/**
* Helper function to update an existing event's tags to tagger storage.
*
Expand Down
20 changes: 20 additions & 0 deletions nag/lib/Driver/Kolab.php
Expand Up @@ -389,6 +389,7 @@ protected function _getObject($task)
*/
protected function _move($taskId, $newTasklist)
{
$this->synchronize();
$this->_getData()->move(
Horde_Url::uriB64Decode($taskId),
$GLOBALS['nag_shares']->getShare($newTasklist)->get('folder')
Expand All @@ -403,6 +404,7 @@ protected function _move($taskId, $newTasklist)
*/
protected function _delete($taskId)
{
$this->synchronize();
$this->_getData()->delete(Horde_Url::uriB64Decode($taskId));
}

Expand All @@ -413,6 +415,7 @@ protected function _delete($taskId)
*/
protected function _deleteAll()
{
$this->synchronize();
$this->retrieve();
$this->tasks->reset();
$ids = array();
Expand Down Expand Up @@ -587,4 +590,21 @@ public function getChildren($parentId, $include_history = true)

return $tasks;
}

/**
* Synchronize with the Kolab backend.
*
* @param mixed $token A value indicating the last synchronization point,
* if available.
*/
public function synchronize($token = false)
{
$data = $this->_getData(true);
$last_token = $GLOBALS['session']->get('nag', 'kolab/token');
if (empty($token) || empty($last_token) || $last_token != $token) {
$GLOBALS['session']->set('nag', 'kolab/token', $token);
$data->synchronize();
}
}

}

0 comments on commit dfd5d79

Please sign in to comment.