Commit 5ef30764 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #22 in ZP/z-push from...

Merge pull request #22 in ZP/z-push from feature/ZP-659-backendcombined-add-changessink-methods to develop

* commit '1af618fb':
  ZP-659 Remove else. Released under the Affero GNU General Public License (AGPL) version 3.
  ZP-659 - Add ChangesSink methods. Released under the Affero GNU General Public License (AGPL) version 3.
parents 4e62da86 1af618fb
......@@ -62,6 +62,7 @@ class BackendCombined extends Backend implements ISearchProvider {
public $backends;
private $activeBackend;
private $activeBackendID;
private $numberChangesSink;
private $logon_done = false;
/**
......@@ -397,6 +398,93 @@ class BackendCombined extends Backend implements ISearchProvider {
}
/**
* Indicates if the backend has a ChangesSink.
* A sink is an active notification mechanism which does not need polling.
*
* @access public
* @return boolean
*/
public function HasChangesSink() {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCombined->HasChangesSink()"));
$this->numberChangesSink = 0;
foreach ($this->backends as $i => $b) {
if ($this->backends[$i]->HasChangesSink()) {
$this->numberChangesSink++;
}
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCombined->HasChangesSink - Number ChangesSink found: %d", $this->numberChangesSink));
return true;
}
/**
* The folder should be considered by the sink.
* Folders which were not initialized should not result in a notification
* of IBacken->ChangesSink().
*
* @param string $folderid
*
* @access public
* @return boolean false if there is any problem with that folder
*/
public function ChangesSinkInitialize($folderid) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCombined->ChangesSinkInitialize('%s')", $folderid));
$backend = $this->GetBackend($folderid);
if($backend === false) {
// if not backend is found we return true, we don't want this to cause an error
return true;
}
if ($backend->HasChangesSink()) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCombined->ChangesSinkInitialize('%s') is supported, initializing", $folderid));
return $backend->ChangesSinkInitialize($this->GetBackendFolder($folderid));
}
// if the backend doesn't support ChangesSink, we also return true so we don't get an error
return true;
}
/**
* The actual ChangesSink.
* For max. the $timeout value this method should block and if no changes
* are available return an empty array.
* If changes are available a list of folderids is expected.
*
* @param int $timeout max. amount of seconds to block
*
* @access public
* @return array
*/
public function ChangesSink($timeout = 30) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCombined->ChangesSink(%d)", $timeout));
$notifications = array();
if ($this->numberChangesSink == 0) {
ZLog::Write(LOGLEVEL_DEBUG, "BackendCombined doesn't include any Sinkable backends");
} else {
$time_each = $timeout / $this->numberChangesSink;
foreach ($this->backends as $i => $b) {
if ($this->backends[$i]->HasChangesSink()) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("BackendCombined->ChangesSink - Calling in '%s' with %d", get_class($b), $time_each));
$notifications_backend = $this->backends[$i]->ChangesSink($time_each);
//preppend backend delimiter
for ($c = 0; $c < count($notifications_backend); $c++) {
$notifications_backend[$c] = $i . $this->config['delimiter'] . $notifications_backend[$c];
}
$notifications = array_merge($notifications, $notifications_backend);
}
}
}
return $notifications;
}
/**
* Finds the correct backend for a folder
*
......
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