6
6
* @author Georg Ehrke <oc.list@georgehrke.com>
7
7
* @author Joas Schilling <coding@schilljs.com>
8
8
* @author Roeland Jago Douma <roeland@famdouma.nl>
9
+ * @author Thomas Citharel <nextcloud@tcit.fr>
9
10
* @author Thomas Müller <thomas.mueller@tmit.eu>
10
11
*
11
12
* @license AGPL-3.0
27
28
28
29
use OCA \DAV \DAV \Sharing \IShareable ;
29
30
use OCA \DAV \Exception \UnsupportedLimitOnInitialSyncException ;
31
+ use OCP \DB \Exception ;
30
32
use OCP \IL10N ;
33
+ use OCP \Server ;
34
+ use Psr \Log \LoggerInterface ;
31
35
use Sabre \CardDAV \Backend \BackendInterface ;
32
- use Sabre \CardDAV \Card ;
33
36
use Sabre \DAV \Exception \Forbidden ;
34
37
use Sabre \DAV \Exception \NotFound ;
38
+ use Sabre \DAV \IMoveTarget ;
39
+ use Sabre \DAV \INode ;
35
40
use Sabre \DAV \PropPatch ;
36
41
37
42
/**
40
45
* @package OCA\DAV\CardDAV
41
46
* @property CardDavBackend $carddavBackend
42
47
*/
43
- class AddressBook extends \Sabre \CardDAV \AddressBook implements IShareable {
48
+ class AddressBook extends \Sabre \CardDAV \AddressBook implements IShareable, IMoveTarget {
44
49
45
50
/**
46
51
* AddressBook constructor.
@@ -52,6 +57,7 @@ class AddressBook extends \Sabre\CardDAV\AddressBook implements IShareable {
52
57
public function __construct (BackendInterface $ carddavBackend , array $ addressBookInfo , IL10N $ l10n ) {
53
58
parent ::__construct ($ carddavBackend , $ addressBookInfo );
54
59
60
+
55
61
if ($ this ->addressBookInfo ['{DAV:}displayname ' ] === CardDavBackend::PERSONAL_ADDRESSBOOK_NAME &&
56
62
$ this ->getName () === CardDavBackend::PERSONAL_ADDRESSBOOK_URI ) {
57
63
$ this ->addressBookInfo ['{DAV:}displayname ' ] = $ l10n ->t ('Contacts ' );
@@ -160,6 +166,30 @@ public function getChild($name) {
160
166
return new Card ($ this ->carddavBackend , $ this ->addressBookInfo , $ obj );
161
167
}
162
168
169
+ public function getChildren ()
170
+ {
171
+ $ objs = $ this ->carddavBackend ->getCards ($ this ->addressBookInfo ['id ' ]);
172
+ $ children = [];
173
+ foreach ($ objs as $ obj ) {
174
+ $ obj ['acl ' ] = $ this ->getChildACL ();
175
+ $ children [] = new Card ($ this ->carddavBackend , $ this ->addressBookInfo , $ obj );
176
+ }
177
+
178
+ return $ children ;
179
+ }
180
+
181
+ public function getMultipleChildren (array $ paths )
182
+ {
183
+ $ objs = $ this ->carddavBackend ->getMultipleCards ($ this ->addressBookInfo ['id ' ], $ paths );
184
+ $ children = [];
185
+ foreach ($ objs as $ obj ) {
186
+ $ obj ['acl ' ] = $ this ->getChildACL ();
187
+ $ children [] = new Card ($ this ->carddavBackend , $ this ->addressBookInfo , $ obj );
188
+ }
189
+
190
+ return $ children ;
191
+ }
192
+
163
193
public function getResourceId (): int {
164
194
return $ this ->addressBookInfo ['id ' ];
165
195
}
@@ -223,4 +253,21 @@ public function getChanges($syncToken, $syncLevel, $limit = null) {
223
253
224
254
return parent ::getChanges ($ syncToken , $ syncLevel , $ limit );
225
255
}
256
+
257
+ /**
258
+ * @inheritDoc
259
+ */
260
+ public function moveInto ($ targetName , $ sourcePath , INode $ sourceNode ) {
261
+ if (!($ sourceNode instanceof Card)) {
262
+ return false ;
263
+ }
264
+
265
+ try {
266
+ return $ this ->carddavBackend ->moveCard ($ sourceNode ->getAddressbookId (), (int )$ this ->addressBookInfo ['id ' ], $ sourceNode ->getUri (), $ sourceNode ->getOwner ());
267
+ } catch (Exception $ e ) {
268
+ // Avoid injecting LoggerInterface everywhere
269
+ Server::get (LoggerInterface::class)->error ('Could not move calendar object: ' . $ e ->getMessage (), ['exception ' => $ e ]);
270
+ return false ;
271
+ }
272
+ }
226
273
}
0 commit comments