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 {
* Gets the state for a specified synckey (uuid + counter)
*
* @param string $synckey
* @param boolean $forceHierarchyLoading, default: false
*
* @access public
* @return string
* @throws StateInvalidException, StateNotFoundException
*/
public function GetSyncState($synckey) {
public function GetSyncState($synckey, $forceHierarchyLoading = false) {
// No sync state for sync key '0'
if($synckey == "0") {
$this->oldStateCounter = 0;
......@@ -217,8 +218,8 @@ class StateManager {
list($this->uuid, $this->oldStateCounter) = self::ParseStateKey($synckey);
// make sure the hierarchy cache is in place
if ($this->hierarchyOperation)
$this->loadHierarchyCache();
if ($this->hierarchyOperation || $forceHierarchyLoading)
$this->loadHierarchyCache($forceHierarchyLoading);
// 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);
......@@ -473,12 +474,14 @@ class StateManager {
* Loads the HierarchyCacheState and initializes the HierarchyChache
* if this is an hierarchy operation
*
* @param boolean $forceLoading, default: false
*
* @access private
* @return boolean
* @throws StateNotFoundException
*/
private function loadHierarchyCache() {
if (!$this->hierarchyOperation)
private function loadHierarchyCache($forceLoading = false) {
if (!$this->hierarchyOperation && $forceLoading == false)
return false;
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 {
// load the latest known syncstate if requested
if ($addStatus && $loadState === true) {
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) {
// 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 {
$exporter->Config($this->addparms[$folderid]["state"]);
$ret = $exporter->InitializeExporter($changesMem);
while(is_array($exporter->Synchronize()));
if ($ret !== false)
$changecount = $exporter->GetChangeCount();
$changecount = $changesMem->GetChangeCount();
$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