@@ -34,258 +34,258 @@ |
||
34 | 34 | |
35 | 35 | class CustomPropertiesBackend implements BackendInterface { |
36 | 36 | |
37 | - /** |
|
38 | - * Ignored properties |
|
39 | - * |
|
40 | - * @var array |
|
41 | - */ |
|
42 | - private $ignoredProperties = array( |
|
43 | - '{DAV:}getcontentlength', |
|
44 | - '{DAV:}getcontenttype', |
|
45 | - '{DAV:}getetag', |
|
46 | - '{DAV:}quota-used-bytes', |
|
47 | - '{DAV:}quota-available-bytes', |
|
48 | - '{http://owncloud.org/ns}permissions', |
|
49 | - '{http://owncloud.org/ns}downloadURL', |
|
50 | - '{http://owncloud.org/ns}dDC', |
|
51 | - '{http://owncloud.org/ns}size', |
|
52 | - ); |
|
53 | - |
|
54 | - /** |
|
55 | - * @var Tree |
|
56 | - */ |
|
57 | - private $tree; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var IDBConnection |
|
61 | - */ |
|
62 | - private $connection; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - private $user; |
|
68 | - |
|
69 | - /** |
|
70 | - * Properties cache |
|
71 | - * |
|
72 | - * @var array |
|
73 | - */ |
|
74 | - private $cache = []; |
|
75 | - |
|
76 | - /** |
|
77 | - * @param Tree $tree node tree |
|
78 | - * @param IDBConnection $connection database connection |
|
79 | - * @param IUser $user owner of the tree and properties |
|
80 | - */ |
|
81 | - public function __construct( |
|
82 | - Tree $tree, |
|
83 | - IDBConnection $connection, |
|
84 | - IUser $user) { |
|
85 | - $this->tree = $tree; |
|
86 | - $this->connection = $connection; |
|
87 | - $this->user = $user->getUID(); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Fetches properties for a path. |
|
92 | - * |
|
93 | - * @param string $path |
|
94 | - * @param PropFind $propFind |
|
95 | - * @return void |
|
96 | - */ |
|
97 | - public function propFind($path, PropFind $propFind) { |
|
98 | - |
|
99 | - $requestedProps = $propFind->get404Properties(); |
|
100 | - |
|
101 | - // these might appear |
|
102 | - $requestedProps = array_diff( |
|
103 | - $requestedProps, |
|
104 | - $this->ignoredProperties |
|
105 | - ); |
|
106 | - |
|
107 | - // substr of calendars/ => path is inside the CalDAV component |
|
108 | - // two '/' => this a calendar (no calendar-home nor calendar object) |
|
109 | - if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) { |
|
110 | - $allRequestedProps = $propFind->getRequestedProperties(); |
|
111 | - $customPropertiesForShares = [ |
|
112 | - '{DAV:}displayname', |
|
113 | - '{urn:ietf:params:xml:ns:caldav}calendar-description', |
|
114 | - '{urn:ietf:params:xml:ns:caldav}calendar-timezone', |
|
115 | - '{http://apple.com/ns/ical/}calendar-order', |
|
116 | - '{http://apple.com/ns/ical/}calendar-color', |
|
117 | - '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', |
|
118 | - ]; |
|
119 | - |
|
120 | - foreach ($customPropertiesForShares as $customPropertyForShares) { |
|
121 | - if (in_array($customPropertyForShares, $allRequestedProps)) { |
|
122 | - $requestedProps[] = $customPropertyForShares; |
|
123 | - } |
|
124 | - } |
|
125 | - } |
|
126 | - |
|
127 | - if (empty($requestedProps)) { |
|
128 | - return; |
|
129 | - } |
|
130 | - |
|
131 | - $props = $this->getProperties($path, $requestedProps); |
|
132 | - foreach ($props as $propName => $propValue) { |
|
133 | - $propFind->set($propName, $propValue); |
|
134 | - } |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * Updates properties for a path |
|
139 | - * |
|
140 | - * @param string $path |
|
141 | - * @param PropPatch $propPatch |
|
142 | - * |
|
143 | - * @return void |
|
144 | - */ |
|
145 | - public function propPatch($path, PropPatch $propPatch) { |
|
146 | - $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
147 | - return $this->updateProperties($path, $changedProps); |
|
148 | - }); |
|
149 | - } |
|
150 | - |
|
151 | - /** |
|
152 | - * This method is called after a node is deleted. |
|
153 | - * |
|
154 | - * @param string $path path of node for which to delete properties |
|
155 | - */ |
|
156 | - public function delete($path) { |
|
157 | - $statement = $this->connection->prepare( |
|
158 | - 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
159 | - ); |
|
160 | - $statement->execute(array($this->user, $path)); |
|
161 | - $statement->closeCursor(); |
|
162 | - |
|
163 | - unset($this->cache[$path]); |
|
164 | - } |
|
165 | - |
|
166 | - /** |
|
167 | - * This method is called after a successful MOVE |
|
168 | - * |
|
169 | - * @param string $source |
|
170 | - * @param string $destination |
|
171 | - * |
|
172 | - * @return void |
|
173 | - */ |
|
174 | - public function move($source, $destination) { |
|
175 | - $statement = $this->connection->prepare( |
|
176 | - 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
177 | - ' WHERE `userid` = ? AND `propertypath` = ?' |
|
178 | - ); |
|
179 | - $statement->execute(array($destination, $this->user, $source)); |
|
180 | - $statement->closeCursor(); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * Returns a list of properties for this nodes.; |
|
185 | - * @param string $path |
|
186 | - * @param array $requestedProperties requested properties or empty array for "all" |
|
187 | - * @return array |
|
188 | - * @note The properties list is a list of propertynames the client |
|
189 | - * requested, encoded as xmlnamespace#tagName, for example: |
|
190 | - * http://www.example.org/namespace#author If the array is empty, all |
|
191 | - * properties should be returned |
|
192 | - */ |
|
193 | - private function getProperties($path, array $requestedProperties) { |
|
194 | - if (isset($this->cache[$path])) { |
|
195 | - return $this->cache[$path]; |
|
196 | - } |
|
197 | - |
|
198 | - // TODO: chunking if more than 1000 properties |
|
199 | - $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
200 | - |
|
201 | - $whereValues = array($this->user, $path); |
|
202 | - $whereTypes = array(null, null); |
|
203 | - |
|
204 | - if (!empty($requestedProperties)) { |
|
205 | - // request only a subset |
|
206 | - $sql .= ' AND `propertyname` in (?)'; |
|
207 | - $whereValues[] = $requestedProperties; |
|
208 | - $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
209 | - } |
|
210 | - |
|
211 | - $result = $this->connection->executeQuery( |
|
212 | - $sql, |
|
213 | - $whereValues, |
|
214 | - $whereTypes |
|
215 | - ); |
|
216 | - |
|
217 | - $props = []; |
|
218 | - while ($row = $result->fetch()) { |
|
219 | - $props[$row['propertyname']] = $row['propertyvalue']; |
|
220 | - } |
|
221 | - |
|
222 | - $result->closeCursor(); |
|
223 | - |
|
224 | - $this->cache[$path] = $props; |
|
225 | - return $props; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * Update properties |
|
230 | - * |
|
231 | - * @param string $path node for which to update properties |
|
232 | - * @param array $properties array of properties to update |
|
233 | - * |
|
234 | - * @return bool |
|
235 | - */ |
|
236 | - private function updateProperties($path, $properties) { |
|
237 | - |
|
238 | - $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
239 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
240 | - |
|
241 | - $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
242 | - ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
243 | - |
|
244 | - $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
245 | - ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
246 | - |
|
247 | - // TODO: use "insert or update" strategy ? |
|
248 | - $existing = $this->getProperties($path, array()); |
|
249 | - $this->connection->beginTransaction(); |
|
250 | - foreach ($properties as $propertyName => $propertyValue) { |
|
251 | - // If it was null, we need to delete the property |
|
252 | - if (is_null($propertyValue)) { |
|
253 | - if (array_key_exists($propertyName, $existing)) { |
|
254 | - $this->connection->executeUpdate($deleteStatement, |
|
255 | - array( |
|
256 | - $this->user, |
|
257 | - $path, |
|
258 | - $propertyName |
|
259 | - ) |
|
260 | - ); |
|
261 | - } |
|
262 | - } else { |
|
263 | - if (!array_key_exists($propertyName, $existing)) { |
|
264 | - $this->connection->executeUpdate($insertStatement, |
|
265 | - array( |
|
266 | - $this->user, |
|
267 | - $path, |
|
268 | - $propertyName, |
|
269 | - $propertyValue |
|
270 | - ) |
|
271 | - ); |
|
272 | - } else { |
|
273 | - $this->connection->executeUpdate($updateStatement, |
|
274 | - array( |
|
275 | - $propertyValue, |
|
276 | - $this->user, |
|
277 | - $path, |
|
278 | - $propertyName |
|
279 | - ) |
|
280 | - ); |
|
281 | - } |
|
282 | - } |
|
283 | - } |
|
284 | - |
|
285 | - $this->connection->commit(); |
|
286 | - unset($this->cache[$path]); |
|
287 | - |
|
288 | - return true; |
|
289 | - } |
|
37 | + /** |
|
38 | + * Ignored properties |
|
39 | + * |
|
40 | + * @var array |
|
41 | + */ |
|
42 | + private $ignoredProperties = array( |
|
43 | + '{DAV:}getcontentlength', |
|
44 | + '{DAV:}getcontenttype', |
|
45 | + '{DAV:}getetag', |
|
46 | + '{DAV:}quota-used-bytes', |
|
47 | + '{DAV:}quota-available-bytes', |
|
48 | + '{http://owncloud.org/ns}permissions', |
|
49 | + '{http://owncloud.org/ns}downloadURL', |
|
50 | + '{http://owncloud.org/ns}dDC', |
|
51 | + '{http://owncloud.org/ns}size', |
|
52 | + ); |
|
53 | + |
|
54 | + /** |
|
55 | + * @var Tree |
|
56 | + */ |
|
57 | + private $tree; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var IDBConnection |
|
61 | + */ |
|
62 | + private $connection; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + private $user; |
|
68 | + |
|
69 | + /** |
|
70 | + * Properties cache |
|
71 | + * |
|
72 | + * @var array |
|
73 | + */ |
|
74 | + private $cache = []; |
|
75 | + |
|
76 | + /** |
|
77 | + * @param Tree $tree node tree |
|
78 | + * @param IDBConnection $connection database connection |
|
79 | + * @param IUser $user owner of the tree and properties |
|
80 | + */ |
|
81 | + public function __construct( |
|
82 | + Tree $tree, |
|
83 | + IDBConnection $connection, |
|
84 | + IUser $user) { |
|
85 | + $this->tree = $tree; |
|
86 | + $this->connection = $connection; |
|
87 | + $this->user = $user->getUID(); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Fetches properties for a path. |
|
92 | + * |
|
93 | + * @param string $path |
|
94 | + * @param PropFind $propFind |
|
95 | + * @return void |
|
96 | + */ |
|
97 | + public function propFind($path, PropFind $propFind) { |
|
98 | + |
|
99 | + $requestedProps = $propFind->get404Properties(); |
|
100 | + |
|
101 | + // these might appear |
|
102 | + $requestedProps = array_diff( |
|
103 | + $requestedProps, |
|
104 | + $this->ignoredProperties |
|
105 | + ); |
|
106 | + |
|
107 | + // substr of calendars/ => path is inside the CalDAV component |
|
108 | + // two '/' => this a calendar (no calendar-home nor calendar object) |
|
109 | + if (substr($path, 0, 10) === 'calendars/' && substr_count($path, '/') === 2) { |
|
110 | + $allRequestedProps = $propFind->getRequestedProperties(); |
|
111 | + $customPropertiesForShares = [ |
|
112 | + '{DAV:}displayname', |
|
113 | + '{urn:ietf:params:xml:ns:caldav}calendar-description', |
|
114 | + '{urn:ietf:params:xml:ns:caldav}calendar-timezone', |
|
115 | + '{http://apple.com/ns/ical/}calendar-order', |
|
116 | + '{http://apple.com/ns/ical/}calendar-color', |
|
117 | + '{urn:ietf:params:xml:ns:caldav}schedule-calendar-transp', |
|
118 | + ]; |
|
119 | + |
|
120 | + foreach ($customPropertiesForShares as $customPropertyForShares) { |
|
121 | + if (in_array($customPropertyForShares, $allRequestedProps)) { |
|
122 | + $requestedProps[] = $customPropertyForShares; |
|
123 | + } |
|
124 | + } |
|
125 | + } |
|
126 | + |
|
127 | + if (empty($requestedProps)) { |
|
128 | + return; |
|
129 | + } |
|
130 | + |
|
131 | + $props = $this->getProperties($path, $requestedProps); |
|
132 | + foreach ($props as $propName => $propValue) { |
|
133 | + $propFind->set($propName, $propValue); |
|
134 | + } |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * Updates properties for a path |
|
139 | + * |
|
140 | + * @param string $path |
|
141 | + * @param PropPatch $propPatch |
|
142 | + * |
|
143 | + * @return void |
|
144 | + */ |
|
145 | + public function propPatch($path, PropPatch $propPatch) { |
|
146 | + $propPatch->handleRemaining(function($changedProps) use ($path) { |
|
147 | + return $this->updateProperties($path, $changedProps); |
|
148 | + }); |
|
149 | + } |
|
150 | + |
|
151 | + /** |
|
152 | + * This method is called after a node is deleted. |
|
153 | + * |
|
154 | + * @param string $path path of node for which to delete properties |
|
155 | + */ |
|
156 | + public function delete($path) { |
|
157 | + $statement = $this->connection->prepare( |
|
158 | + 'DELETE FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?' |
|
159 | + ); |
|
160 | + $statement->execute(array($this->user, $path)); |
|
161 | + $statement->closeCursor(); |
|
162 | + |
|
163 | + unset($this->cache[$path]); |
|
164 | + } |
|
165 | + |
|
166 | + /** |
|
167 | + * This method is called after a successful MOVE |
|
168 | + * |
|
169 | + * @param string $source |
|
170 | + * @param string $destination |
|
171 | + * |
|
172 | + * @return void |
|
173 | + */ |
|
174 | + public function move($source, $destination) { |
|
175 | + $statement = $this->connection->prepare( |
|
176 | + 'UPDATE `*PREFIX*properties` SET `propertypath` = ?' . |
|
177 | + ' WHERE `userid` = ? AND `propertypath` = ?' |
|
178 | + ); |
|
179 | + $statement->execute(array($destination, $this->user, $source)); |
|
180 | + $statement->closeCursor(); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * Returns a list of properties for this nodes.; |
|
185 | + * @param string $path |
|
186 | + * @param array $requestedProperties requested properties or empty array for "all" |
|
187 | + * @return array |
|
188 | + * @note The properties list is a list of propertynames the client |
|
189 | + * requested, encoded as xmlnamespace#tagName, for example: |
|
190 | + * http://www.example.org/namespace#author If the array is empty, all |
|
191 | + * properties should be returned |
|
192 | + */ |
|
193 | + private function getProperties($path, array $requestedProperties) { |
|
194 | + if (isset($this->cache[$path])) { |
|
195 | + return $this->cache[$path]; |
|
196 | + } |
|
197 | + |
|
198 | + // TODO: chunking if more than 1000 properties |
|
199 | + $sql = 'SELECT * FROM `*PREFIX*properties` WHERE `userid` = ? AND `propertypath` = ?'; |
|
200 | + |
|
201 | + $whereValues = array($this->user, $path); |
|
202 | + $whereTypes = array(null, null); |
|
203 | + |
|
204 | + if (!empty($requestedProperties)) { |
|
205 | + // request only a subset |
|
206 | + $sql .= ' AND `propertyname` in (?)'; |
|
207 | + $whereValues[] = $requestedProperties; |
|
208 | + $whereTypes[] = \Doctrine\DBAL\Connection::PARAM_STR_ARRAY; |
|
209 | + } |
|
210 | + |
|
211 | + $result = $this->connection->executeQuery( |
|
212 | + $sql, |
|
213 | + $whereValues, |
|
214 | + $whereTypes |
|
215 | + ); |
|
216 | + |
|
217 | + $props = []; |
|
218 | + while ($row = $result->fetch()) { |
|
219 | + $props[$row['propertyname']] = $row['propertyvalue']; |
|
220 | + } |
|
221 | + |
|
222 | + $result->closeCursor(); |
|
223 | + |
|
224 | + $this->cache[$path] = $props; |
|
225 | + return $props; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * Update properties |
|
230 | + * |
|
231 | + * @param string $path node for which to update properties |
|
232 | + * @param array $properties array of properties to update |
|
233 | + * |
|
234 | + * @return bool |
|
235 | + */ |
|
236 | + private function updateProperties($path, $properties) { |
|
237 | + |
|
238 | + $deleteStatement = 'DELETE FROM `*PREFIX*properties`' . |
|
239 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
240 | + |
|
241 | + $insertStatement = 'INSERT INTO `*PREFIX*properties`' . |
|
242 | + ' (`userid`,`propertypath`,`propertyname`,`propertyvalue`) VALUES(?,?,?,?)'; |
|
243 | + |
|
244 | + $updateStatement = 'UPDATE `*PREFIX*properties` SET `propertyvalue` = ?' . |
|
245 | + ' WHERE `userid` = ? AND `propertypath` = ? AND `propertyname` = ?'; |
|
246 | + |
|
247 | + // TODO: use "insert or update" strategy ? |
|
248 | + $existing = $this->getProperties($path, array()); |
|
249 | + $this->connection->beginTransaction(); |
|
250 | + foreach ($properties as $propertyName => $propertyValue) { |
|
251 | + // If it was null, we need to delete the property |
|
252 | + if (is_null($propertyValue)) { |
|
253 | + if (array_key_exists($propertyName, $existing)) { |
|
254 | + $this->connection->executeUpdate($deleteStatement, |
|
255 | + array( |
|
256 | + $this->user, |
|
257 | + $path, |
|
258 | + $propertyName |
|
259 | + ) |
|
260 | + ); |
|
261 | + } |
|
262 | + } else { |
|
263 | + if (!array_key_exists($propertyName, $existing)) { |
|
264 | + $this->connection->executeUpdate($insertStatement, |
|
265 | + array( |
|
266 | + $this->user, |
|
267 | + $path, |
|
268 | + $propertyName, |
|
269 | + $propertyValue |
|
270 | + ) |
|
271 | + ); |
|
272 | + } else { |
|
273 | + $this->connection->executeUpdate($updateStatement, |
|
274 | + array( |
|
275 | + $propertyValue, |
|
276 | + $this->user, |
|
277 | + $path, |
|
278 | + $propertyName |
|
279 | + ) |
|
280 | + ); |
|
281 | + } |
|
282 | + } |
|
283 | + } |
|
284 | + |
|
285 | + $this->connection->commit(); |
|
286 | + unset($this->cache[$path]); |
|
287 | + |
|
288 | + return true; |
|
289 | + } |
|
290 | 290 | |
291 | 291 | } |
@@ -32,266 +32,266 @@ |
||
32 | 32 | |
33 | 33 | class Calendar extends \Sabre\CalDAV\Calendar implements IShareable { |
34 | 34 | |
35 | - public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { |
|
36 | - parent::__construct($caldavBackend, $calendarInfo); |
|
37 | - |
|
38 | - if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
39 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
40 | - } |
|
41 | - if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
42 | - $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
43 | - $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
44 | - } |
|
45 | - } |
|
46 | - |
|
47 | - /** |
|
48 | - * Updates the list of shares. |
|
49 | - * |
|
50 | - * The first array is a list of people that are to be added to the |
|
51 | - * resource. |
|
52 | - * |
|
53 | - * Every element in the add array has the following properties: |
|
54 | - * * href - A url. Usually a mailto: address |
|
55 | - * * commonName - Usually a first and last name, or false |
|
56 | - * * summary - A description of the share, can also be false |
|
57 | - * * readOnly - A boolean value |
|
58 | - * |
|
59 | - * Every element in the remove array is just the address string. |
|
60 | - * |
|
61 | - * @param array $add |
|
62 | - * @param array $remove |
|
63 | - * @return void |
|
64 | - */ |
|
65 | - function updateShares(array $add, array $remove) { |
|
66 | - /** @var CalDavBackend $calDavBackend */ |
|
67 | - $calDavBackend = $this->caldavBackend; |
|
68 | - $calDavBackend->updateShares($this, $add, $remove); |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * Returns the list of people whom this resource is shared with. |
|
73 | - * |
|
74 | - * Every element in this array should have the following properties: |
|
75 | - * * href - Often a mailto: address |
|
76 | - * * commonName - Optional, for example a first + last name |
|
77 | - * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
78 | - * * readOnly - boolean |
|
79 | - * * summary - Optional, a description for the share |
|
80 | - * |
|
81 | - * @return array |
|
82 | - */ |
|
83 | - function getShares() { |
|
84 | - /** @var CalDavBackend $calDavBackend */ |
|
85 | - $calDavBackend = $this->caldavBackend; |
|
86 | - return $calDavBackend->getShares($this->getResourceId()); |
|
87 | - } |
|
88 | - |
|
89 | - /** |
|
90 | - * @return int |
|
91 | - */ |
|
92 | - public function getResourceId() { |
|
93 | - return $this->calendarInfo['id']; |
|
94 | - } |
|
95 | - |
|
96 | - /** |
|
97 | - * @return string |
|
98 | - */ |
|
99 | - public function getPrincipalURI() { |
|
100 | - return $this->calendarInfo['principaluri']; |
|
101 | - } |
|
102 | - |
|
103 | - function getACL() { |
|
104 | - $acl = [ |
|
105 | - [ |
|
106 | - 'privilege' => '{DAV:}read', |
|
107 | - 'principal' => $this->getOwner(), |
|
108 | - 'protected' => true, |
|
109 | - ]]; |
|
110 | - if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
111 | - $acl[] = [ |
|
112 | - 'privilege' => '{DAV:}write', |
|
113 | - 'principal' => $this->getOwner(), |
|
114 | - 'protected' => true, |
|
115 | - ]; |
|
116 | - } |
|
117 | - if ($this->getOwner() !== parent::getOwner()) { |
|
118 | - $acl[] = [ |
|
119 | - 'privilege' => '{DAV:}read', |
|
120 | - 'principal' => parent::getOwner(), |
|
121 | - 'protected' => true, |
|
122 | - ]; |
|
123 | - if ($this->canWrite()) { |
|
124 | - $acl[] = [ |
|
125 | - 'privilege' => '{DAV:}write', |
|
126 | - 'principal' => parent::getOwner(), |
|
127 | - 'protected' => true, |
|
128 | - ]; |
|
129 | - } |
|
130 | - } |
|
131 | - if ($this->isPublic()) { |
|
132 | - $acl[] = [ |
|
133 | - 'privilege' => '{DAV:}read', |
|
134 | - 'principal' => 'principals/system/public', |
|
135 | - 'protected' => true, |
|
136 | - ]; |
|
137 | - } |
|
138 | - |
|
139 | - /** @var CalDavBackend $calDavBackend */ |
|
140 | - $calDavBackend = $this->caldavBackend; |
|
141 | - return $calDavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
142 | - } |
|
143 | - |
|
144 | - function getChildACL() { |
|
145 | - return $this->getACL(); |
|
146 | - } |
|
147 | - |
|
148 | - function getOwner() { |
|
149 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
150 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
151 | - } |
|
152 | - return parent::getOwner(); |
|
153 | - } |
|
154 | - |
|
155 | - function delete() { |
|
156 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
157 | - $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
158 | - $principal = 'principal:' . parent::getOwner(); |
|
159 | - $shares = $this->getShares(); |
|
160 | - $shares = array_filter($shares, function($share) use ($principal){ |
|
161 | - return $share['href'] === $principal; |
|
162 | - }); |
|
163 | - if (empty($shares)) { |
|
164 | - throw new Forbidden(); |
|
165 | - } |
|
166 | - |
|
167 | - /** @var CalDavBackend $calDavBackend */ |
|
168 | - $calDavBackend = $this->caldavBackend; |
|
169 | - $calDavBackend->updateShares($this, [], [ |
|
170 | - 'href' => $principal |
|
171 | - ]); |
|
172 | - return; |
|
173 | - } |
|
174 | - parent::delete(); |
|
175 | - } |
|
176 | - |
|
177 | - function propPatch(PropPatch $propPatch) { |
|
178 | - // parent::propPatch will only update calendars table |
|
179 | - // if calendar is shared, changes have to be made to the properties table |
|
180 | - if (!$this->isShared()) { |
|
181 | - parent::propPatch($propPatch); |
|
182 | - } |
|
183 | - } |
|
184 | - |
|
185 | - function getChild($name) { |
|
186 | - |
|
187 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
188 | - |
|
189 | - if (!$obj) { |
|
190 | - throw new NotFound('Calendar object not found'); |
|
191 | - } |
|
192 | - |
|
193 | - if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
194 | - throw new NotFound('Calendar object not found'); |
|
195 | - } |
|
196 | - |
|
197 | - $obj['acl'] = $this->getChildACL(); |
|
198 | - |
|
199 | - return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
200 | - |
|
201 | - } |
|
202 | - |
|
203 | - function getChildren() { |
|
204 | - |
|
205 | - $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
206 | - $children = []; |
|
207 | - foreach ($objs as $obj) { |
|
208 | - if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
209 | - continue; |
|
210 | - } |
|
211 | - $obj['acl'] = $this->getChildACL(); |
|
212 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
213 | - } |
|
214 | - return $children; |
|
215 | - |
|
216 | - } |
|
217 | - |
|
218 | - function getMultipleChildren(array $paths) { |
|
219 | - |
|
220 | - $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
221 | - $children = []; |
|
222 | - foreach ($objs as $obj) { |
|
223 | - if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
224 | - continue; |
|
225 | - } |
|
226 | - $obj['acl'] = $this->getChildACL(); |
|
227 | - $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
228 | - } |
|
229 | - return $children; |
|
230 | - |
|
231 | - } |
|
232 | - |
|
233 | - function childExists($name) { |
|
234 | - $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
235 | - if (!$obj) { |
|
236 | - return false; |
|
237 | - } |
|
238 | - if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
239 | - return false; |
|
240 | - } |
|
241 | - |
|
242 | - return true; |
|
243 | - } |
|
244 | - |
|
245 | - function calendarQuery(array $filters) { |
|
246 | - |
|
247 | - $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
248 | - if ($this->isShared()) { |
|
249 | - return array_filter($uris, function ($uri) { |
|
250 | - return $this->childExists($uri); |
|
251 | - }); |
|
252 | - } |
|
253 | - |
|
254 | - return $uris; |
|
255 | - } |
|
256 | - |
|
257 | - /** |
|
258 | - * @param boolean $value |
|
259 | - * @return string|null |
|
260 | - */ |
|
261 | - function setPublishStatus($value) { |
|
262 | - $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
263 | - $this->calendarInfo['publicuri'] = $publicUri; |
|
264 | - return $publicUri; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * @return mixed $value |
|
269 | - */ |
|
270 | - function getPublishStatus() { |
|
271 | - return $this->caldavBackend->getPublishStatus($this); |
|
272 | - } |
|
273 | - |
|
274 | - private function canWrite() { |
|
275 | - if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
276 | - return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
277 | - } |
|
278 | - return true; |
|
279 | - } |
|
280 | - |
|
281 | - private function isPublic() { |
|
282 | - return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
283 | - } |
|
284 | - |
|
285 | - private function isShared() { |
|
286 | - if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
287 | - return false; |
|
288 | - } |
|
289 | - |
|
290 | - return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
291 | - } |
|
292 | - |
|
293 | - public function isSubscription() { |
|
294 | - return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
295 | - } |
|
35 | + public function __construct(BackendInterface $caldavBackend, $calendarInfo, IL10N $l10n) { |
|
36 | + parent::__construct($caldavBackend, $calendarInfo); |
|
37 | + |
|
38 | + if ($this->getName() === BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
39 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Contact birthdays'); |
|
40 | + } |
|
41 | + if ($this->getName() === CalDavBackend::PERSONAL_CALENDAR_URI && |
|
42 | + $this->calendarInfo['{DAV:}displayname'] === CalDavBackend::PERSONAL_CALENDAR_NAME) { |
|
43 | + $this->calendarInfo['{DAV:}displayname'] = $l10n->t('Personal'); |
|
44 | + } |
|
45 | + } |
|
46 | + |
|
47 | + /** |
|
48 | + * Updates the list of shares. |
|
49 | + * |
|
50 | + * The first array is a list of people that are to be added to the |
|
51 | + * resource. |
|
52 | + * |
|
53 | + * Every element in the add array has the following properties: |
|
54 | + * * href - A url. Usually a mailto: address |
|
55 | + * * commonName - Usually a first and last name, or false |
|
56 | + * * summary - A description of the share, can also be false |
|
57 | + * * readOnly - A boolean value |
|
58 | + * |
|
59 | + * Every element in the remove array is just the address string. |
|
60 | + * |
|
61 | + * @param array $add |
|
62 | + * @param array $remove |
|
63 | + * @return void |
|
64 | + */ |
|
65 | + function updateShares(array $add, array $remove) { |
|
66 | + /** @var CalDavBackend $calDavBackend */ |
|
67 | + $calDavBackend = $this->caldavBackend; |
|
68 | + $calDavBackend->updateShares($this, $add, $remove); |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * Returns the list of people whom this resource is shared with. |
|
73 | + * |
|
74 | + * Every element in this array should have the following properties: |
|
75 | + * * href - Often a mailto: address |
|
76 | + * * commonName - Optional, for example a first + last name |
|
77 | + * * status - See the Sabre\CalDAV\SharingPlugin::STATUS_ constants. |
|
78 | + * * readOnly - boolean |
|
79 | + * * summary - Optional, a description for the share |
|
80 | + * |
|
81 | + * @return array |
|
82 | + */ |
|
83 | + function getShares() { |
|
84 | + /** @var CalDavBackend $calDavBackend */ |
|
85 | + $calDavBackend = $this->caldavBackend; |
|
86 | + return $calDavBackend->getShares($this->getResourceId()); |
|
87 | + } |
|
88 | + |
|
89 | + /** |
|
90 | + * @return int |
|
91 | + */ |
|
92 | + public function getResourceId() { |
|
93 | + return $this->calendarInfo['id']; |
|
94 | + } |
|
95 | + |
|
96 | + /** |
|
97 | + * @return string |
|
98 | + */ |
|
99 | + public function getPrincipalURI() { |
|
100 | + return $this->calendarInfo['principaluri']; |
|
101 | + } |
|
102 | + |
|
103 | + function getACL() { |
|
104 | + $acl = [ |
|
105 | + [ |
|
106 | + 'privilege' => '{DAV:}read', |
|
107 | + 'principal' => $this->getOwner(), |
|
108 | + 'protected' => true, |
|
109 | + ]]; |
|
110 | + if ($this->getName() !== BirthdayService::BIRTHDAY_CALENDAR_URI) { |
|
111 | + $acl[] = [ |
|
112 | + 'privilege' => '{DAV:}write', |
|
113 | + 'principal' => $this->getOwner(), |
|
114 | + 'protected' => true, |
|
115 | + ]; |
|
116 | + } |
|
117 | + if ($this->getOwner() !== parent::getOwner()) { |
|
118 | + $acl[] = [ |
|
119 | + 'privilege' => '{DAV:}read', |
|
120 | + 'principal' => parent::getOwner(), |
|
121 | + 'protected' => true, |
|
122 | + ]; |
|
123 | + if ($this->canWrite()) { |
|
124 | + $acl[] = [ |
|
125 | + 'privilege' => '{DAV:}write', |
|
126 | + 'principal' => parent::getOwner(), |
|
127 | + 'protected' => true, |
|
128 | + ]; |
|
129 | + } |
|
130 | + } |
|
131 | + if ($this->isPublic()) { |
|
132 | + $acl[] = [ |
|
133 | + 'privilege' => '{DAV:}read', |
|
134 | + 'principal' => 'principals/system/public', |
|
135 | + 'protected' => true, |
|
136 | + ]; |
|
137 | + } |
|
138 | + |
|
139 | + /** @var CalDavBackend $calDavBackend */ |
|
140 | + $calDavBackend = $this->caldavBackend; |
|
141 | + return $calDavBackend->applyShareAcl($this->getResourceId(), $acl); |
|
142 | + } |
|
143 | + |
|
144 | + function getChildACL() { |
|
145 | + return $this->getACL(); |
|
146 | + } |
|
147 | + |
|
148 | + function getOwner() { |
|
149 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
150 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal']; |
|
151 | + } |
|
152 | + return parent::getOwner(); |
|
153 | + } |
|
154 | + |
|
155 | + function delete() { |
|
156 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal']) && |
|
157 | + $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']) { |
|
158 | + $principal = 'principal:' . parent::getOwner(); |
|
159 | + $shares = $this->getShares(); |
|
160 | + $shares = array_filter($shares, function($share) use ($principal){ |
|
161 | + return $share['href'] === $principal; |
|
162 | + }); |
|
163 | + if (empty($shares)) { |
|
164 | + throw new Forbidden(); |
|
165 | + } |
|
166 | + |
|
167 | + /** @var CalDavBackend $calDavBackend */ |
|
168 | + $calDavBackend = $this->caldavBackend; |
|
169 | + $calDavBackend->updateShares($this, [], [ |
|
170 | + 'href' => $principal |
|
171 | + ]); |
|
172 | + return; |
|
173 | + } |
|
174 | + parent::delete(); |
|
175 | + } |
|
176 | + |
|
177 | + function propPatch(PropPatch $propPatch) { |
|
178 | + // parent::propPatch will only update calendars table |
|
179 | + // if calendar is shared, changes have to be made to the properties table |
|
180 | + if (!$this->isShared()) { |
|
181 | + parent::propPatch($propPatch); |
|
182 | + } |
|
183 | + } |
|
184 | + |
|
185 | + function getChild($name) { |
|
186 | + |
|
187 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
188 | + |
|
189 | + if (!$obj) { |
|
190 | + throw new NotFound('Calendar object not found'); |
|
191 | + } |
|
192 | + |
|
193 | + if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
194 | + throw new NotFound('Calendar object not found'); |
|
195 | + } |
|
196 | + |
|
197 | + $obj['acl'] = $this->getChildACL(); |
|
198 | + |
|
199 | + return new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
200 | + |
|
201 | + } |
|
202 | + |
|
203 | + function getChildren() { |
|
204 | + |
|
205 | + $objs = $this->caldavBackend->getCalendarObjects($this->calendarInfo['id']); |
|
206 | + $children = []; |
|
207 | + foreach ($objs as $obj) { |
|
208 | + if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
209 | + continue; |
|
210 | + } |
|
211 | + $obj['acl'] = $this->getChildACL(); |
|
212 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
213 | + } |
|
214 | + return $children; |
|
215 | + |
|
216 | + } |
|
217 | + |
|
218 | + function getMultipleChildren(array $paths) { |
|
219 | + |
|
220 | + $objs = $this->caldavBackend->getMultipleCalendarObjects($this->calendarInfo['id'], $paths); |
|
221 | + $children = []; |
|
222 | + foreach ($objs as $obj) { |
|
223 | + if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
224 | + continue; |
|
225 | + } |
|
226 | + $obj['acl'] = $this->getChildACL(); |
|
227 | + $children[] = new CalendarObject($this->caldavBackend, $this->calendarInfo, $obj); |
|
228 | + } |
|
229 | + return $children; |
|
230 | + |
|
231 | + } |
|
232 | + |
|
233 | + function childExists($name) { |
|
234 | + $obj = $this->caldavBackend->getCalendarObject($this->calendarInfo['id'], $name); |
|
235 | + if (!$obj) { |
|
236 | + return false; |
|
237 | + } |
|
238 | + if ($this->isShared() && $obj['classification'] === CalDavBackend::CLASSIFICATION_PRIVATE) { |
|
239 | + return false; |
|
240 | + } |
|
241 | + |
|
242 | + return true; |
|
243 | + } |
|
244 | + |
|
245 | + function calendarQuery(array $filters) { |
|
246 | + |
|
247 | + $uris = $this->caldavBackend->calendarQuery($this->calendarInfo['id'], $filters); |
|
248 | + if ($this->isShared()) { |
|
249 | + return array_filter($uris, function ($uri) { |
|
250 | + return $this->childExists($uri); |
|
251 | + }); |
|
252 | + } |
|
253 | + |
|
254 | + return $uris; |
|
255 | + } |
|
256 | + |
|
257 | + /** |
|
258 | + * @param boolean $value |
|
259 | + * @return string|null |
|
260 | + */ |
|
261 | + function setPublishStatus($value) { |
|
262 | + $publicUri = $this->caldavBackend->setPublishStatus($value, $this); |
|
263 | + $this->calendarInfo['publicuri'] = $publicUri; |
|
264 | + return $publicUri; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * @return mixed $value |
|
269 | + */ |
|
270 | + function getPublishStatus() { |
|
271 | + return $this->caldavBackend->getPublishStatus($this); |
|
272 | + } |
|
273 | + |
|
274 | + private function canWrite() { |
|
275 | + if (isset($this->calendarInfo['{http://owncloud.org/ns}read-only'])) { |
|
276 | + return !$this->calendarInfo['{http://owncloud.org/ns}read-only']; |
|
277 | + } |
|
278 | + return true; |
|
279 | + } |
|
280 | + |
|
281 | + private function isPublic() { |
|
282 | + return isset($this->calendarInfo['{http://owncloud.org/ns}public']); |
|
283 | + } |
|
284 | + |
|
285 | + private function isShared() { |
|
286 | + if (!isset($this->calendarInfo['{http://owncloud.org/ns}owner-principal'])) { |
|
287 | + return false; |
|
288 | + } |
|
289 | + |
|
290 | + return $this->calendarInfo['{http://owncloud.org/ns}owner-principal'] !== $this->calendarInfo['principaluri']; |
|
291 | + } |
|
292 | + |
|
293 | + public function isSubscription() { |
|
294 | + return isset($this->calendarInfo['{http://calendarserver.org/ns/}source']); |
|
295 | + } |
|
296 | 296 | |
297 | 297 | } |