Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F2512989
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
36 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/lib/kolab_sync_backend_common.php b/lib/kolab_sync_backend_common.php
index c7c3b58..d72c908 100644
--- a/lib/kolab_sync_backend_common.php
+++ b/lib/kolab_sync_backend_common.php
@@ -1,225 +1,228 @@
<?php
/**
+--------------------------------------------------------------------------+
| Kolab Sync (ActiveSync for Kolab) |
| |
| Copyright (C) 2011-2012, Kolab Systems AG <contact@kolabsys.com> |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
/**
* Parent backend class for kolab backends
*/
class kolab_sync_backend_common implements Syncroton_Backend_IBackend
{
/**
* Table name
*
* @var string
*/
protected $table_name;
/**
* Model interface name
*
* @var string
*/
protected $interface_name;
/**
* Backend interface name
*
* @var string
*/
protected $class_name;
/**
* SQL Database engine
*
* @var rcube_db
*/
protected $db;
/**
* Constructor
*/
function __construct()
{
$this->db = rcube::get_instance()->get_dbh();
if (empty($this->class_name)) {
$this->class_name = str_replace('Model_I', 'Model_', $this->interface_name);
}
}
/**
- * Creates new Syncroton data object in database
+ * Creates new Syncroton object in database
+ *
+ * @param Syncroton_Model_* $object Object
*
- * @param Syncroton_Model_* $object
* @throws InvalidArgumentException
- * @return Syncroton_Model_*
+ * @return Syncroton_Model_* Object
*/
public function create($object)
{
if (! $object instanceof $this->interface_name) {
throw new InvalidArgumentException('$object must be instanace of ' . $this->interface_name);
}
$data = $this->object_to_array($object);
$insert = array();
$data['id'] = $object->id = sha1(mt_rand(). microtime());
foreach ($data as $key => $value) {
$insert[$this->db->quote_identifier($key)] = $this->db->quote($value);
}
$this->db->query('INSERT INTO ' . $this->table_name
. ' (' . implode(', ', array_keys($insert)) . ')' . ' VALUES(' . implode(', ', $insert) . ')');
if (!$this->db->insert_id($this->table_name)) {
// @TODO: throw exception
}
return $object;
}
/**
* Returns Syncroton data object
*
* @param string $id
* @throws Syncroton_Exception_NotFound
* @return Syncroton_Model_*
*/
public function get($id)
{
$id = $id instanceof $this->interface_name ? $id->id : $id;
$select = $this->db->query('SELECT * FROM ' . $this->table_name . ' WHERE id = ?', array($id));
$data = $this->db->fetch_assoc($select);
if (empty($data)) {
throw new Syncroton_Exception_NotFound('Object not found');
}
return $this->get_object($data);
}
/**
* Deletes Syncroton data object
*
- * @param string $id
- * @return bool
+ * @param string|Syncroton_Model_* $id Object or identifier
+ *
+ * @return bool True on success, False on failure
*/
public function delete($id)
{
$id = $id instanceof $this->interface_name ? $id->id : $id;
$result = $this->db->query('DELETE FROM ' . $this->table_name .' WHERE id = ?', array($id));
return (bool) $this->db->affected_rows($result);
}
/**
* Updates Syncroton data object
*
* @param Syncroton_Model_* $object
+ *
* @throws InvalidArgumentException
- * @return Syncroton_Model_*
+ * @return Syncroton_Model_* Object
*/
public function update($object)
{
if (! $object instanceof $this->interface_name) {
throw new InvalidArgumentException('$object must be instanace of ' . $this->interface_name);
}
$data = $this->object_to_array($object);
$set = array();
foreach ($data as $key => $value) {
$set[] = $this->db->quote_identifier($key) . ' = ' . $this->db->quote($value);
}
$this->db->query('UPDATE ' . $this->table_name . ' SET ' . implode(', ', $set)
. ' WHERE ' . $this->db->quote_identifier('id') . ' = ' . $this->db->quote($object->id));
return $object;
}
/**
* Convert array into model object
*/
protected function get_object($data)
{
foreach ($data as $key => $value) {
unset($data[$key]);
if (!empty($value) && preg_match('/^\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}/', $value)) { // 2012-08-12 07:43:26
$value = new DateTime($value, new DateTimeZone('utc'));
}
$data[$this->to_camelcase($key, false)] = $value;
}
return new $this->class_name($data);
}
/**
* Converts model object into array
*/
protected function object_to_array($object)
{
$data = array();
foreach ($object as $key => $value) {
if ($value instanceof DateTime) {
$value = $value->format('Y-m-d H:i:s');
} elseif (is_object($value) && isset($value->id)) {
$value = $value->id;
}
$data[$this->from_camelcase($key)] = $value;
}
return $data;
}
/**
* Convert property name from camel-case to lower-case-with-underscore
*/
protected function from_camelcase($string)
{
$string = lcfirst($string);
return preg_replace_callback('/([A-Z])/', function ($string) { return '_' . strtolower($string[0]); }, $string);
}
/**
* Convert property name from lower-case-with-underscore to camel-case
*/
protected function to_camelcase($string, $ucFirst = true)
{
if ($ucFirst) {
$string = ucfirst($string);
}
return preg_replace_callback('/_([a-z])/', function ($string) { return strtoupper($string[1]); }, $string);
}
}
diff --git a/lib/kolab_sync_backend_content.php b/lib/kolab_sync_backend_content.php
index c13a343..72a673e 100644
--- a/lib/kolab_sync_backend_content.php
+++ b/lib/kolab_sync_backend_content.php
@@ -1,119 +1,118 @@
<?php
/**
+--------------------------------------------------------------------------+
| Kolab Sync (ActiveSync for Kolab) |
| |
| Copyright (C) 2011-2012, Kolab Systems AG <contact@kolabsys.com> |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
/**
* Kolab backend class for content storage
*/
class kolab_sync_backend_content extends kolab_sync_backend_common implements Syncroton_Backend_IContent
{
protected $table_name = 'syncroton_content';
protected $interface_name = 'Syncroton_Model_IContent';
/**
* mark state as deleted. The state gets removed finally,
* when the synckey gets validated during next sync.
*
* @param Syncroton_Model_IContent|string $id
*/
public function delete($id)
{
$id = $id instanceof Syncroton_Model_IContent ? $id->id : $id;
$result = $this->db->query('UPDATE ' . $this->table_name . ' SET is_deleted = 1 WHERE id = ?', array($id));
return (bool) $this->db->affected_rows($result);
}
-
/**
* @param Syncroton_Model_IDevice|string $_deviceId
* @param Syncroton_Model_IFolder|string $_folderId
* @param string $_contentId
* @return Syncroton_Model_IContent
*/
public function getContentState($_deviceId, $_folderId, $_contentId)
{
$deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
$folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->id : $_folderId;
$where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
$where[] = $this->db->quote_identifier('folder_id') . ' = ' . $this->db->quote($folderId);
$where[] = $this->db->quote_identifier('contentid') . ' = ' . $this->db->quote($_contentId);
$where[] = $this->db->quote_identifier('is_deleted') . ' = 0';
$select = $this->db->query('SELECT * FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
$state = $this->db->fetch_assoc($select);
if (empty($state)) {
throw new Syncroton_Exception_NotFound('Content not found');
}
return $this->get_object($state);
}
/**
* get array of ids which got send to the client for a given class
*
* @param Syncroton_Model_IDevice|string $_deviceId
* @param Syncroton_Model_IFolder|string $_folderId
* @return array
*/
public function getFolderState($_deviceId, $_folderId)
{
$deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
$folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->id : $_folderId;
$where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
$where[] = $this->db->quote_identifier('folder_id') . ' = ' . $this->db->quote($folderId);
$where[] = $this->db->quote_identifier('is_deleted') . ' = 0';
$select = $this->db->query('SELECT contentid FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
$result = array();
while ($state = $this->db->fetch_assoc($select)) {
$result[] = $state['contentid'];
}
return $result;
}
/**
* reset list of stored id
*
* @param Syncroton_Model_IDevice|string $_deviceId
* @param Syncroton_Model_IFolder|string $_folderId
*/
public function resetState($_deviceId, $_folderId)
{
$deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
$folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->id : $_folderId;
$where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
$where[] = $this->db->quote_identifier('folder_id') . ' = ' . $this->db->quote($folderId);
$this->db->query('DELETE FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
}
}
diff --git a/lib/kolab_sync_backend_device.php b/lib/kolab_sync_backend_device.php
index 34a9759..fec5193 100644
--- a/lib/kolab_sync_backend_device.php
+++ b/lib/kolab_sync_backend_device.php
@@ -1,129 +1,127 @@
<?php
/**
+--------------------------------------------------------------------------+
| Kolab Sync (ActiveSync for Kolab) |
| |
| Copyright (C) 2011-2012, Kolab Systems AG <contact@kolabsys.com> |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
/**
* Kolab backend class for device storage
*/
class kolab_sync_backend_device extends kolab_sync_backend_common implements Syncroton_Backend_IDevice
{
protected $table_name = 'syncroton_device';
protected $interface_name = 'Syncroton_Model_IDevice';
/**
* Kolab Sync backend
*
* @var kolab_sync_backend
*/
protected $backend;
/**
* Constructor
*/
public function __construct()
{
parent::__construct();
$this->backend = kolab_sync_backend::get_instance();
}
-
/**
- * create new device
+ * Create (register) a new device
*
- * @param Syncroton_Model_IDevice $device
+ * @param Syncroton_Model_IDevice $device Device object
*
- * @return Syncroton_Model_IDevice
+ * @return Syncroton_Model_IDevice Device object
*/
public function create($device)
{
$device = parent::create($device);
// Create device entry in kolab backend
$created = $this->backend->device_create(array(
'ID' => $device->id,
'TYPE' => $device->devicetype,
), $device->deviceid);
if (!$created) {
throw new Syncroton_Exception_NotFound('Device creation failed');
}
return $device;
}
-
/**
* Delete a device
*
- * @param Syncroton_Model_IDevice $device
+ * @param Syncroton_Model_IDevice $device Device object
*
* @return bool True on success, False on failure
*/
public function delete($device)
{
$result = $this->backend->device_delete($device->deviceid);
if ($result) {
$result = parent::delete($device);
}
return $result;
}
-
/**
- * return device for this user
+ * Return device for a given user
+ *
+ * @param string $ownerid User identifier
+ * @param string $deviceid Device identifier
*
- * @param string $ownerId
- * @param string $deviceId
* @throws Syncroton_Exception_NotFound
- * @return Syncroton_Model_Device
+ * @return Syncroton_Model_Device Device object
*/
- public function getUserDevice($ownerId, $deviceId)
+ public function getUserDevice($ownerid, $deviceid)
{
- $where[] = $this->db->quote_identifier('deviceid') . ' = ' . $this->db->quote($deviceId);
- $where[] = $this->db->quote_identifier('owner_id') . ' = ' . $this->db->quote($ownerId);
+ $where[] = $this->db->quote_identifier('deviceid') . ' = ' . $this->db->quote($deviceid);
+ $where[] = $this->db->quote_identifier('owner_id') . ' = ' . $this->db->quote($ownerid);
$select = $this->db->query('SELECT * FROM ' . $this->table_name . ' WHERE ' . implode(' AND ', $where));
$device = $this->db->fetch_assoc($select);
if (empty($device)) {
throw new Syncroton_Exception_NotFound('Device not found');
}
$device = $this->get_object($device);
// Make sure device exists (could be deleted by the user)
- $dev = $this->backend->device_get($deviceId);
+ $dev = $this->backend->device_get($deviceid);
if (empty($dev)) {
// Remove the device (and related cached data) from database
$this->delete($device);
throw new Syncroton_Exception_NotFound('Device not found');
}
return $device;
}
}
diff --git a/lib/kolab_sync_backend_folder.php b/lib/kolab_sync_backend_folder.php
index 8b60b18..f2a846c 100644
--- a/lib/kolab_sync_backend_folder.php
+++ b/lib/kolab_sync_backend_folder.php
@@ -1,147 +1,144 @@
<?php
/**
+--------------------------------------------------------------------------+
| Kolab Sync (ActiveSync for Kolab) |
| |
| Copyright (C) 2011-2012, Kolab Systems AG <contact@kolabsys.com> |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
/**
* Kolab backend class for the folder state storage
*/
class kolab_sync_backend_folder extends kolab_sync_backend_common implements Syncroton_Backend_IFolder
{
protected $table_name = 'syncroton_folder';
protected $interface_name = 'Syncroton_Model_IFolder';
/**
- * delete all stored folderId's for given device
+ * Delete all stored folder ids for a given device
*
- * @param Syncroton_Model_Device|string $_deviceId
- * @param string $_class
+ * @param Syncroton_Model_Device|string $deviceid Device object or identifier
*/
- public function resetState($_deviceId)
+ public function resetState($deviceid)
{
- $deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
+ $device_id = $deviceid instanceof Syncroton_Model_IDevice ? $deviceid->id : $deviceid;
- $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
+ $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($device_id);
$this->db->query('DELETE FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
}
-
/**
- * get array of ids which got send to the client for a given class
+ * Get array of ids which got send to the client for a given class
*
- * @param Syncroton_Model_Device|string $_deviceId
- * @param string $_class
+ * @param Syncroton_Model_Device|string $deviceid Device object or identifier
+ * @param string $class Class name
*
- * @return array
+ * @return array List of object identifiers
*/
- public function getFolderState($_deviceId, $_class)
+ public function getFolderState($deviceid, $class)
{
- $deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
+ $device_id = $deviceid instanceof Syncroton_Model_IDevice ? $deviceid->id : $deviceid;
- $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
- $where[] = $this->db->quote_identifier('class') . ' = ' . $this->db->quote($_class);
+ $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($device_id);
+ $where[] = $this->db->quote_identifier('class') . ' = ' . $this->db->quote($class);
$select = $this->db->query('SELECT * FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
$result = array();
while ($folder = $this->db->fetch_assoc($select)) {
$result[$folder['folderid']] = $this->get_object($folder);
}
return $result;
}
/**
- * get folder indentified by $_folderId
+ * Get folder
+ *
+ * @param Syncroton_Model_Device|string $deviceid Device object or identifier
+ * @param string $folderid Folder identifier
*
- * @param Syncroton_Model_Device|string $_deviceId
- * @param string $_folderId
- * @return Syncroton_Model_IFolder
+ * @return Syncroton_Model_IFolder Folder object
*/
- public function getFolder($_deviceId, $_folderId)
+ public function getFolder($deviceid, $folderid)
{
- $deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
+ $device_id = $deviceid instanceof Syncroton_Model_IDevice ? $deviceid->id : $deviceid;
- $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
- $where[] = $this->db->quote_identifier('folderid') . ' = ' . $this->db->quote($_folderId);
+ $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($device_id);
+ $where[] = $this->db->quote_identifier('folderid') . ' = ' . $this->db->quote($folderid);
$select = $this->db->query('SELECT * FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
$folder = $this->db->fetch_assoc($select);
if (empty($folder)) {
throw new Syncroton_Exception_NotFound('Folder not found');
}
return $this->get_object($folder);
}
-
/**
* (non-PHPdoc)
* @see kolab_sync_backend_common::from_camelcase()
*/
protected function from_camelcase($string)
{
switch ($string) {
case 'displayName':
case 'parentId':
return strtolower($string);
break;
case 'serverId':
return 'folderid';
break;
default:
return parent::from_camelcase($string);
break;
}
}
-
/**
* (non-PHPdoc)
* @see kolab_sync_backend_common::to_camelcase()
*/
protected function to_camelcase($string, $ucFirst = true)
{
switch ($string) {
case 'displayname':
return 'displayName';
break;
case 'parentid':
return 'parentId';
break;
case 'folderid':
return 'serverId';
break;
default:
return parent::to_camelcase($string, $ucFirst);
break;
}
}
}
diff --git a/lib/kolab_sync_backend_state.php b/lib/kolab_sync_backend_state.php
index b239d36..99a69bc 100644
--- a/lib/kolab_sync_backend_state.php
+++ b/lib/kolab_sync_backend_state.php
@@ -1,201 +1,202 @@
<?php
/**
+--------------------------------------------------------------------------+
| Kolab Sync (ActiveSync for Kolab) |
| |
| Copyright (C) 2011-2012, Kolab Systems AG <contact@kolabsys.com> |
| |
| This program is free software: you can redistribute it and/or modify |
| it under the terms of the GNU Affero General Public License as published |
| by the Free Software Foundation, either version 3 of the License, or |
| (at your option) any later version. |
| |
| This program is distributed in the hope that it will be useful, |
| but WITHOUT ANY WARRANTY; without even the implied warranty of |
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| GNU Affero General Public License for more details. |
| |
| You should have received a copy of the GNU Affero General Public License |
| along with this program. If not, see <http://www.gnu.org/licenses/> |
+--------------------------------------------------------------------------+
| Author: Aleksander Machniak <machniak@kolabsys.com> |
+--------------------------------------------------------------------------+
*/
/**
* Kolab backend class for the folder state storage
*/
class kolab_sync_backend_state extends kolab_sync_backend_common implements Syncroton_Backend_ISyncState
{
protected $table_name = 'syncroton_synckey';
protected $interface_name = 'Syncroton_Model_ISyncState';
/**
- * create new sync state
+ * Create new sync state of a folder
+ *
+ * @param Syncroton_Model_ISyncState $object State object
+ * @param bool $keep_previous_state Don't remove other states
*
- * @param Syncroton_Model_ISyncState $_syncState
* @return Syncroton_Model_SyncState
*/
- public function create($object, $_keepPreviousSyncState = true)
+ public function create($object, $keep_previous_state = true)
{
$object = parent::create($object);
- if ($_keepPreviousSyncState !== true) {
+ if ($keep_previous_state !== true) {
// remove all other synckeys
$this->_deleteOtherStates($object);
}
return $object;
}
- protected function _deleteOtherStates(Syncroton_Model_ISyncState $_state)
+ /**
+ * Deletes states other than specified one
+ */
+ protected function _deleteOtherStates(Syncroton_Model_ISyncState $state)
{
// remove all other synckeys
- $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($_state->device_id);
- $where[] = $this->db->quote_identifier('type') . ' = ' . $this->db->quote($_state->type);
- $where[] = $this->db->quote_identifier('counter') . ' <> ' . $this->db->quote($_state->counter);
+ $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($state->device_id);
+ $where[] = $this->db->quote_identifier('type') . ' = ' . $this->db->quote($state->type);
+ $where[] = $this->db->quote_identifier('counter') . ' <> ' . $this->db->quote($state->counter);
$this->db->query('DELETE FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
-
- return true;
}
-
/**
* @see kolab_sync_backend_common::object_to_array()
*/
protected function object_to_array($object)
{
$data = parent::object_to_array($object);
if (is_array($object->pendingdata)) {
$data['pendingdata'] = json_encode($object->pendingdata);
}
return $data;
}
-
/**
* @see kolab_sync_backend_common::get_object()
*/
protected function get_object($data)
{
$object = parent::get_object($data);
if ($object->pendingdata) {
$object->pendingdata = json_decode($object->pendingdata);
}
return $object;
}
-
/**
- * always returns the latest syncstate
+ * Returns the latest sync state
+ *
+ * @param Syncroton_Model_IDevice|string $deviceid Device object or identifier
+ * @param Syncroton_Model_IFolder|string $folderid Folder object or identifier
*
- * @param Syncroton_Model_IDevice|string $_deviceId
- * @param Syncroton_Model_IFolder|string $_folderId
* @return Syncroton_Model_SyncState
*/
- public function getSyncState($_deviceId, $_folderId)
+ public function getSyncState($deviceid, $folderid)
{
- $deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
- $folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->id : $_folderId;
+ $device_id = $deviceid instanceof Syncroton_Model_IDevice ? $deviceid->id : $deviceid;
+ $folder_id = $folderid instanceof Syncroton_Model_IFolder ? $folderid->id : $folderid;
- $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
- $where[] = $this->db->quote_identifier('type') . ' = ' . $this->db->quote($folderId);
+ $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($device_id);
+ $where[] = $this->db->quote_identifier('type') . ' = ' . $this->db->quote($folder_id);
$select = $this->db->limitquery('SELECT * FROM ' . $this->table_name . ' WHERE ' . implode(' AND ', $where)
.' ORDER BY counter DESC', 0, 1);
$state = $this->db->fetch_assoc($select);
if (empty($state)) {
throw new Syncroton_Exception_NotFound('SyncState not found');
}
return $this->get_object($state);
}
/**
- * delete all stored synckeys for given type
+ * Delete all stored synckeys of given type
*
- * @param Syncroton_Model_IDevice|string $_deviceId
- * @param Syncroton_Model_IFolder|string $_folderId
+ * @param Syncroton_Model_IDevice|string $deviceid Device object or identifier
+ * @param Syncroton_Model_IFolder|string $folderid Folder object or identifier
*/
- public function resetState($_deviceId, $_folderId)
+ public function resetState($deviceid, $folderid)
{
- $deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
- $folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->id : $_folderId;
+ $device_id = $deviceid instanceof Syncroton_Model_IDevice ? $deviceid->id : $deviceid;
+ $folder_id = $folderid instanceof Syncroton_Model_IFolder ? $folderid->id : $folderid;
- $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
- $where[] = $this->db->quote_identifier('type') . ' = ' . $this->db->quote($folderId);
+ $where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($device_id);
+ $where[] = $this->db->quote_identifier('type') . ' = ' . $this->db->quote($folder_id);
$this->db->query('DELETE FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
}
-
/**
- * get array of ids which got send to the client for a given class
+ * Validates specified sync state by checking for existance of newer keys
*
- * @param Syncroton_Model_IDevice|string $_deviceId
- * @param Syncroton_Model_IFolder|string $_folderId
+ * @param Syncroton_Model_IDevice|string $deviceid Device object or identifier
+ * @param Syncroton_Model_IFolder|string $folderid Folder object or identifier
+ * @param int $sync_key State key
*
* @return Syncroton_Model_SyncState
*/
- public function validate($_deviceId, $_folderId, $_syncKey)
+ public function validate($deviceid, $folderid, $sync_key)
{
- $deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
- $folderId = $_folderId instanceof Syncroton_Model_IFolder ? $_folderId->id : $_folderId;
+ $device_id = $deviceid instanceof Syncroton_Model_IDevice ? $deviceid->id : $deviceid;
+ $folder_id = $folderid instanceof Syncroton_Model_IFolder ? $folderid->id : $folderid;
// get sync data for current request and check if it's the last one
// by fetching synckey+1
$states = array();
- $keys = array($_syncKey, $_syncKey + 1);
+ $keys = array($sync_key, $sync_key + 1);
- $where['device_id'] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
- $where['type'] = $this->db->quote_identifier('type') . ' = ' . $this->db->quote($folderId);
+ $where['device_id'] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($device_id);
+ $where['type'] = $this->db->quote_identifier('type') . ' = ' . $this->db->quote($folder_id);
$where['counter'] = $this->db->quote_identifier('counter') . ' IN (' . $this->db->array2list($keys, 'int') . ')';
$select = $this->db->query('SELECT * FROM ' . $this->table_name .' WHERE ' . implode(' AND ', $where));
while ($row = $this->db->fetch_assoc($select)) {
$states[$row['counter']] = $this->get_object($row);
}
- if (empty($states) || empty($states[$_syncKey])) {
+ if (empty($states) || empty($states[$sync_key])) {
return false;
}
- $state = $states[$_syncKey];
+ $state = $states[$sync_key];
$where = array();
- $where['device_id'] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
- $where['folder_id'] = $this->db->quote_identifier('folder_id') . ' = ' . $this->db->quote($folderId);
+ $where['device_id'] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($device_id);
+ $where['folder_id'] = $this->db->quote_identifier('folder_id') . ' = ' . $this->db->quote($folder_id);
$where['is_deleted'] = $this->db->quote_identifier('is_deleted') . ' = 1';
// found more recent synckey => the last sync repsonse got not received by the client
- if (!empty($states[$_syncKey + 1])) {
+ if (!empty($states[$sync_key + 1])) {
$where['synckey'] = $this->db->quote_identifier('creation_synckey') . ' = ' . $this->db->quote($state->counter);
// undelete entries marked as deleted in syncroton_content table
$this->db->query('UPDATE syncroton_content SET is_deleted = 0 WHERE ' . implode(' AND ', $where));
// remove entries added during latest sync in syncroton_content table
unset($where['is_deleted']);
$where['synckey'] = $this->db->quote_identifier('creation_synckey') . ' > ' . $this->db->quote($state->counter);
$this->db->query('DELETE FROM syncroton_content WHERE ' . implode(' AND ', $where));
}
else {
// finaly delete all entries marked for removal in syncroton_content table
$this->db->query('DELETE FROM syncroton_content WHERE ' . implode(' AND ', $where));
}
// remove all other synckeys
$this->_deleteOtherStates($state);
return $state;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Sat, Apr 18, 8:20 AM (1 h, 44 s)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
435410
Default Alt Text
(36 KB)
Attached To
Mode
R4 syncroton
Attached
Detach File
Event Timeline
Log In to Comment