From 8c3aa231e12c655eeb99b4f390225aa1162b7c58 Mon Sep 17 00:00:00 2001 From: Thomas Bruederli Date: Mon, 4 Jul 2011 14:57:00 +0200 Subject: [PATCH] Improve folder/address book listing; temporarily add some timer output for profiling --- .../kolab_addressbook/kolab_addressbook.php | 6 ++-- .../lib/rcube_kolab_contacts.php | 31 +++++++++++++++---- plugins/kolab_core/rcube_kolab.php | 13 ++++++++ 3 files changed, 41 insertions(+), 9 deletions(-) diff --git a/plugins/kolab_addressbook/kolab_addressbook.php b/plugins/kolab_addressbook/kolab_addressbook.php index 5432ffac..e323b2c7 100644 --- a/plugins/kolab_addressbook/kolab_addressbook.php +++ b/plugins/kolab_addressbook/kolab_addressbook.php @@ -212,7 +212,7 @@ class kolab_addressbook extends rcube_plugin return $this->sources; $this->sources = array(); - +$timer = rcube_timer(); // Load configuration $this->load_config(); @@ -225,7 +225,7 @@ class kolab_addressbook extends rcube_plugin // get all folders that have "contact" type $this->folders = rcube_kolab::get_folders('contact'); - +rcube_print_time($timer, 'get_folders()'); if (PEAR::isError($this->folders)) { raise_error(array( 'code' => 600, 'type' => 'php', @@ -248,7 +248,7 @@ class kolab_addressbook extends rcube_plugin $this->sources[$abook_id] = $abook; } } - +rcube_print_time($timer, 'list_sources() done.'); return $this->sources; } diff --git a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php index 9a04a265..137e9690 100644 --- a/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php +++ b/plugins/kolab_addressbook/lib/rcube_kolab_contacts.php @@ -56,6 +56,7 @@ class rcube_kolab_contacts extends rcube_addressbook ); private $gid; + private $storagefolder; private $contactstorage; private $liststorage; private $contacts; @@ -115,10 +116,8 @@ class rcube_kolab_contacts extends rcube_addressbook } // fetch objects from the given IMAP folder - $this->contactstorage = rcube_kolab::get_storage($this->imap_folder); - $this->liststorage = rcube_kolab::get_storage($this->imap_folder, 'distributionlist'); - - $this->ready = !PEAR::isError($this->contactstorage) && !PEAR::isError($this->liststorage); + $this->storagefolder = rcube_kolab::get_folder($this->imap_folder); + $this->ready = !PEAR::isError($this->storagefolder); // Set readonly and editable flags according to folder permissions if ($this->ready) { @@ -127,7 +126,7 @@ class rcube_kolab_contacts extends rcube_addressbook $this->readonly = false; } else { - $acl = $this->contactstorage->_folder->getACL(); + $acl = $this->storagefolder->getACL(); $acl = $acl[$_SESSION['username']]; if (strpos($acl, 'i') !== false) $this->readonly = false; @@ -171,7 +170,7 @@ class rcube_kolab_contacts extends rcube_addressbook */ public function get_owner() { - return $this->contactstorage->_folder->getOwner(); + return $this->storagefolder->getOwner(); } @@ -494,6 +493,8 @@ class rcube_kolab_contacts extends rcube_addressbook } if (!$existing) { + $this->_connect(); + // generate new Kolab contact item $object = $this->_from_rcube_contact($save_data); $object['uid'] = $this->contactstorage->generateUID(); @@ -601,6 +602,8 @@ class rcube_kolab_contacts extends rcube_addressbook */ public function delete_all() { + $this->_connect(); + if (!PEAR::isError($this->contactstorage->deleteAll())) { $this->contacts = array(); $this->id2uid = array(); @@ -815,12 +818,26 @@ class rcube_kolab_contacts extends rcube_addressbook } + /** + * Establishes a connection to the Kolab_Data object for accessing contact data + */ + private function _connect() + { + if (!isset($this->contactstorage)) { + $this->contactstorage = $this->storagefolder->getData(null); + $this->liststorage = $this->storagefolder->getData('distributionlist'); + } + } + + /** * Simply fetch all records and store them in private member vars */ private function _fetch_contacts() { if (!isset($this->contacts)) { + $this->_connect(); + // read contacts $this->contacts = $this->id2uid = array(); foreach ((array)$this->contactstorage->getObjects() as $record) { @@ -855,6 +872,8 @@ class rcube_kolab_contacts extends rcube_addressbook private function _fetch_groups() { if (!isset($this->distlists)) { + $this->_connect(); + $this->distlists = $this->groupmembers = array(); foreach ((array)$this->liststorage->getObjects() as $record) { // FIXME: folders without any distribution-list objects return contacts instead ?! diff --git a/plugins/kolab_core/rcube_kolab.php b/plugins/kolab_core/rcube_kolab.php index 16100ba1..be231a3f 100644 --- a/plugins/kolab_core/rcube_kolab.php +++ b/plugins/kolab_core/rcube_kolab.php @@ -119,6 +119,19 @@ class rcube_kolab return self::$ready ? $kolab->getByType($type) : array(); } + /** + * Getter for a specific storage folder + * + * @param string IMAP folder to access (UTF7-IMAP) + * @return object Kolab_Folder The folder object + */ + public static function get_folder($folder) + { + self::setup(); + $kolab = Kolab_List::singleton(); + return self::$ready ? $kolab->getFolder($folder) : null; + } + /** * Get storage object for read/write access to the Kolab backend *