Skip to content
Snippets Groups Projects

BackendCombined: Add option to configure GAL backend directly

Merged Vincent Brillault requested to merge cern_vb into cern
Files
2
@@ -37,6 +37,7 @@ require_once("backend/combined/config.php");
class BackendCombined extends Backend implements ISearchProvider {
public $config;
public $backends;
public $galbackend = NULL;
private $activeBackend;
private $activeBackendID;
private $numberChangesSink;
@@ -50,12 +51,15 @@ class BackendCombined extends Backend implements ISearchProvider {
public function __construct() {
parent::__construct();
$this->config = BackendCombinedConfig::GetBackendCombinedConfig();
$backend_values = array_unique(array_values($this->config['folderbackend']));
foreach ($backend_values as $i) {
ZPush::IncludeBackend($this->config['backends'][$i]['name']);
$this->backends[$i] = new $this->config['backends'][$i]['name']();
}
if(array_key_exists('galbackend', $this->config)) {
ZPush::IncludeBackend($this->config['galbackend']);
$this->galbackend = new $this->config['galbackend']();
}
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Combined %d backends loaded.", count($this->backends)));
}
@@ -558,6 +562,9 @@ class BackendCombined extends Backend implements ISearchProvider {
*/
public function SupportsType($searchtype) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Combined->SupportsType('%s')", $searchtype));
if ($searchtype == ISearchProvider::SEARCH_GAL && !is_null($this->getGALBackendImpl())) {
return true;
}
$i = $this->getSearchBackend($searchtype);
return $i !== false;
@@ -577,11 +584,17 @@ class BackendCombined extends Backend implements ISearchProvider {
*/
public function GetGALSearchResults($searchquery, $searchrange, $searchpicture) {
ZLog::Write(LOGLEVEL_DEBUG, "Combined->GetGALSearchResults()");
$i = $this->getSearchBackend(ISearchProvider::SEARCH_GAL);
$galbackend = $this->getGALBackendImpl();
if (is_null($galbackend)) {
$i = $this->getSearchBackend(ISearchProvider::SEARCH_GAL);
if ($i !== false) {
$galbackend = $this->backends[$i];
}
}
$result = false;
if ($i !== false) {
$result = $this->backends[$i]->GetGALSearchResults($searchquery, $searchrange, $searchpicture);
if (!is_null($galbackend)) {
$result = $galbackend->GetGALSearchResults($searchquery, $searchrange, $searchpicture);
}
return $result;
@@ -646,6 +659,22 @@ class BackendCombined extends Backend implements ISearchProvider {
}
/**
* Check for a dedicated GAL backend
*
* @access private
* @return ISearchProvider
*/
private function getGALBackendImpl() {
if ((!is_null($this->galbackend)) &&
($this->galbackend instanceof ISearchProvider) &&
($this->galbackend->SupportsType(ISearchProvider::SEARCH_GAL))) {
return $this->galbackend;
}
return NULL;
}
/**
* Returns the first backend that support a search type
*
Loading