lib/ext
Aleksander Machniak
machniak at kolabsys.com
Mon Jan 14 13:38:47 CET 2013
lib/ext/Syncroton/Command/Ping.php | 29 +++++++++++++++++++++--------
lib/ext/Syncroton/Command/Sync.php | 11 +++++++----
2 files changed, 28 insertions(+), 12 deletions(-)
New commits:
commit 4801e92442839952e1145475bfff800e2ac38205
Author: Aleksander Machniak <alec at alec.pl>
Date: Mon Jan 14 13:38:27 2013 +0100
Update device record when needed
diff --git a/lib/ext/Syncroton/Command/Ping.php b/lib/ext/Syncroton/Command/Ping.php
index 1bb7da8..21131db 100644
--- a/lib/ext/Syncroton/Command/Ping.php
+++ b/lib/ext/Syncroton/Command/Ping.php
@@ -55,19 +55,19 @@ class Syncroton_Command_Ping extends Syncroton_Command_Wbxml
// the client does not send a wbxml document, if the Ping parameters did not change compared with the last request
if($this->_requestBody instanceof DOMDocument) {
$xml = simplexml_import_dom($this->_requestBody);
- $xml->registerXPathNamespace('Ping', 'Ping');
+ $xml->registerXPathNamespace('Ping', 'Ping');
if(isset($xml->HeartBeatInterval)) {
- $this->_device->pinglifetime = (int)$xml->HeartBeatInterval;
+ $pingLifetime = (int)$xml->HeartBeatInterval;
}
-
- if(isset($xml->Folders->Folder)) {
- $folders = array();
+
+ $folders = array();
+ if (isset($xml->Folders->Folder)) {
foreach ($xml->Folders->Folder as $folderXml) {
try {
// does the folder exist?
$folder = $this->_folderBackend->getFolder($this->_device, (string)$folderXml->Id);
-
+
$folders[$folder->id] = $folder;
} catch (Syncroton_Exception_NotFound $senf) {
if ($this->_logger instanceof Zend_Log)
@@ -76,9 +76,22 @@ class Syncroton_Command_Ping extends Syncroton_Command_Wbxml
break;
}
}
- $this->_device->pingfolder = serialize(array_keys($folders));
}
- $this->_device = $this->_deviceBackend->update($this->_device);
+
+ if ($pingLifetime && $this->_device->pinglifetime != $pinglifetime) {
+ $this->_device->pinglifetime = $pingLifetime;
+ $need_update = true;
+ }
+
+ $pingFolders = serialize(array_keys($folders));
+ if ($this->_device->pingfolder != $pingFolders) {
+ $this->_device->pingfolder = $pingFolders;
+ $need_update = true;
+ }
+
+ if ($need_update) {
+ $this->_device = $this->_deviceBackend->update($this->_device);
+ }
}
$lifeTime = $this->_device->pinglifetime;
diff --git a/lib/ext/Syncroton/Command/Sync.php b/lib/ext/Syncroton/Command/Sync.php
index 46e38c2..ba28d37 100644
--- a/lib/ext/Syncroton/Command/Sync.php
+++ b/lib/ext/Syncroton/Command/Sync.php
@@ -161,10 +161,13 @@ class Syncroton_Command_Sync extends Syncroton_Command_Wbxml
foreach ($collections as $collection) {
$collectionsToSave[$collection->collectionId] = $collection->toArray();
}
-
- $this->_device->lastsynccollection = Zend_Json::encode($collectionsToSave);
-
- Syncroton_Registry::getDeviceBackend()->update($this->_device);
+
+ $lastSyncCollection = Zend_Json::encode($collectionsToSave);
+ if ($this->_device->lastsynccollection != $lastSyncCollection) {
+ $this->_device->lastsynccollection = $lastSyncCollection;
+
+ Syncroton_Registry::getDeviceBackend()->update($this->_device);
+ }
}
foreach ($collections as $collectionData) {
More information about the commits
mailing list