Skip to content
Snippets Groups Projects

BackendCombined: Add option to configure GAL backend directly

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