Changeset View
Changeset View
Standalone View
Standalone View
lib/ext/Syncroton/Command/Sync.php
Show First 20 Lines • Show All 824 Lines • ▼ Show 20 Lines | public function getResponse() | ||||
$applicationData = $add->appendChild($this->_outputDom->createElementNS('uri:AirSync', 'ApplicationData')); | $applicationData = $add->appendChild($this->_outputDom->createElementNS('uri:AirSync', 'ApplicationData')); | ||||
$dataController | $dataController | ||||
->getEntry($collectionData, $serverId) | ->getEntry($collectionData, $serverId) | ||||
->appendXML($applicationData, $this->_device); | ->appendXML($applicationData, $this->_device); | ||||
$commands->appendChild($add); | $commands->appendChild($add); | ||||
$newContentStates[] = new Syncroton_Model_Content(array( | |||||
'device_id' => $this->_device, | |||||
'folder_id' => $collectionData->folder, | |||||
'contentid' => $serverId, | |||||
'creation_time' => $this->_syncTimeStamp, | |||||
'creation_synckey' => $collectionData->syncState->counter + 1 | |||||
)); | |||||
$collectionChanges++; | $collectionChanges++; | ||||
} catch (Syncroton_Exception_MemoryExhausted $seme) { | } catch (Syncroton_Exception_MemoryExhausted $seme) { | ||||
// continue to next entry, as there is not enough memory left for the current entry | // continue to next entry, as there is not enough memory left for the current entry | ||||
// this will lead to MoreAvailable at the end and the entry will be synced during the next Sync command | // this will lead to MoreAvailable at the end and the entry will be synced during the next Sync command | ||||
if ($this->_logger instanceof Zend_Log) | if ($this->_logger instanceof Zend_Log) | ||||
$this->_logger->warn(__METHOD__ . '::' . __LINE__ . " memory exhausted for entry: " . $serverId); | $this->_logger->warn(__METHOD__ . '::' . __LINE__ . " memory exhausted for entry: " . $serverId); | ||||
break; | break; | ||||
} catch (Exception $e) { | } catch (Exception $e) { | ||||
if ($this->_logger instanceof Zend_Log) | if ($this->_logger instanceof Zend_Log) | ||||
$this->_logger->warn(__METHOD__ . '::' . __LINE__ . " unable to convert entry to xml: " . $e->getMessage()); | $this->_logger->warn(__METHOD__ . '::' . __LINE__ . " unable to convert entry to xml: " . $e->getMessage()); | ||||
if ($this->_logger instanceof Zend_Log) | if ($this->_logger instanceof Zend_Log) | ||||
$this->_logger->debug(__METHOD__ . '::' . __LINE__ . " unable to convert entry to xml: " . $e->getTraceAsString()); | $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " unable to convert entry to xml: " . $e->getTraceAsString()); | ||||
// We bump collectionChanges anyways to make sure the windowSize still applies. | |||||
$collectionChanges++; | |||||
} | } | ||||
// mark as sent to the client, even the conversion to xml might have failed | // mark as sent to the client, even the conversion to xml might have failed | ||||
$newContentStates[] = new Syncroton_Model_Content(array( | |||||
'device_id' => $this->_device, | |||||
'folder_id' => $collectionData->folder, | |||||
'contentid' => $serverId, | |||||
'creation_time' => $this->_syncTimeStamp, | |||||
'creation_synckey' => $collectionData->syncState->counter + 1 | |||||
)); | |||||
unset($serverModifications['added'][$id]); | unset($serverModifications['added'][$id]); | ||||
machniak: I think we could be smarter here. For 'added' entries that throw "not found" exception we… | |||||
Done Inline ActionsThat seems useless and potentially harmful indeed. mollekopf: That seems useless and potentially harmful indeed. | |||||
} | } | ||||
/** | /** | ||||
* process entries changed on server side | * process entries changed on server side | ||||
*/ | */ | ||||
foreach($serverModifications['changed'] as $id => $serverId) { | foreach($serverModifications['changed'] as $id => $serverId) { | ||||
if($collectionChanges == $collectionData->windowSize || $totalChanges + $collectionChanges >= $this->_globalWindowSize) { | if($collectionChanges == $collectionData->windowSize || $totalChanges + $collectionChanges >= $this->_globalWindowSize) { | ||||
break; | break; | ||||
Show All 19 Lines | public function getResponse() | ||||
if ($this->_logger instanceof Zend_Log) | if ($this->_logger instanceof Zend_Log) | ||||
$this->_logger->warn(__METHOD__ . '::' . __LINE__ . " memory exhausted for entry: " . $serverId); | $this->_logger->warn(__METHOD__ . '::' . __LINE__ . " memory exhausted for entry: " . $serverId); | ||||
break; | break; | ||||
} catch (Exception $e) { | } catch (Exception $e) { | ||||
if ($this->_logger instanceof Zend_Log) | if ($this->_logger instanceof Zend_Log) | ||||
$this->_logger->warn(__METHOD__ . '::' . __LINE__ . " unable to convert entry to xml: " . $e->getMessage()); | $this->_logger->warn(__METHOD__ . '::' . __LINE__ . " unable to convert entry to xml: " . $e->getMessage()); | ||||
// We bump collectionChanges anyways to make sure the windowSize still applies. | |||||
$collectionChanges++; | |||||
} | } | ||||
unset($serverModifications['changed'][$id]); | unset($serverModifications['changed'][$id]); | ||||
} | } | ||||
foreach($serverModifications['deleted'] as $id => $serverId) { | foreach($serverModifications['deleted'] as $id => $serverId) { | ||||
if($collectionChanges == $collectionData->windowSize || $totalChanges + $collectionChanges >= $this->_globalWindowSize) { | if($collectionChanges == $collectionData->windowSize || $totalChanges + $collectionChanges >= $this->_globalWindowSize) { | ||||
break; | break; | ||||
Show All 9 Lines | public function getResponse() | ||||
$deletedContentStates[] = $state; | $deletedContentStates[] = $state; | ||||
$commands->appendChild($delete); | $commands->appendChild($delete); | ||||
$collectionChanges++; | $collectionChanges++; | ||||
} catch (Exception $e) { | } catch (Exception $e) { | ||||
if ($this->_logger instanceof Zend_Log) | if ($this->_logger instanceof Zend_Log) | ||||
$this->_logger->warn(__METHOD__ . '::' . __LINE__ . " unable to convert entry to xml: " . $e->getMessage()); | $this->_logger->warn(__METHOD__ . '::' . __LINE__ . " unable to convert entry to xml: " . $e->getMessage()); | ||||
// We bump collectionChanges anyways to make sure the windowSize still applies. | |||||
$collectionChanges++; | |||||
} | } | ||||
unset($serverModifications['deleted'][$id]); | unset($serverModifications['deleted'][$id]); | ||||
} | } | ||||
$countOfPendingChanges = (count($serverModifications['added']) + count($serverModifications['changed']) + count($serverModifications['deleted'])); | $countOfPendingChanges = (count($serverModifications['added']) + count($serverModifications['changed']) + count($serverModifications['deleted'])); | ||||
if ($countOfPendingChanges > 0) { | if ($countOfPendingChanges > 0) { | ||||
$collection->appendChild($this->_outputDom->createElementNS('uri:AirSync', 'MoreAvailable')); | $collection->appendChild($this->_outputDom->createElementNS('uri:AirSync', 'MoreAvailable')); | ||||
▲ Show 20 Lines • Show All 242 Lines • Show Last 20 Lines |
I think we could be smarter here. For 'added' entries that throw "not found" exception we should not add them to $newContentStates.