Roundcube Community Forum

 

[0.6] Roundcube CardDAV Plugin

Started by EdMolf, October 02, 2011, 04:23:32 PM

Previous topic - Next topic

alec

There's no num_rows() method in 0.9. Carddav plugin need to be updated to use other method.

oldschool

Quote from: alec 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.

Arrgghh!
Thaaaanks!

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


Rgds.

huhn_m

--- 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;
                }


--- 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:


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`)
);

oldschool

Hi and thanks a lot!

Will give it a try.


Have a nice day!

oldschool

#49
Hi!

I get a:
syntax error, unexpected '[' in .../plugins/carddav/carddav.php on line 364

Rgds.

huhn_m

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)

oldschool

#51
Hi!


Currently using PHP Version 5.3.5.



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 [0] with the result the generated contacts are not shown.
But copied to the carddav server...


Rgds.

huhn_m

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

                            $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?

oldschool

#53
Okay, i tried this:


Replace
($rcmail->db->num_rows($result))
with
($rcmail->db->affected_rows($result))
in carddav_addressbook.php and carddav.php.


But currently i still get a
Couldn't delete CardDAV-Contact from the local database with the vCard id
when copying a contact to the davical server...


Rgds.


PS: Update. This fix problems with previous releases, too!

huhn_m

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.

oldschool

Hi!

Have you checked your PMs?


Rgds.

huhn_m

Sorry ;) I totally missed that. You got a reply now.

mbsouth

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!

oldschool

Quote from: mbsouth 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!

Hi!

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


Gruss.

mbsouth


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.