Commit 1af618fb authored by Sebastian Kummer's avatar Sebastian Kummer

Merge branch 'develop' of https://stash.z-hub.io/scm/zp/z-push into...

Merge branch 'develop' of https://stash.z-hub.io/scm/zp/z-push into feature/ZP-659-backendcombined-add-changessink-methods

Conflicts:
	src/backend/combined/combined.php
parents e06daa65 17f2507c
...@@ -57,12 +57,13 @@ require_once("backend/combined/config.php"); ...@@ -57,12 +57,13 @@ require_once("backend/combined/config.php");
require_once("backend/combined/importer.php"); require_once("backend/combined/importer.php");
require_once("backend/combined/exporter.php"); require_once("backend/combined/exporter.php");
class BackendCombined extends Backend { class BackendCombined extends Backend implements ISearchProvider {
public $config; public $config;
public $backends; public $backends;
private $activeBackend; private $activeBackend;
private $activeBackendID; private $activeBackendID;
private $numberChangesSink; private $numberChangesSink;
private $logon_done = false;
/** /**
* Constructor of the combined backend * Constructor of the combined backend
...@@ -73,12 +74,12 @@ class BackendCombined extends Backend { ...@@ -73,12 +74,12 @@ class BackendCombined extends Backend {
parent::Backend(); parent::Backend();
$this->config = BackendCombinedConfig::GetBackendCombinedConfig(); $this->config = BackendCombinedConfig::GetBackendCombinedConfig();
foreach ($this->config['backends'] as $i => $b){ $backend_values = array_unique(array_values($this->config['folderbackend']));
// load and instatiate backend foreach ($backend_values as $i) {
ZPush::IncludeBackend($b['name']); ZPush::IncludeBackend($this->config['backends'][$i]['name']);
$this->backends[$i] = new $b['name'](); $this->backends[$i] = new $this->config['backends'][$i]['name']();
} }
ZLog::Write(LOGLEVEL_INFO, sprintf("Combined %d backends loaded.", count($this->backends))); ZLog::Write(LOGLEVEL_DEBUG, sprintf("Combined %d backends loaded.", count($this->backends)));
} }
/** /**
...@@ -117,7 +118,9 @@ class BackendCombined extends Backend { ...@@ -117,7 +118,9 @@ class BackendCombined extends Backend {
return false; return false;
} }
} }
ZLog::Write(LOGLEVEL_INFO, "Combined->Logon() success");
$this->logon_done = true;
ZLog::Write(LOGLEVEL_DEBUG, "Combined->Logon() success");
return true; return true;
} }
...@@ -155,7 +158,7 @@ class BackendCombined extends Backend { ...@@ -155,7 +158,7 @@ class BackendCombined extends Backend {
return false; return false;
} }
} }
ZLog::Write(LOGLEVEL_INFO, "Combined->Setup() success"); ZLog::Write(LOGLEVEL_DEBUG, "Combined->Setup() success");
return true; return true;
} }
...@@ -166,6 +169,10 @@ class BackendCombined extends Backend { ...@@ -166,6 +169,10 @@ class BackendCombined extends Backend {
* @return boolean * @return boolean
*/ */
public function Logoff() { public function Logoff() {
// If no Logon in done, omit Logoff
if (!$this->logon_done)
return true;
ZLog::Write(LOGLEVEL_DEBUG, "Combined->Logoff()"); ZLog::Write(LOGLEVEL_DEBUG, "Combined->Logoff()");
foreach ($this->backends as $i => $b){ foreach ($this->backends as $i => $b){
$this->backends[$i]->Logoff(); $this->backends[$i]->Logoff();
...@@ -363,13 +370,34 @@ class BackendCombined extends Backend { ...@@ -363,13 +370,34 @@ class BackendCombined extends Backend {
* @return string id of the created/updated calendar obj * @return string id of the created/updated calendar obj
* @throws StatusException * @throws StatusException
*/ */
public function MeetingResponse($requestid, $folderid, $error) { public function MeetingResponse($requestid, $folderid, $response) {
$backend = $this->GetBackend($folderid);
if($backend === false)
return false;
return $backend->MeetingResponse($requestid, $this->GetBackendFolder($folderid), $response);
}
/**
* Deletes all contents of the specified folder.
* This is generally used to empty the trash (wastebasked), but could also be used on any
* other folder.
*
* @param string $folderid
* @param boolean $includeSubfolders (opt) also delete sub folders, default true
*
* @access public
* @return boolean
* @throws StatusException
*/
public function EmptyFolder($folderid, $includeSubfolders = true) {
$backend = $this->GetBackend($folderid); $backend = $this->GetBackend($folderid);
if($backend === false) if($backend === false)
return false; return false;
return $backend->MeetingResponse($requestid, $this->GetBackendFolder($folderid), $error); return $backend->EmptyFolder($this->GetBackendFolder($folderid), $includeSubfolders);
} }
/** /**
* Indicates if the backend has a ChangesSink. * Indicates if the backend has a ChangesSink.
* A sink is an active notification mechanism which does not need polling. * A sink is an active notification mechanism which does not need polling.
...@@ -507,5 +535,159 @@ class BackendCombined extends Backend { ...@@ -507,5 +535,159 @@ class BackendCombined extends Backend {
return false; return false;
return substr($folderid,0,$pos); return substr($folderid,0,$pos);
} }
/**
* Returns the BackendCombined as it implements the ISearchProvider interface
* This could be overwritten by the global configuration
*
* @access public
* @return object Implementation of ISearchProvider
*/
public function GetSearchProvider() {
return $this;
}
/**
* Indicates which AS version is supported by the backend.
* Return the lowest version supported by the backends used.
*
* @access public
* @return string AS version constant
*/
public function GetSupportedASVersion() {
$version = ZPush::ASV_14;
foreach ($this->backends as $i => $b) {
$subversion = $this->backends[$i]->GetSupportedASVersion();
if ($subversion < $version) {
$version = $subversion;
}
}
return $version;
}
/*-----------------------------------------------------------------------------------------
-- ISearchProvider
------------------------------------------------------------------------------------------*/
/**
* Indicates if a search type is supported by this SearchProvider
* It supports all the search types, searches are delegated.
*
* @param string $searchtype
*
* @access public
* @return boolean
*/
public function SupportsType($searchtype) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Combined->SupportsType('%s')", $searchtype));
$i = $this->getSearchBackend($searchtype);
return $i !== false;
}
/**
* Queries the LDAP backend
*
* @param string $searchquery string to be searched for
* @param string $searchrange specified searchrange
*
* @access public
* @return array search results
*/
public function GetGALSearchResults($searchquery, $searchrange) {
ZLog::Write(LOGLEVEL_DEBUG, "Combined->GetGALSearchResults()");
$i = $this->getSearchBackend(ISearchProvider::SEARCH_GAL);
$result = false;
if ($i !== false) {
$result = $this->backends[$i]->GetGALSearchResults($searchquery, $searchrange);
}
return $result;
}
/**
* Searches for the emails on the server
*
* @param ContentParameter $cpo
*
* @return array
*/
public function GetMailboxSearchResults($cpo) {
ZLog::Write(LOGLEVEL_DEBUG, "Combined->GetMailboxSearchResults()");
$i = $this->getSearchBackend(ISearchProvider::SEARCH_MAILBOX);
$result = false;
if ($i !== false) {
//Convert $cpo GetSearchFolderid
$cpo->SetSearchFolderid($this->GetBackendFolder($cpo->GetSearchFolderid()));
$result = $this->backends[$i]->GetMailboxSearchResults($cpo, $i . $this->config['delimiter']);
}
return $result;
}
/**
* Terminates a search for a given PID
*
* @param int $pid
*
* @return boolean
*/
public function TerminateSearch($pid) {
ZLog::Write(LOGLEVEL_DEBUG, "Combined->TerminateSearch()");
foreach ($this->backends as $i => $b) {
if ($this->backends[$i] instanceof ISearchProvider) {
$this->backends[$i]->TerminateSearch($pid);
}
}
return true;
}
/**
* Disconnects backends
*
* @access public
* @return boolean
*/
public function Disconnect() {
ZLog::Write(LOGLEVEL_DEBUG, "Combined->Disconnect()");
foreach ($this->backends as $i => $b) {
if ($this->backends[$i] instanceof ISearchProvider) {
$this->backends[$i]->Disconnect();
}
}
return true;
}
/**
* Returns the first backend that support a search type
*
* @param string $searchtype
*
* @access private
* @return string
*/
private function getSearchBackend($searchtype) {
foreach ($this->backends as $i => $b) {
if ($this->backends[$i] instanceof ISearchProvider) {
if ($this->backends[$i]->SupportsType($searchtype)) {
return $i;
}
}
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Combined->getSearchBackend('%s') No support found!", $searchtype));
return false;
}
} }
?> ?>
\ No newline at end of file
...@@ -234,7 +234,7 @@ class ExportChangesICS implements IExportChanges{ ...@@ -234,7 +234,7 @@ class ExportChangesICS implements IExportChanges{
$changes = mapi_exportchanges_getchangecount($this->exporter); $changes = mapi_exportchanges_getchangecount($this->exporter);
if($changes || !($this->flags & BACKEND_DISCARD_DATA)) if($changes || !($this->flags & BACKEND_DISCARD_DATA))
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExportChangesICS->InitializeExporter() successfully. %d changes ready to sync.", $changes)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("ExportChangesICS->InitializeExporter() successfully. %d changes ready to sync for '%s'.", $changes, ($this->folderid)?bin2hex($this->folderid) : 'hierarchy'));
return $ret; return $ret;
} }
......
This diff is collapsed.
...@@ -110,7 +110,7 @@ class ExportChangesDiff extends DiffState implements IExportChanges{ ...@@ -110,7 +110,7 @@ class ExportChangesDiff extends DiffState implements IExportChanges{
$this->changes = $this->getDiffTo($folderlist); $this->changes = $this->getDiffTo($folderlist);
} }
ZLog::Write(LOGLEVEL_INFO, sprintf("ExportChangesDiff->InitializeExporter(): Found '%d' changes", count($this->changes) )); ZLog::Write(LOGLEVEL_INFO, sprintf("ExportChangesDiff->InitializeExporter(): Found '%d' changes for '%s'", count($this->changes), ($this->folderid)?$this->folderid : 'hierarchy' ));
} }
/** /**
......
...@@ -129,8 +129,13 @@ abstract class SyncObject extends Streamer { ...@@ -129,8 +129,13 @@ abstract class SyncObject extends Streamer {
$val = $v[self::STREAMER_VAR]; $val = $v[self::STREAMER_VAR];
// array of values? // array of values?
if (isset($v[self::STREAMER_ARRAY])) { if (isset($v[self::STREAMER_ARRAY])) {
// seek for differences in the arrays // if neither array is created then don't fail the comparison
if (is_array($this->$val) && is_array($odo->$val)) { if (!isset($this->$val) && !isset($odo->$val)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() array '%s' is NOT SET in either object", $val));
continue;
}
elseif (is_array($this->$val) && is_array($odo->$val)) {
// if both arrays exist then seek for differences in the arrays
if (count(array_diff($this->$val, $odo->$val)) + count(array_diff($odo->$val, $this->$val)) > 0) { if (count(array_diff($this->$val, $odo->$val)) + count(array_diff($odo->$val, $this->$val)) > 0) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() items in array '%s' differ", $val)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncObject->equals() items in array '%s' differ", $val));
return false; return 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