Commit 57b54cc3 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1134 Set TypeReal on all SyncFolder that pass through

ChangesMemoryWrapper from cache, fixed support for PHP 5.4 that does
clone objects from the cache (requires some explicit setting), moved
patching of folders from Synchronize() to ImportFolderChange() to update
the cache correctly (requires following AddFolder() in PHP 5.4),
introduced ChangesMemoryWrapper::SYNCHRONIZING flag to indicate to
Config() if updates on folders should be performed (should e.g. no for
FolderUpdate command), patch and re-export as new (ADD) secondary
contact folders that were synchronized as standard
(SYNC_FOLDER_TYPE_USER_CONTACT) before (ticket task). 

Released under the Affero GNU General Public License (AGPL) version 3.
parent 4bed9754
......@@ -27,6 +27,7 @@ class ChangesMemoryWrapper extends HierarchyCache implements IImportChanges, IEx
const CHANGE = 1;
const DELETION = 2;
const SOFTDELETION = 3;
const SYNCHRONIZING = 4;
private $changes;
private $step;
......@@ -70,6 +71,13 @@ class ChangesMemoryWrapper extends HierarchyCache implements IImportChanges, IEx
continue;
}
}
// make sure, if the folder is already in cache, to set the TypeReal flag (if available)
$cacheFolder = $this->GetFolder($addFolder->serverid);
if (isset($cacheFolder->TypeReal)) {
$addFolder->TypeReal = $cacheFolder->TypeReal;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ChangesMemoryWrapper->Config(): Set REAL foldertype for folder '%s' from cache: '%s'", $addFolder->displayname, $addFolder->TypeReal));
}
// add folder to the device - if folder is already on the device, nothing will happen
$this->ImportFolderChange($addFolder);
}
......@@ -77,6 +85,15 @@ class ChangesMemoryWrapper extends HierarchyCache implements IImportChanges, IEx
// look for folders which are currently on the device if there are now not to be synched anymore
$alreadyDeleted = $this->GetDeletedFolders();
foreach ($this->ExportFolders(true) as $sid => $folder) {
// check if previously synchronized secondary contact folders were patched for KOE - if no RealType is set they weren't
if ($flags == self::SYNCHRONIZING && ZPush::GetDeviceManager()->IsKoeSupportingSecondaryContacts() && $folder->type == SYNC_FOLDER_TYPE_USER_CONTACT && !isset($folder->TypeReal)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ChangesMemoryWrapper->Config(): Identifided secondary contact folder '%s' that was not patched for KOE before. Re-adding it now.", $folder->displayname));
// we need to delete it from the hierarchy cache so it's exported as NEW (way to convince OL to add it)
$this->DelFolder($folder->serverid);
$folder->flags = SYNC_NEWMESSAGE;
$this->ImportFolderChange($folder);
}
// we are only looking at additional folders
if (isset($folder->NoBackendFolder)) {
// look if this folder is still in the list of additional folders and was not already deleted (e.g. missing permissions)
......@@ -205,9 +222,16 @@ class ChangesMemoryWrapper extends HierarchyCache implements IImportChanges, IEx
$retFolder = false;
}
// KOE ZP-907: When a secondary contact folder is patched (update type & change name) don't import it through the backend
// This is a bit more permissive than ZPush::GetDeviceManager()->IsKoeSupportingSecondaryContacts() so that updates are always catched
// even if the feature was disabled in the meantime.
elseif ($folder->type == SYNC_FOLDER_TYPE_UNKNOWN && ZPush::GetDeviceManager()->IsKoe() && !Utils::IsFolderToBeProcessedByKoe($folder)) {
ZLog::Write(LOGLEVEL_DEBUG, "ChangesMemoryWrapper->ImportFolderChange(): Rewrote folder type to real type, as KOE patched the folder");
$folder->type = $folder->TypeReal;
// cacheFolder contains other properties that must be maintained
// so we continue using the cacheFolder, but rewrite the type and use the incoming displayname
$cacheFolder = $this->GetFolder($folder->serverid);
$cacheFolder->type = $cacheFolder->TypeReal;
$cacheFolder->displayname = $folder->displayname;
$folder = $cacheFolder;
$retFolder = $folder;
}
// do regular folder update
......@@ -254,6 +278,14 @@ class ChangesMemoryWrapper extends HierarchyCache implements IImportChanges, IEx
return false;
}
// ZP-907: if we are ADDING a secondary contact folder and a compatible Outlook is connected, rewrite the type to SYNC_FOLDER_TYPE_UNKNOWN and mark the foldername
if (ZPush::GetDeviceManager()->IsKoeSupportingSecondaryContacts() && $folder->type == SYNC_FOLDER_TYPE_USER_CONTACT &&
(!$this->GetFolder($folder->serverid, true) || !$this->GetFolder($folder->serverid) || $this->GetFolder($folder->serverid)->type === SYNC_FOLDER_TYPE_UNKNOWN)
) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ChangesMemoryWrapper->Synchronize(): Synchronizing new folder '%s' as type SYNC_FOLDER_TYPE_UNKNOWN as Outlook is not able to handle secondary contact folders", $folder->displayname));
$folder = Utils::ChangeFolderToTypeUnknownForKoe($folder);
}
// load this change into memory
$this->changes[] = array(self::CHANGE, $folder);
......@@ -342,16 +374,9 @@ class ChangesMemoryWrapper extends HierarchyCache implements IImportChanges, IEx
$change = $this->changes[$this->step];
if ($change[0] == self::CHANGE) {
if (! $this->GetFolder($change[1]->serverid, true)) {
if (! $this->GetFolder($change[1]->serverid, true))
$change[1]->flags = SYNC_NEWMESSAGE;
// ZP-907: if we are ADDING a secondary contact folder and Outlook is connected, rewrite the type to SYNC_FOLDER_TYPE_UNKNOWN and mark the foldername
// TODO: ZP-1124 this should only be done, if the feature is enabled and the KOE version supports this feature
if (defined('KOE_CAPABILITY_SECONDARYCONTACTS') && KOE_CAPABILITY_SECONDARYCONTACTS && $change[1]->type == SYNC_FOLDER_TYPE_USER_CONTACT && ZPush::GetDeviceManager()->IsKoe()) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ChangesMemoryWrapper->Synchronize(): Synchronizing folder '%s' as type SYNC_FOLDER_TYPE_UNKNOWN as Outlook is not able to handle secondary contact folders", $change[1]->displayname));
$change[1] = Utils::ChangeFolderToTypeUnknownForKoe($change[1]);
}
}
$this->exportImporter->ImportFolderChange($change[1]);
}
// deletion
......
......@@ -77,7 +77,7 @@ class FolderSync extends RequestProcessor {
$changesMem = self::$deviceManager->GetHierarchyChangesWrapper();
// the hierarchyCache should now fully be initialized - check for changes in the additional folders
$changesMem->Config(ZPush::GetAdditionalSyncFolders(false));
$changesMem->Config(ZPush::GetAdditionalSyncFolders(false), ChangesMemoryWrapper::SYNCHRONIZING);
// reset to default store in backend
self::$backend->Setup(false);
......
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