Commit 843c0807 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #20 in ZO/z-push from bugfix/ZO-29-z-push-expose-hidden-public-folder to develop

* commit 'd7241581':
  ZO-29 Don't really fail if backend can't Setup the KOE_GAB_STORE. Return the other folders normally.
  ZP-29 Removed debug line.
  ZO-29 Added IBackend->GetKoeGabBackendFolderId() - implemented in backends, enabled GAB parameters in config, save KOE GAB folder id in ASDevice,  define and checkconfig for KOE GAB parameters, reset to default store before setting up hierarchy exporter, reset filtertype to ALL for GAB folder.
parents c74d567b d7241581
......@@ -1043,6 +1043,30 @@ class BackendZarafa implements IBackend, ISearchProvider {
return false;
}
/**
* Returns the backend ID of the folder of the KOE GAB.
*
* @param string $foldername
*
* @access public
* @return string|boolean
*/
public function GetKoeGabBackendFolderId($foldername) {
$rootfolder = mapi_msgstore_openentry($this->store);
$table = mapi_folder_gethierarchytable($rootfolder, CONVENIENT_DEPTH);
$restriction = array(RES_PROPERTY, array(RELOP => RELOP_EQ, ULPROPTAG => PR_DISPLAY_NAME, VALUE => $foldername));
mapi_table_restrict($table, $restriction);
$querycnt = mapi_table_getrowcount($table);
if ($querycnt == 1) {
$entry = mapi_table_queryallrows($table, array(PR_SOURCE_KEY));
if (isset($entry[0]) && isset($entry[0][PR_SOURCE_KEY])) {
return bin2hex($entry[0][PR_SOURCE_KEY]);
}
}
ZLog::Write(LOGLEVEL_WARN, sprintf("ZarafaBackend->GetKoeGabBackendFolderId() Found %d entries in the store '%s' matching the name '%s'.", $querycnt, $this->storeName, $foldername));
return false;
}
/**----------------------------------------------------------------------------------------------------------
* Implementation of the ISearchProvider interface
......
......@@ -300,12 +300,12 @@
// Notes support
define('KOE_CAPABILITY_NOTES', true);
// To synchronize the GAB, the GAB store and folderid need to be specified.
// Use the gab-sync script to generate the GAB information. The name needs to
// match the config of the gab-sync script. The folderid is informed by the script.
// TODO use defines
// define('KOE_GAB_STORE', 'SYSTEM');
// define('KOE_GAB_FOLDERID', '');
// To synchronize the GAB KOE, the GAB store and folderid need to be specified.
// Use the gab-sync script to generate this data. The name needs to
// match the config of the gab-sync script.
// More information here: https://wiki.z-hub.io/x/z4Aa (GAB Sync Script)
define('KOE_GAB_STORE', 'SYSTEM');
define('KOE_GAB_FOLDERID', '');
define('KOE_GAB_NAME', 'Z-Push-KOE-GAB');
/**********************************************************************************
......
......@@ -75,6 +75,7 @@ class ASDevice extends StateObject {
'olpluginversion' => false,
'olpluginbuild' => false,
'olpluginbuilddate' => false,
'koegabbackendfolderid' => false,
);
static private $loadedData;
......
......@@ -103,7 +103,7 @@ class DeviceManager {
$this->additionalFoldersHash = $this->getAdditionalFoldersHash();
if ($this->IsOutlookClient()) {
if ($this->IsOutlookClient() && $this->device->GetOLPluginVersion() !== false) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("KOE: %s / %s / %s", $this->device->GetOLPluginVersion(), $this->device->GetOLPluginBuild(), strftime("%Y-%m-%d %H:%M", $this->device->GetOLPluginBuildDate())));
}
}
......@@ -458,6 +458,25 @@ class DeviceManager {
return $class;
}
/**
* Returns the backend folder id of the KOE GAB folder.
* This comes either from the configuration or from the device data.
*
* @return string|boolean returns false if not set or found
*/
public function GetKoeGabBackendFolderId() {
$gabid = false;
if (KOE_CAPABILITY_GAB) {
if (KOE_GAB_FOLDERID != false && KOE_GAB_FOLDERID != '') {
$gabid = KOE_GAB_FOLDERID;
}
else if (KOE_GAB_STORE != "" && KOE_GAB_NAME != "") {
$gabid = $this->device->GetKoeGabBackendFolderId();
}
}
return $gabid;
}
/**
* Returns the additional folders as SyncFolder objects.
*
......@@ -467,18 +486,34 @@ class DeviceManager {
public function GetAdditionalUserSyncFolders() {
$folders = array();
foreach($this->device->GetAdditionalFolders() as $df) {
$folder = new SyncFolder();
$folder->BackendId = $df['folderid'];
$folder->serverid = $this->GetFolderIdForBackendId($folder->BackendId, true);
$folder->parentid = 0; // only top folders are supported
$folder->displayname = $df['name'];
$folder->type = $df['type'];
// save store as custom property which is not streamed directly to the device
$folder->NoBackendFolder = true;
$folder->Store = $df['store'];
$folder = $this->getAdditionalSyncFolder($df['store'], $df['folderid'], $df['name'], $df['type']);
$folders[$folder->BackendId] = $folder;
}
// ZO-40: add KOE GAB folder
if (KOE_CAPABILITY_GAB && $this->IsOutlookClient() && KOE_GAB_STORE != "" && KOE_GAB_NAME != "") {
// if KOE_GAB_FOLDERID is set, use it
if (KOE_GAB_FOLDERID != "") {
$folder = $this->getAdditionalSyncFolder(KOE_GAB_STORE, KOE_GAB_FOLDERID, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT);
$folders[$folder->BackendId] = $folder;
}
else {
// get the GAB id from the device and from the backend
$deviceGabId = $this->device->GetKoeGabBackendFolderId();
if (!ZPush::GetBackend()->Setup(KOE_GAB_STORE)) {
ZLog::Write(LOGLEVEL_WARN, sprintf("DeviceManager->GetAdditionalUserSyncFolders(): setup for store '%s' failed. Unable to search for KOE GAB folder.", KOE_GAB_STORE));
}
else {
$backendGabId = ZPush::GetBackend()->GetKoeGabBackendFolderId(KOE_GAB_NAME);
if ($deviceGabId !== $backendGabId) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("DeviceManager->GetAdditionalUserSyncFolders(): Backend found different KOE GAB backend folderid: '%s'. Updating ASDevice.", $backendGabId));
$this->device->SetKoeGabBackendFolderId($backendGabId);
}
$folders[$backendGabId] = $this->getAdditionalSyncFolder(KOE_GAB_STORE, $backendGabId, KOE_GAB_NAME, SYNC_FOLDER_TYPE_USER_APPOINTMENT);
}
}
}
return $folders;
}
......@@ -491,6 +526,11 @@ class DeviceManager {
* @return boolean|string
*/
public function GetAdditionalUserSyncFolderStore($folderid) {
// is this the KOE GAB folder?
if ($folderid == $this->GetKoeGabBackendFolderId()) {
return KOE_GAB_STORE;
}
$f = $this->device->GetAdditionalFolder($folderid);
if ($f) {
return $f['store'];
......@@ -1065,11 +1105,35 @@ class DeviceManager {
* @access private
* @return string
*/
private function getPolicyName() {
$policyName = ZPush::GetBackend()->GetUserPolicyName();
$policyName = ((!empty($policyName) && $policyName !== false) ? $policyName : ASDevice::DEFAULTPOLICYNAME);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("DeviceManager->getPolicyName(): determined policy name: '%s'", $policyName));
return $policyName;
}
/**
* Generates and SyncFolder object and returns it.
*
* @param string $store
* @param string $folderid
* @param string $name
* @param int $type
*
* @access private
* @returns SyncFolder
*/
private function getAdditionalSyncFolder($store, $folderid, $name, $type) {
$folder = new SyncFolder();
$folder->BackendId = $folderid;
$folder->serverid = $this->GetFolderIdForBackendId($folder->BackendId, true);
$folder->parentid = 0; // only top folders are supported
$folder->displayname = $name;
$folder->type = $type;
// save store as custom property which is not streamed directly to the device
$folder->NoBackendFolder = true;
$folder->Store = $store;
return $folder;
}
}
......@@ -736,12 +736,13 @@ class SyncCollections implements Iterator {
if ($this->hierarchyExporterChecked === true && !$this->LoadCollection(false, true, false))
throw new StatusException("Invalid states found while re-loading hierarchy data.");
// reset backend to the main store
ZPush::GetBackend()->Setup(false);
$changesMem = ZPush::GetDeviceManager()->GetHierarchyChangesWrapper();
$changesMem = ZPush::GetDeviceManager()->GetHierarchyChangesWrapper();
// the hierarchyCache should now fully be initialized - check for changes in the additional folders
$changesMem->Config(ZPush::GetAdditionalSyncFolders(false));
// reset backend to the main store
ZPush::GetBackend()->Setup(false);
$exporter = ZPush::GetBackend()->GetExporter();
if ($exporter !== false && isset($this->addparms[$folderid]["state"])) {
$exporter->Config($this->addparms[$folderid]["state"]);
......
......@@ -360,6 +360,15 @@ class ZPush {
if (!defined('KOE_CAPABILITY_NOTES')) {
define('KOE_CAPABILITY_NOTES', false);
}
if (!defined('KOE_GAB_FOLDERID')) {
define('KOE_GAB_FOLDERID', '');
}
if (!defined('KOE_GAB_STORE')) {
define('KOE_GAB_STORE', '');
}
if (!defined('KOE_GAB_NAME')) {
define('KOE_GAB_NAME', false);
}
// the check on additional folders will not throw hard errors, as this is probably changed on live systems
if (isset($additionalFolders) && !is_array($additionalFolders))
......
......@@ -365,4 +365,15 @@ abstract class Backend implements IBackend {
return false;
}
/**
* Returns the backend ID of the folder of the KOE GAB.
*
* @param string $foldername
*
* @access public
* @return string|boolean
*/
public function GetKoeGabBackendFolderId($foldername) {
return false;
}
}
......@@ -340,4 +340,14 @@ interface IBackend {
* @return string|boolean
*/
public function GetUserPolicyName();
/**
* Returns the backend ID of the folder of the KOE GAB.
*
* @param string $foldername
*
* @access public
* @return string|boolean
*/
public function GetKoeGabBackendFolderId($foldername);
}
......@@ -134,6 +134,9 @@ class FolderChange extends RequestProcessor {
// the hierarchyCache should now fully be initialized - check for changes in the additional folders
$changesMem->Config(ZPush::GetAdditionalSyncFolders(false));
// reset to default store in backend
self::$backend->Setup(false);
// there are unprocessed changes in the hierarchy, trigger resync
if ($changesMem->GetChangeCount() > 0)
throw new StatusException("HandleFolderChange() can not proceed as there are unprocessed hierarchy changes", SYNC_FSSTATUS_SERVERERROR);
......
......@@ -97,6 +97,9 @@ class FolderSync extends RequestProcessor {
// the hierarchyCache should now fully be initialized - check for changes in the additional folders
$changesMem->Config(ZPush::GetAdditionalSyncFolders(false));
// reset to default store in backend
self::$backend->Setup(false);
// process incoming changes
if(self::$decoder->getElementStartTag(SYNC_FOLDERHIERARCHY_CHANGES)) {
// Ignore <Count> if present
......
......@@ -396,6 +396,12 @@ class Sync extends RequestProcessor {
$spa->SetFilterType(SYNC_FILTERTIME_MAX);
}
// unset filtertype for KOE GAB folder
if (KOE_CAPABILITY_GAB && self::$deviceManager->IsOutlookClient() && $spa->GetBackendFolderId() == self::$deviceManager->GetKoeGabBackendFolderId()) {
$spa->SetFilterType(SYNC_FILTERTYPE_ALL);
ZLog::Write(LOGLEVEL_DEBUG, "HandleSync(): KOE GAB folder - setting filter type to unlimited");
}
if ($currentFilterType != $spa->GetFilterType()) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): filter type has changed (old: '%s', new: '%s'), removing folderstat to force Exporter setup", $currentFilterType, $spa->GetFilterType()));
$spa->DelFolderStat();
......
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