Author Topic: [0.6] Roundcube CardDAV Plugin  (Read 61904 times)

Offline alec

  • Hero Member
  • *****
  • Posts: 1,365
Re: [0.6] Roundcube CardDAV Plugin
« Reply #45 on: January 18, 2013, 11:49:42 AM »
There's no num_rows() method in 0.9. Carddav plugin need to be updated to use other method.

Offline oldschool

  • Sr. Member
  • ****
  • Posts: 406
Re: [0.6] Roundcube CardDAV Plugin
« Reply #46 on: January 18, 2013, 11:55:33 AM »
There's no num_rows() method in 0.9. Carddav plugin need to be updated to use other method.

Arrgghh!
Thaaaanks!

Hi, Christian, bekommst das vielleicht zeitnah hin?
;)


Rgds.

Offline huhn_m

  • Newbie
  • *
  • Posts: 7
Re: [0.6] Roundcube CardDAV Plugin
« Reply #47 on: January 27, 2013, 09:45:34 AM »
Code: [Select]
--- carddav.php.orig    2013-01-27 15:37:45.285051841 +0100
+++ carddav.php 2013-01-27 15:39:55.035182800 +0100
@@ -352,7 +351,7 @@
 
                $query = "
                        SELECT
-                               *
+                               COUNT(*)
                        FROM
                                ".get_table_name('carddav_server')."
                        WHERE
@@ -361,7 +360,7 @@
 
                $result = $rcmail->db->query($query, $user_id);
 
-               if ($rcmail->db->num_rows($result))
+               if ($rcmail->db->fetch_array($result)[0] > 0)
                {
                        return true;
                }

Code: [Select]
--- carddav_addressbook.php.orig        2013-01-27 15:37:26.504033155 +0100
+++ carddav_addressbook.php     2013-01-27 15:43:15.075379470 +0100
@@ -162,14 +162,11 @@
                        $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 @@
 
                $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 @@
 
                $query = "
                        SELECT
-                               *
+                               COUNT (*)
                        FROM
                                ".get_table_name('carddav_contacts')."
                        WHERE
@@ -229,7 +221,7 @@
 
                $result = $rcmail->db->query($query, $rcmail->user->data['user_id'], $this->carddav_server_id);
 
