Skip to content

Commit

Permalink
Synchronize with Kolab backend.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Jun 24, 2015
1 parent 956694d commit 22f7bd3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 2 deletions.
7 changes: 7 additions & 0 deletions mnemo/lib/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,13 @@ public function listUids($notepads = null)
*/
public function getChanges($start, $end, $isModSeq = false, $notepads = null)
{
global $injector;

$notepad = Mnemo::getDefaultNotepad();
$injector->getInstance('Mnemo_Factory_Driver')
->create($notepad)
->syncronize($end);

return array('add' => $this->listBy('add', $start, $notepads, $end, $isModSeq),
'modify' => $this->listBy('modify', $start, $notepads, $end, $isModSeq),
'delete' => $this->listBy('delete', $start, $notepads, $end, $isModSeq));
Expand Down
11 changes: 11 additions & 0 deletions mnemo/lib/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -513,6 +513,17 @@ public function fromiCalendar(Horde_Icalendar_Vnote $vNote)
return $memo;
}

/**
* Perform any synchronization with backend data handlers that may be
* necessary for the driver.
*
* @param mixed $token A value indicating the last synchronization point,
* if available.
*/
public function synchronize($token = false)
{
}

/**
* Generates a local note ID.
*
Expand Down
30 changes: 28 additions & 2 deletions mnemo/lib/Driver/Kolab.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ protected function _modify($noteId, $desc, $body, $tags)
*/
protected function _buildObject($noteId, $desc, $body, $tags)
{
// Not really needed but it's nice to update the view
$this->synchronize();

$uid = Horde_Url::uriB64Decode($noteId);
$object = array(
'uid' => $uid,
Expand All @@ -205,6 +208,7 @@ protected function _buildObject($noteId, $desc, $body, $tags)
*/
protected function _move($noteId, $newNotepad)
{
$this->synchronize();
$uid = Horde_Url::uriB64Decode($noteId);
try {
$this->_getData()->move(
Expand All @@ -215,6 +219,7 @@ protected function _move($noteId, $newNotepad)
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}

return $uid;
}

Expand All @@ -228,12 +233,14 @@ protected function _move($noteId, $newNotepad)
*/
protected function _delete($noteId)
{
$this->synchronize();
$uid = Horde_Url::uriB64Decode($noteId);
try {
$this->_getData()->delete($uid);
} catch (Horde_Kolab_Storage_Exception $e) {
throw new Mnemo_Exception($e);
}

return $uid;
}

Expand All @@ -245,6 +252,7 @@ protected function _delete($noteId)
*/
protected function _deleteAll()
{
$this->synchronize();
try {
$uids = $this->_getData()->getObjectIds();
$this->_getData()->deleteAll();
Expand All @@ -258,16 +266,18 @@ protected function _deleteAll()
/**
* Return the Kolab data handler for the current notepad.
*
* @param boolean $force Force returning a new handler.
*
* @return Horde_Kolab_Storage_Data The data handler.
*/
protected function _getData()
protected function _getData($force = false)
{
if (empty($this->_notepad)) {
throw new LogicException(
'The notepad has been left undefined but is required!'
);
}
if ($this->_data === null) {
if ($this->_data === null || $force) {
$this->_data = $this->_getDataForNotepad($this->_notepad);
}
return $this->_data;
Expand Down Expand Up @@ -298,6 +308,22 @@ protected function _getDataForNotepad($notepad)
}
}

/**
* 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('mnemo', 'kolab/token');
if (empty($token) || (empty($last_token) || $last_token != $token)) {
$GLOBALS['session']->set('mnemo', 'kolab/token', $token);
$data->synchronize();
}
}

/**
* Build a note based on data array
*
Expand Down

0 comments on commit 22f7bd3

Please sign in to comment.