Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F117886933
kolab_sync_backend_folder.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Authored By
Unknown
Size
7 KB
Referenced Files
None
Subscribers
None
kolab_sync_backend_folder.php
View Options
<?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 folder ids for a given device
*
* @param Syncroton_Model_Device|string $deviceid Device object or identifier
*/
public
function
resetState
(
$deviceid
)
{
$device_id
=
$deviceid
instanceof
Syncroton_Model_IDevice
?
$deviceid
->
id
:
$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
*
* @param Syncroton_Model_Device|string $deviceid Device object or identifier
* @param string $class Class name
*
* @return array List of object identifiers
*/
public
function
getFolderState
(
$deviceid
,
$class
)
{
$device_id
=
$deviceid
instanceof
Syncroton_Model_IDevice
?
$deviceid
->
id
:
$deviceid
;
$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
*
* @param Syncroton_Model_Device|string $deviceid Device object or identifier
* @param string $folderid Folder identifier
*
* @return Syncroton_Model_IFolder Folder object
*/
public
function
getFolder
(
$deviceid
,
$folderid
)
{
$device_id
=
$deviceid
instanceof
Syncroton_Model_IDevice
?
$deviceid
->
id
:
$deviceid
;
$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
);
}
/**
* Find out if the folder hierarchy changed since the last FolderSync
*
* @param Syncroton_Model_Device $device Device object
*
* @return bool True if folders hierarchy changed, False otherwise
*/
public
function
hasHierarchyChanges
(
$device
)
{
$timestamp
=
new
DateTime
(
'now'
,
new
DateTimeZone
(
'utc'
));
$client_crc
=
''
;
$server_crc
=
''
;
$client_folders
=
array
();
$server_folders
=
array
();
$folder_classes
=
array
(
Syncroton_Data_Factory
::
CLASS_CALENDAR
,
Syncroton_Data_Factory
::
CLASS_CONTACTS
,
Syncroton_Data_Factory
::
CLASS_EMAIL
,
Syncroton_Data_Factory
::
CLASS_NOTES
,
Syncroton_Data_Factory
::
CLASS_TASKS
);
// Reset imap cache so we work with up-to-date folders list
rcube
::
get_instance
()->
get_storage
()->
clear_cache
(
'mailboxes'
,
true
);
foreach
(
$folder_classes
as
$class
)
{
try
{
// retrieve all folders available in data backend
$dataController
=
Syncroton_Data_Factory
::
factory
(
$class
,
$device
,
$timestamp
);
$server_folders
=
array_merge
(
$server_folders
,
$dataController
->
getAllFolders
());
}
catch
(
Exception
$e
)
{
rcube
::
raise_error
(
$e
,
true
,
false
);
// This is server error, returning True might cause infinite sync loops
return
false
;
}
}
// retrieve all folders sent to the client
$select
=
$this
->
db
->
query
(
"SELECT * FROM `{$this->table_name}` WHERE `device_id` = ?"
,
$device
->
id
);
while
(
$folder
=
$this
->
db
->
fetch_assoc
(
$select
))
{
$client_folders
[
$folder
[
'folderid'
]]
=
$this
->
get_object
(
$folder
);
}
ksort
(
$client_folders
);
ksort
(
$server_folders
);
foreach
(
$client_folders
as
$folder
)
{
$client_crc
.=
'^'
.
$folder
->
serverId
.
':'
.
$folder
->
displayName
.
':'
.
$folder
->
parentId
;
}
foreach
(
$server_folders
as
$folder
)
{
$server_crc
.=
'^'
.
$folder
->
serverId
.
':'
.
$folder
->
displayName
.
':'
.
$folder
->
parentId
;
}
return
$client_crc
!==
$server_crc
;
}
/**
* (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
;
}
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Mon, Apr 6, 2:47 AM (2 w, 5 d ago)
Storage Engine
local-disk
Storage Format
Raw Data
Storage Handle
64/6e/1bc77bb3e8e7ad0d45e8c381ccf5
Default Alt Text
kolab_sync_backend_folder.php (7 KB)
Attached To
Mode
rS syncroton
Attached
Detach File
Event Timeline