3131use OCP \IL10N ;
3232use OCP \Share \Exceptions \GenericShareException ;
3333use OCP \Share \Exceptions \ShareNotFound ;
34+ use OCP \Share \IAttributes ;
3435use OCP \Share \IManager ;
3536use OCP \Share \IShare ;
3637
@@ -133,6 +134,11 @@ public function create(IShare $share) {
133134 )
134135 );*/
135136
137+ // set share attributes
138+ $ shareAttributes = $ this ->formatShareAttributes (
139+ $ share ->getAttributes ()
140+ );
141+
136142 $ shareId = $ this ->addShareToDB (
137143 $ share ->getSharedWith (),
138144 $ share ->getSharedBy (),
@@ -142,7 +148,8 @@ public function create(IShare $share) {
142148 $ share ->getTarget (),
143149 $ share ->getPermissions (),
144150 $ share ->getToken () ?? '' ,
145- $ share ->getExpirationDate ()
151+ $ share ->getExpirationDate (),
152+ $ shareAttributes
146153 );
147154 $ data = $ this ->getRawShare ($ shareId );
148155
@@ -163,6 +170,7 @@ public function create(IShare $share) {
163170 * @param int $permissions
164171 * @param string $token
165172 * @param \DateTime|null $expirationDate
173+ * @param string|null $attributes
166174 * @return int
167175 */
168176 private function addShareToDB (
@@ -194,6 +202,10 @@ private function addShareToDB(
194202 $ qb ->setValue ('expiration ' , $ qb ->createNamedParameter ($ expirationDate , 'datetime ' ));
195203 }
196204
205+ if ($ attributes !== null ) {
206+ $ qb ->setValue ('attributes ' , $ qb ->createNamedParameter ($ attributes ));
207+ }
208+
197209 $ qb ->executeStatement ();
198210
199211 return $ qb ->getLastInsertId ();
@@ -264,6 +276,9 @@ private function createShareObject(array $data): IShare {
264276 $ entryData ['parent ' ] = $ entryData ['f_parent ' ];
265277 $ share ->setNodeCacheEntry (Cache::cacheEntryFromData ($ entryData , $ this ->mimeTypeLoader ));
266278 }
279+
280+ $ share = $ this ->updateShareAttributes ($ share , $ data ['attributes ' ] ?? null );
281+
267282 return $ share ;
268283 }
269284
@@ -1046,6 +1061,42 @@ public function getAllShares(): iterable {
10461061 $ cursor ->closeCursor ();
10471062 }
10481063
1064+ protected function updateShareAttributes (IShare $ share , ?string $ data ): IShare {
1065+ if ($ data !== null && $ data !== '' ) {
1066+ $ attributes = $ share ->getAttributes () ?? $ share ->newAttributes ();
1067+ $ compressedAttributes = \json_decode ($ data , true );
1068+ if ($ compressedAttributes === false || $ compressedAttributes === null ) {
1069+ return $ share ;
1070+ }
1071+ foreach ($ compressedAttributes as $ compressedAttribute ) {
1072+ $ attributes ->setAttribute (
1073+ $ compressedAttribute [0 ],
1074+ $ compressedAttribute [1 ],
1075+ $ compressedAttribute [2 ]
1076+ );
1077+ }
1078+ $ share ->setAttributes ($ attributes );
1079+ }
1080+
1081+ return $ share ;
1082+ }
1083+
1084+ protected function formatShareAttributes (?IAttributes $ attributes ): ?string {
1085+ if ($ attributes === null || empty ($ attributes ->toArray ())) {
1086+ return null ;
1087+ }
1088+
1089+ $ compressedAttributes = [];
1090+ foreach ($ attributes ->toArray () as $ attribute ) {
1091+ $ compressedAttributes [] = [
1092+ 0 => $ attribute ['scope ' ],
1093+ 1 => $ attribute ['key ' ],
1094+ 2 => $ attribute ['value ' ]
1095+ ];
1096+ }
1097+ return \json_encode ($ compressedAttributes ) ?: null ;
1098+ }
1099+
10491100 public function getOrphanedAttachmentShares (): array {
10501101 $ allCardIds = $ this ->cardMapper ->getAllCardIds ();
10511102 $ qb = $ this ->dbConnection ->getQueryBuilder ();
0 commit comments