Page MenuHomePhorge

kolab_sync_backend_folder.php
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

kolab_sync_backend_folder.php

<?php
/**
* sql backend class for the folder state
*
* @package Syncroton
* @subpackage Backend
*/
class kolab_sync_backend_folder implements Syncroton_Backend_IFolder
{
/**
* the database adapter
*
* @var rcube_mdb2
*/
protected $db;
public function __construct()
{
$this->db = rcube::get_instance()->get_dbh();
}
/**
* create new folder state
*
* @param Syncroton_Model_IFolder $_folder
* @return Syncroton_Model_IFolder
*/
public function create(Syncroton_Model_IFolder $_folder)
{
$id = sha1(mt_rand(). microtime());
$deviceId = $_folder->device_id instanceof Syncroton_Model_IDevice ? $_folder->device_id->id : $_folder->device_id;
$folderId = $_folder->folderid instanceof Syncroton_Model_IFolder ? $_folder->folderid->id : $_folder->folderid;
$insert[$this->db->quote_identifier('id')] = $this->db->quote($id);
$insert[$this->db->quote_identifier('device_id')] = $this->db->quote($deviceId);
$insert[$this->db->quote_identifier('class')] = $this->db->quote($_folder->class);
$insert[$this->db->quote_identifier('folderid')] = $this->db->quote($folderId);
$insert[$this->db->quote_identifier('parentid')] = $this->db->quote($_folder->parentid);
$insert[$this->db->quote_identifier('displayname')] = $this->db->quote($_folder->displayname);
$insert[$this->db->quote_identifier('type')] = $this->db->quote($_folder->type);
$insert[$this->db->quote_identifier('creation_time')] = $this->db->quote($_folder->creation_time->format('Y-m-d H:i:s'));
$insert[$this->db->quote_identifier('lastfiltertype')] = $this->db->quote($_folder->lastfiltertype);
$this->db->query('INSERT INTO syncroton_folder'
. ' (' . implode(', ', array_keys($insert)) . ')' . ' VALUES(' . implode(', ', $insert) . ')');
return $this->get($id);
}
public function delete($_id)
{
$id = $_id instanceof Syncroton_Model_IFolder ? $_id->id : $_id;
$result = $this->db->query('DELETE FROM syncroton_folder WHERE id = ?', array($id));
return (bool) $this->db->affected_rows($result);
}
/**
* @param string $_id
* @throws Syncroton_Exception_NotFound
* @return Syncroton_Model_IFolder
*/
public function get($_id)
{
$select = $this->db->query('SELECT * FROM syncroton_folder WHERE id = ?', array($_id));
if ($state = $this->db->fetch_assoc($select)) {
$state = new Syncroton_Model_Folder($state);
}
if (! $state instanceof Syncroton_Model_IFolder) {
throw new Syncroton_Exception_NotFound('id not found');
}
if (!empty($state->creation_time)) {
$state->creation_time = new DateTime($state->creation_time, new DateTimeZone('utc'));
}
return $state;
}
/**
* delete all stored folderId's for given device
*
* @param Syncroton_Model_Device|string $_deviceId
* @param string $_class
*/
public function resetState($_deviceId)
{
$deviceId = $_deviceId instanceof Syncroton_Model_IDevice ? $_deviceId->id : $_deviceId;
$where[] = $this->db->quote_identifier('device_id') . ' = ' . $this->db->quote($deviceId);
$this->db->query('DELETE FROM syncroton_folder WHERE ' . implode(' AND ', $where));
}
public function update(Syncroton_Model_IFolder $_folder)
{
$this->db->query('UPDATE syncroton_folder SET lastfiltertype = ? WHERE id = ?',
array($_folder->lastfiltertype, $_folder->id));
return $this->get($_folder->id);
}
/**
* get array of ids which got send to the client for a given class
*
* @param Syncroton_Model_Device|string $_deviceId
* @param string $_class
*
* @return array
*/
public function getFolderState($_deviceId, $_class)
{
$deviceId = $_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);
$select = $this->db->query('SELECT * FROM syncroton_folder WHERE ' . implode(' AND ', $where));
$result = array();
while ($row = $this->db->fetch_assoc($select)) {
$result[$row['folderid']] = new Syncroton_Model_Folder($row);
}
return $result;
}
/**
* get folder indentified by $_folderId
*
* @param Syncroton_Model_Device|string $_deviceId
* @param string $_folderId
* @return Syncroton_Model_IFolder
*/
public function getFolder($_deviceId, $_folderId)
{
$deviceId = $_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);
$select = $this->db->query('SELECT * FROM syncroton_folder WHERE ' . implode(' AND ', $where));
if ($folder = $this->db->fetch_assoc($select)) {
$folder = new Syncroton_Model_Folder($folder);
}
if (! $folder instanceof Syncroton_Model_IFolder) {
throw new Syncroton_Exception_NotFound('folder not found');
}
if (!empty($folder->creation_time)) {
$folder->creation_time = new DateTime($folder->creation_time, new DateTimeZone('utc'));
}
return $folder;
}
}

File Metadata

Mime Type
text/x-php
Expires
Thu, Jul 9, 1:00 AM (3 h, 26 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1052390
Default Alt Text
kolab_sync_backend_folder.php (5 KB)

Event Timeline