From a234865f71ebc98114295e27ff839c11f2da87ca Mon Sep 17 00:00:00 2001 From: LEDfan Date: Tue, 1 Apr 2014 19:36:39 +0200 Subject: [PATCH] Create addressbook if don't exists --- lib/backend/owncloudusers.php | 36 +++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/lib/backend/owncloudusers.php b/lib/backend/owncloudusers.php index eb4074e9..6f009b5b 100644 --- a/lib/backend/owncloudusers.php +++ b/lib/backend/owncloudusers.php @@ -35,14 +35,42 @@ class OwnCloudUsers extends AbstractBackend { public function getAddressBooksForUser(array $options = array()) { // Only 1 addressbook for every user - $sql = 'SELECT * FROM ' . $this->addressBooksTableName . ' WHERE userid = ?'; + $sql = 'SELECT * FROM ' . $this->addressBooksTableName . ' WHERE id = ?'; $args = array($this->userid); $query = \OCP\DB::prepare($sql); $result = $query->execute($args); $row = $result->fetchRow(); - $row['permissions'] = \OCP\PERMISSION_ALL; - - return array($row); + // Check if there are no results TODO? + if(!$row){ + // Create new addressbook + $sql = 'INSERT INTO ' . $this->addressBooksTableName + . ' ( ' + . 'id, ' + . 'displayname, ' + //. 'uri, ' TODO + . 'description, ' + // . 'ctag, ' + . 'active ' + . ') VALUES ( ' + . '?, ' + . '?, ' + . '?, ' + . '? ' + . ')'; + $args = array( + $this->userid, + 'ownCloud Users', + 'ownCloud Users', + 1 + ); + $query = \OCP\DB::prepare($sql); + $query->execute($args); + + return $this->getAddressBooksForUser(); + } else { + $row['permissions'] = \OCP\PERMISSION_ALL; + return array($row); + } } public function getAddressBook($addressBookId, array $options = array()) {