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 { ...@@ -793,7 +793,7 @@ class ASDevice extends StateObject {
return false; 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) { foreach ($this->additionalfolders as $k => $folder) {
if ($folder['name'] == $name) { 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)); 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 @@ ...@@ -10,7 +10,7 @@
* *
* Created : 11.04.2011 * 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 * 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, * it under the terms of the GNU Affero General Public License, version 3,
...@@ -403,6 +403,44 @@ class DeviceManager { ...@@ -403,6 +403,44 @@ class DeviceManager {
return $class; 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 * Checks if the message should be streamed to a mobile
* Should always be called before a message is sent to the mobile * Should always be called before a message is sent to the mobile
......
...@@ -528,8 +528,9 @@ class ZPush { ...@@ -528,8 +528,9 @@ class ZPush {
* @return array * @return array
*/ */
static public function GetAdditionalSyncFolders() { static public function GetAdditionalSyncFolders() {
// TODO if there are any user based folders which should be synchronized, they have to be returned here as well!! // get user based folders which should be synchronized
return self::$addSyncFolders; $userFolder = self::GetDeviceManager()->GetAdditionalUserSyncFolders();
return array_merge(self::$addSyncFolders, $userFolder);
} }
/** /**
...@@ -542,7 +543,13 @@ class ZPush { ...@@ -542,7 +543,13 @@ class ZPush {
* @return string * @return string
*/ */
static public function GetAdditionalSyncFolderStore($folderid, $noDebug = false) { 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) if (!$noDebug)
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPush::GetAdditionalSyncFolderStore('%s'): '%s'", $folderid, Utils::PrintAsString($val))); ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPush::GetAdditionalSyncFolderStore('%s'): '%s'", $folderid, Utils::PrintAsString($val)));
return $val; return $val;
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Created : 01.10.2007 * 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 * 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, * it under the terms of the GNU Affero General Public License, version 3,
...@@ -324,6 +324,7 @@ define("SYNC_FOLDERHIERARCHY_COUNT","FolderHierarchy:Count"); ...@@ -324,6 +324,7 @@ define("SYNC_FOLDERHIERARCHY_COUNT","FolderHierarchy:Count");
define("SYNC_FOLDERHIERARCHY_VERSION","FolderHierarchy:Version"); define("SYNC_FOLDERHIERARCHY_VERSION","FolderHierarchy:Version");
// only for internal use - never to be streamed to the mobile // only for internal use - never to be streamed to the mobile
define("SYNC_FOLDERHIERARCHY_IGNORE_STORE","FolderHierarchy:IgnoreStore"); define("SYNC_FOLDERHIERARCHY_IGNORE_STORE","FolderHierarchy:IgnoreStore");
define("SYNC_FOLDERHIERARCHY_IGNORE_NOBCKENDFLD","FolderHierarchy:IgnoreNoBackendFolder");
// MeetingResponse // MeetingResponse
define("SYNC_MEETINGRESPONSE_CALENDARID","MeetingResponse:CalendarId"); define("SYNC_MEETINGRESPONSE_CALENDARID","MeetingResponse:CalendarId");
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* *
* Created : 16.02.2012 * 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 * 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, * it under the terms of the GNU Affero General Public License, version 3,
...@@ -121,6 +121,9 @@ class FolderChange extends RequestProcessor { ...@@ -121,6 +121,9 @@ class FolderChange extends RequestProcessor {
$syncstate = self::$deviceManager->GetStateManager()->GetSyncState($synckey); $syncstate = self::$deviceManager->GetStateManager()->GetSyncState($synckey);
$newsynckey = self::$deviceManager->GetStateManager()->GetNewSyncKey($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 // Over the ChangesWrapper the HierarchyCache is notified about all changes
$changesMem = self::$deviceManager->GetHierarchyChangesWrapper(); $changesMem = self::$deviceManager->GetHierarchyChangesWrapper();
...@@ -238,9 +241,14 @@ class FolderChange extends RequestProcessor { ...@@ -238,9 +241,14 @@ class FolderChange extends RequestProcessor {
self::$topCollector->AnnounceInformation(sprintf("Operation status %d", $status), true); self::$topCollector->AnnounceInformation(sprintf("Operation status %d", $status), true);
// Save the sync state for the next time // Save the sync state for the next time
if (isset($importer)) if (isset($importer)) {
self::$deviceManager->GetStateManager()->SetSyncState($newsynckey, $importer->GetState()); self::$deviceManager->GetStateManager()->SetSyncState($newsynckey, $importer->GetState());
// update SPA & save it
$spa->SetSyncKey($newsynckey);
self::$deviceManager->GetStateManager()->SetSynchedFolderState($spa);
}
return true; return true;
} }
} }
...@@ -81,6 +81,9 @@ class FolderSync extends RequestProcessor { ...@@ -81,6 +81,9 @@ class FolderSync extends RequestProcessor {
// We will be saving the sync state under 'newsynckey' // We will be saving the sync state under 'newsynckey'
$newsynckey = self::$deviceManager->GetStateManager()->GetNewSyncKey($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);
} }
catch (StateNotFoundException $snfex) { catch (StateNotFoundException $snfex) {
$status = SYNC_FSSTATUS_SYNCKEYERROR; $status = SYNC_FSSTATUS_SYNCKEYERROR;
...@@ -257,8 +260,13 @@ class FolderSync extends RequestProcessor { ...@@ -257,8 +260,13 @@ class FolderSync extends RequestProcessor {
self::$topCollector->AnnounceInformation(sprintf("Outgoing %d folders",$changeCount), true); self::$topCollector->AnnounceInformation(sprintf("Outgoing %d folders",$changeCount), true);
// everything fine, save the sync state for the next time // everything fine, save the sync state for the next time
if ($synckey == $newsynckey) if ($synckey == $newsynckey) {
self::$deviceManager->GetStateManager()->SetSyncState($newsynckey, $newsyncstate); self::$deviceManager->GetStateManager()->SetSyncState($newsynckey, $newsyncstate);
// update SPA & save it
$spa->SetSyncKey($newsynckey);
self::$deviceManager->GetStateManager()->SetSynchedFolderState($spa);
}
} }
} }
self::$encoder->endTag(); self::$encoder->endTag();
......
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
* *
* Created : 05.09.2011 * 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 * 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, * it under the terms of the GNU Affero General Public License, version 3,
...@@ -52,6 +52,7 @@ class SyncFolder extends SyncObject { ...@@ -52,6 +52,7 @@ class SyncFolder extends SyncObject {
public $displayname; public $displayname;
public $type; public $type;
public $Store; public $Store;
public $NoBackendFolder;
function SyncFolder() { function SyncFolder() {
$mapping = array ( $mapping = array (
...@@ -71,6 +72,9 @@ class SyncFolder extends SyncObject { ...@@ -71,6 +72,9 @@ class SyncFolder extends SyncObject {
SYNC_FOLDERHIERARCHY_IGNORE_STORE => array ( self::STREAMER_VAR => "Store", SYNC_FOLDERHIERARCHY_IGNORE_STORE => array ( self::STREAMER_VAR => "Store",
self::STREAMER_TYPE => self::STREAMER_TYPE_IGNORE), 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); 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