Commit 2b8a889b authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-769 Expose additional folders via DeviceManager, get user/device

based additional folders from the ZPush class, make sure the
NoBackendFlag is un/serialized correctly, write a FOLDERDATA (fd) state
also for hierarchy states to retrieve the lastest sync counters.

Released under the Affero GNU General Public License (AGPL) version 3.
parent af430126
......@@ -793,7 +793,7 @@ class ASDevice extends StateObject {
return false;
}
// check if a folder with that Name is already in the list
// check if a folder with the new name is already in the list
foreach ($this->additionalfolders as $k => $folder) {
if ($folder['name'] == $name) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ASDevice->EditAdditionalFolder(): folder can not be added because there is already an additional folder with the same name: '%s'", $name));
......
......@@ -10,7 +10,7 @@
*
* Created : 11.04.2011
*
* Copyright 2007 - 2013 Zarafa Deutschland GmbH
* Copyright 2007 - 2015 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
......@@ -403,6 +403,44 @@ class DeviceManager {
return $class;
}
/**
* Returns the additional folders as SyncFolder objects.
*
* @access public
* @return array of SyncFolder
*/
public function GetAdditionalUserSyncFolders() {
$folders = array();
foreach($this->device->GetAdditionalFolders() as $df) {
$folder = new SyncFolder();
$folder->serverid = $df['folderid'];
$folder->parentid = 0; // only top folders are supported
$folder->displayname = $df['name'];
$folder->type = $df['type'];
// save store as custom property which is not streamed directly to the device
$folder->NoBackendFolder = true;
$folder->Store = $df['store'];
$folders[$folder->serverid] = $folder;
}
return $folders;
}
/**
* Get the store of an additional folder.
*
* @access public
* @return boolean|string
*/
public function GetAdditionalUserSyncFolderStore($folderid) {
$f = $this->device->GetAdditionalFolder($folderid);
if ($f) {
return $f['store'];
}
return false;
}
/**
* Checks if the message should be streamed to a mobile
* Should always be called before a message is sent to the mobile
......
......@@ -528,8 +528,9 @@ class ZPush {
* @return array
*/
static public function GetAdditionalSyncFolders() {
// TODO if there are any user based folders which should be synchronized, they have to be returned here as well!!
return self::$addSyncFolders;
// get user based folders which should be synchronized
$userFolder = self::GetDeviceManager()->GetAdditionalUserSyncFolders();
return array_merge(self::$addSyncFolders, $userFolder);
}
/**
......@@ -542,7 +543,13 @@ class ZPush {
* @return string
*/
static public function GetAdditionalSyncFolderStore($folderid, $noDebug = false) {
$val = (isset(self::$addSyncFolders[$folderid]->Store))? self::$addSyncFolders[$folderid]->Store : false;
if(isset(self::$addSyncFolders[$folderid]->Store)) {
$val = self::$addSyncFolders[$folderid]->Store;
}
else {
$val = self::GetDeviceManager()->GetAdditionalUserSyncFolderStore($folderid);
}
if (!$noDebug)
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPush::GetAdditionalSyncFolderStore('%s'): '%s'", $folderid, Utils::PrintAsString($val)));
return $val;
......
......@@ -6,7 +6,7 @@
*
* Created : 01.10.2007
*
* Copyright 2007 - 2013 Zarafa Deutschland GmbH
* Copyright 2007 - 2015 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
......@@ -324,6 +324,7 @@ define("SYNC_FOLDERHIERARCHY_COUNT","FolderHierarchy:Count");
define("SYNC_FOLDERHIERARCHY_VERSION","FolderHierarchy:Version");
// only for internal use - never to be streamed to the mobile
define("SYNC_FOLDERHIERARCHY_IGNORE_STORE","FolderHierarchy:IgnoreStore");
define("SYNC_FOLDERHIERARCHY_IGNORE_NOBCKENDFLD","FolderHierarchy:IgnoreNoBackendFolder");
// MeetingResponse
define("SYNC_MEETINGRESPONSE_CALENDARID","MeetingResponse:CalendarId");
......
......@@ -6,7 +6,7 @@
*
* Created : 16.02.2012
*
* Copyright 2007 - 2013 Zarafa Deutschland GmbH
* Copyright 2007 - 2015 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
......@@ -121,6 +121,9 @@ class FolderChange extends RequestProcessor {
$syncstate = self::$deviceManager->GetStateManager()->GetSyncState($synckey);
$newsynckey = self::$deviceManager->GetStateManager()->GetNewSyncKey($synckey);
// there are no SyncParameters for the hierarchy, but we use it to save the latest synckeys
$spa = self::$deviceManager->GetStateManager()->GetSynchedFolderState(false);
// Over the ChangesWrapper the HierarchyCache is notified about all changes
$changesMem = self::$deviceManager->GetHierarchyChangesWrapper();
......@@ -238,9 +241,14 @@ class FolderChange extends RequestProcessor {
self::$topCollector->AnnounceInformation(sprintf("Operation status %d", $status), true);
// Save the sync state for the next time
if (isset($importer))
if (isset($importer)) {
self::$deviceManager->GetStateManager()->SetSyncState($newsynckey, $importer->GetState());
// update SPA & save it
$spa->SetSyncKey($newsynckey);
self::$deviceManager->GetStateManager()->SetSynchedFolderState($spa);
}
return true;
}
}
......@@ -81,6 +81,9 @@ class FolderSync extends RequestProcessor {
// We will be saving the sync state under 'newsynckey'
$newsynckey = self::$deviceManager->GetStateManager()->GetNewSyncKey($synckey);
// there are no SyncParameters for the hierarchy, but we use it to save the latest synckeys
$spa = self::$deviceManager->GetStateManager()->GetSynchedFolderState(false);
}
catch (StateNotFoundException $snfex) {
$status = SYNC_FSSTATUS_SYNCKEYERROR;
......@@ -257,8 +260,13 @@ class FolderSync extends RequestProcessor {
self::$topCollector->AnnounceInformation(sprintf("Outgoing %d folders",$changeCount), true);
// everything fine, save the sync state for the next time
if ($synckey == $newsynckey)
if ($synckey == $newsynckey) {
self::$deviceManager->GetStateManager()->SetSyncState($newsynckey, $newsyncstate);
// update SPA & save it
$spa->SetSyncKey($newsynckey);
self::$deviceManager->GetStateManager()->SetSynchedFolderState($spa);
}
}
}
self::$encoder->endTag();
......
......@@ -10,7 +10,7 @@
*
* Created : 05.09.2011
*
* Copyright 2007 - 2013 Zarafa Deutschland GmbH
* Copyright 2007 - 2015 Zarafa Deutschland GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
......@@ -52,6 +52,7 @@ class SyncFolder extends SyncObject {
public $displayname;
public $type;
public $Store;
public $NoBackendFolder;
function SyncFolder() {
$mapping = array (
......@@ -71,6 +72,9 @@ class SyncFolder extends SyncObject {
SYNC_FOLDERHIERARCHY_IGNORE_STORE => array ( self::STREAMER_VAR => "Store",
self::STREAMER_TYPE => self::STREAMER_TYPE_IGNORE),
SYNC_FOLDERHIERARCHY_IGNORE_NOBCKENDFLD => array ( self::STREAMER_VAR => "NoBackendFolder",
self::STREAMER_TYPE => self::STREAMER_TYPE_IGNORE),
);
parent::SyncObject($mapping);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment