@@ -34,24 +34,24 @@ |
||
34 | 34 | |
35 | 35 | interface IAvatarManager { |
36 | 36 | |
37 | - /** |
|
38 | - * return a user specific instance of \OCP\IAvatar |
|
39 | - * @see IAvatar |
|
40 | - * @param string $user the ownCloud user id |
|
41 | - * @return IAvatar |
|
42 | - * @throws \Exception In case the username is potentially dangerous |
|
43 | - * @throws \OCP\Files\NotFoundException In case there is no user folder yet |
|
44 | - * @since 6.0.0 |
|
45 | - */ |
|
46 | - public function getAvatar(string $user) : IAvatar; |
|
37 | + /** |
|
38 | + * return a user specific instance of \OCP\IAvatar |
|
39 | + * @see IAvatar |
|
40 | + * @param string $user the ownCloud user id |
|
41 | + * @return IAvatar |
|
42 | + * @throws \Exception In case the username is potentially dangerous |
|
43 | + * @throws \OCP\Files\NotFoundException In case there is no user folder yet |
|
44 | + * @since 6.0.0 |
|
45 | + */ |
|
46 | + public function getAvatar(string $user) : IAvatar; |
|
47 | 47 | |
48 | - /** |
|
49 | - * Returns a guest user avatar instance. |
|
50 | - * |
|
51 | - * @param string $name The guest name, e.g. "Albert". |
|
52 | - * @return IAvatar |
|
53 | - * @since 16.0.0 |
|
54 | - */ |
|
55 | - public function getGuestAvatar(string $name): IAvatar; |
|
48 | + /** |
|
49 | + * Returns a guest user avatar instance. |
|
50 | + * |
|
51 | + * @param string $name The guest name, e.g. "Albert". |
|
52 | + * @return IAvatar |
|
53 | + * @since 16.0.0 |
|
54 | + */ |
|
55 | + public function getGuestAvatar(string $name): IAvatar; |
|
56 | 56 | |
57 | 57 | } |
@@ -30,90 +30,90 @@ |
||
30 | 30 | * This class represents a guest user's avatar. |
31 | 31 | */ |
32 | 32 | class GuestAvatar extends Avatar { |
33 | - /** |
|
34 | - * Holds the guest user display name. |
|
35 | - * |
|
36 | - * @var string |
|
37 | - */ |
|
38 | - private $userDisplayName; |
|
33 | + /** |
|
34 | + * Holds the guest user display name. |
|
35 | + * |
|
36 | + * @var string |
|
37 | + */ |
|
38 | + private $userDisplayName; |
|
39 | 39 | |
40 | - /** |
|
41 | - * GuestAvatar constructor. |
|
42 | - * |
|
43 | - * @param string $userDisplayName The guest user display name |
|
44 | - * @param ILogger $logger The logger |
|
45 | - */ |
|
46 | - public function __construct(string $userDisplayName, ILogger $logger) { |
|
47 | - parent::__construct($logger); |
|
48 | - $this->userDisplayName = $userDisplayName; |
|
49 | - } |
|
40 | + /** |
|
41 | + * GuestAvatar constructor. |
|
42 | + * |
|
43 | + * @param string $userDisplayName The guest user display name |
|
44 | + * @param ILogger $logger The logger |
|
45 | + */ |
|
46 | + public function __construct(string $userDisplayName, ILogger $logger) { |
|
47 | + parent::__construct($logger); |
|
48 | + $this->userDisplayName = $userDisplayName; |
|
49 | + } |
|
50 | 50 | |
51 | - /** |
|
52 | - * Tests if the user has an avatar. |
|
53 | - * |
|
54 | - * @return true Guests always have an avatar. |
|
55 | - */ |
|
56 | - public function exists() { |
|
57 | - return true; |
|
58 | - } |
|
51 | + /** |
|
52 | + * Tests if the user has an avatar. |
|
53 | + * |
|
54 | + * @return true Guests always have an avatar. |
|
55 | + */ |
|
56 | + public function exists() { |
|
57 | + return true; |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * Returns the guest user display name. |
|
62 | - * |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function getDisplayName(): string { |
|
66 | - return $this->userDisplayName; |
|
67 | - } |
|
60 | + /** |
|
61 | + * Returns the guest user display name. |
|
62 | + * |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function getDisplayName(): string { |
|
66 | + return $this->userDisplayName; |
|
67 | + } |
|
68 | 68 | |
69 | - /** |
|
70 | - * Setting avatars isn't implemented for guests. |
|
71 | - * |
|
72 | - * @param \OCP\IImage|resource|string $data |
|
73 | - * @return void |
|
74 | - */ |
|
75 | - public function set($data) { |
|
76 | - // unimplemented for guest user avatars |
|
77 | - } |
|
69 | + /** |
|
70 | + * Setting avatars isn't implemented for guests. |
|
71 | + * |
|
72 | + * @param \OCP\IImage|resource|string $data |
|
73 | + * @return void |
|
74 | + */ |
|
75 | + public function set($data) { |
|
76 | + // unimplemented for guest user avatars |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * Removing avatars isn't implemented for guests. |
|
81 | - */ |
|
82 | - public function remove() { |
|
83 | - // unimplemented for guest user avatars |
|
84 | - } |
|
79 | + /** |
|
80 | + * Removing avatars isn't implemented for guests. |
|
81 | + */ |
|
82 | + public function remove() { |
|
83 | + // unimplemented for guest user avatars |
|
84 | + } |
|
85 | 85 | |
86 | - /** |
|
87 | - * Generates an avatar for the guest. |
|
88 | - * |
|
89 | - * @param int $size The desired image size. |
|
90 | - * @return InMemoryFile |
|
91 | - */ |
|
92 | - public function getFile($size) { |
|
93 | - $avatar = $this->generateAvatar($this->userDisplayName, $size); |
|
94 | - return new InMemoryFile('avatar.png', $avatar); |
|
95 | - } |
|
86 | + /** |
|
87 | + * Generates an avatar for the guest. |
|
88 | + * |
|
89 | + * @param int $size The desired image size. |
|
90 | + * @return InMemoryFile |
|
91 | + */ |
|
92 | + public function getFile($size) { |
|
93 | + $avatar = $this->generateAvatar($this->userDisplayName, $size); |
|
94 | + return new InMemoryFile('avatar.png', $avatar); |
|
95 | + } |
|
96 | 96 | |
97 | - /** |
|
98 | - * Updates the display name if changed. |
|
99 | - * |
|
100 | - * @param string $feature The changed feature |
|
101 | - * @param mixed $oldValue The previous value |
|
102 | - * @param mixed $newValue The new value |
|
103 | - * @return void |
|
104 | - */ |
|
105 | - public function userChanged($feature, $oldValue, $newValue) { |
|
106 | - if ($feature === 'displayName') { |
|
107 | - $this->userDisplayName = $newValue; |
|
108 | - } |
|
109 | - } |
|
97 | + /** |
|
98 | + * Updates the display name if changed. |
|
99 | + * |
|
100 | + * @param string $feature The changed feature |
|
101 | + * @param mixed $oldValue The previous value |
|
102 | + * @param mixed $newValue The new value |
|
103 | + * @return void |
|
104 | + */ |
|
105 | + public function userChanged($feature, $oldValue, $newValue) { |
|
106 | + if ($feature === 'displayName') { |
|
107 | + $this->userDisplayName = $newValue; |
|
108 | + } |
|
109 | + } |
|
110 | 110 | |
111 | - /** |
|
112 | - * Guests don't have custom avatars. |
|
113 | - * |
|
114 | - * @return bool |
|
115 | - */ |
|
116 | - public function isCustomAvatar(): bool { |
|
117 | - return false; |
|
118 | - } |
|
111 | + /** |
|
112 | + * Guests don't have custom avatars. |
|
113 | + * |
|
114 | + * @return bool |
|
115 | + */ |
|
116 | + public function isCustomAvatar(): bool { |
|
117 | + return false; |
|
118 | + } |
|
119 | 119 | } |
@@ -33,75 +33,75 @@ |
||
33 | 33 | */ |
34 | 34 | class GuestAvatarController extends Controller { |
35 | 35 | |
36 | - /** |
|
37 | - * @var ILogger |
|
38 | - */ |
|
39 | - private $logger; |
|
36 | + /** |
|
37 | + * @var ILogger |
|
38 | + */ |
|
39 | + private $logger; |
|
40 | 40 | |
41 | - /** |
|
42 | - * @var IAvatarManager |
|
43 | - */ |
|
44 | - private $avatarManager; |
|
41 | + /** |
|
42 | + * @var IAvatarManager |
|
43 | + */ |
|
44 | + private $avatarManager; |
|
45 | 45 | |
46 | - /** |
|
47 | - * GuestAvatarController constructor. |
|
48 | - * |
|
49 | - * @param $appName |
|
50 | - * @param IRequest $request |
|
51 | - * @param IAvatarManager $avatarManager |
|
52 | - * @param ILogger $logger |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - $appName, |
|
56 | - IRequest $request, |
|
57 | - IAvatarManager $avatarManager, |
|
58 | - ILogger $logger |
|
59 | - ) { |
|
60 | - parent::__construct($appName, $request); |
|
61 | - $this->avatarManager = $avatarManager; |
|
62 | - $this->logger = $logger; |
|
63 | - } |
|
46 | + /** |
|
47 | + * GuestAvatarController constructor. |
|
48 | + * |
|
49 | + * @param $appName |
|
50 | + * @param IRequest $request |
|
51 | + * @param IAvatarManager $avatarManager |
|
52 | + * @param ILogger $logger |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + $appName, |
|
56 | + IRequest $request, |
|
57 | + IAvatarManager $avatarManager, |
|
58 | + ILogger $logger |
|
59 | + ) { |
|
60 | + parent::__construct($appName, $request); |
|
61 | + $this->avatarManager = $avatarManager; |
|
62 | + $this->logger = $logger; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * Returns a guest avatar image response. |
|
67 | - * |
|
68 | - * @PublicPage |
|
69 | - * @NoCSRFRequired |
|
70 | - * |
|
71 | - * @param string $guestName The guest name, e.g. "Albert" |
|
72 | - * @param string $size The desired avatar size, e.g. 64 for 64x64px |
|
73 | - * @return FileDisplayResponse|Http\Response |
|
74 | - */ |
|
75 | - public function getAvatar($guestName, $size) { |
|
76 | - $size = (int) $size; |
|
65 | + /** |
|
66 | + * Returns a guest avatar image response. |
|
67 | + * |
|
68 | + * @PublicPage |
|
69 | + * @NoCSRFRequired |
|
70 | + * |
|
71 | + * @param string $guestName The guest name, e.g. "Albert" |
|
72 | + * @param string $size The desired avatar size, e.g. 64 for 64x64px |
|
73 | + * @return FileDisplayResponse|Http\Response |
|
74 | + */ |
|
75 | + public function getAvatar($guestName, $size) { |
|
76 | + $size = (int) $size; |
|
77 | 77 | |
78 | - // min/max size |
|
79 | - if ($size > 2048) { |
|
80 | - $size = 2048; |
|
81 | - } elseif ($size <= 0) { |
|
82 | - $size = 64; |
|
83 | - } |
|
78 | + // min/max size |
|
79 | + if ($size > 2048) { |
|
80 | + $size = 2048; |
|
81 | + } elseif ($size <= 0) { |
|
82 | + $size = 64; |
|
83 | + } |
|
84 | 84 | |
85 | - try { |
|
86 | - $avatar = $this->avatarManager->getGuestAvatar($guestName); |
|
87 | - $avatarFile = $avatar->getFile($size); |
|
85 | + try { |
|
86 | + $avatar = $this->avatarManager->getGuestAvatar($guestName); |
|
87 | + $avatarFile = $avatar->getFile($size); |
|
88 | 88 | |
89 | - $resp = new FileDisplayResponse( |
|
90 | - $avatarFile, |
|
91 | - $avatar->isCustomAvatar() ? Http::STATUS_OK : Http::STATUS_CREATED, |
|
92 | - ['Content-Type' => $avatarFile->getMimeType()] |
|
93 | - ); |
|
94 | - } catch (\Exception $e) { |
|
95 | - $this->logger->error('error while creating guest avatar', [ |
|
96 | - 'err' => $e, |
|
97 | - ]); |
|
98 | - $resp = new Http\Response(); |
|
99 | - $resp->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); |
|
100 | - return $resp; |
|
101 | - } |
|
89 | + $resp = new FileDisplayResponse( |
|
90 | + $avatarFile, |
|
91 | + $avatar->isCustomAvatar() ? Http::STATUS_OK : Http::STATUS_CREATED, |
|
92 | + ['Content-Type' => $avatarFile->getMimeType()] |
|
93 | + ); |
|
94 | + } catch (\Exception $e) { |
|
95 | + $this->logger->error('error while creating guest avatar', [ |
|
96 | + 'err' => $e, |
|
97 | + ]); |
|
98 | + $resp = new Http\Response(); |
|
99 | + $resp->setStatus(Http::STATUS_INTERNAL_SERVER_ERROR); |
|
100 | + return $resp; |
|
101 | + } |
|
102 | 102 | |
103 | - // Cache for 30 minutes |
|
104 | - $resp->cacheFor(1800); |
|
105 | - return $resp; |
|
106 | - } |
|
103 | + // Cache for 30 minutes |
|
104 | + $resp->cacheFor(1800); |
|
105 | + return $resp; |
|
106 | + } |
|
107 | 107 | } |
@@ -38,326 +38,326 @@ |
||
38 | 38 | * @since 8.2.0 |
39 | 39 | */ |
40 | 40 | interface IEvent { |
41 | - /** |
|
42 | - * Set the app of the activity |
|
43 | - * |
|
44 | - * @param string $app |
|
45 | - * @return IEvent |
|
46 | - * @throws \InvalidArgumentException if the app id is invalid |
|
47 | - * @since 8.2.0 |
|
48 | - */ |
|
49 | - public function setApp(string $app): self; |
|
50 | - |
|
51 | - /** |
|
52 | - * Set the type of the activity |
|
53 | - * |
|
54 | - * @param string $type |
|
55 | - * @return IEvent |
|
56 | - * @throws \InvalidArgumentException if the type is invalid |
|
57 | - * @since 8.2.0 |
|
58 | - */ |
|
59 | - public function setType(string $type): self; |
|
60 | - |
|
61 | - /** |
|
62 | - * Set the affected user of the activity |
|
63 | - * |
|
64 | - * @param string $user |
|
65 | - * @return IEvent |
|
66 | - * @throws \InvalidArgumentException if the affected user is invalid |
|
67 | - * @since 8.2.0 |
|
68 | - */ |
|
69 | - public function setAffectedUser(string $user): self; |
|
70 | - |
|
71 | - /** |
|
72 | - * Set the author of the activity |
|
73 | - * |
|
74 | - * @param string $author |
|
75 | - * @return IEvent |
|
76 | - * @throws \InvalidArgumentException if the author is invalid |
|
77 | - * @since 8.2.0 |
|
78 | - */ |
|
79 | - public function setAuthor(string $author): self; |
|
80 | - |
|
81 | - /** |
|
82 | - * Set the author of the activity |
|
83 | - * |
|
84 | - * @param int $timestamp |
|
85 | - * @return IEvent |
|
86 | - * @throws \InvalidArgumentException if the timestamp is invalid |
|
87 | - * @since 8.2.0 |
|
88 | - */ |
|
89 | - public function setTimestamp(int $timestamp): self; |
|
90 | - |
|
91 | - /** |
|
92 | - * Set the subject of the activity |
|
93 | - * |
|
94 | - * @param string $subject |
|
95 | - * @param array $parameters |
|
96 | - * @return IEvent |
|
97 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
98 | - * @since 8.2.0 |
|
99 | - */ |
|
100 | - public function setSubject(string $subject, array $parameters = []): self; |
|
101 | - |
|
102 | - /** |
|
103 | - * Set a parsed subject |
|
104 | - * |
|
105 | - * HTML is not allowed in the parsed subject and will be escaped |
|
106 | - * automatically by the clients. You can use the RichObjectString system |
|
107 | - * provided by the Nextcloud server to highlight important parameters via |
|
108 | - * the setRichSubject method, but make sure, that a plain text message is |
|
109 | - * always set via setParsedSubject, to support clients which can not handle |
|
110 | - * rich strings. |
|
111 | - * |
|
112 | - * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
113 | - * |
|
114 | - * @param string $subject |
|
115 | - * @return $this |
|
116 | - * @throws \InvalidArgumentException if the subject is invalid |
|
117 | - * @since 11.0.0 |
|
118 | - */ |
|
119 | - public function setParsedSubject(string $subject): self; |
|
120 | - |
|
121 | - /** |
|
122 | - * @return string |
|
123 | - * @since 11.0.0 |
|
124 | - */ |
|
125 | - public function getParsedSubject(): string; |
|
126 | - |
|
127 | - /** |
|
128 | - * Set a RichObjectString subject |
|
129 | - * |
|
130 | - * HTML is not allowed in the rich subject and will be escaped automatically |
|
131 | - * by the clients, but you can use the RichObjectString system provided by |
|
132 | - * the Nextcloud server to highlight important parameters. |
|
133 | - * Also make sure, that a plain text subject is always set via |
|
134 | - * setParsedSubject, to support clients which can not handle rich strings. |
|
135 | - * |
|
136 | - * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
137 | - * |
|
138 | - * @param string $subject |
|
139 | - * @param array $parameters |
|
140 | - * @return $this |
|
141 | - * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
142 | - * @since 11.0.0 |
|
143 | - */ |
|
144 | - public function setRichSubject(string $subject, array $parameters = []): self; |
|
145 | - |
|
146 | - /** |
|
147 | - * @return string |
|
148 | - * @since 11.0.0 |
|
149 | - */ |
|
150 | - public function getRichSubject(): string; |
|
151 | - |
|
152 | - /** |
|
153 | - * @return array[] |
|
154 | - * @since 11.0.0 |
|
155 | - */ |
|
156 | - public function getRichSubjectParameters(): array; |
|
157 | - |
|
158 | - /** |
|
159 | - * Set the message of the activity |
|
160 | - * |
|
161 | - * @param string $message |
|
162 | - * @param array $parameters |
|
163 | - * @return IEvent |
|
164 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
165 | - * @since 8.2.0 |
|
166 | - */ |
|
167 | - public function setMessage(string $message, array $parameters = []): self; |
|
168 | - |
|
169 | - /** |
|
170 | - * Set a parsed message |
|
171 | - * |
|
172 | - * HTML is not allowed in the parsed message and will be escaped |
|
173 | - * automatically by the clients. You can use the RichObjectString system |
|
174 | - * provided by the Nextcloud server to highlight important parameters via |
|
175 | - * the setRichMessage method, but make sure, that a plain text message is |
|
176 | - * always set via setParsedMessage, to support clients which can not handle |
|
177 | - * rich strings. |
|
178 | - * |
|
179 | - * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
180 | - * |
|
181 | - * @param string $message |
|
182 | - * @return $this |
|
183 | - * @throws \InvalidArgumentException if the message is invalid |
|
184 | - * @since 11.0.0 |
|
185 | - */ |
|
186 | - public function setParsedMessage(string $message): self; |
|
187 | - |
|
188 | - /** |
|
189 | - * @return string |
|
190 | - * @since 11.0.0 |
|
191 | - */ |
|
192 | - public function getParsedMessage(): string; |
|
193 | - |
|
194 | - /** |
|
195 | - * Set a RichObjectString message |
|
196 | - * |
|
197 | - * HTML is not allowed in the rich message and will be escaped automatically |
|
198 | - * by the clients, but you can use the RichObjectString system provided by |
|
199 | - * the Nextcloud server to highlight important parameters. |
|
200 | - * Also make sure, that a plain text message is always set via |
|
201 | - * setParsedMessage, to support clients which can not handle rich strings. |
|
202 | - * |
|
203 | - * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
204 | - * |
|
205 | - * @param string $message |
|
206 | - * @param array $parameters |
|
207 | - * @return $this |
|
208 | - * @throws \InvalidArgumentException if the message or parameters are invalid |
|
209 | - * @since 11.0.0 |
|
210 | - */ |
|
211 | - public function setRichMessage(string $message, array $parameters = []): self; |
|
212 | - |
|
213 | - /** |
|
214 | - * @return string |
|
215 | - * @since 11.0.0 |
|
216 | - */ |
|
217 | - public function getRichMessage(): string; |
|
218 | - |
|
219 | - /** |
|
220 | - * @return array[] |
|
221 | - * @since 11.0.0 |
|
222 | - */ |
|
223 | - public function getRichMessageParameters(): array; |
|
224 | - |
|
225 | - /** |
|
226 | - * Set the object of the activity |
|
227 | - * |
|
228 | - * @param string $objectType |
|
229 | - * @param int $objectId |
|
230 | - * @param string $objectName |
|
231 | - * @return IEvent |
|
232 | - * @throws \InvalidArgumentException if the object is invalid |
|
233 | - * @since 8.2.0 |
|
234 | - */ |
|
235 | - public function setObject(string $objectType, int $objectId, string $objectName = ''): self; |
|
236 | - |
|
237 | - /** |
|
238 | - * Set the link of the activity |
|
239 | - * |
|
240 | - * @param string $link |
|
241 | - * @return IEvent |
|
242 | - * @throws \InvalidArgumentException if the link is invalid |
|
243 | - * @since 8.2.0 |
|
244 | - */ |
|
245 | - public function setLink(string $link): self; |
|
246 | - |
|
247 | - /** |
|
248 | - * @return string |
|
249 | - * @since 8.2.0 |
|
250 | - */ |
|
251 | - public function getApp(): string; |
|
252 | - |
|
253 | - /** |
|
254 | - * @return string |
|
255 | - * @since 8.2.0 |
|
256 | - */ |
|
257 | - public function getType(): string; |
|
258 | - |
|
259 | - /** |
|
260 | - * @return string |
|
261 | - * @since 8.2.0 |
|
262 | - */ |
|
263 | - public function getAffectedUser(): string; |
|
264 | - |
|
265 | - /** |
|
266 | - * @return string |
|
267 | - * @since 8.2.0 |
|
268 | - */ |
|
269 | - public function getAuthor(): string; |
|
270 | - |
|
271 | - /** |
|
272 | - * @return int |
|
273 | - * @since 8.2.0 |
|
274 | - */ |
|
275 | - public function getTimestamp(): int; |
|
276 | - |
|
277 | - /** |
|
278 | - * @return string |
|
279 | - * @since 8.2.0 |
|
280 | - */ |
|
281 | - public function getSubject(): string; |
|
282 | - |
|
283 | - /** |
|
284 | - * @return array |
|
285 | - * @since 8.2.0 |
|
286 | - */ |
|
287 | - public function getSubjectParameters(): array; |
|
288 | - |
|
289 | - /** |
|
290 | - * @return string |
|
291 | - * @since 8.2.0 |
|
292 | - */ |
|
293 | - public function getMessage(): string; |
|
294 | - |
|
295 | - /** |
|
296 | - * @return array |
|
297 | - * @since 8.2.0 |
|
298 | - */ |
|
299 | - public function getMessageParameters(): array; |
|
300 | - |
|
301 | - /** |
|
302 | - * @return string |
|
303 | - * @since 8.2.0 |
|
304 | - */ |
|
305 | - public function getObjectType(): string; |
|
306 | - |
|
307 | - /** |
|
308 | - * @return int |
|
309 | - * @since 8.2.0 |
|
310 | - */ |
|
311 | - public function getObjectId(): int; |
|
312 | - |
|
313 | - /** |
|
314 | - * @return string |
|
315 | - * @since 8.2.0 |
|
316 | - */ |
|
317 | - public function getObjectName(): string; |
|
318 | - |
|
319 | - /** |
|
320 | - * @return string |
|
321 | - * @since 8.2.0 |
|
322 | - */ |
|
323 | - public function getLink(): string; |
|
324 | - |
|
325 | - /** |
|
326 | - * @param string $icon |
|
327 | - * @return $this |
|
328 | - * @throws \InvalidArgumentException if the icon is invalid |
|
329 | - * @since 11.0.0 |
|
330 | - */ |
|
331 | - public function setIcon(string $icon): self; |
|
332 | - |
|
333 | - /** |
|
334 | - * @return string |
|
335 | - * @since 11.0.0 |
|
336 | - */ |
|
337 | - public function getIcon(): string; |
|
338 | - |
|
339 | - /** |
|
340 | - * @param IEvent $child |
|
341 | - * @return $this |
|
342 | - * @since 11.0.0 - Since 15.0.0 returns $this |
|
343 | - */ |
|
344 | - public function setChildEvent(IEvent $child): self; |
|
345 | - |
|
346 | - /** |
|
347 | - * @return IEvent|null |
|
348 | - * @since 11.0.0 |
|
349 | - */ |
|
350 | - public function getChildEvent(); |
|
351 | - |
|
352 | - /** |
|
353 | - * @return bool |
|
354 | - * @since 11.0.0 |
|
355 | - */ |
|
356 | - public function isValid(): bool; |
|
357 | - |
|
358 | - /** |
|
359 | - * @return bool |
|
360 | - * @since 11.0.0 |
|
361 | - */ |
|
362 | - public function isValidParsed(): bool; |
|
41 | + /** |
|
42 | + * Set the app of the activity |
|
43 | + * |
|
44 | + * @param string $app |
|
45 | + * @return IEvent |
|
46 | + * @throws \InvalidArgumentException if the app id is invalid |
|
47 | + * @since 8.2.0 |
|
48 | + */ |
|
49 | + public function setApp(string $app): self; |
|
50 | + |
|
51 | + /** |
|
52 | + * Set the type of the activity |
|
53 | + * |
|
54 | + * @param string $type |
|
55 | + * @return IEvent |
|
56 | + * @throws \InvalidArgumentException if the type is invalid |
|
57 | + * @since 8.2.0 |
|
58 | + */ |
|
59 | + public function setType(string $type): self; |
|
60 | + |
|
61 | + /** |
|
62 | + * Set the affected user of the activity |
|
63 | + * |
|
64 | + * @param string $user |
|
65 | + * @return IEvent |
|
66 | + * @throws \InvalidArgumentException if the affected user is invalid |
|
67 | + * @since 8.2.0 |
|
68 | + */ |
|
69 | + public function setAffectedUser(string $user): self; |
|
70 | + |
|
71 | + /** |
|
72 | + * Set the author of the activity |
|
73 | + * |
|
74 | + * @param string $author |
|
75 | + * @return IEvent |
|
76 | + * @throws \InvalidArgumentException if the author is invalid |
|
77 | + * @since 8.2.0 |
|
78 | + */ |
|
79 | + public function setAuthor(string $author): self; |
|
80 | + |
|
81 | + /** |
|
82 | + * Set the author of the activity |
|
83 | + * |
|
84 | + * @param int $timestamp |
|
85 | + * @return IEvent |
|
86 | + * @throws \InvalidArgumentException if the timestamp is invalid |
|
87 | + * @since 8.2.0 |
|
88 | + */ |
|
89 | + public function setTimestamp(int $timestamp): self; |
|
90 | + |
|
91 | + /** |
|
92 | + * Set the subject of the activity |
|
93 | + * |
|
94 | + * @param string $subject |
|
95 | + * @param array $parameters |
|
96 | + * @return IEvent |
|
97 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
98 | + * @since 8.2.0 |
|
99 | + */ |
|
100 | + public function setSubject(string $subject, array $parameters = []): self; |
|
101 | + |
|
102 | + /** |
|
103 | + * Set a parsed subject |
|
104 | + * |
|
105 | + * HTML is not allowed in the parsed subject and will be escaped |
|
106 | + * automatically by the clients. You can use the RichObjectString system |
|
107 | + * provided by the Nextcloud server to highlight important parameters via |
|
108 | + * the setRichSubject method, but make sure, that a plain text message is |
|
109 | + * always set via setParsedSubject, to support clients which can not handle |
|
110 | + * rich strings. |
|
111 | + * |
|
112 | + * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
113 | + * |
|
114 | + * @param string $subject |
|
115 | + * @return $this |
|
116 | + * @throws \InvalidArgumentException if the subject is invalid |
|
117 | + * @since 11.0.0 |
|
118 | + */ |
|
119 | + public function setParsedSubject(string $subject): self; |
|
120 | + |
|
121 | + /** |
|
122 | + * @return string |
|
123 | + * @since 11.0.0 |
|
124 | + */ |
|
125 | + public function getParsedSubject(): string; |
|
126 | + |
|
127 | + /** |
|
128 | + * Set a RichObjectString subject |
|
129 | + * |
|
130 | + * HTML is not allowed in the rich subject and will be escaped automatically |
|
131 | + * by the clients, but you can use the RichObjectString system provided by |
|
132 | + * the Nextcloud server to highlight important parameters. |
|
133 | + * Also make sure, that a plain text subject is always set via |
|
134 | + * setParsedSubject, to support clients which can not handle rich strings. |
|
135 | + * |
|
136 | + * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
137 | + * |
|
138 | + * @param string $subject |
|
139 | + * @param array $parameters |
|
140 | + * @return $this |
|
141 | + * @throws \InvalidArgumentException if the subject or parameters are invalid |
|
142 | + * @since 11.0.0 |
|
143 | + */ |
|
144 | + public function setRichSubject(string $subject, array $parameters = []): self; |
|
145 | + |
|
146 | + /** |
|
147 | + * @return string |
|
148 | + * @since 11.0.0 |
|
149 | + */ |
|
150 | + public function getRichSubject(): string; |
|
151 | + |
|
152 | + /** |
|
153 | + * @return array[] |
|
154 | + * @since 11.0.0 |
|
155 | + */ |
|
156 | + public function getRichSubjectParameters(): array; |
|
157 | + |
|
158 | + /** |
|
159 | + * Set the message of the activity |
|
160 | + * |
|
161 | + * @param string $message |
|
162 | + * @param array $parameters |
|
163 | + * @return IEvent |
|
164 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
165 | + * @since 8.2.0 |
|
166 | + */ |
|
167 | + public function setMessage(string $message, array $parameters = []): self; |
|
168 | + |
|
169 | + /** |
|
170 | + * Set a parsed message |
|
171 | + * |
|
172 | + * HTML is not allowed in the parsed message and will be escaped |
|
173 | + * automatically by the clients. You can use the RichObjectString system |
|
174 | + * provided by the Nextcloud server to highlight important parameters via |
|
175 | + * the setRichMessage method, but make sure, that a plain text message is |
|
176 | + * always set via setParsedMessage, to support clients which can not handle |
|
177 | + * rich strings. |
|
178 | + * |
|
179 | + * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
180 | + * |
|
181 | + * @param string $message |
|
182 | + * @return $this |
|
183 | + * @throws \InvalidArgumentException if the message is invalid |
|
184 | + * @since 11.0.0 |
|
185 | + */ |
|
186 | + public function setParsedMessage(string $message): self; |
|
187 | + |
|
188 | + /** |
|
189 | + * @return string |
|
190 | + * @since 11.0.0 |
|
191 | + */ |
|
192 | + public function getParsedMessage(): string; |
|
193 | + |
|
194 | + /** |
|
195 | + * Set a RichObjectString message |
|
196 | + * |
|
197 | + * HTML is not allowed in the rich message and will be escaped automatically |
|
198 | + * by the clients, but you can use the RichObjectString system provided by |
|
199 | + * the Nextcloud server to highlight important parameters. |
|
200 | + * Also make sure, that a plain text message is always set via |
|
201 | + * setParsedMessage, to support clients which can not handle rich strings. |
|
202 | + * |
|
203 | + * See https://github.com/nextcloud/server/issues/1706 for more information. |
|
204 | + * |
|
205 | + * @param string $message |
|
206 | + * @param array $parameters |
|
207 | + * @return $this |
|
208 | + * @throws \InvalidArgumentException if the message or parameters are invalid |
|
209 | + * @since 11.0.0 |
|
210 | + */ |
|
211 | + public function setRichMessage(string $message, array $parameters = []): self; |
|
212 | + |
|
213 | + /** |
|
214 | + * @return string |
|
215 | + * @since 11.0.0 |
|
216 | + */ |
|
217 | + public function getRichMessage(): string; |
|
218 | + |
|
219 | + /** |
|
220 | + * @return array[] |
|
221 | + * @since 11.0.0 |
|
222 | + */ |
|
223 | + public function getRichMessageParameters(): array; |
|
224 | + |
|
225 | + /** |
|
226 | + * Set the object of the activity |
|
227 | + * |
|
228 | + * @param string $objectType |
|
229 | + * @param int $objectId |
|
230 | + * @param string $objectName |
|
231 | + * @return IEvent |
|
232 | + * @throws \InvalidArgumentException if the object is invalid |
|
233 | + * @since 8.2.0 |
|
234 | + */ |
|
235 | + public function setObject(string $objectType, int $objectId, string $objectName = ''): self; |
|
236 | + |
|
237 | + /** |
|
238 | + * Set the link of the activity |
|
239 | + * |
|
240 | + * @param string $link |
|
241 | + * @return IEvent |
|
242 | + * @throws \InvalidArgumentException if the link is invalid |
|
243 | + * @since 8.2.0 |
|
244 | + */ |
|
245 | + public function setLink(string $link): self; |
|
246 | + |
|
247 | + /** |
|
248 | + * @return string |
|
249 | + * @since 8.2.0 |
|
250 | + */ |
|
251 | + public function getApp(): string; |
|
252 | + |
|
253 | + /** |
|
254 | + * @return string |
|
255 | + * @since 8.2.0 |
|
256 | + */ |
|
257 | + public function getType(): string; |
|
258 | + |
|
259 | + /** |
|
260 | + * @return string |
|
261 | + * @since 8.2.0 |
|
262 | + */ |
|
263 | + public function getAffectedUser(): string; |
|
264 | + |
|
265 | + /** |
|
266 | + * @return string |
|
267 | + * @since 8.2.0 |
|
268 | + */ |
|
269 | + public function getAuthor(): string; |
|
270 | + |
|
271 | + /** |
|
272 | + * @return int |
|
273 | + * @since 8.2.0 |
|
274 | + */ |
|
275 | + public function getTimestamp(): int; |
|
276 | + |
|
277 | + /** |
|
278 | + * @return string |
|
279 | + * @since 8.2.0 |
|
280 | + */ |
|
281 | + public function getSubject(): string; |
|
282 | + |
|
283 | + /** |
|
284 | + * @return array |
|
285 | + * @since 8.2.0 |
|
286 | + */ |
|
287 | + public function getSubjectParameters(): array; |
|
288 | + |
|
289 | + /** |
|
290 | + * @return string |
|
291 | + * @since 8.2.0 |
|
292 | + */ |
|
293 | + public function getMessage(): string; |
|
294 | + |
|
295 | + /** |
|
296 | + * @return array |
|
297 | + * @since 8.2.0 |
|
298 | + */ |
|
299 | + public function getMessageParameters(): array; |
|
300 | + |
|
301 | + /** |
|
302 | + * @return string |
|
303 | + * @since 8.2.0 |
|
304 | + */ |
|
305 | + public function getObjectType(): string; |
|
306 | + |
|
307 | + /** |
|
308 | + * @return int |
|
309 | + * @since 8.2.0 |
|
310 | + */ |
|
311 | + public function getObjectId(): int; |
|
312 | + |
|
313 | + /** |
|
314 | + * @return string |
|
315 | + * @since 8.2.0 |
|
316 | + */ |
|
317 | + public function getObjectName(): string; |
|
318 | + |
|
319 | + /** |
|
320 | + * @return string |
|
321 | + * @since 8.2.0 |
|
322 | + */ |
|
323 | + public function getLink(): string; |
|
324 | + |
|
325 | + /** |
|
326 | + * @param string $icon |
|
327 | + * @return $this |
|
328 | + * @throws \InvalidArgumentException if the icon is invalid |
|
329 | + * @since 11.0.0 |
|
330 | + */ |
|
331 | + public function setIcon(string $icon): self; |
|
332 | + |
|
333 | + /** |
|
334 | + * @return string |
|
335 | + * @since 11.0.0 |
|
336 | + */ |
|
337 | + public function getIcon(): string; |
|
338 | + |
|
339 | + /** |
|
340 | + * @param IEvent $child |
|
341 | + * @return $this |
|
342 | + * @since 11.0.0 - Since 15.0.0 returns $this |
|
343 | + */ |
|
344 | + public function setChildEvent(IEvent $child): self; |
|
345 | + |
|
346 | + /** |
|
347 | + * @return IEvent|null |
|
348 | + * @since 11.0.0 |
|
349 | + */ |
|
350 | + public function getChildEvent(); |
|
351 | + |
|
352 | + /** |
|
353 | + * @return bool |
|
354 | + * @since 11.0.0 |
|
355 | + */ |
|
356 | + public function isValid(): bool; |
|
357 | + |
|
358 | + /** |
|
359 | + * @return bool |
|
360 | + * @since 11.0.0 |
|
361 | + */ |
|
362 | + public function isValidParsed(): bool; |
|
363 | 363 | } |
@@ -67,7 +67,7 @@ discard block |
||
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
70 | - $folders = array_filter($folders, function (ISimpleFolder $folder) { |
|
70 | + $folders = array_filter($folders, function(ISimpleFolder $folder) { |
|
71 | 71 | return $folder->fileExists('photo.'); |
72 | 72 | }); |
73 | 73 | |
@@ -75,7 +75,7 @@ discard block |
||
75 | 75 | return; |
76 | 76 | } |
77 | 77 | |
78 | - $output->info('Delete ' . count($folders) . ' "photo." files'); |
|
78 | + $output->info('Delete '.count($folders).' "photo." files'); |
|
79 | 79 | |
80 | 80 | foreach ($folders as $folder) { |
81 | 81 | try { |
@@ -83,7 +83,7 @@ discard block |
||
83 | 83 | $folder->getFile('photo.')->delete(); |
84 | 84 | } catch (\Exception $e) { |
85 | 85 | $this->logger->logException($e); |
86 | - $output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."'); |
|
86 | + $output->warning('Could not delete file "dav-photocache/'.$folder->getName().'/photo."'); |
|
87 | 87 | } |
88 | 88 | } |
89 | 89 | } |
@@ -47,67 +47,67 @@ |
||
47 | 47 | */ |
48 | 48 | class CleanupCardDAVPhotoCache implements IRepairStep { |
49 | 49 | |
50 | - /** @var IConfig */ |
|
51 | - private $config; |
|
52 | - |
|
53 | - /** @var IAppData */ |
|
54 | - private $appData; |
|
55 | - |
|
56 | - /** @var ILogger */ |
|
57 | - private $logger; |
|
58 | - |
|
59 | - public function __construct(IConfig $config, IAppData $appData, ILogger $logger) { |
|
60 | - $this->config = $config; |
|
61 | - $this->appData = $appData; |
|
62 | - $this->logger = $logger; |
|
63 | - } |
|
64 | - |
|
65 | - public function getName(): string { |
|
66 | - return 'Cleanup invalid photocache files for carddav'; |
|
67 | - } |
|
68 | - |
|
69 | - private function repair(IOutput $output): void { |
|
70 | - try { |
|
71 | - $folders = $this->appData->getDirectoryListing(); |
|
72 | - } catch (NotFoundException $e) { |
|
73 | - return; |
|
74 | - } catch (RuntimeException $e) { |
|
75 | - $this->logger->logException($e, ['message' => 'Failed to fetch directory listing in CleanupCardDAVPhotoCache']); |
|
76 | - return; |
|
77 | - } |
|
78 | - |
|
79 | - $folders = array_filter($folders, function (ISimpleFolder $folder) { |
|
80 | - return $folder->fileExists('photo.'); |
|
81 | - }); |
|
82 | - |
|
83 | - if (empty($folders)) { |
|
84 | - return; |
|
85 | - } |
|
86 | - |
|
87 | - $output->info('Delete ' . count($folders) . ' "photo." files'); |
|
88 | - |
|
89 | - foreach ($folders as $folder) { |
|
90 | - try { |
|
91 | - /** @var ISimpleFolder $folder */ |
|
92 | - $folder->getFile('photo.')->delete(); |
|
93 | - } catch (\Exception $e) { |
|
94 | - $this->logger->logException($e); |
|
95 | - $output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."'); |
|
96 | - } |
|
97 | - } |
|
98 | - } |
|
99 | - |
|
100 | - private function shouldRun(): bool { |
|
101 | - return version_compare( |
|
102 | - $this->config->getSystemValue('version', '0.0.0.0'), |
|
103 | - '16.0.0.0', |
|
104 | - '<=' |
|
105 | - ); |
|
106 | - } |
|
107 | - |
|
108 | - public function run(IOutput $output): void { |
|
109 | - if ($this->shouldRun()) { |
|
110 | - $this->repair($output); |
|
111 | - } |
|
112 | - } |
|
50 | + /** @var IConfig */ |
|
51 | + private $config; |
|
52 | + |
|
53 | + /** @var IAppData */ |
|
54 | + private $appData; |
|
55 | + |
|
56 | + /** @var ILogger */ |
|
57 | + private $logger; |
|
58 | + |
|
59 | + public function __construct(IConfig $config, IAppData $appData, ILogger $logger) { |
|
60 | + $this->config = $config; |
|
61 | + $this->appData = $appData; |
|
62 | + $this->logger = $logger; |
|
63 | + } |
|
64 | + |
|
65 | + public function getName(): string { |
|
66 | + return 'Cleanup invalid photocache files for carddav'; |
|
67 | + } |
|
68 | + |
|
69 | + private function repair(IOutput $output): void { |
|
70 | + try { |
|
71 | + $folders = $this->appData->getDirectoryListing(); |
|
72 | + } catch (NotFoundException $e) { |
|
73 | + return; |
|
74 | + } catch (RuntimeException $e) { |
|
75 | + $this->logger->logException($e, ['message' => 'Failed to fetch directory listing in CleanupCardDAVPhotoCache']); |
|
76 | + return; |
|
77 | + } |
|
78 | + |
|
79 | + $folders = array_filter($folders, function (ISimpleFolder $folder) { |
|
80 | + return $folder->fileExists('photo.'); |
|
81 | + }); |
|
82 | + |
|
83 | + if (empty($folders)) { |
|
84 | + return; |
|
85 | + } |
|
86 | + |
|
87 | + $output->info('Delete ' . count($folders) . ' "photo." files'); |
|
88 | + |
|
89 | + foreach ($folders as $folder) { |
|
90 | + try { |
|
91 | + /** @var ISimpleFolder $folder */ |
|
92 | + $folder->getFile('photo.')->delete(); |
|
93 | + } catch (\Exception $e) { |
|
94 | + $this->logger->logException($e); |
|
95 | + $output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."'); |
|
96 | + } |
|
97 | + } |
|
98 | + } |
|
99 | + |
|
100 | + private function shouldRun(): bool { |
|
101 | + return version_compare( |
|
102 | + $this->config->getSystemValue('version', '0.0.0.0'), |
|
103 | + '16.0.0.0', |
|
104 | + '<=' |
|
105 | + ); |
|
106 | + } |
|
107 | + |
|
108 | + public function run(IOutput $output): void { |
|
109 | + if ($this->shouldRun()) { |
|
110 | + $this->repair($output); |
|
111 | + } |
|
112 | + } |
|
113 | 113 | } |
@@ -30,10 +30,10 @@ |
||
30 | 30 | * @since 16.0.0 |
31 | 31 | */ |
32 | 32 | interface IConfigHandler { |
33 | - /** |
|
34 | - * @param mixed $optionValue |
|
35 | - * @return mixed the same type as $optionValue |
|
36 | - * @since 16.0.0 |
|
37 | - */ |
|
38 | - public function handle($optionValue); |
|
33 | + /** |
|
34 | + * @param mixed $optionValue |
|
35 | + * @return mixed the same type as $optionValue |
|
36 | + * @since 16.0.0 |
|
37 | + */ |
|
38 | + public function handle($optionValue); |
|
39 | 39 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | IClientService $httpClientService, |
75 | 75 | ICloudIdManager $cloudIdManager, |
76 | 76 | ILogger $logger) { |
77 | - $this->cloudFederationProvider= []; |
|
77 | + $this->cloudFederationProvider = []; |
|
78 | 78 | $this->appManager = $appManager; |
79 | 79 | $this->httpClientService = $httpClientService; |
80 | 80 | $this->cloudIdManager = $cloudIdManager; |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | |
141 | 141 | $client = $this->httpClientService->newClient(); |
142 | 142 | try { |
143 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
143 | + $response = $client->post($ocmEndPoint.'/shares', [ |
|
144 | 144 | 'body' => json_encode($share->getShare()), |
145 | 145 | 'headers' => ['content-type' => 'application/json'], |
146 | 146 | 'timeout' => 10, |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | |
181 | 181 | $client = $this->httpClientService->newClient(); |
182 | 182 | try { |
183 | - $response = $client->post($ocmEndPoint . '/notifications', [ |
|
183 | + $response = $client->post($ocmEndPoint.'/notifications', [ |
|
184 | 184 | 'body' => json_encode($notification->getMessage()), |
185 | 185 | 'headers' => ['content-type' => 'application/json'], |
186 | 186 | 'timeout' => 10, |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | } |
193 | 193 | } catch (\Exception $e) { |
194 | 194 | // log the error and return false |
195 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
195 | + $this->logger->error('error while sending notification for federated share: '.$e->getMessage()); |
|
196 | 196 | } |
197 | 197 | |
198 | 198 | return false; |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | |
221 | 221 | $client = $this->httpClientService->newClient(); |
222 | 222 | try { |
223 | - $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
223 | + $response = $client->get($url.'/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
224 | 224 | } catch (\Exception $e) { |
225 | 225 | $this->ocmEndPoints[$url] = ''; |
226 | 226 | return ''; |
@@ -43,197 +43,197 @@ |
||
43 | 43 | */ |
44 | 44 | class CloudFederationProviderManager implements ICloudFederationProviderManager { |
45 | 45 | |
46 | - /** @var array list of available cloud federation providers */ |
|
47 | - private $cloudFederationProvider; |
|
48 | - |
|
49 | - /** @var IAppManager */ |
|
50 | - private $appManager; |
|
51 | - |
|
52 | - /** @var IClientService */ |
|
53 | - private $httpClientService; |
|
54 | - |
|
55 | - /** @var ICloudIdManager */ |
|
56 | - private $cloudIdManager; |
|
57 | - |
|
58 | - /** @var ILogger */ |
|
59 | - private $logger; |
|
60 | - |
|
61 | - /** @var array cache OCM end-points */ |
|
62 | - private $ocmEndPoints = []; |
|
63 | - |
|
64 | - private $supportedAPIVersion = '1.0-proposal1'; |
|
65 | - |
|
66 | - /** |
|
67 | - * CloudFederationProviderManager constructor. |
|
68 | - * |
|
69 | - * @param IAppManager $appManager |
|
70 | - * @param IClientService $httpClientService |
|
71 | - * @param ICloudIdManager $cloudIdManager |
|
72 | - * @param ILogger $logger |
|
73 | - */ |
|
74 | - public function __construct(IAppManager $appManager, |
|
75 | - IClientService $httpClientService, |
|
76 | - ICloudIdManager $cloudIdManager, |
|
77 | - ILogger $logger) { |
|
78 | - $this->cloudFederationProvider= []; |
|
79 | - $this->appManager = $appManager; |
|
80 | - $this->httpClientService = $httpClientService; |
|
81 | - $this->cloudIdManager = $cloudIdManager; |
|
82 | - $this->logger = $logger; |
|
83 | - } |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * Registers an callback function which must return an cloud federation provider |
|
88 | - * |
|
89 | - * @param string $resourceType which resource type does the provider handles |
|
90 | - * @param string $displayName user facing name of the federated share provider |
|
91 | - * @param callable $callback |
|
92 | - */ |
|
93 | - public function addCloudFederationProvider($resourceType, $displayName, callable $callback) { |
|
94 | - $this->cloudFederationProvider[$resourceType] = [ |
|
95 | - 'resourceType' => $resourceType, |
|
96 | - 'displayName' => $displayName, |
|
97 | - 'callback' => $callback, |
|
98 | - ]; |
|
99 | - } |
|
100 | - |
|
101 | - /** |
|
102 | - * remove cloud federation provider |
|
103 | - * |
|
104 | - * @param string $providerId |
|
105 | - */ |
|
106 | - public function removeCloudFederationProvider($providerId) { |
|
107 | - unset($this->cloudFederationProvider[$providerId]); |
|
108 | - } |
|
109 | - |
|
110 | - /** |
|
111 | - * get a list of all cloudFederationProviders |
|
112 | - * |
|
113 | - * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
114 | - */ |
|
115 | - public function getAllCloudFederationProviders() { |
|
116 | - return $this->cloudFederationProvider; |
|
117 | - } |
|
118 | - |
|
119 | - /** |
|
120 | - * get a specific cloud federation provider |
|
121 | - * |
|
122 | - * @param string $resourceType |
|
123 | - * @return ICloudFederationProvider |
|
124 | - * @throws ProviderDoesNotExistsException |
|
125 | - */ |
|
126 | - public function getCloudFederationProvider($resourceType) { |
|
127 | - if (isset($this->cloudFederationProvider[$resourceType])) { |
|
128 | - return call_user_func($this->cloudFederationProvider[$resourceType]['callback']); |
|
129 | - } else { |
|
130 | - throw new ProviderDoesNotExistsException($resourceType); |
|
131 | - } |
|
132 | - } |
|
133 | - |
|
134 | - public function sendShare(ICloudFederationShare $share) { |
|
135 | - $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
136 | - $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
137 | - if (empty($ocmEndPoint)) { |
|
138 | - return false; |
|
139 | - } |
|
140 | - |
|
141 | - $client = $this->httpClientService->newClient(); |
|
142 | - try { |
|
143 | - $response = $client->post($ocmEndPoint . '/shares', [ |
|
144 | - 'body' => json_encode($share->getShare()), |
|
145 | - 'headers' => ['content-type' => 'application/json'], |
|
146 | - 'timeout' => 10, |
|
147 | - 'connect_timeout' => 10, |
|
148 | - ]); |
|
149 | - |
|
150 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
151 | - $result = json_decode($response->getBody(), true); |
|
152 | - return (is_array($result)) ? $result : []; |
|
153 | - } |
|
154 | - } catch (\Exception $e) { |
|
155 | - // if flat re-sharing is not supported by the remote server |
|
156 | - // we re-throw the exception and fall back to the old behaviour. |
|
157 | - // (flat re-shares has been introduced in Nextcloud 9.1) |
|
158 | - if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
159 | - $this->logger->debug($e->getMessage()); |
|
160 | - throw $e; |
|
161 | - } |
|
162 | - } |
|
163 | - |
|
164 | - return false; |
|
165 | - } |
|
166 | - |
|
167 | - /** |
|
168 | - * @param string $url |
|
169 | - * @param ICloudFederationNotification $notification |
|
170 | - * @return mixed |
|
171 | - */ |
|
172 | - public function sendNotification($url, ICloudFederationNotification $notification) { |
|
173 | - $ocmEndPoint = $this->getOCMEndPoint($url); |
|
174 | - |
|
175 | - if (empty($ocmEndPoint)) { |
|
176 | - return false; |
|
177 | - } |
|
178 | - |
|
179 | - $client = $this->httpClientService->newClient(); |
|
180 | - try { |
|
181 | - $response = $client->post($ocmEndPoint . '/notifications', [ |
|
182 | - 'body' => json_encode($notification->getMessage()), |
|
183 | - 'headers' => ['content-type' => 'application/json'], |
|
184 | - 'timeout' => 10, |
|
185 | - 'connect_timeout' => 10, |
|
186 | - ]); |
|
187 | - if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
188 | - $result = json_decode($response->getBody(), true); |
|
189 | - return (is_array($result)) ? $result : []; |
|
190 | - } |
|
191 | - } catch (\Exception $e) { |
|
192 | - // log the error and return false |
|
193 | - $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
194 | - } |
|
195 | - |
|
196 | - return false; |
|
197 | - } |
|
198 | - |
|
199 | - /** |
|
200 | - * check if the new cloud federation API is ready to be used |
|
201 | - * |
|
202 | - * @return bool |
|
203 | - */ |
|
204 | - public function isReady() { |
|
205 | - return $this->appManager->isEnabledForUser('cloud_federation_api'); |
|
206 | - } |
|
207 | - /** |
|
208 | - * check if server supports the new OCM api and ask for the correct end-point |
|
209 | - * |
|
210 | - * @param string $url full base URL of the cloud server |
|
211 | - * @return string |
|
212 | - */ |
|
213 | - protected function getOCMEndPoint($url) { |
|
214 | - if (isset($this->ocmEndPoints[$url])) { |
|
215 | - return $this->ocmEndPoints[$url]; |
|
216 | - } |
|
217 | - |
|
218 | - $client = $this->httpClientService->newClient(); |
|
219 | - try { |
|
220 | - $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
221 | - } catch (\Exception $e) { |
|
222 | - $this->ocmEndPoints[$url] = ''; |
|
223 | - return ''; |
|
224 | - } |
|
225 | - |
|
226 | - $result = $response->getBody(); |
|
227 | - $result = json_decode($result, true); |
|
228 | - |
|
229 | - $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
230 | - |
|
231 | - if (isset($result['endPoint']) && $supportedVersion) { |
|
232 | - $this->ocmEndPoints[$url] = $result['endPoint']; |
|
233 | - return $result['endPoint']; |
|
234 | - } |
|
235 | - |
|
236 | - $this->ocmEndPoints[$url] = ''; |
|
237 | - return ''; |
|
238 | - } |
|
46 | + /** @var array list of available cloud federation providers */ |
|
47 | + private $cloudFederationProvider; |
|
48 | + |
|
49 | + /** @var IAppManager */ |
|
50 | + private $appManager; |
|
51 | + |
|
52 | + /** @var IClientService */ |
|
53 | + private $httpClientService; |
|
54 | + |
|
55 | + /** @var ICloudIdManager */ |
|
56 | + private $cloudIdManager; |
|
57 | + |
|
58 | + /** @var ILogger */ |
|
59 | + private $logger; |
|
60 | + |
|
61 | + /** @var array cache OCM end-points */ |
|
62 | + private $ocmEndPoints = []; |
|
63 | + |
|
64 | + private $supportedAPIVersion = '1.0-proposal1'; |
|
65 | + |
|
66 | + /** |
|
67 | + * CloudFederationProviderManager constructor. |
|
68 | + * |
|
69 | + * @param IAppManager $appManager |
|
70 | + * @param IClientService $httpClientService |
|
71 | + * @param ICloudIdManager $cloudIdManager |
|
72 | + * @param ILogger $logger |
|
73 | + */ |
|
74 | + public function __construct(IAppManager $appManager, |
|
75 | + IClientService $httpClientService, |
|
76 | + ICloudIdManager $cloudIdManager, |
|
77 | + ILogger $logger) { |
|
78 | + $this->cloudFederationProvider= []; |
|
79 | + $this->appManager = $appManager; |
|
80 | + $this->httpClientService = $httpClientService; |
|
81 | + $this->cloudIdManager = $cloudIdManager; |
|
82 | + $this->logger = $logger; |
|
83 | + } |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * Registers an callback function which must return an cloud federation provider |
|
88 | + * |
|
89 | + * @param string $resourceType which resource type does the provider handles |
|
90 | + * @param string $displayName user facing name of the federated share provider |
|
91 | + * @param callable $callback |
|
92 | + */ |
|
93 | + public function addCloudFederationProvider($resourceType, $displayName, callable $callback) { |
|
94 | + $this->cloudFederationProvider[$resourceType] = [ |
|
95 | + 'resourceType' => $resourceType, |
|
96 | + 'displayName' => $displayName, |
|
97 | + 'callback' => $callback, |
|
98 | + ]; |
|
99 | + } |
|
100 | + |
|
101 | + /** |
|
102 | + * remove cloud federation provider |
|
103 | + * |
|
104 | + * @param string $providerId |
|
105 | + */ |
|
106 | + public function removeCloudFederationProvider($providerId) { |
|
107 | + unset($this->cloudFederationProvider[$providerId]); |
|
108 | + } |
|
109 | + |
|
110 | + /** |
|
111 | + * get a list of all cloudFederationProviders |
|
112 | + * |
|
113 | + * @return array [resourceType => ['resourceType' => $resourceType, 'displayName' => $displayName, 'callback' => callback]] |
|
114 | + */ |
|
115 | + public function getAllCloudFederationProviders() { |
|
116 | + return $this->cloudFederationProvider; |
|
117 | + } |
|
118 | + |
|
119 | + /** |
|
120 | + * get a specific cloud federation provider |
|
121 | + * |
|
122 | + * @param string $resourceType |
|
123 | + * @return ICloudFederationProvider |
|
124 | + * @throws ProviderDoesNotExistsException |
|
125 | + */ |
|
126 | + public function getCloudFederationProvider($resourceType) { |
|
127 | + if (isset($this->cloudFederationProvider[$resourceType])) { |
|
128 | + return call_user_func($this->cloudFederationProvider[$resourceType]['callback']); |
|
129 | + } else { |
|
130 | + throw new ProviderDoesNotExistsException($resourceType); |
|
131 | + } |
|
132 | + } |
|
133 | + |
|
134 | + public function sendShare(ICloudFederationShare $share) { |
|
135 | + $cloudID = $this->cloudIdManager->resolveCloudId($share->getShareWith()); |
|
136 | + $ocmEndPoint = $this->getOCMEndPoint($cloudID->getRemote()); |
|
137 | + if (empty($ocmEndPoint)) { |
|
138 | + return false; |
|
139 | + } |
|
140 | + |
|
141 | + $client = $this->httpClientService->newClient(); |
|
142 | + try { |
|
143 | + $response = $client->post($ocmEndPoint . '/shares', [ |
|
144 | + 'body' => json_encode($share->getShare()), |
|
145 | + 'headers' => ['content-type' => 'application/json'], |
|
146 | + 'timeout' => 10, |
|
147 | + 'connect_timeout' => 10, |
|
148 | + ]); |
|
149 | + |
|
150 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
151 | + $result = json_decode($response->getBody(), true); |
|
152 | + return (is_array($result)) ? $result : []; |
|
153 | + } |
|
154 | + } catch (\Exception $e) { |
|
155 | + // if flat re-sharing is not supported by the remote server |
|
156 | + // we re-throw the exception and fall back to the old behaviour. |
|
157 | + // (flat re-shares has been introduced in Nextcloud 9.1) |
|
158 | + if ($e->getCode() === Http::STATUS_INTERNAL_SERVER_ERROR) { |
|
159 | + $this->logger->debug($e->getMessage()); |
|
160 | + throw $e; |
|
161 | + } |
|
162 | + } |
|
163 | + |
|
164 | + return false; |
|
165 | + } |
|
166 | + |
|
167 | + /** |
|
168 | + * @param string $url |
|
169 | + * @param ICloudFederationNotification $notification |
|
170 | + * @return mixed |
|
171 | + */ |
|
172 | + public function sendNotification($url, ICloudFederationNotification $notification) { |
|
173 | + $ocmEndPoint = $this->getOCMEndPoint($url); |
|
174 | + |
|
175 | + if (empty($ocmEndPoint)) { |
|
176 | + return false; |
|
177 | + } |
|
178 | + |
|
179 | + $client = $this->httpClientService->newClient(); |
|
180 | + try { |
|
181 | + $response = $client->post($ocmEndPoint . '/notifications', [ |
|
182 | + 'body' => json_encode($notification->getMessage()), |
|
183 | + 'headers' => ['content-type' => 'application/json'], |
|
184 | + 'timeout' => 10, |
|
185 | + 'connect_timeout' => 10, |
|
186 | + ]); |
|
187 | + if ($response->getStatusCode() === Http::STATUS_CREATED) { |
|
188 | + $result = json_decode($response->getBody(), true); |
|
189 | + return (is_array($result)) ? $result : []; |
|
190 | + } |
|
191 | + } catch (\Exception $e) { |
|
192 | + // log the error and return false |
|
193 | + $this->logger->error('error while sending notification for federated share: ' . $e->getMessage()); |
|
194 | + } |
|
195 | + |
|
196 | + return false; |
|
197 | + } |
|
198 | + |
|
199 | + /** |
|
200 | + * check if the new cloud federation API is ready to be used |
|
201 | + * |
|
202 | + * @return bool |
|
203 | + */ |
|
204 | + public function isReady() { |
|
205 | + return $this->appManager->isEnabledForUser('cloud_federation_api'); |
|
206 | + } |
|
207 | + /** |
|
208 | + * check if server supports the new OCM api and ask for the correct end-point |
|
209 | + * |
|
210 | + * @param string $url full base URL of the cloud server |
|
211 | + * @return string |
|
212 | + */ |
|
213 | + protected function getOCMEndPoint($url) { |
|
214 | + if (isset($this->ocmEndPoints[$url])) { |
|
215 | + return $this->ocmEndPoints[$url]; |
|
216 | + } |
|
217 | + |
|
218 | + $client = $this->httpClientService->newClient(); |
|
219 | + try { |
|
220 | + $response = $client->get($url . '/ocm-provider/', ['timeout' => 10, 'connect_timeout' => 10]); |
|
221 | + } catch (\Exception $e) { |
|
222 | + $this->ocmEndPoints[$url] = ''; |
|
223 | + return ''; |
|
224 | + } |
|
225 | + |
|
226 | + $result = $response->getBody(); |
|
227 | + $result = json_decode($result, true); |
|
228 | + |
|
229 | + $supportedVersion = isset($result['apiVersion']) && $result['apiVersion'] === $this->supportedAPIVersion; |
|
230 | + |
|
231 | + if (isset($result['endPoint']) && $supportedVersion) { |
|
232 | + $this->ocmEndPoints[$url] = $result['endPoint']; |
|
233 | + return $result['endPoint']; |
|
234 | + } |
|
235 | + |
|
236 | + $this->ocmEndPoints[$url] = ''; |
|
237 | + return ''; |
|
238 | + } |
|
239 | 239 | } |
@@ -28,47 +28,47 @@ |
||
28 | 28 | |
29 | 29 | class GenerateBirthdayCalendarBackgroundJob extends QueuedJob { |
30 | 30 | |
31 | - /** @var BirthdayService */ |
|
32 | - private $birthdayService; |
|
31 | + /** @var BirthdayService */ |
|
32 | + private $birthdayService; |
|
33 | 33 | |
34 | - /** @var IConfig */ |
|
35 | - private $config; |
|
34 | + /** @var IConfig */ |
|
35 | + private $config; |
|
36 | 36 | |
37 | - /** |
|
38 | - * GenerateAllBirthdayCalendarsBackgroundJob constructor. |
|
39 | - * |
|
40 | - * @param BirthdayService $birthdayService |
|
41 | - * @param IConfig $config |
|
42 | - */ |
|
43 | - public function __construct(BirthdayService $birthdayService, |
|
44 | - IConfig $config) { |
|
45 | - $this->birthdayService = $birthdayService; |
|
46 | - $this->config = $config; |
|
47 | - } |
|
37 | + /** |
|
38 | + * GenerateAllBirthdayCalendarsBackgroundJob constructor. |
|
39 | + * |
|
40 | + * @param BirthdayService $birthdayService |
|
41 | + * @param IConfig $config |
|
42 | + */ |
|
43 | + public function __construct(BirthdayService $birthdayService, |
|
44 | + IConfig $config) { |
|
45 | + $this->birthdayService = $birthdayService; |
|
46 | + $this->config = $config; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * @param array $arguments |
|
51 | - */ |
|
52 | - public function run($arguments) { |
|
53 | - $userId = $arguments['userId']; |
|
54 | - $purgeBeforeGenerating = $arguments['purgeBeforeGenerating'] ?? false; |
|
49 | + /** |
|
50 | + * @param array $arguments |
|
51 | + */ |
|
52 | + public function run($arguments) { |
|
53 | + $userId = $arguments['userId']; |
|
54 | + $purgeBeforeGenerating = $arguments['purgeBeforeGenerating'] ?? false; |
|
55 | 55 | |
56 | - // make sure admin didn't change his mind |
|
57 | - $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
58 | - if ($isGloballyEnabled !== 'yes') { |
|
59 | - return; |
|
60 | - } |
|
56 | + // make sure admin didn't change his mind |
|
57 | + $isGloballyEnabled = $this->config->getAppValue('dav', 'generateBirthdayCalendar', 'yes'); |
|
58 | + if ($isGloballyEnabled !== 'yes') { |
|
59 | + return; |
|
60 | + } |
|
61 | 61 | |
62 | - // did the user opt out? |
|
63 | - $isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
64 | - if ($isUserEnabled !== 'yes') { |
|
65 | - return; |
|
66 | - } |
|
62 | + // did the user opt out? |
|
63 | + $isUserEnabled = $this->config->getUserValue($userId, 'dav', 'generateBirthdayCalendar', 'yes'); |
|
64 | + if ($isUserEnabled !== 'yes') { |
|
65 | + return; |
|
66 | + } |
|
67 | 67 | |
68 | - if ($purgeBeforeGenerating) { |
|
69 | - $this->birthdayService->resetForUser($userId); |
|
70 | - } |
|
68 | + if ($purgeBeforeGenerating) { |
|
69 | + $this->birthdayService->resetForUser($userId); |
|
70 | + } |
|
71 | 71 | |
72 | - $this->birthdayService->syncUser($userId); |
|
73 | - } |
|
72 | + $this->birthdayService->syncUser($userId); |
|
73 | + } |
|
74 | 74 | } |
@@ -28,38 +28,38 @@ |
||
28 | 28 | |
29 | 29 | class Capabilities implements ICapability { |
30 | 30 | |
31 | - /** @var IURLGenerator */ |
|
32 | - private $urlGenerator; |
|
31 | + /** @var IURLGenerator */ |
|
32 | + private $urlGenerator; |
|
33 | 33 | |
34 | - public function __construct(IURLGenerator $urlGenerator) { |
|
35 | - $this->urlGenerator = $urlGenerator; |
|
36 | - } |
|
34 | + public function __construct(IURLGenerator $urlGenerator) { |
|
35 | + $this->urlGenerator = $urlGenerator; |
|
36 | + } |
|
37 | 37 | |
38 | - /** |
|
39 | - * Function an app uses to return the capabilities |
|
40 | - * |
|
41 | - * @return array Array containing the apps capabilities |
|
42 | - * @since 8.2.0 |
|
43 | - */ |
|
44 | - public function getCapabilities() { |
|
45 | - $url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare'); |
|
46 | - $capabilities = ['ocm' => |
|
47 | - [ |
|
48 | - 'enabled' => true, |
|
49 | - 'apiVersion' => '1.0-proposal1', |
|
50 | - 'endPoint' => substr($url, 0, strrpos($url, '/')), |
|
51 | - 'resourceTypes' => [ |
|
52 | - [ |
|
53 | - 'name' => 'file', |
|
54 | - 'shareTypes' => ['user', 'group'], |
|
55 | - 'protocols' => [ |
|
56 | - 'webdav' => '/public.php/webdav/', |
|
57 | - ] |
|
58 | - ], |
|
59 | - ] |
|
60 | - ] |
|
61 | - ]; |
|
38 | + /** |
|
39 | + * Function an app uses to return the capabilities |
|
40 | + * |
|
41 | + * @return array Array containing the apps capabilities |
|
42 | + * @since 8.2.0 |
|
43 | + */ |
|
44 | + public function getCapabilities() { |
|
45 | + $url = $this->urlGenerator->linkToRouteAbsolute('cloud_federation_api.requesthandlercontroller.addShare'); |
|
46 | + $capabilities = ['ocm' => |
|
47 | + [ |
|
48 | + 'enabled' => true, |
|
49 | + 'apiVersion' => '1.0-proposal1', |
|
50 | + 'endPoint' => substr($url, 0, strrpos($url, '/')), |
|
51 | + 'resourceTypes' => [ |
|
52 | + [ |
|
53 | + 'name' => 'file', |
|
54 | + 'shareTypes' => ['user', 'group'], |
|
55 | + 'protocols' => [ |
|
56 | + 'webdav' => '/public.php/webdav/', |
|
57 | + ] |
|
58 | + ], |
|
59 | + ] |
|
60 | + ] |
|
61 | + ]; |
|
62 | 62 | |
63 | - return $capabilities; |
|
64 | - } |
|
63 | + return $capabilities; |
|
64 | + } |
|
65 | 65 | } |