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:
parent
e95ca5124b
commit
dd68af97e4
@ -73,7 +73,7 @@ class OwnCloudUsers extends AbstractBackend {
|
|||||||
"displayname" => 'ownCloudUsers',
|
"displayname" => 'ownCloudUsers',
|
||||||
"description" => 'ownCloud Users',
|
"description" => 'ownCloud Users',
|
||||||
"ctag" => time(),
|
"ctag" => time(),
|
||||||
"permissions" => \OCP\PERMISSION_ALL,
|
"permissions" => \OCP\PERMISSION_READ,
|
||||||
"backend" => $this->name,
|
"backend" => $this->name,
|
||||||
"active" => 1
|
"active" => 1
|
||||||
);
|
);
|
||||||
@ -90,7 +90,7 @@ class OwnCloudUsers extends AbstractBackend {
|
|||||||
public function getContacts($addressbookid, array $options = array()){
|
public function getContacts($addressbookid, array $options = array()){
|
||||||
$contacts = array();
|
$contacts = array();
|
||||||
try{
|
try{
|
||||||
$sql = 'SELECT * FROM ' . $this->cardsTableName . ' WHERE owner = ?';
|
$sql = 'SELECT * FROM ' . $this->cardsTableName . ' WHERE addressbookid = ?';
|
||||||
$query = \OCP\DB::prepare($sql);
|
$query = \OCP\DB::prepare($sql);
|
||||||
$result = $query->execute(array($this->userid));
|
$result = $query->execute(array($this->userid));
|
||||||
|
|
||||||
@ -100,7 +100,7 @@ class OwnCloudUsers extends AbstractBackend {
|
|||||||
return array();
|
return array();
|
||||||
} else {
|
} else {
|
||||||
while($row = $result->fetchRow()){
|
while($row = $result->fetchRow()){
|
||||||
$row['permissions'] = \OCP\PERMISSION_ALL;
|
$row['permissions'] = \OCP\PERMISSION_UPDATE;
|
||||||
$contacts[] = $row;
|
$contacts[] = $row;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -148,7 +148,7 @@ class OwnCloudUsers extends AbstractBackend {
|
|||||||
*/
|
*/
|
||||||
public function getContact($addressbookid, $id, array $options = array()){
|
public function getContact($addressbookid, $id, array $options = array()){
|
||||||
try{
|
try{
|
||||||
$sql = 'SELECT * FROM ' . $this->cardsTableName . ' WHERE owner = ?';
|
$sql = 'SELECT * FROM ' . $this->cardsTableName . ' WHERE addressbookid = ?';
|
||||||
$query = \OCP\DB::prepare($sql);
|
$query = \OCP\DB::prepare($sql);
|
||||||
$result = $query->execute(array($this->userid));
|
$result = $query->execute(array($this->userid));
|
||||||
|
|
||||||
@ -158,7 +158,7 @@ class OwnCloudUsers extends AbstractBackend {
|
|||||||
return array();
|
return array();
|
||||||
} else {
|
} else {
|
||||||
$row = $result->fetchRow();
|
$row = $result->fetchRow();
|
||||||
$row['permissions'] = \OCP\PERMISSION_ALL;
|
$row['permissions'] = \OCP\PERMISSION_UPDATE;
|
||||||
return $row;
|
return $row;
|
||||||
}
|
}
|
||||||
} catch(\Exception $e) {
|
} catch(\Exception $e) {
|
||||||
@ -185,36 +185,32 @@ class OwnCloudUsers extends AbstractBackend {
|
|||||||
try{
|
try{
|
||||||
$sql = 'INSERT INTO ' . $this->cardsTableName . ' ('
|
$sql = 'INSERT INTO ' . $this->cardsTableName . ' ('
|
||||||
. 'id, '
|
. 'id, '
|
||||||
. 'owner,'
|
|
||||||
. 'addressbookid, '
|
. 'addressbookid, '
|
||||||
. 'fullname, '
|
. 'fullname, '
|
||||||
. 'carddata, '
|
. 'carddata, '
|
||||||
. 'uri, '
|
|
||||||
. 'lastmodified'
|
. 'lastmodified'
|
||||||
. ') VALUES ('
|
. ') VALUES ('
|
||||||
. '?,'
|
. '?,'
|
||||||
. '?,'
|
. '?,'
|
||||||
. '?,'
|
. '?,'
|
||||||
. '?,'
|
. '?,'
|
||||||
. '?,'
|
|
||||||
. '?,'
|
|
||||||
. '?'
|
. '?'
|
||||||
. ')';
|
. ')';
|
||||||
|
|
||||||
$query = \OCP\DB::prepare($sql);
|
$query = \OCP\DB::prepare($sql);
|
||||||
|
|
||||||
$contact = new Contact(
|
$vcard = \Sabre\VObject\Component::create('VCARD');
|
||||||
$addressBook = new AddressBook($this , $this->getAddressBooksForUser()), // since there is only one addressbook with OC users for each OC user we can use this function
|
$vcard->FN = \OCP\User::getDisplayName($user);
|
||||||
$this,
|
$now = new \DateTime('now');
|
||||||
array(
|
$vcard->REV = $now->format(\DateTime::W3C);
|
||||||
"id" => $user,
|
|
||||||
"lastmodified" => time(),
|
$appinfo = \OCP\App::getAppInfo('contacts');
|
||||||
"displayname" => \OCP\User::getDisplayName($user),
|
$appversion = \OCP\App::getAppVersion('contacts');
|
||||||
"fullname" => \OCP\User::getDisplayName($user)
|
$prodid = '-//ownCloud//NONSGML ' . $appinfo['name'] . ' ' . $appversion.'//EN';
|
||||||
)
|
$vcard->PRODID = $prodid;
|
||||||
);
|
|
||||||
$carddata = $this->generateCardData($contact);
|
|
||||||
$result = $query->execute(array($user, $this->userid, $addressbookid, \OCP\User::getDisplayName($user), $carddata->serialize(), 'test', time()));
|
$result = $query->execute(array($user, $this->userid, \OCP\User::getDisplayName($user), $vcard->serialize(), time()));
|
||||||
|
|
||||||
if (\OCP\DB::isError($result)) {
|
if (\OCP\DB::isError($result)) {
|
||||||
\OCP\Util::writeLog('contacts', __METHOD__. 'DB error: '
|
\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
|
* @inheritdoc
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user