-               return $rcmail->db->num_rows($result);
+               return $rcmail->db->fetch_array($result)[0];
        }
 
        /**
@@ -791,16 +783,12 @@
 
                $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;

And for people that like sqlite here is the sqlite.sql  for the SQL directory:

Code: [Select]
PRAGMA foreign_keys = ON;

CREATE TABLE IF NOT EXISTS `carddav_server` (
  `carddav_server_id` INTEGER PRIMARY KEY AUTOINCREMENT,
  `user_id` int(10) NOT NULL REFERENCES `users` (`user_id`) ON DELETE CASCADE,
  `url` varchar(255) NOT NULL,
  `username` varchar(128) NOT NULL,
  `password` varchar(128) NOT NULL,
  `label` varchar(128) NOT NULL,
  `read_only` tinyint(1) NOT NULL
);

CREATE TABLE IF NOT EXISTS `carddav_contacts` (
  `carddav_contact_id` INTEGER PRIMARY KEY AUTOINCREMENT,
  `carddav_server_id` int(10)  NOT NULL REFERENCES `carddav_server` (`carddav_server_id`) ON DELETE CASCADE,
  `user_id` int(10) NOT NULL,
  `etag` varchar(64) NOT NULL,
  `last_modified` varchar(128) NOT NULL,
  `vcard_id` varchar(64) NOT NULL,
  `vcard` longtext NOT NULL,
  `words` text,
  `firstname` varchar(128) DEFAULT NULL,
  `surname` varchar(128) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  UNIQUE (`carddav_server_id`,`user_id`,`vcard_id`)
);

Offline oldschool

  • Sr. Member
  • ****
  • Posts: 406
Re: [0.6] Roundcube CardDAV Plugin
« Reply #48 on: January 27, 2013, 02:34:37 PM »
Hi and thanks a lot!

Will give it a try.


Have a nice day!

Offline oldschool

  • Sr. Member
  • ****
  • Posts: 406
Re: [0.6] Roundcube CardDAV Plugin
« Reply #49 on: January 27, 2013, 10:47:39 PM »
Hi!

I get a:
Code: [Select]
syntax error, unexpected '[' in .../plugins/carddav/carddav.php on line 364
Rgds.
« Last Edit: January 28, 2013, 12:06:37 AM by oldschool »

Offline huhn_m

  • Newbie
  • *
  • Posts: 7
Re: [0.6] Roundcube CardDAV Plugin
« Reply #50 on: January 29, 2013, 07:16:32 AM »
Huh? Works for me. fetchArray returns an array and i retrieve the first element. What php version are you using?
Are you sure you have not mistyped a bracket or something? Can you show me the lines arround the error (e.g. 5 before, 5 after or sth. like that)

Offline oldschool

  • Sr. Member
  • ****
  • Posts: 406
Re: [0.6] Roundcube CardDAV Plugin
« Reply #51 on: January 29, 2013, 12:07:26 PM »
Hi!


Currently using PHP Version 5.3.5.


Code: [Select]
protected function carddav_server_available()
{
$rcmail = rcmail::get_instance();
$user_id = $rcmail->user->data['user_id'];

$query = "
SELECT
      COUNT(*)
      FROM
      ".get_table_name('carddav_server')."
      WHERE
user_id = ?
";

$result = $rcmail->db->query($query, $user_id);

if ($rcmail->db->fetch_array($result)[0] > 0)
{
return true;
}
else
{
return false;
}
}

I removed the
Code: [Select]
[0] with the result the generated contacts are not shown.
But copied to the carddav server...


Rgds.
« Last Edit: January 29, 2013, 12:08:59 PM by oldschool »

Offline huhn_m

  • Newbie
  • *
  • Posts: 7
Re: [0.6] Roundcube CardDAV Plugin
« Reply #52 on: January 30, 2013, 04:00:00 AM »
Hm. Might be it works for me because I use php 5.4. But I'm not sure. Also, the function should not have the effect you described. It just decides whether a server is available (and based on that if anything works at all with this server). So there might be another problem (because I use the same method with the index in another method in carddav_addressbook.php).

One try might be to use
Code: [Select]
                            $result = $rcmail->db->query($query, $user_id);
                            $resultArray = $rcmail->db->fetch_array($result);

if ($resultArray[0] > 0)
{
return true;
}
else
{
return false;
}

instead if the above code.
(And the anologous version in the carddav_addressbook.php). Could you give this a try?

Offline oldschool

  • Sr. Member
  • ****
  • Posts: 406
Re: [0.6] Roundcube CardDAV Plugin
« Reply #53 on: January 30, 2013, 07:07:41 PM »
Okay, i tried this:


Replace
Code: [Select]
($rcmail->db->num_rows($result))with
Code: [Select]
($rcmail->db->affected_rows($result))in carddav_addressbook.php and carddav.php.


But currently i still get a
Code: [Select]
Couldn't delete CardDAV-Contact from the local database with the vCard idwhen copying a contact to the davical server...


Rgds.


PS: Update. This fix problems with previous releases, too!
« Last Edit: January 30, 2013, 07:33:29 PM by oldschool »

Offline huhn_m

  • Newbie
  • *
  • Posts: 7
Re: [0.6] Roundcube CardDAV Plugin
« Reply #54 on: January 31, 2013, 03:26:23 AM »
you can NOT replace num_rows with affected rows for select statements. It only returns affected rows (DELETE, INSERT, UPDATE). You need to replace the SELECT * with SELECT COUNT(*) and evaluate the result, just like my patch did. Else you effectively always get zero results for SELECT statements.

Offline oldschool

  • Sr. Member
  • ****
  • Posts: 406
Re: [0.6] Roundcube CardDAV Plugin
« Reply #55 on: January 31, 2013, 08:59:09 AM »
Hi!

Have you checked your PMs?


Rgds.

Offline huhn_m

  • Newbie
  • *
  • Posts: 7
Re: [0.6] Roundcube CardDAV Plugin
« Reply #56 on: February 01, 2013, 10:12:44 AM »
Sorry ;) I totally missed that. You got a reply now.

Offline mbsouth

  • Full Member
  • ***
  • Posts: 71
Re: [0.6] Roundcube CardDAV Plugin
« Reply #57 on: February 02, 2013, 09:48:08 PM »
Der hier produzierte Code-Hick/Hack ist absoluter Schrott!
Seht euch die Methoden in RC0.9 einmal an, zumal betrifft das "num_rows($result)" - Problem nicht nur dieses sondern viele der 3d-Party PlugIns!

Offline oldschool

  • Sr. Member
  • ****
  • Posts: 406
Re: [0.6] Roundcube CardDAV Plugin
« Reply #58 on: February 03, 2013, 07:40:07 AM »
Der hier produzierte Code-Hick/Hack ist absoluter Schrott!
Seht euch die Methoden in RC0.9 einmal an, zumal betrifft das "num_rows($result)" - Problem nicht nur dieses sondern viele der 3d-Party PlugIns!

Hi!

Nicht nur rumhupen.
Haste auch was Konstruktives am Start?
;)


Gruss.

Offline mbsouth

  • Full Member
  • ***
  • Posts: 71
Re: [0.6] Roundcube CardDAV Plugin
« Reply #59 on: February 04, 2013, 07:40:33 AM »

You can read all relevant post on the project home: https://github.com/graviox/Roundcube-CardDAV/issues.
It seems, that the developement is at a stilstand; therefore it would be better, to post bugs or feature requests on the project page. Perhaps, Christian Putzke is further continuing the development of this great plugin.