@@ -33,100 +33,100 @@ |
||
33 | 33 | */ |
34 | 34 | abstract class ExternalAddressBook implements IAddressBook, DAV\IProperties { |
35 | 35 | |
36 | - /** @var string */ |
|
37 | - private const PREFIX = 'z-app-generated'; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - * |
|
42 | - * Double dash is a valid delimiter, |
|
43 | - * because it will always split the URIs correctly: |
|
44 | - * - our prefix contains only one dash and won't be split |
|
45 | - * - appIds are not allowed to contain dashes as per spec: |
|
46 | - * > must contain only lowercase ASCII characters and underscore |
|
47 | - * - explode has a limit of three, so even if the app-generated |
|
48 | - * URI has double dashes, it won't be split |
|
49 | - */ |
|
50 | - private const DELIMITER = '--'; |
|
51 | - |
|
52 | - /** @var string */ |
|
53 | - private $appId; |
|
54 | - |
|
55 | - /** @var string */ |
|
56 | - private $uri; |
|
57 | - |
|
58 | - /** |
|
59 | - * @param string $appId |
|
60 | - * @param string $uri |
|
61 | - */ |
|
62 | - public function __construct(string $appId, string $uri) { |
|
63 | - $this->appId = $appId; |
|
64 | - $this->uri = $uri; |
|
65 | - } |
|
66 | - |
|
67 | - /** |
|
68 | - * @inheritDoc |
|
69 | - */ |
|
70 | - final public function getName() { |
|
71 | - return implode(self::DELIMITER, [ |
|
72 | - self::PREFIX, |
|
73 | - $this->appId, |
|
74 | - $this->uri, |
|
75 | - ]); |
|
76 | - } |
|
77 | - |
|
78 | - /** |
|
79 | - * @inheritDoc |
|
80 | - */ |
|
81 | - final public function setName($name) { |
|
82 | - throw new DAV\Exception\MethodNotAllowed('Renaming address books is not yet supported'); |
|
83 | - } |
|
84 | - |
|
85 | - /** |
|
86 | - * @inheritDoc |
|
87 | - */ |
|
88 | - final public function createDirectory($name) { |
|
89 | - throw new DAV\Exception\MethodNotAllowed('Creating collections in address book objects is not allowed'); |
|
90 | - } |
|
91 | - |
|
92 | - /** |
|
93 | - * Checks whether the address book uri is app-generated |
|
94 | - * |
|
95 | - * @param string $uri |
|
96 | - * |
|
97 | - * @return bool |
|
98 | - */ |
|
99 | - public static function isAppGeneratedAddressBook(string $uri): bool { |
|
100 | - return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2; |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * Splits an app-generated uri into appId and uri |
|
105 | - * |
|
106 | - * @param string $uri |
|
107 | - * |
|
108 | - * @return array |
|
109 | - */ |
|
110 | - public static function splitAppGeneratedAddressBookUri(string $uri): array { |
|
111 | - $array = array_slice(explode(self::DELIMITER, $uri, 3), 1); |
|
112 | - // Check the array has expected amount of elements |
|
113 | - // and none of them is an empty string |
|
114 | - if (\count($array) !== 2 || \in_array('', $array, true)) { |
|
115 | - throw new \InvalidArgumentException('Provided address book uri was not app-generated'); |
|
116 | - } |
|
117 | - |
|
118 | - return $array; |
|
119 | - } |
|
120 | - |
|
121 | - /** |
|
122 | - * Checks whether a address book name the user wants to create violates |
|
123 | - * the reserved name for URIs |
|
124 | - * |
|
125 | - * @param string $uri |
|
126 | - * |
|
127 | - * @return bool |
|
128 | - */ |
|
129 | - public static function doesViolateReservedName(string $uri): bool { |
|
130 | - return strpos($uri, self::PREFIX) === 0; |
|
131 | - } |
|
36 | + /** @var string */ |
|
37 | + private const PREFIX = 'z-app-generated'; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + * |
|
42 | + * Double dash is a valid delimiter, |
|
43 | + * because it will always split the URIs correctly: |
|
44 | + * - our prefix contains only one dash and won't be split |
|
45 | + * - appIds are not allowed to contain dashes as per spec: |
|
46 | + * > must contain only lowercase ASCII characters and underscore |
|
47 | + * - explode has a limit of three, so even if the app-generated |
|
48 | + * URI has double dashes, it won't be split |
|
49 | + */ |
|
50 | + private const DELIMITER = '--'; |
|
51 | + |
|
52 | + /** @var string */ |
|
53 | + private $appId; |
|
54 | + |
|
55 | + /** @var string */ |
|
56 | + private $uri; |
|
57 | + |
|
58 | + /** |
|
59 | + * @param string $appId |
|
60 | + * @param string $uri |
|
61 | + */ |
|
62 | + public function __construct(string $appId, string $uri) { |
|
63 | + $this->appId = $appId; |
|
64 | + $this->uri = $uri; |
|
65 | + } |
|
66 | + |
|
67 | + /** |
|
68 | + * @inheritDoc |
|
69 | + */ |
|
70 | + final public function getName() { |
|
71 | + return implode(self::DELIMITER, [ |
|
72 | + self::PREFIX, |
|
73 | + $this->appId, |
|
74 | + $this->uri, |
|
75 | + ]); |
|
76 | + } |
|
77 | + |
|
78 | + /** |
|
79 | + * @inheritDoc |
|
80 | + */ |
|
81 | + final public function setName($name) { |
|
82 | + throw new DAV\Exception\MethodNotAllowed('Renaming address books is not yet supported'); |
|
83 | + } |
|
84 | + |
|
85 | + /** |
|
86 | + * @inheritDoc |
|
87 | + */ |
|
88 | + final public function createDirectory($name) { |
|
89 | + throw new DAV\Exception\MethodNotAllowed('Creating collections in address book objects is not allowed'); |
|
90 | + } |
|
91 | + |
|
92 | + /** |
|
93 | + * Checks whether the address book uri is app-generated |
|
94 | + * |
|
95 | + * @param string $uri |
|
96 | + * |
|
97 | + * @return bool |
|
98 | + */ |
|
99 | + public static function isAppGeneratedAddressBook(string $uri): bool { |
|
100 | + return strpos($uri, self::PREFIX) === 0 && substr_count($uri, self::DELIMITER) >= 2; |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * Splits an app-generated uri into appId and uri |
|
105 | + * |
|
106 | + * @param string $uri |
|
107 | + * |
|
108 | + * @return array |
|
109 | + */ |
|
110 | + public static function splitAppGeneratedAddressBookUri(string $uri): array { |
|
111 | + $array = array_slice(explode(self::DELIMITER, $uri, 3), 1); |
|
112 | + // Check the array has expected amount of elements |
|
113 | + // and none of them is an empty string |
|
114 | + if (\count($array) !== 2 || \in_array('', $array, true)) { |
|
115 | + throw new \InvalidArgumentException('Provided address book uri was not app-generated'); |
|
116 | + } |
|
117 | + |
|
118 | + return $array; |
|
119 | + } |
|
120 | + |
|
121 | + /** |
|
122 | + * Checks whether a address book name the user wants to create violates |
|
123 | + * the reserved name for URIs |
|
124 | + * |
|
125 | + * @param string $uri |
|
126 | + * |
|
127 | + * @return bool |
|
128 | + */ |
|
129 | + public static function doesViolateReservedName(string $uri): bool { |
|
130 | + return strpos($uri, self::PREFIX) === 0; |
|
131 | + } |
|
132 | 132 | } |
@@ -31,110 +31,110 @@ |
||
31 | 31 | use OCP\IUser; |
32 | 32 | |
33 | 33 | class RecentContactMapper extends QBMapper { |
34 | - public const TABLE_NAME = 'recent_contact'; |
|
35 | - |
|
36 | - public function __construct(IDBConnection $db) { |
|
37 | - parent::__construct($db, self::TABLE_NAME); |
|
38 | - } |
|
39 | - |
|
40 | - /** |
|
41 | - * @return RecentContact[] |
|
42 | - */ |
|
43 | - public function findAll(string $uid): array { |
|
44 | - $qb = $this->db->getQueryBuilder(); |
|
45 | - |
|
46 | - $select = $qb |
|
47 | - ->select('*') |
|
48 | - ->from($this->getTableName()) |
|
49 | - ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
50 | - |
|
51 | - return $this->findEntities($select); |
|
52 | - } |
|
53 | - |
|
54 | - /** |
|
55 | - * @param string $uid |
|
56 | - * @param int $id |
|
57 | - * |
|
58 | - * @return RecentContact |
|
59 | - * @throws DoesNotExistException |
|
60 | - */ |
|
61 | - public function find(string $uid, int $id): RecentContact { |
|
62 | - $qb = $this->db->getQueryBuilder(); |
|
63 | - |
|
64 | - $select = $qb |
|
65 | - ->select('*') |
|
66 | - ->from($this->getTableName()) |
|
67 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $qb::PARAM_INT))) |
|
68 | - ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
69 | - |
|
70 | - return $this->findEntity($select); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @param IUser $user |
|
75 | - * @param string|null $uid |
|
76 | - * @param string|null $email |
|
77 | - * @param string|null $cloudId |
|
78 | - * |
|
79 | - * @return RecentContact[] |
|
80 | - */ |
|
81 | - public function findMatch(IUser $user, |
|
82 | - ?string $uid, |
|
83 | - ?string $email, |
|
84 | - ?string $cloudId): array { |
|
85 | - $qb = $this->db->getQueryBuilder(); |
|
86 | - |
|
87 | - $or = $qb->expr()->orX(); |
|
88 | - if ($uid !== null) { |
|
89 | - $or->add($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); |
|
90 | - } |
|
91 | - if ($email !== null) { |
|
92 | - $or->add($qb->expr()->eq('email', $qb->createNamedParameter($email))); |
|
93 | - } |
|
94 | - if ($cloudId !== null) { |
|
95 | - $or->add($qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId))); |
|
96 | - } |
|
97 | - |
|
98 | - $select = $qb |
|
99 | - ->select('*') |
|
100 | - ->from($this->getTableName()) |
|
101 | - ->where($or) |
|
102 | - ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID()))); |
|
103 | - |
|
104 | - return $this->findEntities($select); |
|
105 | - } |
|
106 | - |
|
107 | - /** |
|
108 | - * @param string $uid |
|
109 | - * @return int|null |
|
110 | - */ |
|
111 | - public function findLastUpdatedForUserId(string $uid):?int { |
|
112 | - $qb = $this->db->getQueryBuilder(); |
|
113 | - |
|
114 | - $select = $qb |
|
115 | - ->select('last_contact') |
|
116 | - ->from($this->getTableName()) |
|
117 | - ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))) |
|
118 | - ->orderBy('last_contact', 'DESC') |
|
119 | - ->setMaxResults(1); |
|
120 | - |
|
121 | - $cursor = $select->execute(); |
|
122 | - $row = $cursor->fetch(); |
|
123 | - |
|
124 | - if ($row === false) { |
|
125 | - return null; |
|
126 | - } |
|
127 | - |
|
128 | - return (int)$row['last_contact']; |
|
129 | - } |
|
130 | - |
|
131 | - public function cleanUp(int $olderThan): void { |
|
132 | - $qb = $this->db->getQueryBuilder(); |
|
133 | - |
|
134 | - $delete = $qb |
|
135 | - ->delete($this->getTableName()) |
|
136 | - ->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan))); |
|
137 | - |
|
138 | - $delete->execute(); |
|
139 | - } |
|
34 | + public const TABLE_NAME = 'recent_contact'; |
|
35 | + |
|
36 | + public function __construct(IDBConnection $db) { |
|
37 | + parent::__construct($db, self::TABLE_NAME); |
|
38 | + } |
|
39 | + |
|
40 | + /** |
|
41 | + * @return RecentContact[] |
|
42 | + */ |
|
43 | + public function findAll(string $uid): array { |
|
44 | + $qb = $this->db->getQueryBuilder(); |
|
45 | + |
|
46 | + $select = $qb |
|
47 | + ->select('*') |
|
48 | + ->from($this->getTableName()) |
|
49 | + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
50 | + |
|
51 | + return $this->findEntities($select); |
|
52 | + } |
|
53 | + |
|
54 | + /** |
|
55 | + * @param string $uid |
|
56 | + * @param int $id |
|
57 | + * |
|
58 | + * @return RecentContact |
|
59 | + * @throws DoesNotExistException |
|
60 | + */ |
|
61 | + public function find(string $uid, int $id): RecentContact { |
|
62 | + $qb = $this->db->getQueryBuilder(); |
|
63 | + |
|
64 | + $select = $qb |
|
65 | + ->select('*') |
|
66 | + ->from($this->getTableName()) |
|
67 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $qb::PARAM_INT))) |
|
68 | + ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
69 | + |
|
70 | + return $this->findEntity($select); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @param IUser $user |
|
75 | + * @param string|null $uid |
|
76 | + * @param string|null $email |
|
77 | + * @param string|null $cloudId |
|
78 | + * |
|
79 | + * @return RecentContact[] |
|
80 | + */ |
|
81 | + public function findMatch(IUser $user, |
|
82 | + ?string $uid, |
|
83 | + ?string $email, |
|
84 | + ?string $cloudId): array { |
|
85 | + $qb = $this->db->getQueryBuilder(); |
|
86 | + |
|
87 | + $or = $qb->expr()->orX(); |
|
88 | + if ($uid !== null) { |
|
89 | + $or->add($qb->expr()->eq('uid', $qb->createNamedParameter($uid))); |
|
90 | + } |
|
91 | + if ($email !== null) { |
|
92 | + $or->add($qb->expr()->eq('email', $qb->createNamedParameter($email))); |
|
93 | + } |
|
94 | + if ($cloudId !== null) { |
|
95 | + $or->add($qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId))); |
|
96 | + } |
|
97 | + |
|
98 | + $select = $qb |
|
99 | + ->select('*') |
|
100 | + ->from($this->getTableName()) |
|
101 | + ->where($or) |
|
102 | + ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID()))); |
|
103 | + |
|
104 | + return $this->findEntities($select); |
|
105 | + } |
|
106 | + |
|
107 | + /** |
|
108 | + * @param string $uid |
|
109 | + * @return int|null |
|
110 | + */ |
|
111 | + public function findLastUpdatedForUserId(string $uid):?int { |
|
112 | + $qb = $this->db->getQueryBuilder(); |
|
113 | + |
|
114 | + $select = $qb |
|
115 | + ->select('last_contact') |
|
116 | + ->from($this->getTableName()) |
|
117 | + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))) |
|
118 | + ->orderBy('last_contact', 'DESC') |
|
119 | + ->setMaxResults(1); |
|
120 | + |
|
121 | + $cursor = $select->execute(); |
|
122 | + $row = $cursor->fetch(); |
|
123 | + |
|
124 | + if ($row === false) { |
|
125 | + return null; |
|
126 | + } |
|
127 | + |
|
128 | + return (int)$row['last_contact']; |
|
129 | + } |
|
130 | + |
|
131 | + public function cleanUp(int $olderThan): void { |
|
132 | + $qb = $this->db->getQueryBuilder(); |
|
133 | + |
|
134 | + $delete = $qb |
|
135 | + ->delete($this->getTableName()) |
|
136 | + ->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan))); |
|
137 | + |
|
138 | + $delete->execute(); |
|
139 | + } |
|
140 | 140 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @param string $uid |
109 | 109 | * @return int|null |
110 | 110 | */ |
111 | - public function findLastUpdatedForUserId(string $uid):?int { |
|
111 | + public function findLastUpdatedForUserId(string $uid): ?int { |
|
112 | 112 | $qb = $this->db->getQueryBuilder(); |
113 | 113 | |
114 | 114 | $select = $qb |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | return null; |
126 | 126 | } |
127 | 127 | |
128 | - return (int)$row['last_contact']; |
|
128 | + return (int) $row['last_contact']; |
|
129 | 129 | } |
130 | 130 | |
131 | 131 | public function cleanUp(int $olderThan): void { |
@@ -39,138 +39,138 @@ |
||
39 | 39 | use Sabre\DAVACL\IACL; |
40 | 40 | |
41 | 41 | class AddressBook extends ExternalAddressBook implements IACL { |
42 | - public const URI = 'recent'; |
|
43 | - |
|
44 | - use ACLTrait; |
|
45 | - |
|
46 | - /** @var RecentContactMapper */ |
|
47 | - private $mapper; |
|
48 | - |
|
49 | - /** @var IL10N */ |
|
50 | - private $l10n; |
|
51 | - |
|
52 | - /** @var string */ |
|
53 | - private $principalUri; |
|
54 | - |
|
55 | - public function __construct(RecentContactMapper $mapper, |
|
56 | - IL10N $l10n, |
|
57 | - string $principalUri) { |
|
58 | - parent::__construct(Application::APP_ID, self::URI); |
|
59 | - |
|
60 | - $this->mapper = $mapper; |
|
61 | - $this->l10n = $l10n; |
|
62 | - $this->principalUri = $principalUri; |
|
63 | - } |
|
64 | - |
|
65 | - /** |
|
66 | - * @inheritDoc |
|
67 | - */ |
|
68 | - public function delete(): void { |
|
69 | - throw new Exception("This addressbook is immutable"); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @inheritDoc |
|
74 | - */ |
|
75 | - public function createFile($name, $data = null) { |
|
76 | - throw new Exception("This addressbook is immutable"); |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @inheritDoc |
|
81 | - * @throws NotFound |
|
82 | - */ |
|
83 | - public function getChild($name) { |
|
84 | - try { |
|
85 | - return new Card( |
|
86 | - $this->mapper->find( |
|
87 | - $this->getUid(), |
|
88 | - (int)$name |
|
89 | - ), |
|
90 | - $this->principalUri, |
|
91 | - $this->getACL() |
|
92 | - ); |
|
93 | - } catch (DoesNotExistException $ex) { |
|
94 | - throw new NotFound("Contact does not exist: " . $ex->getMessage(), 0, $ex); |
|
95 | - } |
|
96 | - } |
|
97 | - |
|
98 | - /** |
|
99 | - * @inheritDoc |
|
100 | - */ |
|
101 | - public function getChildren(): array { |
|
102 | - return array_map( |
|
103 | - function (RecentContact $contact) { |
|
104 | - return new Card( |
|
105 | - $contact, |
|
106 | - $this->principalUri, |
|
107 | - $this->getACL() |
|
108 | - ); |
|
109 | - }, |
|
110 | - $this->mapper->findAll($this->getUid()) |
|
111 | - ); |
|
112 | - } |
|
113 | - |
|
114 | - /** |
|
115 | - * @inheritDoc |
|
116 | - */ |
|
117 | - public function childExists($name) { |
|
118 | - try { |
|
119 | - $this->mapper->find( |
|
120 | - $this->getUid(), |
|
121 | - (int)$name |
|
122 | - ); |
|
123 | - return true; |
|
124 | - } catch (DoesNotExistException $e) { |
|
125 | - return false; |
|
126 | - } |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @inheritDoc |
|
131 | - */ |
|
132 | - public function getLastModified(): ?int { |
|
133 | - return $this->mapper->findLastUpdatedForUserId($this->getUid()); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @inheritDoc |
|
138 | - */ |
|
139 | - public function propPatch(PropPatch $propPatch) { |
|
140 | - throw new Exception("This addressbook is immutable"); |
|
141 | - } |
|
142 | - |
|
143 | - /** |
|
144 | - * @inheritDoc |
|
145 | - */ |
|
146 | - public function getProperties($properties) { |
|
147 | - return [ |
|
148 | - 'principaluri' => $this->principalUri, |
|
149 | - '{DAV:}displayname' => $this->l10n->t('Recently contacted'), |
|
150 | - '{' . Plugin::NS_OWNCLOUD . '}read-only' => true, |
|
151 | - '{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0), |
|
152 | - ]; |
|
153 | - } |
|
154 | - |
|
155 | - public function getOwner(): string { |
|
156 | - return $this->principalUri; |
|
157 | - } |
|
158 | - |
|
159 | - /** |
|
160 | - * @inheritDoc |
|
161 | - */ |
|
162 | - public function getACL() { |
|
163 | - return [ |
|
164 | - [ |
|
165 | - 'privilege' => '{DAV:}read', |
|
166 | - 'principal' => $this->getOwner(), |
|
167 | - 'protected' => true, |
|
168 | - ], |
|
169 | - ]; |
|
170 | - } |
|
171 | - |
|
172 | - private function getUid(): string { |
|
173 | - list(, $uid) = \Sabre\Uri\split($this->principalUri); |
|
174 | - return $uid; |
|
175 | - } |
|
42 | + public const URI = 'recent'; |
|
43 | + |
|
44 | + use ACLTrait; |
|
45 | + |
|
46 | + /** @var RecentContactMapper */ |
|
47 | + private $mapper; |
|
48 | + |
|
49 | + /** @var IL10N */ |
|
50 | + private $l10n; |
|
51 | + |
|
52 | + /** @var string */ |
|
53 | + private $principalUri; |
|
54 | + |
|
55 | + public function __construct(RecentContactMapper $mapper, |
|
56 | + IL10N $l10n, |
|
57 | + string $principalUri) { |
|
58 | + parent::__construct(Application::APP_ID, self::URI); |
|
59 | + |
|
60 | + $this->mapper = $mapper; |
|
61 | + $this->l10n = $l10n; |
|
62 | + $this->principalUri = $principalUri; |
|
63 | + } |
|
64 | + |
|
65 | + /** |
|
66 | + * @inheritDoc |
|
67 | + */ |
|
68 | + public function delete(): void { |
|
69 | + throw new Exception("This addressbook is immutable"); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @inheritDoc |
|
74 | + */ |
|
75 | + public function createFile($name, $data = null) { |
|
76 | + throw new Exception("This addressbook is immutable"); |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @inheritDoc |
|
81 | + * @throws NotFound |
|
82 | + */ |
|
83 | + public function getChild($name) { |
|
84 | + try { |
|
85 | + return new Card( |
|
86 | + $this->mapper->find( |
|
87 | + $this->getUid(), |
|
88 | + (int)$name |
|
89 | + ), |
|
90 | + $this->principalUri, |
|
91 | + $this->getACL() |
|
92 | + ); |
|
93 | + } catch (DoesNotExistException $ex) { |
|
94 | + throw new NotFound("Contact does not exist: " . $ex->getMessage(), 0, $ex); |
|
95 | + } |
|
96 | + } |
|
97 | + |
|
98 | + /** |
|
99 | + * @inheritDoc |
|
100 | + */ |
|
101 | + public function getChildren(): array { |
|
102 | + return array_map( |
|
103 | + function (RecentContact $contact) { |
|
104 | + return new Card( |
|
105 | + $contact, |
|
106 | + $this->principalUri, |
|
107 | + $this->getACL() |
|
108 | + ); |
|
109 | + }, |
|
110 | + $this->mapper->findAll($this->getUid()) |
|
111 | + ); |
|
112 | + } |
|
113 | + |
|
114 | + /** |
|
115 | + * @inheritDoc |
|
116 | + */ |
|
117 | + public function childExists($name) { |
|
118 | + try { |
|
119 | + $this->mapper->find( |
|
120 | + $this->getUid(), |
|
121 | + (int)$name |
|
122 | + ); |
|
123 | + return true; |
|
124 | + } catch (DoesNotExistException $e) { |
|
125 | + return false; |
|
126 | + } |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @inheritDoc |
|
131 | + */ |
|
132 | + public function getLastModified(): ?int { |
|
133 | + return $this->mapper->findLastUpdatedForUserId($this->getUid()); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @inheritDoc |
|
138 | + */ |
|
139 | + public function propPatch(PropPatch $propPatch) { |
|
140 | + throw new Exception("This addressbook is immutable"); |
|
141 | + } |
|
142 | + |
|
143 | + /** |
|
144 | + * @inheritDoc |
|
145 | + */ |
|
146 | + public function getProperties($properties) { |
|
147 | + return [ |
|
148 | + 'principaluri' => $this->principalUri, |
|
149 | + '{DAV:}displayname' => $this->l10n->t('Recently contacted'), |
|
150 | + '{' . Plugin::NS_OWNCLOUD . '}read-only' => true, |
|
151 | + '{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0), |
|
152 | + ]; |
|
153 | + } |
|
154 | + |
|
155 | + public function getOwner(): string { |
|
156 | + return $this->principalUri; |
|
157 | + } |
|
158 | + |
|
159 | + /** |
|
160 | + * @inheritDoc |
|
161 | + */ |
|
162 | + public function getACL() { |
|
163 | + return [ |
|
164 | + [ |
|
165 | + 'privilege' => '{DAV:}read', |
|
166 | + 'principal' => $this->getOwner(), |
|
167 | + 'protected' => true, |
|
168 | + ], |
|
169 | + ]; |
|
170 | + } |
|
171 | + |
|
172 | + private function getUid(): string { |
|
173 | + list(, $uid) = \Sabre\Uri\split($this->principalUri); |
|
174 | + return $uid; |
|
175 | + } |
|
176 | 176 | } |
@@ -85,13 +85,13 @@ discard block |
||
85 | 85 | return new Card( |
86 | 86 | $this->mapper->find( |
87 | 87 | $this->getUid(), |
88 | - (int)$name |
|
88 | + (int) $name |
|
89 | 89 | ), |
90 | 90 | $this->principalUri, |
91 | 91 | $this->getACL() |
92 | 92 | ); |
93 | 93 | } catch (DoesNotExistException $ex) { |
94 | - throw new NotFound("Contact does not exist: " . $ex->getMessage(), 0, $ex); |
|
94 | + throw new NotFound("Contact does not exist: ".$ex->getMessage(), 0, $ex); |
|
95 | 95 | } |
96 | 96 | } |
97 | 97 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function getChildren(): array { |
102 | 102 | return array_map( |
103 | - function (RecentContact $contact) { |
|
103 | + function(RecentContact $contact) { |
|
104 | 104 | return new Card( |
105 | 105 | $contact, |
106 | 106 | $this->principalUri, |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | try { |
119 | 119 | $this->mapper->find( |
120 | 120 | $this->getUid(), |
121 | - (int)$name |
|
121 | + (int) $name |
|
122 | 122 | ); |
123 | 123 | return true; |
124 | 124 | } catch (DoesNotExistException $e) { |
@@ -147,8 +147,8 @@ discard block |
||
147 | 147 | return [ |
148 | 148 | 'principaluri' => $this->principalUri, |
149 | 149 | '{DAV:}displayname' => $this->l10n->t('Recently contacted'), |
150 | - '{' . Plugin::NS_OWNCLOUD . '}read-only' => true, |
|
151 | - '{' . \OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER . '}getctag' => 'http://sabre.io/ns/sync/' . ($this->getLastModified() ?? 0), |
|
150 | + '{'.Plugin::NS_OWNCLOUD.'}read-only' => true, |
|
151 | + '{'.\OCA\DAV\CalDAV\Plugin::NS_CALENDARSERVER.'}getctag' => 'http://sabre.io/ns/sync/'.($this->getLastModified() ?? 0), |
|
152 | 152 | ]; |
153 | 153 | } |
154 | 154 |
@@ -32,104 +32,104 @@ |
||
32 | 32 | use Sabre\DAVACL\IACL; |
33 | 33 | |
34 | 34 | class Card implements ICard, IACL { |
35 | - use ACLTrait; |
|
36 | - |
|
37 | - /** @var RecentContact */ |
|
38 | - private $contact; |
|
39 | - |
|
40 | - /** @var string */ |
|
41 | - private $principal; |
|
42 | - |
|
43 | - /** @var array */ |
|
44 | - private $acls; |
|
45 | - |
|
46 | - public function __construct(RecentContact $contact, string $principal, array $acls) { |
|
47 | - $this->contact = $contact; |
|
48 | - $this->principal = $principal; |
|
49 | - $this->acls = $acls; |
|
50 | - } |
|
51 | - |
|
52 | - /** |
|
53 | - * @inheritDoc |
|
54 | - */ |
|
55 | - public function getOwner(): ?string { |
|
56 | - $this->principal; |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * @inheritDoc |
|
61 | - */ |
|
62 | - public function getACL(): array { |
|
63 | - return $this->acls; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * @inheritDoc |
|
68 | - */ |
|
69 | - public function setAcls(array $acls): void { |
|
70 | - throw new NotImplemented(); |
|
71 | - } |
|
72 | - |
|
73 | - /** |
|
74 | - * @inheritDoc |
|
75 | - */ |
|
76 | - public function put($data): ?string { |
|
77 | - throw new NotImplemented(); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * @inheritDoc |
|
82 | - */ |
|
83 | - public function get() { |
|
84 | - return $this->contact->getCard(); |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @inheritDoc |
|
89 | - */ |
|
90 | - public function getContentType(): ?string { |
|
91 | - return 'text/vcard; charset=utf-8'; |
|
92 | - } |
|
93 | - |
|
94 | - /** |
|
95 | - * @inheritDoc |
|
96 | - */ |
|
97 | - public function getETag(): ?string { |
|
98 | - return '"' . md5((string) $this->getLastModified()) . '"'; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * @inheritDoc |
|
103 | - */ |
|
104 | - public function getSize(): int { |
|
105 | - throw new NotImplemented(); |
|
106 | - } |
|
107 | - |
|
108 | - /** |
|
109 | - * @inheritDoc |
|
110 | - */ |
|
111 | - public function delete(): void { |
|
112 | - throw new NotImplemented(); |
|
113 | - } |
|
114 | - |
|
115 | - /** |
|
116 | - * @inheritDoc |
|
117 | - */ |
|
118 | - public function getName(): string { |
|
119 | - return (string) $this->contact->getId(); |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * @inheritDoc |
|
124 | - */ |
|
125 | - public function setName($name): void { |
|
126 | - throw new NotImplemented(); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @inheritDoc |
|
131 | - */ |
|
132 | - public function getLastModified(): ?int { |
|
133 | - return $this->contact->getLastContact(); |
|
134 | - } |
|
35 | + use ACLTrait; |
|
36 | + |
|
37 | + /** @var RecentContact */ |
|
38 | + private $contact; |
|
39 | + |
|
40 | + /** @var string */ |
|
41 | + private $principal; |
|
42 | + |
|
43 | + /** @var array */ |
|
44 | + private $acls; |
|
45 | + |
|
46 | + public function __construct(RecentContact $contact, string $principal, array $acls) { |
|
47 | + $this->contact = $contact; |
|
48 | + $this->principal = $principal; |
|
49 | + $this->acls = $acls; |
|
50 | + } |
|
51 | + |
|
52 | + /** |
|
53 | + * @inheritDoc |
|
54 | + */ |
|
55 | + public function getOwner(): ?string { |
|
56 | + $this->principal; |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * @inheritDoc |
|
61 | + */ |
|
62 | + public function getACL(): array { |
|
63 | + return $this->acls; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * @inheritDoc |
|
68 | + */ |
|
69 | + public function setAcls(array $acls): void { |
|
70 | + throw new NotImplemented(); |
|
71 | + } |
|
72 | + |
|
73 | + /** |
|
74 | + * @inheritDoc |
|
75 | + */ |
|
76 | + public function put($data): ?string { |
|
77 | + throw new NotImplemented(); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * @inheritDoc |
|
82 | + */ |
|
83 | + public function get() { |
|
84 | + return $this->contact->getCard(); |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @inheritDoc |
|
89 | + */ |
|
90 | + public function getContentType(): ?string { |
|
91 | + return 'text/vcard; charset=utf-8'; |
|
92 | + } |
|
93 | + |
|
94 | + /** |
|
95 | + * @inheritDoc |
|
96 | + */ |
|
97 | + public function getETag(): ?string { |
|
98 | + return '"' . md5((string) $this->getLastModified()) . '"'; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * @inheritDoc |
|
103 | + */ |
|
104 | + public function getSize(): int { |
|
105 | + throw new NotImplemented(); |
|
106 | + } |
|
107 | + |
|
108 | + /** |
|
109 | + * @inheritDoc |
|
110 | + */ |
|
111 | + public function delete(): void { |
|
112 | + throw new NotImplemented(); |
|
113 | + } |
|
114 | + |
|
115 | + /** |
|
116 | + * @inheritDoc |
|
117 | + */ |
|
118 | + public function getName(): string { |
|
119 | + return (string) $this->contact->getId(); |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * @inheritDoc |
|
124 | + */ |
|
125 | + public function setName($name): void { |
|
126 | + throw new NotImplemented(); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @inheritDoc |
|
131 | + */ |
|
132 | + public function getLastModified(): ?int { |
|
133 | + return $this->contact->getLastContact(); |
|
134 | + } |
|
135 | 135 | } |
@@ -95,7 +95,7 @@ |
||
95 | 95 | * @inheritDoc |
96 | 96 | */ |
97 | 97 | public function getETag(): ?string { |
98 | - return '"' . md5((string) $this->getLastModified()) . '"'; |
|
98 | + return '"'.md5((string) $this->getLastModified()).'"'; |
|
99 | 99 | } |
100 | 100 | |
101 | 101 | /** |