Commit 4ad877f6 authored by Manfred Kutas's avatar Manfred Kutas

ZP-777 Catch and filter hierarchy events.

Released under the Affero GNU General Public License (AGPL) version 3.
parent b8c0dbcc
......@@ -900,7 +900,23 @@ class BackendZarafa implements IBackend, ISearchProvider {
public function ChangesSink($timeout = 30) {
$notifications = array();
$sinkresult = @mapi_sink_timedwait($this->changesSink, $timeout * 1000);
// reverse array so that the changes on folders are before changes on messages and
// it's possible to filter such notifications
$sinkresult = array_reverse($sinkresult, true);
foreach ($sinkresult as $sinknotif) {
// add a notification on a folder
if ($sinknotif['objtype'] == MAPI_FOLDER) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendZarafa->ChangesSink() Hierarchy notification for folder %s", bin2hex($sinknotif['entryid'])));
$notifications[$sinknotif['entryid']] = IBackend::HIERARCHYNOTIFICATION;
}
// change on a message, remove hierarchy notification
if (isset($sinknotif['parentid']) && $sinknotif['objtype'] == MAPI_MESSAGE && isset($notifications[$sinknotif['parentid']])) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendZarafa->ChangesSink() Remove hierarchy notification for %s because it is not relevant",
bin2hex($sinknotif['parentid'])));
unset($notifications[$sinknotif['parentid']]);
}
// TODO check if adding $sinknotif['objtype'] = MAPI_MESSAGE wouldn't break anything
// check if something in the monitored folders changed
if (isset($sinknotif['parentid']) && array_key_exists($sinknotif['parentid'], $this->changesSinkFolders)) {
$notifications[] = $this->changesSinkFolders[$sinknotif['parentid']];
......
......@@ -14,7 +14,7 @@
*
* Created : 06.01.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,
......@@ -517,6 +517,11 @@ class SyncCollections implements Iterator {
$validNotifications = false;
foreach ($notifications as $folderid) {
if ($folderid == IBackend::HIERARCHYNOTIFICATION) {
// TODO verify hierarchy notification by configuring an exporter with the latest changes.
ZLog::Write(LOGLEVEL_DEBUG, "Found hierarchy notification.");
continue;
}
// check if the notification on the folder is within our filter
if ($this->CountChange($folderid)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncCollections->CheckForChanges(): Notification received on folder '%s'", $folderid));
......
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