Changeset View
Changeset View
Standalone View
Standalone View
plugins/libkolab/lib/kolab_storage_folder.php
Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | class kolab_storage_folder extends kolab_storage_folder_api | ||||
* Set the IMAP folder this instance connects to | * Set the IMAP folder this instance connects to | ||||
* | * | ||||
* @param string The folder name/path | * @param string The folder name/path | ||||
* @param string Expected folder type | * @param string Expected folder type | ||||
* @param string Optional folder type if known | * @param string Optional folder type if known | ||||
*/ | */ | ||||
public function set_folder($name, $type = null, $type_annotation = null) | public function set_folder($name, $type = null, $type_annotation = null) | ||||
{ | { | ||||
$this->name = $name; | |||||
if (empty($type_annotation)) { | if (empty($type_annotation)) { | ||||
$type_annotation = kolab_storage::folder_type($name); | $type_annotation = $this->get_type(); | ||||
} | } | ||||
$oldtype = $this->type; | $oldtype = $this->type; | ||||
list($this->type, $suffix) = explode('.', $type_annotation); | list($this->type, $suffix) = explode('.', $type_annotation); | ||||
$this->default = $suffix == 'default'; | $this->default = $suffix == 'default'; | ||||
$this->subtype = $this->default ? '' : $suffix; | $this->subtype = $this->default ? '' : $suffix; | ||||
$this->name = $name; | |||||
$this->id = kolab_storage::folder_id($name); | $this->id = kolab_storage::folder_id($name); | ||||
$this->valid = !empty($this->type) && $this->type != 'mail' && (!$type || $this->type == $type); | $this->valid = !empty($this->type) && $this->type != 'mail' && (!$type || $this->type == $type); | ||||
if (!$this->valid) { | if (!$this->valid) { | ||||
$this->error = $this->imap->get_error_code() < 0 ? kolab_storage::ERROR_IMAP_CONN : kolab_storage::ERROR_INVALID_FOLDER; | $this->error = $this->imap->get_error_code() < 0 ? kolab_storage::ERROR_IMAP_CONN : kolab_storage::ERROR_INVALID_FOLDER; | ||||
} | } | ||||
// reset cached object properties | // reset cached object properties | ||||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Lines | class kolab_storage_folder extends kolab_storage_folder_api | ||||
* Helper method to extract folder UID metadata | * Helper method to extract folder UID metadata | ||||
* | * | ||||
* @return string Folder's UID | * @return string Folder's UID | ||||
*/ | */ | ||||
public function get_uid() | public function get_uid() | ||||
{ | { | ||||
// UID is defined in folder METADATA | // UID is defined in folder METADATA | ||||
$metakeys = array(kolab_storage::UID_KEY_SHARED, kolab_storage::UID_KEY_CYRUS); | $metakeys = array(kolab_storage::UID_KEY_SHARED, kolab_storage::UID_KEY_CYRUS); | ||||
$metadata = $this->get_metadata($metakeys); | $metadata = $this->get_metadata(); | ||||
if ($metadata !== null) { | if ($metadata !== null) { | ||||
foreach ($metakeys as $key) { | foreach ($metakeys as $key) { | ||||
if ($uid = $metadata[$key]) { | if ($uid = $metadata[$key]) { | ||||
return $uid; | return $uid; | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 175 Lines • ▼ Show 20 Lines | class kolab_storage_folder extends kolab_storage_folder_api | ||||
*/ | */ | ||||
public function set_order_and_limit($sortcols, $length = null, $offset = 0) | public function set_order_and_limit($sortcols, $length = null, $offset = 0) | ||||
{ | { | ||||
$this->cache->set_order_by($sortcols); | $this->cache->set_order_by($sortcols); | ||||
if ($length !== null) { | if ($length !== null) { | ||||
$this->cache->set_limit($length, $offset); | $this->cache->set_limit($length, $offset); | ||||
} | } | ||||
$this->order_and_limit = array( | |||||
'cols' => $sortcols, | |||||
'limit' => $length, | |||||
'offset' => $offset, | |||||
); | |||||
} | } | ||||
/** | /** | ||||
* Helper method to sanitize query arguments | * Helper method to sanitize query arguments | ||||
*/ | */ | ||||
private function _prepare_query($query) | private function _prepare_query($query) | ||||
{ | { | ||||
// string equals type query | // string equals type query | ||||
Show All 12 Lines | private function _prepare_query($query) | ||||
if (is_numeric($param[2])) | if (is_numeric($param[2])) | ||||
$query[$i][2] = date('Y-m-d H:i:s', $param[2]); | $query[$i][2] = date('Y-m-d H:i:s', $param[2]); | ||||
} | } | ||||
} | } | ||||
return $query; | return $query; | ||||
} | } | ||||
/** | /** | ||||
* Getter for a single Kolab object, identified by its UID | * Getter for a single Kolab object, identified by its UID | ||||
* | * | ||||
* @param string $uid Object UID | * @param string $uid Object UID | ||||
* @param string $type Object type (e.g. contact, event, todo, journal, note, configuration) | * @param string $type Object type (e.g. contact, event, todo, journal, note, configuration) | ||||
* Defaults to folder type | * Defaults to folder type | ||||
* | * | ||||
* @return array The Kolab object represented as hash array | * @return array The Kolab object represented as hash array | ||||
*/ | */ | ||||
public function get_object($uid, $type = null) | public function get_object($uid, $type = null) | ||||
{ | { | ||||
if (!$this->valid) { | if (!$this->valid || !$uid) { | ||||
return false; | return false; | ||||
} | } | ||||
$query = array(array('uid', '=', $uid)); | |||||
if ($type) { | |||||
$query[] = array('type', '=', $type); | |||||
} | |||||
// synchronize caches | // synchronize caches | ||||
$this->cache->synchronize(); | $this->cache->synchronize(); | ||||
$msguid = $this->cache->uid2msguid($uid); | // we don't use cache->get() here because we don't have msguid | ||||
// yet, using select() is faster | |||||
if ($msguid && ($object = $this->cache->get($msguid, $type))) { | // set order to make sure we get most recent object version | ||||
return $object; | // set limit to skip count query | ||||
$this->cache->set_order_by('msguid DESC'); | |||||
$this->cache->set_limit(1); | |||||
$list = $this->cache->select($this->_prepare_query($query)); | |||||
// set the order/limit back to defined value | |||||
$this->cache->set_order_by($this->order_and_limit['order']); | |||||
$this->cache->set_limit($this->order_and_limit['limit'], $this->order_and_limit['offset']); | |||||
if (!empty($list) && !empty($list[0])) { | |||||
return $list[0]; | |||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
/** | /** | ||||
* Fetch a Kolab object attachment which is stored in a separate part | * Fetch a Kolab object attachment which is stored in a separate part | ||||
▲ Show 20 Lines • Show All 492 Lines • ▼ Show 20 Lines | public function move($uid, $target_folder) | ||||
$target_folder = kolab_storage::get_folder($target_folder); | $target_folder = kolab_storage::get_folder($target_folder); | ||||
if ($msguid = $this->cache->uid2msguid($uid)) { | if ($msguid = $this->cache->uid2msguid($uid)) { | ||||
$this->cache->bypass(true); | $this->cache->bypass(true); | ||||
$result = $this->imap->move_message($msguid, $target_folder->name, $this->name); | $result = $this->imap->move_message($msguid, $target_folder->name, $this->name); | ||||
$this->cache->bypass(false); | $this->cache->bypass(false); | ||||
if ($result) { | if ($result) { | ||||
$this->cache->move($msguid, $uid, $target_folder); | $new_uid = ($copyuid = $this->imap->conn->data['COPYUID']) ? $copyuid[1] : null; | ||||
$this->cache->move($msguid, $uid, $target_folder, $new_uid); | |||||
return true; | return true; | ||||
} | } | ||||
else { | else { | ||||
rcube::raise_error(array( | rcube::raise_error(array( | ||||
'code' => 600, 'type' => 'php', | 'code' => 600, 'type' => 'php', | ||||
'file' => __FILE__, 'line' => __LINE__, | 'file' => __FILE__, 'line' => __LINE__, | ||||
'message' => "Failed to move message $msguid to $target_folder: " . $this->imap->get_error_str(), | 'message' => "Failed to move message $msguid to $target_folder: " . $this->imap->get_error_str(), | ||||
), true); | ), true); | ||||
▲ Show 20 Lines • Show All 245 Lines • ▼ Show 20 Lines | private function trigger_url($url, $auth_user = null, $auth_passwd = null) | ||||
// rcube::write_log('trigger', $result->getBody()); | // rcube::write_log('trigger', $result->getBody()); | ||||
} | } | ||||
catch (Exception $e) { | catch (Exception $e) { | ||||
return PEAR::raiseError($e->getMessage()); | return PEAR::raiseError($e->getMessage()); | ||||
} | } | ||||
return true; | return true; | ||||
} | } | ||||
} | } | ||||