/** * Returns the timestamp of the last synchronization of a device. * * @param $device an ASDevice * * @access public * @return int timestamp */ public static function GetLastSyncTimeOfDevice(&$device) { // we need a StateManager for this operation $stateManager = new StateManager(); $stateManager->SetDevice($device); $sc = new SyncCollections(); $sc->SetStateManager($stateManager); // load all collections of device without loading states or checking permissions $sc->LoadAllCollections(true, false, false); return $sc->GetLastSyncTime(); }
/** * Returns details of a device like synctimes, * policy and wipe status, synched folders etc * * @param string $devid device id * @param string $user user to be looked up * * @return ASDevice object * @access public */ public static function GetDeviceDetails($devid, $user) { try { $device = new ASDevice($devid, ASDevice::UNDEFINED, $user, ASDevice::UNDEFINED); $device->SetData(ZPush::GetStateMachine()->GetState($devid, IStateMachine::DEVICEDATA), false); $device->StripData(); try { // we need a StateManager for this operation $stateManager = new StateManager(); $stateManager->SetDevice($device); $sc = new SyncCollections(); $sc->SetStateManager($stateManager); // load all collections of device without loading states or checking permissions $sc->LoadAllCollections(true, false, false); if ($sc->GetLastSyncTime()) { $device->SetLastSyncTime($sc->GetLastSyncTime()); } // get information about the folder synchronization status from SyncCollections $folders = $device->GetAllFolderIds(); foreach ($folders as $folderid) { $fstatus = $device->GetFolderSyncStatus($folderid); if ($fstatus !== false && isset($fstatus[ASDevice::FOLDERSYNCSTATUS])) { $spa = $sc->GetCollection($folderid); $total = $spa->GetFolderSyncTotal(); $todo = $spa->GetFolderSyncRemaining(); $fstatus['status'] = $fstatus[ASDevice::FOLDERSYNCSTATUS] == 1 ? 'Initialized' : 'Synchronizing'; $fstatus['total'] = $total; $fstatus['done'] = $total - $todo; $fstatus['todo'] = $todo; $device->SetFolderSyncStatus($folderid, $fstatus); } } } catch (StateInvalidException $sive) { ZLog::Write(LOGLEVEL_WARN, sprintf("ZPushAdmin::GetDeviceDetails(): device '%s' of user '%s' has invalid states. Please sync to solve this issue.", $devid, $user)); $device->SetDeviceError("Invalid states. Please force synchronization!"); } return $device; } catch (StateNotFoundException $e) { ZLog::Write(LOGLEVEL_ERROR, sprintf("ZPushAdmin::GetDeviceDetails(): device '%s' of user '%s' can not be found", $devid, $user)); return false; } }