using new z-push 2 / hashed device directory for folder hashes, falling back to old directory/file for reading it

This commit is contained in:
Ralf Becker 2015-09-15 07:45:58 +00:00
parent faac36b434
commit 4757b67af0

View File

@ -1983,7 +1983,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
{ {
if(!isset($this->folderHashes)) $this->readFolderHashes(); if(!isset($this->folderHashes)) $this->readFolderHashes();
return $this->folderHashes[$account][$index]; return isset($this->folderHashes[$account]) ? $this->folderHashes[$account][$index] : null;
} }
private $folderHashes; private $folderHashes;
@ -1993,7 +1993,7 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
*/ */
private function readFolderHashes() private function readFolderHashes()
{ {
if (file_exists($file = $this->hashFile()) && if ((file_exists($file = $this->hashFile()) || file_exists($file = $this->hashFile(true))) &&
($hashes = file_get_contents($file))) ($hashes = file_get_contents($file)))
{ {
$this->folderHashes = json_decode($hashes,true); $this->folderHashes = json_decode($hashes,true);
@ -2024,19 +2024,26 @@ class mail_zpush implements activesync_plugin_write, activesync_plugin_sendmail,
/** /**
* Get name of hashfile in state dir * Get name of hashfile in state dir
* *
* New z-push 2 directory is in activesync_statemachine::getDeviceDirectory.
* On request this function also returns, but never creates (!), old z-push 1 directory.
*
* @param boolean $old =false true: return old / pre-15 hash-file
* @throws egw_exception_assertion_failed * @throws egw_exception_assertion_failed
*/ */
private function hashFile() private function hashFile($old=false)
{ {
if (!($dev_id=Request::GetDeviceID())) if (!($dev_id=Request::GetDeviceID()))
{ {
throw new egw_exception_assertion_failed(__METHOD__."() called without this->_devid set!"); throw new egw_exception_assertion_failed(__METHOD__."() no DeviceID set!");
} }
if (!file_exists(STATE_DIR.$dev_id)) if ($old)
{ {
mkdir(STATE_DIR.$dev_id);
}
return STATE_DIR.$dev_id.'/'.$dev_id.'.hashes'; return STATE_DIR.$dev_id.'/'.$dev_id.'.hashes';
} }
if (!file_exists($dir = activesync_statemachine::getDeviceDirectory($dev_id)))
{
mkdir($dir);
}
return $dir.'/'.$dev_id.'.hashes';
}
} }