From 15a53d24a2f18e3f4447553614c599909273d2d7 Mon Sep 17 00:00:00 2001 From: a-sassermann Date: Thu, 29 May 2014 17:14:04 +0200 Subject: [PATCH 1/4] Fix failure to display subsequent pages in contacts There is a bug in rcube_db::num_rows when used on a limitquery the query has a record offset. fix: removed all references to deprecated rcube_db::num_rows replaced with db count where count is required (also less expensive). removed counting where not required --- carddav.php | 13 ++++--------- carddav_addressbook.php | 32 ++++++++++---------------------- 2 files changed, 14 insertions(+), 31 deletions(-) diff --git a/carddav.php b/carddav.php index a715de2..dedc800 100644 --- a/carddav.php +++ b/carddav.php @@ -353,7 +353,7 @@ protected function carddav_server_available() $query = " SELECT - * + count(*) FROM ".get_table_name('carddav_server')." WHERE @@ -362,14 +362,9 @@ protected function carddav_server_available() $result = $rcmail->db->query($query, $user_id); - if ($rcmail->db->num_rows($result)) - { - return true; - } - else - { - return false; - } + $count = $rcmail->db->fetch_array($result); + return ($count[0] > 0); + } /** diff --git a/carddav_addressbook.php b/carddav_addressbook.php index a7ca7b8..dfc35c8 100644 --- a/carddav_addressbook.php +++ b/carddav_addressbook.php @@ -162,12 +162,9 @@ private function get_carddav_addressbook_contacts($limit = array()) $result = $rcmail->db->limitquery($query, $limit['start'], $limit['length'], $rcmail->user->data['user_id'], $this->carddav_server_id); } - if ($rcmail->db->num_rows($result)) + while ($contact = $rcmail->db->fetch_assoc($result)) { - while ($contact = $rcmail->db->fetch_assoc($result)) - { - $carddav_addressbook_contacts[$contact['vcard_id']] = $contact; - } + $carddav_addressbook_contacts[$contact['vcard_id']] = $contact; } return $carddav_addressbook_contacts; @@ -196,12 +193,7 @@ private function get_carddav_addressbook_contact($carddav_contact_id) $result = $rcmail->db->query($query, $rcmail->user->data['user_id'], $carddav_contact_id); - if ($rcmail->db->num_rows($result)) - { - return $rcmail->db->fetch_assoc($result); - } - - return false; + return $rcmail->db->fetch_assoc($result); } /** @@ -215,7 +207,7 @@ private function get_carddav_addressbook_contacts_count() $query = " SELECT - * + count(*) FROM ".get_table_name('carddav_contacts')." WHERE @@ -228,8 +220,8 @@ private function get_carddav_addressbook_contacts_count() "; $result = $rcmail->db->query($query, $rcmail->user->data['user_id'], $this->carddav_server_id); - - return $rcmail->db->num_rows($result); + $count = $rcmail->db->fetch_array($result); + return $count[0]; } /** @@ -791,16 +783,12 @@ private function search_carddav_addressbook_contacts() $result = $rcmail->db->query($query, $rcmail->user->data['user_id']); - if ($rcmail->db->num_rows($result)) + while ($contact = $rcmail->db->fetch_assoc($result)) { - while ($contact = $rcmail->db->fetch_assoc($result)) - { - $record['name'] = $contact['name']; - $record['email'] = explode(', ', $contact['email']); - - $this->result->add($record); - } + $record['name'] = $contact['name']; + $record['email'] = explode(', ', $contact['email']); + $this->result->add($record); } return $this->result; From e5ec512d0b670c1524cd6467d69de9798df7d1c0 Mon Sep 17 00:00:00 2001 From: a-sassermann Date: Thu, 29 May 2014 17:43:35 +0200 Subject: [PATCH 2/4] Error when saving new contact Fix: calling carddav_addressbook_sync with null instead of false for card_id prevents the sync to try an update on nonexisting card_id false. --- carddav_addressbook.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/carddav_addressbook.php b/carddav_addressbook.php index dfc35c8..a20df99 100644 --- a/carddav_addressbook.php +++ b/carddav_addressbook.php @@ -645,7 +645,7 @@ private function carddav_add($vcard) if ($carddav_backend->check_connection()) { $vcard_id = $carddav_backend->add($vcard); - $this->carddav_addressbook_sync($server, false, $vcard_id); + $this->carddav_addressbook_sync($server, null, $vcard_id); return $rcmail->db->insert_id(get_table_name('carddav_contacts')); } From 139d3d60263684d69fea96f25cc3755a75cb25b5 Mon Sep 17 00:00:00 2001 From: a-sassermann Date: Sat, 31 May 2014 17:27:38 +0200 Subject: [PATCH 3/4] replaced access to deprecated rcmail functions functions found: - get_table_name - write_log --- carddav.php | 10 +++++----- carddav_addressbook.php | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/carddav.php b/carddav.php index dedc800..b08b98a 100644 --- a/carddav.php +++ b/carddav.php @@ -155,7 +155,7 @@ public function get_carddav_server($carddav_server_id = false) SELECT * FROM - ".get_table_name('carddav_server')." + ".$rcmail->db->table_name('carddav_server')." WHERE user_id = ? ".($carddav_server_id !== false ? " AND carddav_server_id = ?" : null)." @@ -355,7 +355,7 @@ protected function carddav_server_available() SELECT count(*) FROM - ".get_table_name('carddav_server')." + ".$rcmail->db->table_name('carddav_server')." WHERE user_id = ? "; @@ -529,7 +529,7 @@ public function carddav_server_save() $query = " INSERT INTO - ".get_table_name('carddav_server')." (user_id, url, username, password, label, read_only) + ".$rcmail->db->table_name('carddav_server')." (user_id, url, username, password, label, read_only) VALUES (?, ?, ?, ?, ?, ?) "; @@ -576,7 +576,7 @@ public function carddav_server_delete() $query = " DELETE FROM - ".get_table_name('carddav_server')." + ".$rcmail->db->table_name('carddav_server')." WHERE user_id = ? AND @@ -610,6 +610,6 @@ public function carddav_server_delete() */ public function write_log($message) { - write_log('CardDAV', 'v' . self::VERSION . ' | ' . $message); + rcmail::write_log('CardDAV', 'v' . self::VERSION . ' | ' . $message); } } diff --git a/carddav_addressbook.php b/carddav_addressbook.php index a20df99..b2c7f5c 100644 --- a/carddav_addressbook.php +++ b/carddav_addressbook.php @@ -143,7 +143,7 @@ private function get_carddav_addressbook_contacts($limit = array()) SELECT * FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE user_id = ? AND @@ -184,7 +184,7 @@ private function get_carddav_addressbook_contact($carddav_contact_id) SELECT * FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE user_id = ? AND @@ -209,7 +209,7 @@ private function get_carddav_addressbook_contacts_count() SELECT count(*) FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE user_id = ? AND @@ -499,7 +499,7 @@ private function carddav_addressbook_add($carddav_content) $query = " INSERT INTO - ".get_table_name('carddav_contacts')." (carddav_server_id, user_id, etag, last_modified, vcard_id, vcard, words, firstname, surname, name, email) + ".$rcmail->db->table_name('carddav_contacts')." (carddav_server_id, user_id, etag, last_modified, vcard_id, vcard, words, firstname, surname, name, email) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) "; @@ -549,7 +549,7 @@ private function carddav_addressbook_update($carddav_content) $query = " UPDATE - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." SET etag = ?, last_modified = ?, @@ -606,7 +606,7 @@ private function carddav_addressbook_delete($vcard_id) $query = " DELETE FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE vcard_id = ? AND @@ -647,7 +647,7 @@ private function carddav_add($vcard) $vcard_id = $carddav_backend->add($vcard); $this->carddav_addressbook_sync($server, null, $vcard_id); - return $rcmail->db->insert_id(get_table_name('carddav_contacts')); + return $rcmail->db->insert_id($rcmail->db->table_name('carddav_contacts')); } return false; @@ -773,7 +773,7 @@ private function search_carddav_addressbook_contacts() SELECT * FROM - ".get_table_name('carddav_contacts')." + ".$rcmail->db->table_name('carddav_contacts')." WHERE user_id = ? ".$this->get_search_set()." From d4ffdf3eda40890b073a816046d2878d6c1a1305 Mon Sep 17 00:00:00 2001 From: Finn Christiansen Date: Fri, 27 Jun 2014 07:11:54 +0200 Subject: [PATCH 4/4] removed ORDER BY for count(*) query which caused an error --- carddav_addressbook.php | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/carddav_addressbook.php b/carddav_addressbook.php index b2c7f5c..3e1f577 100644 --- a/carddav_addressbook.php +++ b/carddav_addressbook.php @@ -214,10 +214,7 @@ private function get_carddav_addressbook_contacts_count() user_id = ? AND carddav_server_id = ? - ".$this->get_search_set()." - ORDER BY - name ASC - "; + ".$this->get_search_set(); $result = $rcmail->db->query($query, $rcmail->user->data['user_id'], $this->carddav_server_id); $count = $rcmail->db->fetch_array($result);