mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-11-29 11:24:11 +01:00
More fixes
This commit is contained in:
parent
b670a85387
commit
d724149c56
@ -59,6 +59,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
/**
|
/**
|
||||||
* @param AbstractBackend $backend The storage backend
|
* @param AbstractBackend $backend The storage backend
|
||||||
* @param array $addressBookInfo
|
* @param array $addressBookInfo
|
||||||
|
* @throws \Exception
|
||||||
*/
|
*/
|
||||||
public function __construct(Backend\AbstractBackend $backend, array $addressBookInfo) {
|
public function __construct(Backend\AbstractBackend $backend, array $addressBookInfo) {
|
||||||
self::$l10n = \OCP\Util::getL10N('contacts');
|
self::$l10n = \OCP\Util::getL10N('contacts');
|
||||||
@ -69,8 +70,10 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
if ($id === false) {
|
if ($id === false) {
|
||||||
throw new \Exception('Error creating address book.', 500);
|
throw new \Exception('Error creating address book.', 500);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->addressBookInfo = $this->backend->getAddressBook($id);
|
$this->addressBookInfo = $this->backend->getAddressBook($id);
|
||||||
}
|
}
|
||||||
|
|
||||||
//\OCP\Util::writeLog('contacts', __METHOD__.' backend: ' . print_r($this->backend, true), \OCP\Util::DEBUG);
|
//\OCP\Util::writeLog('contacts', __METHOD__.' backend: ' . print_r($this->backend, true), \OCP\Util::DEBUG);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -152,12 +155,14 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
*
|
*
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @return Contact|null
|
* @return Contact|null
|
||||||
|
* @throws \Exception On not found
|
||||||
*/
|
*/
|
||||||
public function getChild($id) {
|
public function getChild($id) {
|
||||||
//\OCP\Util::writeLog('contacts', __METHOD__.' id: '.$id, \OCP\Util::DEBUG);
|
//\OCP\Util::writeLog('contacts', __METHOD__.' id: '.$id, \OCP\Util::DEBUG);
|
||||||
if (!$this->hasPermission(\OCP\PERMISSION_READ)) {
|
if (!$this->hasPermission(\OCP\PERMISSION_READ)) {
|
||||||
throw new \Exception(self::$l10n->t('You do not have permissions to see this contacts'), 403);
|
throw new \Exception(self::$l10n->t('You do not have permissions to see this contacts'), 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($this->objects[$id])) {
|
if (!isset($this->objects[$id])) {
|
||||||
$contact = $this->backend->getContact($this->getId(), $id);
|
$contact = $this->backend->getContact($this->getId(), $id);
|
||||||
if ($contact) {
|
if ($contact) {
|
||||||
@ -166,6 +171,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
throw new \Exception(self::$l10n->t('Contact not found'), 404);
|
throw new \Exception(self::$l10n->t('Contact not found'), 404);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// When requesting a single contact we preparse it
|
// When requesting a single contact we preparse it
|
||||||
if (isset($this->objects[$id])) {
|
if (isset($this->objects[$id])) {
|
||||||
$this->objects[$id]->retrieve();
|
$this->objects[$id]->retrieve();
|
||||||
@ -201,8 +207,10 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
if (!isset($this->objects[$contact['id']])) {
|
if (!isset($this->objects[$contact['id']])) {
|
||||||
$this->objects[$contact['id']] = new Contact($this, $this->backend, $contact);
|
$this->objects[$contact['id']] = new Contact($this, $this->backend, $contact);
|
||||||
}
|
}
|
||||||
|
|
||||||
$contacts[] = $this->objects[$contact['id']];
|
$contacts[] = $this->objects[$contact['id']];
|
||||||
}
|
}
|
||||||
|
|
||||||
//\OCP\Util::writeLog('contacts', __METHOD__.' children: '.count($contacts), \OCP\Util::DEBUG);
|
//\OCP\Util::writeLog('contacts', __METHOD__.' children: '.count($contacts), \OCP\Util::DEBUG);
|
||||||
return $contacts;
|
return $contacts;
|
||||||
}
|
}
|
||||||
@ -214,22 +222,29 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
*
|
*
|
||||||
* @param array|VObject\VCard $data
|
* @param array|VObject\VCard $data
|
||||||
* @return int|bool
|
* @return int|bool
|
||||||
|
* @throws \Exception on missing permissions
|
||||||
*/
|
*/
|
||||||
public function addChild($data = null) {
|
public function addChild($data = null) {
|
||||||
if (!$this->hasPermission(\OCP\PERMISSION_CREATE)) {
|
if (!$this->hasPermission(\OCP\PERMISSION_CREATE)) {
|
||||||
throw new \Exception(self::$l10n->t('You do not have permissions add contacts to the address book'), 403);
|
throw new \Exception(self::$l10n->t('You do not have permissions add contacts to the address book'), 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_CREATE)) {
|
if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_CREATE)) {
|
||||||
throw new \Exception(self::$l10n->t('The backend for this address book does not support adding contacts'), 501);
|
throw new \Exception(self::$l10n->t('The backend for this address book does not support adding contacts'), 501);
|
||||||
}
|
}
|
||||||
|
|
||||||
$contact = new Contact($this, $this->backend, $data);
|
$contact = new Contact($this, $this->backend, $data);
|
||||||
|
|
||||||
if ($contact->save() === false) {
|
if ($contact->save() === false) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$id = $contact->getId();
|
$id = $contact->getId();
|
||||||
|
|
||||||
if ($this->count() !== null) {
|
if ($this->count() !== null) {
|
||||||
$this->_count += 1;
|
$this->_count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
\OCP\Util::writeLog('contacts', __METHOD__.' id: '.$id, \OCP\Util::DEBUG);
|
\OCP\Util::writeLog('contacts', __METHOD__.' id: '.$id, \OCP\Util::DEBUG);
|
||||||
return $id;
|
return $id;
|
||||||
}
|
}
|
||||||
@ -246,18 +261,23 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
if (!$this->hasPermission(\OCP\PERMISSION_DELETE)) {
|
if (!$this->hasPermission(\OCP\PERMISSION_DELETE)) {
|
||||||
throw new \Exception(self::$l10n->t('You do not have permissions to delete this contact'), 403);
|
throw new \Exception(self::$l10n->t('You do not have permissions to delete this contact'), 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_DELETE)) {
|
if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_DELETE)) {
|
||||||
throw new \Exception(self::$l10n->t('The backend for this address book does not support deleting contacts'), 501);
|
throw new \Exception(self::$l10n->t('The backend for this address book does not support deleting contacts'), 501);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->backend->deleteContact($this->getId(), $id, $options)) {
|
if ($this->backend->deleteContact($this->getId(), $id, $options)) {
|
||||||
if (isset($this->objects[$id])) {
|
if (isset($this->objects[$id])) {
|
||||||
unset($this->objects[$id]);
|
unset($this->objects[$id]);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->count() !== null) {
|
if ($this->count() !== null) {
|
||||||
$this->_count -= 1;
|
$this->_count -= 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -272,6 +292,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
if (!$this->hasPermission(\OCP\PERMISSION_DELETE)) {
|
if (!$this->hasPermission(\OCP\PERMISSION_DELETE)) {
|
||||||
throw new \Exception(self::$l10n->t('You do not have permissions to delete this contact'), 403);
|
throw new \Exception(self::$l10n->t('You do not have permissions to delete this contact'), 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_DELETE)) {
|
if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_DELETE)) {
|
||||||
throw new \Exception(self::$l10n->t('The backend for this address book does not support deleting contacts'), 501);
|
throw new \Exception(self::$l10n->t('The backend for this address book does not support deleting contacts'), 501);
|
||||||
}
|
}
|
||||||
@ -321,6 +342,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
if (!isset($this->_count)) {
|
if (!isset($this->_count)) {
|
||||||
$this->_count = $this->backend->numContacts($this->getId());
|
$this->_count = $this->backend->numContacts($this->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->_count;
|
return $this->_count;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -335,12 +357,15 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
if (!$this->hasPermission(\OCP\PERMISSION_UPDATE)) {
|
if (!$this->hasPermission(\OCP\PERMISSION_UPDATE)) {
|
||||||
throw new \Exception('Access denied');
|
throw new \Exception('Access denied');
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_UPDATE)) {
|
if (!$this->getBackend()->hasContactMethodFor(\OCP\PERMISSION_UPDATE)) {
|
||||||
throw new \Exception(self::$l10n->t('The backend for this address book does not support updating'), 501);
|
throw new \Exception(self::$l10n->t('The backend for this address book does not support updating'), 501);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($data) === 0) {
|
if (count($data) === 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($data as $key => $value) {
|
foreach ($data as $key => $value) {
|
||||||
switch ($key) {
|
switch ($key) {
|
||||||
case 'displayname':
|
case 'displayname':
|
||||||
@ -351,6 +376,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->backend->updateAddressBook($this->getId(), $data);
|
return $this->backend->updateAddressBook($this->getId(), $data);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -363,6 +389,7 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
if (!$this->hasPermission(\OCP\PERMISSION_DELETE)) {
|
if (!$this->hasPermission(\OCP\PERMISSION_DELETE)) {
|
||||||
throw new Exception(self::$l10n->t('You don\'t have permissions to delete the address book.'), 403);
|
throw new Exception(self::$l10n->t('You don\'t have permissions to delete the address book.'), 403);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->backend->deleteAddressBook($this->getId());
|
return $this->backend->deleteAddressBook($this->getId());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -386,11 +413,13 @@ class Addressbook extends AbstractPIMCollection {
|
|||||||
public function getBirthdayEvents() {
|
public function getBirthdayEvents() {
|
||||||
|
|
||||||
$events = array();
|
$events = array();
|
||||||
|
|
||||||
foreach ($this->getChildren() as $contact) {
|
foreach ($this->getChildren() as $contact) {
|
||||||
if ($event = $contact->getBirthdayEvent()) {
|
if ($event = $contact->getBirthdayEvent()) {
|
||||||
$events[] = $event;
|
$events[] = $event;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return $events;
|
return $events;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -113,13 +113,18 @@ class App {
|
|||||||
\OCP\Util::ERROR
|
\OCP\Util::ERROR
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($addressBooks as $addressBook) {
|
foreach ($addressBooks as $addressBook) {
|
||||||
$addressBook['backend'] = $backendName;
|
$addressBook['backend'] = $backendName;
|
||||||
self::$addressBooks[] = new AddressBook($backend, $addressBook);
|
self::$addressBooks[] = new AddressBook($backend, $addressBook);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return self::$addressBooks;
|
return self::$addressBooks;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -142,9 +147,11 @@ class App {
|
|||||||
|
|
||||||
$backend = self::getBackend($backendName, $this->user);
|
$backend = self::getBackend($backendName, $this->user);
|
||||||
$info = $backend->getAddressBook($addressbookid);
|
$info = $backend->getAddressBook($addressbookid);
|
||||||
|
|
||||||
if (!$info) {
|
if (!$info) {
|
||||||
throw new \Exception(self::$l10n->t('Address book not found'), 404);
|
throw new \Exception(self::$l10n->t('Address book not found'), 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
$addressBook = new AddressBook($backend, $info);
|
$addressBook = new AddressBook($backend, $info);
|
||||||
self::$addressBooks[] = $addressBook;
|
self::$addressBooks[] = $addressBook;
|
||||||
return $addressBook;
|
return $addressBook;
|
||||||
|
@ -94,7 +94,6 @@ abstract class AbstractBackend {
|
|||||||
$permissions = 0;
|
$permissions = 0;
|
||||||
|
|
||||||
foreach ($this->possibleContactPermissions as $permission => $methodName) {
|
foreach ($this->possibleContactPermissions as $permission => $methodName) {
|
||||||
|
|
||||||
if(method_exists($this, $methodName)) {
|
if(method_exists($this, $methodName)) {
|
||||||
$permissions |= $permission;
|
$permissions |= $permission;
|
||||||
}
|
}
|
||||||
@ -117,7 +116,6 @@ abstract class AbstractBackend {
|
|||||||
$permissions = 0;
|
$permissions = 0;
|
||||||
|
|
||||||
foreach ($this->possibleAddressBookPermissions as $permission => $methodName) {
|
foreach ($this->possibleAddressBookPermissions as $permission => $methodName) {
|
||||||
|
|
||||||
if (method_exists($this, $methodName)) {
|
if (method_exists($this, $methodName)) {
|
||||||
$permissions |= $permission;
|
$permissions |= $permission;
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,6 @@ class Database extends AbstractBackend {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function hasAddressBook($addressbookid, array $options = array()) {
|
public function hasAddressBook($addressbookid, array $options = array()) {
|
||||||
@ -190,7 +189,6 @@ class Database extends AbstractBackend {
|
|||||||
$updates = array();
|
$updates = array();
|
||||||
|
|
||||||
if (isset($changes['displayname'])) {
|
if (isset($changes['displayname'])) {
|
||||||
|
|
||||||
$query .= '`displayname` = ?, ';
|
$query .= '`displayname` = ?, ';
|
||||||
$updates[] = $changes['displayname'];
|
$updates[] = $changes['displayname'];
|
||||||
|
|
||||||
@ -331,7 +329,6 @@ class Database extends AbstractBackend {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_null($result)) {
|
if (!is_null($result)) {
|
||||||
|
|
||||||
while ($id = $result->fetchOne()) {
|
while ($id = $result->fetchOne()) {
|
||||||
$ids[] = $id;
|
$ids[] = $id;
|
||||||
}
|
}
|
||||||
|
@ -53,7 +53,7 @@ class Contact extends VObject\VCard implements IPIMObject {
|
|||||||
* Create a new Contact object
|
* Create a new Contact object
|
||||||
*
|
*
|
||||||
* @param AddressBook $parent
|
* @param AddressBook $parent
|
||||||
* @param AbstractBackend $backend
|
* @param Backend\AbstractBackend $backend
|
||||||
* @param mixed $data
|
* @param mixed $data
|
||||||
*/
|
*/
|
||||||
public function __construct($parent, $backend, $data = null) {
|
public function __construct($parent, $backend, $data = null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user