From 9daf32495a7a57ab5df70dc8acd513db661ed3d9 Mon Sep 17 00:00:00 2001 From: Aleksander Machniak Date: Mon, 7 Mar 2016 17:54:01 +0100 Subject: [PATCH] Fix regression in get_object() (T1098) Also remove the second argument as it was useless. --- plugins/libkolab/lib/kolab_storage.php | 2 +- plugins/libkolab/lib/kolab_storage_cache.php | 27 +++++++++++++ plugins/libkolab/lib/kolab_storage_folder.php | 40 ++----------------- 3 files changed, 32 insertions(+), 37 deletions(-) diff --git a/plugins/libkolab/lib/kolab_storage.php b/plugins/libkolab/lib/kolab_storage.php index db7e0ba3..53687cdb 100644 --- a/plugins/libkolab/lib/kolab_storage.php +++ b/plugins/libkolab/lib/kolab_storage.php @@ -221,7 +221,7 @@ class kolab_storage else $folder->set_folder($foldername, $type, $folderdata[$foldername]); - if ($object = $folder->get_object($uid, '*')) + if ($object = $folder->get_object($uid)) return $object; } diff --git a/plugins/libkolab/lib/kolab_storage_cache.php b/plugins/libkolab/lib/kolab_storage_cache.php index 41984702..5f8d3fe5 100644 --- a/plugins/libkolab/lib/kolab_storage_cache.php +++ b/plugins/libkolab/lib/kolab_storage_cache.php @@ -323,6 +323,33 @@ class kolab_storage_cache return $this->objects[$msguid]; } + /** + * Getter for a single Kolab object identified by its UID + * + * @param string $uid Object UID + * + * @return array The Kolab object represented as hash array + */ + public function get_by_uid($uid) + { + $old_order_by = $this->order_by; + $old_limit = $this->limit; + + // set order to make sure we get most recent object version + // set limit to skip count query + $this->order_by = '`msguid` DESC'; + $this->limit = array(1, 0); + + $list = $this->select(array(array('uid', '=', $uid))); + + // set the order/limit back to defined value + $this->order_by = $old_order_by; + $this->limit = $old_limit; + + if (!empty($list) && !empty($list[0])) { + return $list[0]; + } + } /** * Insert/Update a cache entry diff --git a/plugins/libkolab/lib/kolab_storage_folder.php b/plugins/libkolab/lib/kolab_storage_folder.php index 00d02efc..ce121ba7 100644 --- a/plugins/libkolab/lib/kolab_storage_folder.php +++ b/plugins/libkolab/lib/kolab_storage_folder.php @@ -348,12 +348,6 @@ class kolab_storage_folder extends kolab_storage_folder_api if ($length !== null) { $this->cache->set_limit($length, $offset); } - - $this->order_and_limit = array( - 'cols' => $sortcols, - 'limit' => $length, - 'offset' => $offset, - ); } /** @@ -383,48 +377,22 @@ class kolab_storage_folder extends kolab_storage_folder_api } /** - * 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 $type Object type (e.g. contact, event, todo, journal, note, configuration) - * Defaults to folder type + * @param string $uid Object UID * * @return array The Kolab object represented as hash array */ - public function get_object($uid, $type = null) + public function get_object($uid) { if (!$this->valid || !$uid) { return false; } - $query = array(array('uid', '=', $uid)); - - if ($type) { - $query[] = array('type', '=', $type); - } - // synchronize caches $this->cache->synchronize(); - // we don't use cache->get() here because we don't have msguid - // yet, using select() is faster - - // set order to make sure we get most recent object version - // 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 $this->cache->get_by_uid($uid); }