1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

Fix several issues

This commit is contained in:
LEDfan 2014-04-02 18:54:09 +02:00
parent e95ca5124b
commit dd68af97e4

View File

@ -73,7 +73,7 @@ class OwnCloudUsers extends AbstractBackend {
"displayname" => 'ownCloudUsers',
"description" => 'ownCloud Users',
"ctag" => time(),
"permissions" => \OCP\PERMISSION_ALL,
"permissions" => \OCP\PERMISSION_READ,
"backend" => $this->name,
"active" => 1
);
@ -90,7 +90,7 @@ class OwnCloudUsers extends AbstractBackend {
public function getContacts($addressbookid, array $options = array()){
$contacts = array();
try{
$sql = 'SELECT * FROM ' . $this->cardsTableName . ' WHERE owner = ?';
$sql = 'SELECT * FROM ' . $this->cardsTableName . ' WHERE addressbookid = ?';
$query = \OCP\DB::prepare($sql);
$result = $query->execute(array($this->userid));
@ -100,7 +100,7 @@ class OwnCloudUsers extends AbstractBackend {
return array();
} else {
while($row = $result->fetchRow()){
$row['permissions'] = \OCP\PERMISSION_ALL;
$row['permissions'] = \OCP\PERMISSION_UPDATE;
$contacts[] = $row;
}
@ -148,7 +148,7 @@ class OwnCloudUsers extends AbstractBackend {
*/
public function getContact($addressbookid, $id, array $options = array()){
try{
$sql = 'SELECT * FROM ' . $this->cardsTableName . ' WHERE owner = ?';
$sql = 'SELECT * FROM ' . $this->cardsTableName . ' WHERE addressbookid = ?';
$query = \OCP\DB::prepare($sql);
$result = $query->execute(array($this->userid));
@ -158,7 +158,7 @@ class OwnCloudUsers extends AbstractBackend {
return array();
} else {
$row = $result->fetchRow();
$row['permissions'] = \OCP\PERMISSION_ALL;
$row['permissions'] = \OCP\PERMISSION_UPDATE;
return $row;
}
} catch(\Exception $e) {
@ -185,36 +185,32 @@ class OwnCloudUsers extends AbstractBackend {
try{
$sql = 'INSERT INTO ' . $this->cardsTableName . ' ('
. 'id, '
. 'owner,'
. 'addressbookid, '
. 'fullname, '
. 'carddata, '
. 'uri, '
. 'lastmodified'
. ') VALUES ('
. '?,'
. '?,'
. '?,'
. '?,'
. '?,'
. '?,'
. '?'
. ')';
$query = \OCP\DB::prepare($sql);
$contact = new Contact(
$addressBook = new AddressBook($this , $this->getAddressBooksForUser()), // since there is only one addressbook with OC users for each OC user we can use this function
$this,
array(
"id" => $user,
"lastmodified" => time(),
"displayname" => \OCP\User::getDisplayName($user),
"fullname" => \OCP\User::getDisplayName($user)
)
);
$carddata = $this->generateCardData($contact);
$result = $query->execute(array($user, $this->userid, $addressbookid, \OCP\User::getDisplayName($user), $carddata->serialize(), 'test', time()));
$vcard = \Sabre\VObject\Component::create('VCARD');
$vcard->FN = \OCP\User::getDisplayName($user);
$now = new \DateTime('now');
$vcard->REV = $now->format(\DateTime::W3C);
$appinfo = \OCP\App::getAppInfo('contacts');
$appversion = \OCP\App::getAppVersion('contacts');
$prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion.'//EN';
$vcard->PRODID = $prodid;
$result = $query->execute(array($user, $this->userid, \OCP\User::getDisplayName($user), $vcard->serialize(), time()));
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('contacts', __METHOD__. 'DB error: '
@ -258,40 +254,6 @@ class OwnCloudUsers extends AbstractBackend {
}
}
/**
* Help function to generate the carddate which than can be stored in the db
* @param string|VCard $data
* @return Vcard
*/
private function generateCardData($data){
if (!$data instanceof VCard) {
try {
$data = Reader::read($data);
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), \OCP\Util::ERROR);
return false;
}
}
try {
$data->validate(VCard::REPAIR|VCard::UPGRADE);
} catch (\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__ . ' ' .
'Error validating vcard: ' . $e->getMessage(), \OCP\Util::ERROR);
return false;
}
$now = new \DateTime;
$data->REV = $now->format(\DateTime::W3C);
$appinfo = \OCP\App::getAppInfo('contacts');
$appversion = \OCP\App::getAppVersion('contacts');
$prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion.'//EN';
$data->PRODID = $prodid;
return $data;
}
/**
* @inheritdoc
*/