Commit 3a080ad0 authored by Sebastian Kummer's avatar Sebastian Kummer

ZP-778 Make sure the hierarchy cache is loaded when verifying hierarchy

changes in SyncCollections.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 68fe5754
...@@ -201,12 +201,13 @@ class StateManager { ...@@ -201,12 +201,13 @@ class StateManager {
* Gets the state for a specified synckey (uuid + counter) * Gets the state for a specified synckey (uuid + counter)
* *
* @param string $synckey * @param string $synckey
* @param boolean $forceHierarchyLoading, default: false
* *
* @access public * @access public
* @return string * @return string
* @throws StateInvalidException, StateNotFoundException * @throws StateInvalidException, StateNotFoundException
*/ */
public function GetSyncState($synckey) { public function GetSyncState($synckey, $forceHierarchyLoading = false) {
// No sync state for sync key '0' // No sync state for sync key '0'
if($synckey == "0") { if($synckey == "0") {
$this->oldStateCounter = 0; $this->oldStateCounter = 0;
...@@ -217,8 +218,8 @@ class StateManager { ...@@ -217,8 +218,8 @@ class StateManager {
list($this->uuid, $this->oldStateCounter) = self::ParseStateKey($synckey); list($this->uuid, $this->oldStateCounter) = self::ParseStateKey($synckey);
// make sure the hierarchy cache is in place // make sure the hierarchy cache is in place
if ($this->hierarchyOperation) if ($this->hierarchyOperation || $forceHierarchyLoading)
$this->loadHierarchyCache(); $this->loadHierarchyCache($forceHierarchyLoading);
// the state machine will discard any sync states before this one, as they are no longer required // the state machine will discard any sync states before this one, as they are no longer required
return $this->statemachine->GetState($this->device->GetDeviceId(), IStateMachine::DEFTYPE, $this->uuid, $this->oldStateCounter, $this->deleteOldStates); return $this->statemachine->GetState($this->device->GetDeviceId(), IStateMachine::DEFTYPE, $this->uuid, $this->oldStateCounter, $this->deleteOldStates);
...@@ -473,12 +474,14 @@ class StateManager { ...@@ -473,12 +474,14 @@ class StateManager {
* Loads the HierarchyCacheState and initializes the HierarchyChache * Loads the HierarchyCacheState and initializes the HierarchyChache
* if this is an hierarchy operation * if this is an hierarchy operation
* *
* @param boolean $forceLoading, default: false
*
* @access private * @access private
* @return boolean * @return boolean
* @throws StateNotFoundException * @throws StateNotFoundException
*/ */
private function loadHierarchyCache() { private function loadHierarchyCache($forceLoading = false) {
if (!$this->hierarchyOperation) if (!$this->hierarchyOperation && $forceLoading == false)
return false; return false;
ZLog::Write(LOGLEVEL_DEBUG, sprintf("StateManager->loadHierarchyCache(): '%s-%s-%s-%d'", $this->device->GetDeviceId(), $this->uuid, IStateMachine::HIERARCHY, $this->oldStateCounter)); ZLog::Write(LOGLEVEL_DEBUG, sprintf("StateManager->loadHierarchyCache(): '%s-%s-%s-%d'", $this->device->GetDeviceId(), $this->uuid, IStateMachine::HIERARCHY, $this->oldStateCounter));
......
...@@ -205,7 +205,8 @@ class SyncCollections implements Iterator { ...@@ -205,7 +205,8 @@ class SyncCollections implements Iterator {
// load the latest known syncstate if requested // load the latest known syncstate if requested
if ($addStatus && $loadState === true) { if ($addStatus && $loadState === true) {
try { try {
$this->addparms[$folderid]["state"] = $this->stateManager->GetSyncState($spa->GetLatestSyncKey()); // make sure the hierarchy cache is loaded when we are loading hierarchy states
$this->addparms[$folderid]["state"] = $this->stateManager->GetSyncState($spa->GetLatestSyncKey(), ($folderid === false));
} }
catch (StateNotFoundException $snfe) { catch (StateNotFoundException $snfe) {
// if we can't find the state, first we should try a sync of that folder, so // if we can't find the state, first we should try a sync of that folder, so
...@@ -725,9 +726,10 @@ class SyncCollections implements Iterator { ...@@ -725,9 +726,10 @@ class SyncCollections implements Iterator {
$exporter->Config($this->addparms[$folderid]["state"]); $exporter->Config($this->addparms[$folderid]["state"]);
$ret = $exporter->InitializeExporter($changesMem); $ret = $exporter->InitializeExporter($changesMem);
while(is_array($exporter->Synchronize()));
if ($ret !== false) if ($ret !== false)
$changecount = $exporter->GetChangeCount(); $changecount = $changesMem->GetChangeCount();
$this->hierarchyExporterChecked = true; $this->hierarchyExporterChecked = true;
} }
......
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