Commit f1288f64 authored by Sebastian Kummer's avatar Sebastian Kummer

Merging in latest from upstream (ZP/z-push:refs/heads/develop)

* commit 'c42848ed':
  ZP-840 Rename exception variable.
  ZP-840 Renamed exception variable.
  ZP-832 Do comparing only if the folder already has a folder stat, but still get the newFolderStat even if the folder has none yet.
  ZP-840 Catch StateInvalidException when in partial mode.
  ZP-840 Do not throw StateNotFoundException as this messes up Ping. Just treat it as StateInvalid (which is true, FD indicates a state that is not available), do not catch both types in Ping as only StateInvalidException will be thrown.
  ZP-839 Get collection count from SyncCollections, show 'no changes' only if nothing was queued (e.g. new exporter registered), fixed typo showing exceptions.
  ZP-840 Invalidate the folder stats in case the exporter state can not be found, improved PingableFolders(), refactored folder stat invalidated into a private method.
  ZP-840 On StateNotFoundException of the exporter state generate a fake change so Ping indicates the synchronization of the folder.
  ZP-841 Reset folderstat when SyncKey "0" is received.
  ZP-839 One line z-push-top announcement for multi-folder sync.
parents 3dbf6bd1 c42848ed
...@@ -125,7 +125,7 @@ class SyncCollections implements Iterator { ...@@ -125,7 +125,7 @@ class SyncCollections implements Iterator {
* *
* @access public * @access public
* @throws StatusException with SyncCollections::ERROR_WRONG_HIERARCHY if permission check fails * @throws StatusException with SyncCollections::ERROR_WRONG_HIERARCHY if permission check fails
* @throws StateNotFoundException if the sync state can not be found ($loadState = true) * @throws StateInvalidException if the sync state can not be found or relation between states is invalid ($loadState = true)
* @return boolean * @return boolean
*/ */
public function LoadAllCollections($overwriteLoaded = false, $loadState = false, $checkPermissions = false) { public function LoadAllCollections($overwriteLoaded = false, $loadState = false, $checkPermissions = false) {
...@@ -161,7 +161,7 @@ class SyncCollections implements Iterator { ...@@ -161,7 +161,7 @@ class SyncCollections implements Iterator {
* *
* @access public * @access public
* @throws StatusException with SyncCollections::ERROR_WRONG_HIERARCHY if permission check fails * @throws StatusException with SyncCollections::ERROR_WRONG_HIERARCHY if permission check fails
* @throws StateNotFoundException if the sync state can not be found ($loadState = true) * @throws StateInvalidException if the sync state can not be found or relation between states is invalid ($loadState = true)
* @return boolean * @return boolean
*/ */
public function LoadCollection($folderid, $loadState = false, $checkPermissions = false) { public function LoadCollection($folderid, $loadState = false, $checkPermissions = false) {
...@@ -194,8 +194,21 @@ class SyncCollections implements Iterator { ...@@ -194,8 +194,21 @@ class SyncCollections implements Iterator {
$addStatus = $this->AddCollection($spa); $addStatus = $this->AddCollection($spa);
// load the latest known syncstate if requested // load the latest known syncstate if requested
if ($addStatus && $loadState === true) if ($addStatus && $loadState === true) {
$this->addparms[$folderid]["state"] = $this->stateManager->GetSyncState($spa->GetLatestSyncKey()); try {
$this->addparms[$folderid]["state"] = $this->stateManager->GetSyncState($spa->GetLatestSyncKey());
}
catch (StateNotFoundException $snfe) {
// if we can't find the state, first we should try a sync of that folder, so
// we generate a fake change, so a sync on this folder is triggered
$this->changes[$folderid] = 1;
// make sure this folder is fully synched on next Sync request
$this->invalidateFolderStat($spa);
return false;
}
}
return $addStatus; return $addStatus;
} }
...@@ -286,6 +299,16 @@ class SyncCollections implements Iterator { ...@@ -286,6 +299,16 @@ class SyncCollections implements Iterator {
return ! empty($this->collections); return ! empty($this->collections);
} }
/**
* Indicates the amount of collections loaded.
*
* @access public
* @return int
*/
public function GetCollectionCount() {
return count($this->collections);
}
/** /**
* Add a non-permanent key/value pair for a SyncParameters object * Add a non-permanent key/value pair for a SyncParameters object
* *
...@@ -639,11 +662,8 @@ class SyncCollections implements Iterator { ...@@ -639,11 +662,8 @@ class SyncCollections implements Iterator {
ZLog::Write(LOGLEVEL_WARN, "SyncCollections->CountChange(): exporter can not be re-configured due to state error, emulating change in folder to force Sync."); ZLog::Write(LOGLEVEL_WARN, "SyncCollections->CountChange(): exporter can not be re-configured due to state error, emulating change in folder to force Sync.");
$this->changes[$folderid] = 1; $this->changes[$folderid] = 1;
// make sure this folder is fully synched on next Sync request // make sure this folder is fully synched on next Sync request
if($spa->HasFolderStat()) { $this->invalidateFolderStat($spa);
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncCollections->CountChange(): removing folder stat '%s' for folderid '%s'", $spa->GetFolderStat(), $spa->GetFolderId()));
$spa->DelFolderStat();
$this->SaveCollection($spa);
}
return true; return true;
} }
throw new StatusException("SyncCollections->CountChange(): exporter can not be re-configured.", self::ERROR_WRONG_HIERARCHY, null, LOGLEVEL_WARN); throw new StatusException("SyncCollections->CountChange(): exporter can not be re-configured.", self::ERROR_WRONG_HIERARCHY, null, LOGLEVEL_WARN);
...@@ -675,14 +695,13 @@ class SyncCollections implements Iterator { ...@@ -675,14 +695,13 @@ class SyncCollections implements Iterator {
* @return boolean * @return boolean
*/ */
public function PingableFolders() { public function PingableFolders() {
$pingable = false;
foreach ($this->collections as $folderid => $spa) { foreach ($this->collections as $folderid => $spa) {
if ($spa->GetPingableFlag() == true) if ($spa->GetPingableFlag() == true) {
$pingable = true; return true;
}
} }
return $pingable; return false;
} }
/** /**
...@@ -762,4 +781,22 @@ class SyncCollections implements Iterator { ...@@ -762,4 +781,22 @@ class SyncCollections implements Iterator {
if (!isset($this->stateManager)) if (!isset($this->stateManager))
$this->stateManager = ZPush::GetDeviceManager()->GetStateManager(); $this->stateManager = ZPush::GetDeviceManager()->GetStateManager();
} }
/**
* Remove folder statistics from a SyncParameter object.
*
* @param SyncParameters $spa
*
* @access public
* @return
*/
private function invalidateFolderStat($spa) {
if($spa->HasFolderStat()) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("SyncCollections->invalidateFolderStat(): removing folder stat '%s' for folderid '%s'", $spa->GetFolderStat(), $spa->GetFolderId()));
$spa->DelFolderStat();
$this->SaveCollection($spa);
return true;
}
return false;
}
} }
...@@ -67,23 +67,19 @@ class Ping extends RequestProcessor { ...@@ -67,23 +67,19 @@ class Ping extends RequestProcessor {
try { try {
$sc->LoadAllCollections(true, true, true); $sc->LoadAllCollections(true, true, true);
} }
catch (StateNotFoundException $snfex) { catch (StateInvalidException $siex) {
// if no params are present, indicate to send params, else do hierarchy sync // if no params are present, indicate to send params, else do hierarchy sync
if (!$params_present) { if (!$params_present) {
$pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS; $pingstatus = SYNC_PINGSTATUS_FAILINGPARAMS;
self::$topCollector->AnnounceInformation("StateNotFoundException: require PingParameters", true); self::$topCollector->AnnounceInformation("StateInvalidException: require PingParameters", true);
} }
else { else {
$pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED; // we do not have a ping status for this, but SyncCollections should have generated fake changes for the folders which are broken
self::$topCollector->AnnounceInformation("StateNotFoundException: require HierarchySync", true); $fakechanges = $sc->GetChangedFolderIds();
} $foundchanges = true;
}
catch (StateInvalidException $snfex) {
// we do not have a ping status for this, but SyncCollections should have generated fake changes for the folders which are broken
$fakechanges = $sc->GetChangedFolderIds();
$foundchanges = true;
self::$topCollector->AnnounceInformation("StateInvalidException: force sync", true); self::$topCollector->AnnounceInformation("StateInvalidException: force sync", true);
}
} }
catch (StatusException $stex) { catch (StatusException $stex) {
$pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED; $pingstatus = SYNC_PINGSTATUS_FOLDERHIERSYNCREQUIRED;
......
This diff is collapsed.
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