/** * Called at the end of the request * Statistics about received/sent data is saved here * * @access public * @return boolean */ public function Save() { // TODO save other stuff // check if previousily ignored messages were synchronized for the current folder // on multifolder operations of AS14 this is done by setLatestFolder() if ($this->latestFolder !== false) { $this->checkBrokenMessages($this->latestFolder); } // update the user agent and AS version on the device $this->device->SetUserAgent(Request::GetUserAgent()); $this->device->SetASVersion(Request::GetProtocolVersion()); // update data from the OL plugin (if available) if (Request::HasKoeStats()) { $this->device->SetKoeVersion(Request::GetKoeVersion()); $this->device->SetKoeBuild(Request::GetKoeBuild()); $this->device->SetKoeBuildDate(Request::GetKoeBuildDate()); } // data to be saved $data = $this->device->GetData(); if ($data && Request::IsValidDeviceID() && $this->saveDevice) { ZLog::Write(LOGLEVEL_DEBUG, "DeviceManager->Save(): Device data changed"); try { // check if this is the first time the device data is saved and it is authenticated. If so, link the user to the device id if ($this->device->IsNewDevice() && RequestProcessor::isUserAuthenticated()) { ZLog::Write(LOGLEVEL_INFO, sprintf("Linking device ID '%s' to user '%s'", $this->devid, $this->device->GetDeviceUser())); $this->statemachine->LinkUserDevice($this->device->GetDeviceUser(), $this->devid); } if (RequestProcessor::isUserAuthenticated() || $this->device->GetForceSave()) { $this->statemachine->SetState($data, $this->devid, IStateMachine::DEVICEDATA); ZLog::Write(LOGLEVEL_DEBUG, "DeviceManager->Save(): Device data saved"); } } catch (StateNotFoundException $snfex) { ZLog::Write(LOGLEVEL_ERROR, "DeviceManager->Save(): Exception: " . $snfex->getMessage()); } } // remove old search data $oldpid = $this->loopdetection->ProcessLoopDetectionGetOutdatedSearchPID(); if ($oldpid) { ZPush::GetBackend()->GetSearchProvider()->TerminateSearch($oldpid); } // we terminated this process if ($this->loopdetection) { $this->loopdetection->ProcessLoopDetectionTerminate(); } return true; }