Commit bdd1d470 authored by Sebastian Kummer's avatar Sebastian Kummer

Merge pull request #625 in ZP/z-push from...

Merge pull request #625 in ZP/z-push from feature/ZP-1205-set-custom-sync-period-on-the-server to develop

* commit '432dee8a':
  ZP-1205 Fixed issue so the highest restriction is used.
  ZP-1298 Implemented SetDeviceOptions webservice call.
  ZP-1297 Rename method name and slightly adjust function.
  ZP-1299 Expose set filter type (also global value).
  ZP-1297 Added SetDeviceFilterType().
  ZP-1296 Fix bug comparing values.
  ZP-1296 Add FilterType to device and query it.
parents 3ccbfd83 432dee8a
...@@ -60,6 +60,7 @@ class ASDevice extends StateObject { ...@@ -60,6 +60,7 @@ class ASDevice extends StateObject {
'koegabbackendfolderid' => false, 'koegabbackendfolderid' => false,
'koecapabilities' => array(), 'koecapabilities' => array(),
'koelastaccess' => false, 'koelastaccess' => false,
'syncfiltertype' => false,
); );
static private $loadedData; static private $loadedData;
......
...@@ -688,6 +688,30 @@ class DeviceManager { ...@@ -688,6 +688,30 @@ class DeviceManager {
return $this->device->GetSupportedFields($folderid); 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 > SYNC_FILTERTYPE_ALL && ($maxAllowed == SYNC_FILTERTYPE_ALL || $maxDevice < $maxAllowed)) {
$maxAllowed = $maxDevice;
}
return $maxAllowed;
}
/** /**
* Removes all linked states of a specific folder. * Removes all linked states of a specific folder.
* During next request the folder is resynchronized. * During next request the folder is resynchronized.
......
...@@ -415,10 +415,11 @@ class Sync extends RequestProcessor { ...@@ -415,10 +415,11 @@ class Sync extends RequestProcessor {
} }
// limit items to be synchronized to the mobiles if configured // limit items to be synchronized to the mobiles if configured
if (defined('SYNC_FILTERTIME_MAX') && SYNC_FILTERTIME_MAX > SYNC_FILTERTYPE_ALL && $maxAllowed = self::$deviceManager->GetFilterType($spa->GetFolderId());
(!$spa->HasFilterType() || $spa->GetFilterType() == SYNC_FILTERTYPE_ALL || $spa->GetFilterType() > SYNC_FILTERTIME_MAX)) { if ($maxAllowed > SYNC_FILTERTYPE_ALL &&
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SYNC_FILTERTIME_MAX defined. Filter set to value: %s", SYNC_FILTERTIME_MAX)); (!$spa->HasFilterType() || $spa->GetFilterType() == SYNC_FILTERTYPE_ALL || $spa->GetFilterType() > $maxAllowed)) {
$spa->SetFilterType(SYNC_FILTERTIME_MAX); ZLog::Write(LOGLEVEL_DEBUG, sprintf("HandleSync(): FilterType applied globally or specifically, using value: %s", $maxAllowed));
$spa->SetFilterType($maxAllowed);
} }
// unset filtertype for KOE GAB folder // unset filtertype for KOE GAB folder
...@@ -428,7 +429,7 @@ class Sync extends RequestProcessor { ...@@ -428,7 +429,7 @@ class Sync extends RequestProcessor {
} }
if ($currentFilterType != $spa->GetFilterType()) { 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(); $spa->DelFolderStat();
} }
......
...@@ -319,16 +319,76 @@ class ZPushAdmin { ...@@ -319,16 +319,76 @@ class ZPushAdmin {
return true; return true;
} }
/**
* Sets options for a device.
* First argument is the FilterType.
* This value is superseeded by the globally configured SYNC_FILTERTIME_MAX.
* If set to false the value will not be modified in the device.
*
* @param string $user user of the device
* @param string $devid device id that should be modified
* @param int $filtertype SYNC_FILTERTYPE_1DAY to SYNC_FILTERTYPE_ALL, false to ignore
*
* @access public
* @return boolean
*/
public static function SetDeviceOptions($user, $devid, $filtertype) {
if ($user === false || $devid === false) {
ZLog::Write(LOGLEVEL_ERROR, "ZPushAdmin::SetDeviceOptions(): user and device must be specified");
return false;
}
if ($filtertype !== false && $filtertype < SYNC_FILTERTYPE_ALL || $filtertype > SYNC_FILTERTYPE_INCOMPLETETASKS) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::SetDeviceOptions(): specified FilterType '%s' is out of bounds", $filtertype));
return false;
}
// load device data
$device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED);
try {
$device->SetData(ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA), false);
}
catch (StateNotFoundException $e) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::SetDeviceOptions(): device '%s' of user '%s' can not be found", $devid, $user));
return false;
}
if ($filtertype !== false) {
if ($filtertype === $device->GetSyncFilterType()) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::SetDeviceOptions(): device '%s' of user '%s' - device FilterType already at '%s'. Terminating.", $devid, $user, $filtertype));
}
else {
$device->SetSyncFilterType($filtertype);
}
}
// save device data
if ($device->IsDataChanged()) {
try {
if ($device->IsNewDevice() || $device->GetData() === false) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::SetDeviceOptions(): data of user '%s' not synchronized on device '%s'. Aborting.", $user, $devid));
return false;
}
ZPush::GetStateMachine()->SetState($device->GetData(), $devid, IStateMachine::DEVICEDATA);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("ZPushAdmin::SetDeviceOptions(): device '%s' of user '%s' - device FilterType updated to '%s'", $devid, $user, $filtertype));
}
catch (StateNotFoundException $e) {
ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::SetDeviceOptions(): state for device '%s' of user '%s' can not be saved", $devid, $user));
return false;
}
}
return true;
}
/** /**
* Marks a folder of a device of a user for re-synchronization * Marks a folder of a device of a user for re-synchronization.
* *
* @param string $user user of the device * @param string $user user of the device
* @param string $devid device id which should be re-synchronized * @param string $devid device id which should be re-synchronized
* @param mixed $folderid a single folder id or an array of folder ids * @param mixed $folderid a single folder id or an array of folder ids
* *
* @return boolean
* @access public * @access public
* @return boolean
*/ */
static public function ResyncFolder($user, $devid, $folderid) { static public function ResyncFolder($user, $devid, $folderid) {
// load device data // load device data
......
...@@ -108,6 +108,29 @@ class WebserviceDevice { ...@@ -108,6 +108,29 @@ class WebserviceDevice {
return true; return true;
} }
/**
* Sets device options of the Request::GetGETUser().
*
* @param string $deviceId the device id
* @param int $filtertype SYNC_FILTERTYPE_1DAY to SYNC_FILTERTYPE_ALL, false to ignore
*
* @access public
* @return boolean
* @throws SoapFault
*/
public function SetDeviceOptions($deviceId, $filtertype) {
$deviceId = preg_replace("/[^A-Za-z0-9]/", "", $deviceId);
ZLog::Write(LOGLEVEL_INFO, sprintf("WebserviceDevice::SetDeviceOptions('%s', '%s'): set FilterType to '%s'", $deviceId, Request::GetGETUser(), Utils::PrintAsString($filtertype)));
if (! ZPushAdmin::SetDeviceOptions(Request::GetGETUser(), $deviceId, $filtertype)) {
ZPush::GetTopCollector()->AnnounceInformation(ZLog::GetLastMessage(LOGLEVEL_ERROR), true);
throw new SoapFault("ERROR", ZLog::GetLastMessage(LOGLEVEL_ERROR));
}
ZPush::GetTopCollector()->AnnounceInformation(sprintf("FilterType set to '%s' - device id '%s'", Utils::PrintAsString($filtertype), $deviceId), true);
return true;
}
/** /**
* Marks a device of the Request::GetGETUser() for resynchronization. * Marks a device of the Request::GetGETUser() for resynchronization.
* *
......
...@@ -915,6 +915,38 @@ class ZPushAdminCLI { ...@@ -915,6 +915,38 @@ class ZPushAdminCLI {
echo "ActiveSync version:\t".($device->GetASVersion() ? $device->GetASVersion() : "unknown") ."\n"; echo "ActiveSync version:\t".($device->GetASVersion() ? $device->GetASVersion() : "unknown") ."\n";
echo "First sync:\t\t". strftime("%Y-%m-%d %H:%M", $device->GetFirstSyncTime()) ."\n"; echo "First sync:\t\t". strftime("%Y-%m-%d %H:%M", $device->GetFirstSyncTime()) ."\n";
echo "Last sync:\t\t". ($device->GetLastSyncTime() ? strftime("%Y-%m-%d %H:%M", $device->GetLastSyncTime()) : "never")."\n"; echo "Last sync:\t\t". ($device->GetLastSyncTime() ? strftime("%Y-%m-%d %H:%M", $device->GetLastSyncTime()) : "never")."\n";
$filterType = (defined('SYNC_FILTERTIME_MAX') && SYNC_FILTERTIME_MAX > SYNC_FILTERTYPE_ALL) ? SYNC_FILTERTIME_MAX : SYNC_FILTERTYPE_ALL;
$maxDevice = $device->GetSyncFilterType();
if ($maxDevice !== false && $maxDevice > SYNC_FILTERTYPE_ALL && ($filterType == SYNC_FILTERTYPE_ALL || $maxDevice < $filterType)) {
$filterType = $maxDevice;
}
switch($filterType) {
case SYNC_FILTERTYPE_1DAY:
$filterTypeString = "1 day back";
break;
case SYNC_FILTERTYPE_3DAYS:
$filterTypeString = "3 days back";
break;
case SYNC_FILTERTYPE_1WEEK:
$filterTypeString = "1 week back";
break;
case SYNC_FILTERTYPE_2WEEKS:
$filterTypeString = "2 weeks back";
break;
case SYNC_FILTERTYPE_1MONTH:
$filterTypeString = "1 month back";
break;
case SYNC_FILTERTYPE_3MONTHS:
$filterTypeString = "3 months back";
break;
case SYNC_FILTERTYPE_6MONTHS:
$filterTypeString = "6 months back";
break;
default:
$filterTypeString = "unlimited";
}
echo "Sync Period:\t\t". $filterTypeString . " (".$filterType.")\n";
echo "Total folders:\t\t". count($folders). "\n"; echo "Total folders:\t\t". count($folders). "\n";
echo "Short folder Ids:\t". ($device->HasFolderIdMapping() ? "Yes":"No") ."\n"; echo "Short folder Ids:\t". ($device->HasFolderIdMapping() ? "Yes":"No") ."\n";
echo "Synchronized folders:\t". $synchedFolders; echo "Synchronized folders:\t". $synchedFolders;
......
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