Commit 4f78028c authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-1296 Add FilterType to device and query it.

Code can be extended to support a different filtertype per folder (e.g.
for shared folders). Still, only the FilterType MAX from the config is
supported (user can not superseed server value).

Released under the Affero GNU General Public License (AGPL) version 3.
parent 3ccbfd83
......@@ -60,6 +60,7 @@ class ASDevice extends StateObject {
'koegabbackendfolderid' => false,
'koecapabilities' => array(),
'koelastaccess' => false,
'syncfiltertype' => false,
);
static private $loadedData;
......
......@@ -688,6 +688,30 @@ class DeviceManager {
return $this->device->GetSupportedFields($folderid);
}
/**
* Returns the maximum filter type for a folder.
* This might be limited globally, per device or per folder.
*
* @param string $folderid
*
* @access public
* @return int
*/
public function GetFilterType($folderid) {
// either globally configured SYNC_FILTERTIME_MAX or ALL (no limit)
$maxAllowed = (defined('SYNC_FILTERTIME_MAX') && SYNC_FILTERTIME_MAX > SYNC_FILTERTYPE_ALL) ? SYNC_FILTERTIME_MAX : SYNC_FILTERTYPE_ALL;
// TODO we could/should check for a specific value for the folder, if it's available
$maxDevice = $this->device->GetSyncFilterType();
// ALL has a value of 0, all limitations have higher integer values, see SYNC_FILTERTYPE_ALL definition
if ($maxDevice !== false && $maxDevice > $maxAllowed) {
$maxAllowed = $maxDevice;
}
return $maxAllowed;
}
/**
* Removes all linked states of a specific folder.
* During next request the folder is resynchronized.
......
......@@ -415,10 +415,11 @@ class Sync extends RequestProcessor {
}
// limit items to be synchronized to the mobiles if configured
if (defined('SYNC_FILTERTIME_MAX') && SYNC_FILTERTIME_MAX > SYNC_FILTERTYPE_ALL &&
(!$spa->HasFilterType() || $spa->GetFilterType() == SYNC_FILTERTYPE_ALL || $spa->GetFilterType() > SYNC_FILTERTIME_MAX)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SYNC_FILTERTIME_MAX defined. Filter set to value: %s", SYNC_FILTERTIME_MAX));
$spa->SetFilterType(SYNC_FILTERTIME_MAX);
$maxAllowed = self::$deviceManager->GetFilterType($spa->GetFolderId());
if ($maxAllowed > SYNC_FILTERTYPE_ALL &&
(!$spa->HasFilterType() || $spa->GetFilterType() == SYNC_FILTERTYPE_ALL || $spa->GetFilterType() > $maxAllowed)) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): FilterType applied globally or specifically, using value: %s", $maxAllowed));
$spa->SetFilterType($maxAllowed);
}
// unset filtertype for KOE GAB folder
......@@ -428,7 +429,7 @@ class Sync extends RequestProcessor {
}
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()));
ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): FilterType 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