filestatemachine.php (Z-Push-2.6.3) | : | filestatemachine.php (Z-Push-2.6.4) | ||
---|---|---|---|---|
skipping to change at line 119 | skipping to change at line 119 | |||
* @throws StateNotFoundException, StateInvalidException, UnavailableExcepti on | * @throws StateNotFoundException, StateInvalidException, UnavailableExcepti on | |||
*/ | */ | |||
public function GetState($devid, $type, $key = false, $counter = false, $cle anstates = true) { | public function GetState($devid, $type, $key = false, $counter = false, $cle anstates = true) { | |||
if ($counter && $cleanstates) | if ($counter && $cleanstates) | |||
$this->CleanStates($devid, $type, $key, $counter); | $this->CleanStates($devid, $type, $key, $counter); | |||
// Read current sync state | // Read current sync state | |||
$filename = $this->getFullFilePath($devid, $type, $key, $counter); | $filename = $this->getFullFilePath($devid, $type, $key, $counter); | |||
if(file_exists($filename)) { | if(file_exists($filename)) { | |||
$contents = Utils::SafeGetContentsUnserialize($filename, __FUNCTION_ _, false); | $contents = Utils::SafeGetContents($filename, __FUNCTION__, false, t rue); | |||
return $contents; | return $contents; | |||
} | } | |||
// throw an exception on all other states, but not FAILSAVE as it's most of the times not there by default | // throw an exception on all other states, but not FAILSAVE as it's most of the times not there by default | |||
else if ($type !== IStateMachine::FAILSAVE) | else if ($type !== IStateMachine::FAILSAVE) | |||
throw new StateNotFoundException(sprintf("FileStateMachine->GetState (): Could not locate state '%s'",$filename)); | throw new StateNotFoundException(sprintf("FileStateMachine->GetState (): Could not locate state '%s'",$filename)); | |||
} | } | |||
/** | /** | |||
* Writes ta state to for a key and counter | * Writes ta state to for a key and counter | |||
* | * | |||
skipping to change at line 206 | skipping to change at line 206 | |||
* | * | |||
* @access public | * @access public | |||
* @return boolean indicating if the user was added or not (existed alre ady) | * @return boolean indicating if the user was added or not (existed alre ady) | |||
*/ | */ | |||
public function LinkUserDevice($username, $devid) { | public function LinkUserDevice($username, $devid) { | |||
$mutex = new SimpleMutex(); | $mutex = new SimpleMutex(); | |||
$changed = false; | $changed = false; | |||
// exclusive block | // exclusive block | |||
if ($mutex->Block()) { | if ($mutex->Block()) { | |||
$users = Utils::SafeGetContentsUnserialize($this->userfilename, __FU NCTION__, true); | $users = Utils::SafeGetContents($this->userfilename, __FUNCTION__, t rue, true); | |||
if (!$users) { | if (!$users) { | |||
$users = array(); | $users = array(); | |||
} | } | |||
// add user/device to the list | // add user/device to the list | |||
if (!isset($users[$username])) { | if (!isset($users[$username])) { | |||
$users[$username] = array(); | $users[$username] = array(); | |||
$changed = true; | $changed = true; | |||
} | } | |||
if (!isset($users[$username][$devid])) { | if (!isset($users[$username][$devid])) { | |||
$users[$username][$devid] = 1; | $users[$username][$devid] = 1; | |||
skipping to change at line 247 | skipping to change at line 247 | |||
* | * | |||
* @access public | * @access public | |||
* @return boolean | * @return boolean | |||
*/ | */ | |||
public function UnLinkUserDevice($username, $devid) { | public function UnLinkUserDevice($username, $devid) { | |||
$mutex = new SimpleMutex(); | $mutex = new SimpleMutex(); | |||
$changed = false; | $changed = false; | |||
// exclusive block | // exclusive block | |||
if ($mutex->Block()) { | if ($mutex->Block()) { | |||
$users = Utils::SafeGetContentsUnserialize($this->userfilename, __FU NCTION__, true); | $users = Utils::SafeGetContents($this->userfilename, __FUNCTION__, t rue, true); | |||
if (!$users) { | if (!$users) { | |||
$users = array(); | $users = array(); | |||
} | } | |||
// is this user listed at all? | // is this user listed at all? | |||
if (isset($users[$username])) { | if (isset($users[$username])) { | |||
if (isset($users[$username][$devid])) { | if (isset($users[$username][$devid])) { | |||
unset($users[$username][$devid]); | unset($users[$username][$devid]); | |||
$changed = true; | $changed = true; | |||
} | } | |||
skipping to change at line 296 | skipping to change at line 296 | |||
public function GetAllDevices($username = false) { | public function GetAllDevices($username = false) { | |||
$out = array(); | $out = array(); | |||
if ($username === false) { | if ($username === false) { | |||
foreach ($this->getDeviceDataFiles() as $devdata) | foreach ($this->getDeviceDataFiles() as $devdata) | |||
// TODO do we still need this check here? | // TODO do we still need this check here? | |||
if (preg_match('/\/([A-Za-z0-9]+)-'. IStateMachine::DEVICEDATA. '$/', $devdata, $matches)) | if (preg_match('/\/([A-Za-z0-9]+)-'. IStateMachine::DEVICEDATA. '$/', $devdata, $matches)) | |||
$out[] = $matches[1]; | $out[] = $matches[1]; | |||
return $out; | return $out; | |||
} | } | |||
else { | else { | |||
$users = Utils::SafeGetContentsUnserialize($this->userfilename, __FU NCTION__, false); | $users = Utils::SafeGetContents($this->userfilename, __FUNCTION__, f alse, true); | |||
if (!$users) { | if (!$users) { | |||
$users = array(); | $users = array(); | |||
} | } | |||
// get device list for the user | // get device list for the user | |||
if (isset($users[$username])) | if (isset($users[$username])) | |||
return array_keys($users[$username]); | return array_keys($users[$username]); | |||
else | else | |||
return array(); | return array(); | |||
} | } | |||
} | } | |||
/** | /** | |||
* Returns the current version of the state files | * Returns the current version of the state files | |||
* | * | |||
* @access public | * @access public | |||
* @return int | * @return int | |||
*/ | */ | |||
public function GetStateVersion() { | public function GetStateVersion() { | |||
if (file_exists($this->settingsfilename)) { | if (file_exists($this->settingsfilename)) { | |||
$settings = Utils::SafeGetContentsUnserialize($this->settingsfilenam e, __FUNCTION__, false); | $settings = Utils::SafeGetContents($this->settingsfilename, __FUNCTI ON__, false, true); | |||
if (strtolower(gettype($settings) == "string") && strtolower($settin gs) == '2:1:{s:7:"version";s:1:"2";}') { | if (strtolower(gettype($settings) == "string") && strtolower($settin gs) == '2:1:{s:7:"version";s:1:"2";}') { | |||
ZLog::Write(LOGLEVEL_INFO, "Broken state version file found. Att empt to autofix it. See https://jira.zarafa.com/browse/ZP-493 for more informati on."); | ZLog::Write(LOGLEVEL_INFO, "Broken state version file found. Att empt to autofix it. See https://jira.zarafa.com/browse/ZP-493 for more informati on."); | |||
unlink($this->settingsfilename); | unlink($this->settingsfilename); | |||
$this->SetStateVersion(IStateMachine::STATEVERSION_02); | $this->SetStateVersion(IStateMachine::STATEVERSION_02); | |||
$settings = array(self::VERSION => IStateMachine::STATEVERSION_0 2); | $settings = array(self::VERSION => IStateMachine::STATEVERSION_0 2); | |||
} | } | |||
} | } | |||
else { | else { | |||
$filecontents = Utils::SafeGetContents($this->userfilename, __FUNCTI ON__, true); | $filecontents = Utils::SafeGetContents($this->userfilename, __FUNCTI ON__, true); | |||
if ($filecontents) | if ($filecontents) | |||
skipping to change at line 347 | skipping to change at line 347 | |||
/** | /** | |||
* Sets the current version of the state files | * Sets the current version of the state files | |||
* | * | |||
* @param int $version the new supported version | * @param int $version the new supported version | |||
* | * | |||
* @access public | * @access public | |||
* @return boolean | * @return boolean | |||
*/ | */ | |||
public function SetStateVersion($version) { | public function SetStateVersion($version) { | |||
if (file_exists($this->settingsfilename)){ | if (file_exists($this->settingsfilename)){ | |||
$settings = Utils::SafeGetContentsUnserialize($this->settingsfilenam e, __FUNCTION__, false); | $settings = Utils::SafeGetContents($this->settingsfilename, __FUNCTI ON__, false, true); | |||
} | } | |||
else | else | |||
$settings = array(self::VERSION => IStateMachine::STATEVERSION_01); | $settings = array(self::VERSION => IStateMachine::STATEVERSION_01); | |||
$settings[self::VERSION] = $version; | $settings[self::VERSION] = $version; | |||
ZLog::Write(LOGLEVEL_INFO, sprintf("FileStateMachine->SetStateVersion() saving supported state version, value '%d'", $version)); | ZLog::Write(LOGLEVEL_INFO, sprintf("FileStateMachine->SetStateVersion() saving supported state version, value '%d'", $version)); | |||
$status = Utils::SafePutContents($this->settingsfilename, serialize($set tings)); | $status = Utils::SafePutContents($this->settingsfilename, serialize($set tings)); | |||
return $status; | return $status; | |||
} | } | |||
End of changes. 6 change blocks. | ||||
6 lines changed or deleted | 6 lines changed or added |