@@ -65,196 +65,196 @@ |
||
65 | 65 | final class SearchTemplate implements ISearchTemplate, JsonSerializable { |
66 | 66 | |
67 | 67 | |
68 | - /** @var string */ |
|
69 | - private $icon = ''; |
|
70 | - |
|
71 | - /** @var string */ |
|
72 | - private $css = ''; |
|
73 | - |
|
74 | - /** @var string */ |
|
75 | - private $template = ''; |
|
76 | - |
|
77 | - /** @var SearchOption[] */ |
|
78 | - private $panelOptions = []; |
|
79 | - |
|
80 | - /** @var SearchOption[] */ |
|
81 | - private $navigationOptions = []; |
|
82 | - |
|
83 | - |
|
84 | - /** |
|
85 | - * ISearchTemplate constructor. |
|
86 | - * |
|
87 | - * the class of the icon and the css file to be loaded can be set during the |
|
88 | - * creation of the object. |
|
89 | - * |
|
90 | - * @since 15.0.0 |
|
91 | - * |
|
92 | - * @param string $icon |
|
93 | - * @param string $css |
|
94 | - */ |
|
95 | - public function __construct(string $icon = '', string $css = '') { |
|
96 | - $this->icon = $icon; |
|
97 | - $this->css = $css; |
|
98 | - } |
|
99 | - |
|
100 | - |
|
101 | - /** |
|
102 | - * Set the class of the icon to be displayed in the left panel of the |
|
103 | - * FullTextSearch navigation page, in front of the related Content Provider. |
|
104 | - * |
|
105 | - * @since 15.0.0 |
|
106 | - * |
|
107 | - * @param string $class |
|
108 | - * |
|
109 | - * @return ISearchTemplate |
|
110 | - */ |
|
111 | - public function setIcon(string $class): ISearchTemplate { |
|
112 | - $this->icon = $class; |
|
113 | - |
|
114 | - return $this; |
|
115 | - } |
|
116 | - |
|
117 | - /** |
|
118 | - * Get the class of the icon. |
|
119 | - * |
|
120 | - * @since 15.0.0 |
|
121 | - * |
|
122 | - * @return string |
|
123 | - */ |
|
124 | - public function getIcon(): string { |
|
125 | - return $this->icon; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * Set the path of a CSS file that will be loaded when needed. |
|
131 | - * |
|
132 | - * @since 15.0.0 |
|
133 | - * |
|
134 | - * @param string $css |
|
135 | - * |
|
136 | - * @return ISearchTemplate |
|
137 | - */ |
|
138 | - public function setCss(string $css): ISearchTemplate { |
|
139 | - $this->css = $css; |
|
140 | - |
|
141 | - return $this; |
|
142 | - } |
|
143 | - |
|
144 | - /** |
|
145 | - * Get the path of the CSS file. |
|
146 | - * |
|
147 | - * @since 15.0.0 |
|
148 | - * |
|
149 | - * @return string |
|
150 | - */ |
|
151 | - public function getCss(): string { |
|
152 | - return $this->css; |
|
153 | - } |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * Set the path of the file of a template that the HTML will be displayed |
|
158 | - * below the Options. |
|
159 | - * This should only be used if your Content Provider needs to set options in |
|
160 | - * a way not generated by FullTextSearch |
|
161 | - * |
|
162 | - * @since 15.0.0 |
|
163 | - * |
|
164 | - * @param string $template |
|
165 | - * |
|
166 | - * @return ISearchTemplate |
|
167 | - */ |
|
168 | - public function setTemplate(string $template): ISearchTemplate { |
|
169 | - $this->template = $template; |
|
170 | - |
|
171 | - return $this; |
|
172 | - } |
|
173 | - |
|
174 | - /** |
|
175 | - * Get the path of the template file. |
|
176 | - * |
|
177 | - * @since 15.0.0 |
|
178 | - * |
|
179 | - * @return string |
|
180 | - */ |
|
181 | - public function getTemplate(): string { |
|
182 | - return $this->template; |
|
183 | - } |
|
184 | - |
|
185 | - |
|
186 | - /** |
|
187 | - * Add an option in the Panel that is displayed when the user start a search |
|
188 | - * within the app that generate the content. |
|
189 | - * |
|
190 | - * @see ISearchOption |
|
191 | - * |
|
192 | - * @since 15.0.0 |
|
193 | - * |
|
194 | - * @param ISearchOption $option |
|
195 | - * |
|
196 | - * @return ISearchTemplate |
|
197 | - */ |
|
198 | - public function addPanelOption(ISearchOption $option): ISearchTemplate { |
|
199 | - $this->panelOptions[] = $option; |
|
200 | - |
|
201 | - return $this; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Get all options to be displayed in the Panel. |
|
206 | - * |
|
207 | - * @since 15.0.0 |
|
208 | - * |
|
209 | - * @return SearchOption[] |
|
210 | - */ |
|
211 | - public function getPanelOptions(): array { |
|
212 | - return $this->panelOptions; |
|
213 | - } |
|
214 | - |
|
215 | - |
|
216 | - /** |
|
217 | - * Add an option in the left panel of the FullTextSearch navigation page. |
|
218 | - * |
|
219 | - * @see ISearchOption |
|
220 | - * |
|
221 | - * @since 15.0.0 |
|
222 | - * |
|
223 | - * @param ISearchOption $option |
|
224 | - * |
|
225 | - * @return ISearchTemplate |
|
226 | - */ |
|
227 | - public function addNavigationOption(ISearchOption $option): ISearchTemplate { |
|
228 | - $this->navigationOptions[] = $option; |
|
229 | - |
|
230 | - return $this; |
|
231 | - } |
|
232 | - |
|
233 | - /** |
|
234 | - * Get all options to be displayed in the FullTextSearch navigation page. |
|
235 | - * |
|
236 | - * @since 15.0.0 |
|
237 | - * |
|
238 | - * @return array |
|
239 | - */ |
|
240 | - public function getNavigationOptions(): array { |
|
241 | - return $this->navigationOptions; |
|
242 | - } |
|
243 | - |
|
244 | - |
|
245 | - /** |
|
246 | - * @since 15.0.0 |
|
247 | - * |
|
248 | - * @return array |
|
249 | - */ |
|
250 | - public function jsonSerialize(): array { |
|
251 | - return [ |
|
252 | - 'icon' => $this->getIcon(), |
|
253 | - 'css' => $this->getCss(), |
|
254 | - 'template' => $this->getTemplate(), |
|
255 | - 'panel' => $this->getPanelOptions(), |
|
256 | - 'navigation' => $this->getNavigationOptions() |
|
257 | - ]; |
|
258 | - } |
|
68 | + /** @var string */ |
|
69 | + private $icon = ''; |
|
70 | + |
|
71 | + /** @var string */ |
|
72 | + private $css = ''; |
|
73 | + |
|
74 | + /** @var string */ |
|
75 | + private $template = ''; |
|
76 | + |
|
77 | + /** @var SearchOption[] */ |
|
78 | + private $panelOptions = []; |
|
79 | + |
|
80 | + /** @var SearchOption[] */ |
|
81 | + private $navigationOptions = []; |
|
82 | + |
|
83 | + |
|
84 | + /** |
|
85 | + * ISearchTemplate constructor. |
|
86 | + * |
|
87 | + * the class of the icon and the css file to be loaded can be set during the |
|
88 | + * creation of the object. |
|
89 | + * |
|
90 | + * @since 15.0.0 |
|
91 | + * |
|
92 | + * @param string $icon |
|
93 | + * @param string $css |
|
94 | + */ |
|
95 | + public function __construct(string $icon = '', string $css = '') { |
|
96 | + $this->icon = $icon; |
|
97 | + $this->css = $css; |
|
98 | + } |
|
99 | + |
|
100 | + |
|
101 | + /** |
|
102 | + * Set the class of the icon to be displayed in the left panel of the |
|
103 | + * FullTextSearch navigation page, in front of the related Content Provider. |
|
104 | + * |
|
105 | + * @since 15.0.0 |
|
106 | + * |
|
107 | + * @param string $class |
|
108 | + * |
|
109 | + * @return ISearchTemplate |
|
110 | + */ |
|
111 | + public function setIcon(string $class): ISearchTemplate { |
|
112 | + $this->icon = $class; |
|
113 | + |
|
114 | + return $this; |
|
115 | + } |
|
116 | + |
|
117 | + /** |
|
118 | + * Get the class of the icon. |
|
119 | + * |
|
120 | + * @since 15.0.0 |
|
121 | + * |
|
122 | + * @return string |
|
123 | + */ |
|
124 | + public function getIcon(): string { |
|
125 | + return $this->icon; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * Set the path of a CSS file that will be loaded when needed. |
|
131 | + * |
|
132 | + * @since 15.0.0 |
|
133 | + * |
|
134 | + * @param string $css |
|
135 | + * |
|
136 | + * @return ISearchTemplate |
|
137 | + */ |
|
138 | + public function setCss(string $css): ISearchTemplate { |
|
139 | + $this->css = $css; |
|
140 | + |
|
141 | + return $this; |
|
142 | + } |
|
143 | + |
|
144 | + /** |
|
145 | + * Get the path of the CSS file. |
|
146 | + * |
|
147 | + * @since 15.0.0 |
|
148 | + * |
|
149 | + * @return string |
|
150 | + */ |
|
151 | + public function getCss(): string { |
|
152 | + return $this->css; |
|
153 | + } |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * Set the path of the file of a template that the HTML will be displayed |
|
158 | + * below the Options. |
|
159 | + * This should only be used if your Content Provider needs to set options in |
|
160 | + * a way not generated by FullTextSearch |
|
161 | + * |
|
162 | + * @since 15.0.0 |
|
163 | + * |
|
164 | + * @param string $template |
|
165 | + * |
|
166 | + * @return ISearchTemplate |
|
167 | + */ |
|
168 | + public function setTemplate(string $template): ISearchTemplate { |
|
169 | + $this->template = $template; |
|
170 | + |
|
171 | + return $this; |
|
172 | + } |
|
173 | + |
|
174 | + /** |
|
175 | + * Get the path of the template file. |
|
176 | + * |
|
177 | + * @since 15.0.0 |
|
178 | + * |
|
179 | + * @return string |
|
180 | + */ |
|
181 | + public function getTemplate(): string { |
|
182 | + return $this->template; |
|
183 | + } |
|
184 | + |
|
185 | + |
|
186 | + /** |
|
187 | + * Add an option in the Panel that is displayed when the user start a search |
|
188 | + * within the app that generate the content. |
|
189 | + * |
|
190 | + * @see ISearchOption |
|
191 | + * |
|
192 | + * @since 15.0.0 |
|
193 | + * |
|
194 | + * @param ISearchOption $option |
|
195 | + * |
|
196 | + * @return ISearchTemplate |
|
197 | + */ |
|
198 | + public function addPanelOption(ISearchOption $option): ISearchTemplate { |
|
199 | + $this->panelOptions[] = $option; |
|
200 | + |
|
201 | + return $this; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Get all options to be displayed in the Panel. |
|
206 | + * |
|
207 | + * @since 15.0.0 |
|
208 | + * |
|
209 | + * @return SearchOption[] |
|
210 | + */ |
|
211 | + public function getPanelOptions(): array { |
|
212 | + return $this->panelOptions; |
|
213 | + } |
|
214 | + |
|
215 | + |
|
216 | + /** |
|
217 | + * Add an option in the left panel of the FullTextSearch navigation page. |
|
218 | + * |
|
219 | + * @see ISearchOption |
|
220 | + * |
|
221 | + * @since 15.0.0 |
|
222 | + * |
|
223 | + * @param ISearchOption $option |
|
224 | + * |
|
225 | + * @return ISearchTemplate |
|
226 | + */ |
|
227 | + public function addNavigationOption(ISearchOption $option): ISearchTemplate { |
|
228 | + $this->navigationOptions[] = $option; |
|
229 | + |
|
230 | + return $this; |
|
231 | + } |
|
232 | + |
|
233 | + /** |
|
234 | + * Get all options to be displayed in the FullTextSearch navigation page. |
|
235 | + * |
|
236 | + * @since 15.0.0 |
|
237 | + * |
|
238 | + * @return array |
|
239 | + */ |
|
240 | + public function getNavigationOptions(): array { |
|
241 | + return $this->navigationOptions; |
|
242 | + } |
|
243 | + |
|
244 | + |
|
245 | + /** |
|
246 | + * @since 15.0.0 |
|
247 | + * |
|
248 | + * @return array |
|
249 | + */ |
|
250 | + public function jsonSerialize(): array { |
|
251 | + return [ |
|
252 | + 'icon' => $this->getIcon(), |
|
253 | + 'css' => $this->getCss(), |
|
254 | + 'template' => $this->getTemplate(), |
|
255 | + 'panel' => $this->getPanelOptions(), |
|
256 | + 'navigation' => $this->getNavigationOptions() |
|
257 | + ]; |
|
258 | + } |
|
259 | 259 | } |
260 | 260 |
@@ -58,308 +58,308 @@ |
||
58 | 58 | final class DocumentAccess implements IDocumentAccess, JsonSerializable { |
59 | 59 | |
60 | 60 | |
61 | - /** @var string */ |
|
62 | - private $ownerId; |
|
63 | - |
|
64 | - /** @var string */ |
|
65 | - private $viewerId = ''; |
|
66 | - |
|
67 | - /** @var array */ |
|
68 | - private $users = []; |
|
69 | - |
|
70 | - /** @var array */ |
|
71 | - private $groups = []; |
|
72 | - |
|
73 | - /** @var array */ |
|
74 | - private $circles = []; |
|
75 | - |
|
76 | - /** @var array */ |
|
77 | - private $links = []; |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * Owner of the document can be set at the init of the object. |
|
82 | - * |
|
83 | - * @since 16.0.0 |
|
84 | - * |
|
85 | - * IDocumentAccess constructor. |
|
86 | - * |
|
87 | - * @param string $ownerId |
|
88 | - */ |
|
89 | - public function __construct(string $ownerId = '') { |
|
90 | - $this->setOwnerId($ownerId); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Set the Owner of the document. |
|
96 | - * |
|
97 | - * @since 16.0.0 |
|
98 | - * |
|
99 | - * @param string $ownerId |
|
100 | - * |
|
101 | - * @return IDocumentAccess |
|
102 | - */ |
|
103 | - public function setOwnerId(string $ownerId): IDocumentAccess { |
|
104 | - $this->ownerId = $ownerId; |
|
105 | - |
|
106 | - return $this; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Get the Owner of the document. |
|
111 | - * |
|
112 | - * @since 16.0.0 |
|
113 | - * |
|
114 | - * @return string |
|
115 | - */ |
|
116 | - public function getOwnerId(): string { |
|
117 | - return $this->ownerId; |
|
118 | - } |
|
119 | - |
|
120 | - |
|
121 | - /** |
|
122 | - * Set the viewer of the document. |
|
123 | - * |
|
124 | - * @since 16.0.0 |
|
125 | - * |
|
126 | - * @param string $viewerId |
|
127 | - * |
|
128 | - * @return IDocumentAccess |
|
129 | - */ |
|
130 | - public function setViewerId(string $viewerId): IDocumentAccess { |
|
131 | - $this->viewerId = $viewerId; |
|
132 | - |
|
133 | - return $this; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * Get the viewer of the document. |
|
138 | - * |
|
139 | - * @since 16.0.0 |
|
140 | - * |
|
141 | - * @return string |
|
142 | - */ |
|
143 | - public function getViewerId(): string { |
|
144 | - return $this->viewerId; |
|
145 | - } |
|
146 | - |
|
147 | - |
|
148 | - /** |
|
149 | - * Set the list of users that have read access to the document. |
|
150 | - * |
|
151 | - * @since 16.0.0 |
|
152 | - * |
|
153 | - * @param array $users |
|
154 | - * |
|
155 | - * @return IDocumentAccess |
|
156 | - */ |
|
157 | - public function setUsers(array $users): IDocumentAccess { |
|
158 | - $this->users = $users; |
|
159 | - |
|
160 | - return $this; |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Add an entry to the list of users that have read access to the document. |
|
165 | - * |
|
166 | - * @since 16.0.0 |
|
167 | - * |
|
168 | - * @param string $user |
|
169 | - * |
|
170 | - * @return IDocumentAccess |
|
171 | - */ |
|
172 | - public function addUser(string $user): IDocumentAccess { |
|
173 | - $this->users[] = $user; |
|
174 | - |
|
175 | - return $this; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * Add multiple entries to the list of users that have read access to the |
|
180 | - * document. |
|
181 | - * |
|
182 | - * @since 16.0.0 |
|
183 | - * |
|
184 | - * @param array $users |
|
185 | - * |
|
186 | - * @return IDocumentAccess |
|
187 | - */ |
|
188 | - public function addUsers($users): IDocumentAccess { |
|
189 | - $this->users = array_merge($this->users, $users); |
|
190 | - |
|
191 | - return $this; |
|
192 | - } |
|
193 | - |
|
194 | - /** |
|
195 | - * Get the complete list of users that have read access to the document. |
|
196 | - * |
|
197 | - * @since 16.0.0 |
|
198 | - * |
|
199 | - * @return array |
|
200 | - */ |
|
201 | - public function getUsers(): array { |
|
202 | - return $this->users; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * Set the list of groups that have read access to the document. |
|
208 | - * |
|
209 | - * @since 16.0.0 |
|
210 | - * |
|
211 | - * @param array $groups |
|
212 | - * |
|
213 | - * @return IDocumentAccess |
|
214 | - */ |
|
215 | - public function setGroups(array $groups): IDocumentAccess { |
|
216 | - $this->groups = $groups; |
|
217 | - |
|
218 | - return $this; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * Add an entry to the list of groups that have read access to the document. |
|
223 | - * |
|
224 | - * @since 16.0.0 |
|
225 | - * |
|
226 | - * @param string $group |
|
227 | - * |
|
228 | - * @return IDocumentAccess |
|
229 | - */ |
|
230 | - public function addGroup(string $group): IDocumentAccess { |
|
231 | - $this->groups[] = $group; |
|
232 | - |
|
233 | - return $this; |
|
234 | - } |
|
235 | - |
|
236 | - /** |
|
237 | - * Add multiple entries to the list of groups that have read access to the |
|
238 | - * document. |
|
239 | - * |
|
240 | - * @since 16.0.0 |
|
241 | - * |
|
242 | - * @param array $groups |
|
243 | - * |
|
244 | - * @return IDocumentAccess |
|
245 | - */ |
|
246 | - public function addGroups(array $groups) { |
|
247 | - $this->groups = array_merge($this->groups, $groups); |
|
248 | - |
|
249 | - return $this; |
|
250 | - } |
|
251 | - |
|
252 | - /** |
|
253 | - * Get the complete list of groups that have read access to the document. |
|
254 | - * |
|
255 | - * @since 16.0.0 |
|
256 | - * |
|
257 | - * @return array |
|
258 | - */ |
|
259 | - public function getGroups(): array { |
|
260 | - return $this->groups; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * Set the list of circles that have read access to the document. |
|
266 | - * |
|
267 | - * @since 16.0.0 |
|
268 | - * |
|
269 | - * @param array $circles |
|
270 | - * |
|
271 | - * @return IDocumentAccess |
|
272 | - */ |
|
273 | - public function setCircles(array $circles): IDocumentAccess { |
|
274 | - $this->circles = $circles; |
|
275 | - |
|
276 | - return $this; |
|
277 | - } |
|
278 | - |
|
279 | - /** |
|
280 | - * Add an entry to the list of circles that have read access to the document. |
|
281 | - * |
|
282 | - * @since 16.0.0 |
|
283 | - * |
|
284 | - * @param string $circle |
|
285 | - * |
|
286 | - * @return IDocumentAccess |
|
287 | - */ |
|
288 | - public function addCircle(string $circle): IDocumentAccess { |
|
289 | - $this->circles[] = $circle; |
|
290 | - |
|
291 | - return $this; |
|
292 | - } |
|
293 | - |
|
294 | - /** |
|
295 | - * Add multiple entries to the list of groups that have read access to the |
|
296 | - * document. |
|
297 | - * |
|
298 | - * @since 16.0.0 |
|
299 | - * |
|
300 | - * @param array $circles |
|
301 | - * |
|
302 | - * @return IDocumentAccess |
|
303 | - */ |
|
304 | - public function addCircles(array $circles): IDocumentAccess { |
|
305 | - $this->circles = array_merge($this->circles, $circles); |
|
306 | - |
|
307 | - return $this; |
|
308 | - } |
|
309 | - |
|
310 | - /** |
|
311 | - * Get the complete list of circles that have read access to the document. |
|
312 | - * |
|
313 | - * @since 16.0.0 |
|
314 | - * |
|
315 | - * @return array |
|
316 | - */ |
|
317 | - public function getCircles(): array { |
|
318 | - return $this->circles; |
|
319 | - } |
|
320 | - |
|
321 | - |
|
322 | - /** |
|
323 | - * Set the list of links that have read access to the document. |
|
324 | - * |
|
325 | - * @since 16.0.0 |
|
326 | - * |
|
327 | - * @param array $links |
|
328 | - * |
|
329 | - * @return IDocumentAccess |
|
330 | - */ |
|
331 | - public function setLinks(array $links): IDocumentAccess { |
|
332 | - $this->links = $links; |
|
333 | - |
|
334 | - return $this; |
|
335 | - } |
|
336 | - |
|
337 | - /** |
|
338 | - * Get the list of links that have read access to the document. |
|
339 | - * |
|
340 | - * @since 16.0.0 |
|
341 | - * |
|
342 | - * @return array |
|
343 | - */ |
|
344 | - public function getLinks(): array { |
|
345 | - return $this->links; |
|
346 | - } |
|
347 | - |
|
348 | - |
|
349 | - /** |
|
350 | - * @since 16.0.0 |
|
351 | - * |
|
352 | - * @return array |
|
353 | - */ |
|
354 | - public function jsonSerialize(): array { |
|
355 | - return [ |
|
356 | - 'ownerId' => $this->getOwnerId(), |
|
357 | - 'viewerId' => $this->getViewerId(), |
|
358 | - 'users' => $this->getUsers(), |
|
359 | - 'groups' => $this->getGroups(), |
|
360 | - 'circles' => $this->getCircles(), |
|
361 | - 'links' => $this->getLinks() |
|
362 | - ]; |
|
363 | - } |
|
61 | + /** @var string */ |
|
62 | + private $ownerId; |
|
63 | + |
|
64 | + /** @var string */ |
|
65 | + private $viewerId = ''; |
|
66 | + |
|
67 | + /** @var array */ |
|
68 | + private $users = []; |
|
69 | + |
|
70 | + /** @var array */ |
|
71 | + private $groups = []; |
|
72 | + |
|
73 | + /** @var array */ |
|
74 | + private $circles = []; |
|
75 | + |
|
76 | + /** @var array */ |
|
77 | + private $links = []; |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * Owner of the document can be set at the init of the object. |
|
82 | + * |
|
83 | + * @since 16.0.0 |
|
84 | + * |
|
85 | + * IDocumentAccess constructor. |
|
86 | + * |
|
87 | + * @param string $ownerId |
|
88 | + */ |
|
89 | + public function __construct(string $ownerId = '') { |
|
90 | + $this->setOwnerId($ownerId); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Set the Owner of the document. |
|
96 | + * |
|
97 | + * @since 16.0.0 |
|
98 | + * |
|
99 | + * @param string $ownerId |
|
100 | + * |
|
101 | + * @return IDocumentAccess |
|
102 | + */ |
|
103 | + public function setOwnerId(string $ownerId): IDocumentAccess { |
|
104 | + $this->ownerId = $ownerId; |
|
105 | + |
|
106 | + return $this; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Get the Owner of the document. |
|
111 | + * |
|
112 | + * @since 16.0.0 |
|
113 | + * |
|
114 | + * @return string |
|
115 | + */ |
|
116 | + public function getOwnerId(): string { |
|
117 | + return $this->ownerId; |
|
118 | + } |
|
119 | + |
|
120 | + |
|
121 | + /** |
|
122 | + * Set the viewer of the document. |
|
123 | + * |
|
124 | + * @since 16.0.0 |
|
125 | + * |
|
126 | + * @param string $viewerId |
|
127 | + * |
|
128 | + * @return IDocumentAccess |
|
129 | + */ |
|
130 | + public function setViewerId(string $viewerId): IDocumentAccess { |
|
131 | + $this->viewerId = $viewerId; |
|
132 | + |
|
133 | + return $this; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * Get the viewer of the document. |
|
138 | + * |
|
139 | + * @since 16.0.0 |
|
140 | + * |
|
141 | + * @return string |
|
142 | + */ |
|
143 | + public function getViewerId(): string { |
|
144 | + return $this->viewerId; |
|
145 | + } |
|
146 | + |
|
147 | + |
|
148 | + /** |
|
149 | + * Set the list of users that have read access to the document. |
|
150 | + * |
|
151 | + * @since 16.0.0 |
|
152 | + * |
|
153 | + * @param array $users |
|
154 | + * |
|
155 | + * @return IDocumentAccess |
|
156 | + */ |
|
157 | + public function setUsers(array $users): IDocumentAccess { |
|
158 | + $this->users = $users; |
|
159 | + |
|
160 | + return $this; |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Add an entry to the list of users that have read access to the document. |
|
165 | + * |
|
166 | + * @since 16.0.0 |
|
167 | + * |
|
168 | + * @param string $user |
|
169 | + * |
|
170 | + * @return IDocumentAccess |
|
171 | + */ |
|
172 | + public function addUser(string $user): IDocumentAccess { |
|
173 | + $this->users[] = $user; |
|
174 | + |
|
175 | + return $this; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * Add multiple entries to the list of users that have read access to the |
|
180 | + * document. |
|
181 | + * |
|
182 | + * @since 16.0.0 |
|
183 | + * |
|
184 | + * @param array $users |
|
185 | + * |
|
186 | + * @return IDocumentAccess |
|
187 | + */ |
|
188 | + public function addUsers($users): IDocumentAccess { |
|
189 | + $this->users = array_merge($this->users, $users); |
|
190 | + |
|
191 | + return $this; |
|
192 | + } |
|
193 | + |
|
194 | + /** |
|
195 | + * Get the complete list of users that have read access to the document. |
|
196 | + * |
|
197 | + * @since 16.0.0 |
|
198 | + * |
|
199 | + * @return array |
|
200 | + */ |
|
201 | + public function getUsers(): array { |
|
202 | + return $this->users; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * Set the list of groups that have read access to the document. |
|
208 | + * |
|
209 | + * @since 16.0.0 |
|
210 | + * |
|
211 | + * @param array $groups |
|
212 | + * |
|
213 | + * @return IDocumentAccess |
|
214 | + */ |
|
215 | + public function setGroups(array $groups): IDocumentAccess { |
|
216 | + $this->groups = $groups; |
|
217 | + |
|
218 | + return $this; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * Add an entry to the list of groups that have read access to the document. |
|
223 | + * |
|
224 | + * @since 16.0.0 |
|
225 | + * |
|
226 | + * @param string $group |
|
227 | + * |
|
228 | + * @return IDocumentAccess |
|
229 | + */ |
|
230 | + public function addGroup(string $group): IDocumentAccess { |
|
231 | + $this->groups[] = $group; |
|
232 | + |
|
233 | + return $this; |
|
234 | + } |
|
235 | + |
|
236 | + /** |
|
237 | + * Add multiple entries to the list of groups that have read access to the |
|
238 | + * document. |
|
239 | + * |
|
240 | + * @since 16.0.0 |
|
241 | + * |
|
242 | + * @param array $groups |
|
243 | + * |
|
244 | + * @return IDocumentAccess |
|
245 | + */ |
|
246 | + public function addGroups(array $groups) { |
|
247 | + $this->groups = array_merge($this->groups, $groups); |
|
248 | + |
|
249 | + return $this; |
|
250 | + } |
|
251 | + |
|
252 | + /** |
|
253 | + * Get the complete list of groups that have read access to the document. |
|
254 | + * |
|
255 | + * @since 16.0.0 |
|
256 | + * |
|
257 | + * @return array |
|
258 | + */ |
|
259 | + public function getGroups(): array { |
|
260 | + return $this->groups; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * Set the list of circles that have read access to the document. |
|
266 | + * |
|
267 | + * @since 16.0.0 |
|
268 | + * |
|
269 | + * @param array $circles |
|
270 | + * |
|
271 | + * @return IDocumentAccess |
|
272 | + */ |
|
273 | + public function setCircles(array $circles): IDocumentAccess { |
|
274 | + $this->circles = $circles; |
|
275 | + |
|
276 | + return $this; |
|
277 | + } |
|
278 | + |
|
279 | + /** |
|
280 | + * Add an entry to the list of circles that have read access to the document. |
|
281 | + * |
|
282 | + * @since 16.0.0 |
|
283 | + * |
|
284 | + * @param string $circle |
|
285 | + * |
|
286 | + * @return IDocumentAccess |
|
287 | + */ |
|
288 | + public function addCircle(string $circle): IDocumentAccess { |
|
289 | + $this->circles[] = $circle; |
|
290 | + |
|
291 | + return $this; |
|
292 | + } |
|
293 | + |
|
294 | + /** |
|
295 | + * Add multiple entries to the list of groups that have read access to the |
|
296 | + * document. |
|
297 | + * |
|
298 | + * @since 16.0.0 |
|
299 | + * |
|
300 | + * @param array $circles |
|
301 | + * |
|
302 | + * @return IDocumentAccess |
|
303 | + */ |
|
304 | + public function addCircles(array $circles): IDocumentAccess { |
|
305 | + $this->circles = array_merge($this->circles, $circles); |
|
306 | + |
|
307 | + return $this; |
|
308 | + } |
|
309 | + |
|
310 | + /** |
|
311 | + * Get the complete list of circles that have read access to the document. |
|
312 | + * |
|
313 | + * @since 16.0.0 |
|
314 | + * |
|
315 | + * @return array |
|
316 | + */ |
|
317 | + public function getCircles(): array { |
|
318 | + return $this->circles; |
|
319 | + } |
|
320 | + |
|
321 | + |
|
322 | + /** |
|
323 | + * Set the list of links that have read access to the document. |
|
324 | + * |
|
325 | + * @since 16.0.0 |
|
326 | + * |
|
327 | + * @param array $links |
|
328 | + * |
|
329 | + * @return IDocumentAccess |
|
330 | + */ |
|
331 | + public function setLinks(array $links): IDocumentAccess { |
|
332 | + $this->links = $links; |
|
333 | + |
|
334 | + return $this; |
|
335 | + } |
|
336 | + |
|
337 | + /** |
|
338 | + * Get the list of links that have read access to the document. |
|
339 | + * |
|
340 | + * @since 16.0.0 |
|
341 | + * |
|
342 | + * @return array |
|
343 | + */ |
|
344 | + public function getLinks(): array { |
|
345 | + return $this->links; |
|
346 | + } |
|
347 | + |
|
348 | + |
|
349 | + /** |
|
350 | + * @since 16.0.0 |
|
351 | + * |
|
352 | + * @return array |
|
353 | + */ |
|
354 | + public function jsonSerialize(): array { |
|
355 | + return [ |
|
356 | + 'ownerId' => $this->getOwnerId(), |
|
357 | + 'viewerId' => $this->getViewerId(), |
|
358 | + 'users' => $this->getUsers(), |
|
359 | + 'groups' => $this->getGroups(), |
|
360 | + 'circles' => $this->getCircles(), |
|
361 | + 'links' => $this->getLinks() |
|
362 | + ]; |
|
363 | + } |
|
364 | 364 | } |
365 | 365 |
@@ -53,7 +53,7 @@ |
||
53 | 53 | $providers = $this->registry->getProviderStates($event->getUser()); |
54 | 54 | |
55 | 55 | // Loop over all providers. If all are disabled we remove the job |
56 | - $state = array_reduce($providers, function (bool $carry, bool $enabled) { |
|
56 | + $state = array_reduce($providers, function(bool $carry, bool $enabled) { |
|
57 | 57 | return $carry || $enabled; |
58 | 58 | }, false); |
59 | 59 |
@@ -35,33 +35,33 @@ |
||
35 | 35 | |
36 | 36 | class ProviderDisabled implements IEventListener { |
37 | 37 | |
38 | - /** @var IRegistry */ |
|
39 | - private $registry; |
|
38 | + /** @var IRegistry */ |
|
39 | + private $registry; |
|
40 | 40 | |
41 | - /** @var IJobList */ |
|
42 | - private $jobList; |
|
41 | + /** @var IJobList */ |
|
42 | + private $jobList; |
|
43 | 43 | |
44 | - public function __construct(IRegistry $registry, |
|
45 | - IJobList $jobList) { |
|
46 | - $this->registry = $registry; |
|
47 | - $this->jobList = $jobList; |
|
48 | - } |
|
44 | + public function __construct(IRegistry $registry, |
|
45 | + IJobList $jobList) { |
|
46 | + $this->registry = $registry; |
|
47 | + $this->jobList = $jobList; |
|
48 | + } |
|
49 | 49 | |
50 | - public function handle(Event $event): void { |
|
51 | - if (!($event instanceof RegistryEvent)) { |
|
52 | - return; |
|
53 | - } |
|
50 | + public function handle(Event $event): void { |
|
51 | + if (!($event instanceof RegistryEvent)) { |
|
52 | + return; |
|
53 | + } |
|
54 | 54 | |
55 | - $providers = $this->registry->getProviderStates($event->getUser()); |
|
55 | + $providers = $this->registry->getProviderStates($event->getUser()); |
|
56 | 56 | |
57 | - // Loop over all providers. If all are disabled we remove the job |
|
58 | - $state = array_reduce($providers, function (bool $carry, bool $enabled) { |
|
59 | - return $carry || $enabled; |
|
60 | - }, false); |
|
57 | + // Loop over all providers. If all are disabled we remove the job |
|
58 | + $state = array_reduce($providers, function (bool $carry, bool $enabled) { |
|
59 | + return $carry || $enabled; |
|
60 | + }, false); |
|
61 | 61 | |
62 | - if ($state === false) { |
|
63 | - $this->jobList->remove(RememberBackupCodesJob::class, ['uid' => $event->getUser()->getUID()]); |
|
64 | - } |
|
65 | - } |
|
62 | + if ($state === false) { |
|
63 | + $this->jobList->remove(RememberBackupCodesJob::class, ['uid' => $event->getUser()->getUID()]); |
|
64 | + } |
|
65 | + } |
|
66 | 66 | |
67 | 67 | } |
@@ -29,31 +29,31 @@ |
||
29 | 29 | |
30 | 30 | class PgSqlExpressionBuilder extends ExpressionBuilder { |
31 | 31 | |
32 | - /** |
|
33 | - * Returns a IQueryFunction that casts the column to the given type |
|
34 | - * |
|
35 | - * @param string $column |
|
36 | - * @param mixed $type One of IQueryBuilder::PARAM_* |
|
37 | - * @return string |
|
38 | - */ |
|
39 | - public function castColumn($column, $type) { |
|
40 | - switch ($type) { |
|
41 | - case IQueryBuilder::PARAM_INT: |
|
42 | - return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS INT)'); |
|
43 | - case IQueryBuilder::PARAM_STR: |
|
44 | - return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)'); |
|
45 | - default: |
|
46 | - return parent::castColumn($column, $type); |
|
47 | - } |
|
48 | - } |
|
32 | + /** |
|
33 | + * Returns a IQueryFunction that casts the column to the given type |
|
34 | + * |
|
35 | + * @param string $column |
|
36 | + * @param mixed $type One of IQueryBuilder::PARAM_* |
|
37 | + * @return string |
|
38 | + */ |
|
39 | + public function castColumn($column, $type) { |
|
40 | + switch ($type) { |
|
41 | + case IQueryBuilder::PARAM_INT: |
|
42 | + return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS INT)'); |
|
43 | + case IQueryBuilder::PARAM_STR: |
|
44 | + return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)'); |
|
45 | + default: |
|
46 | + return parent::castColumn($column, $type); |
|
47 | + } |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @inheritdoc |
|
52 | - */ |
|
53 | - public function iLike($x, $y, $type = null) { |
|
54 | - $x = $this->helper->quoteColumnName($x); |
|
55 | - $y = $this->helper->quoteColumnName($y); |
|
56 | - return $this->expressionBuilder->comparison($x, 'ILIKE', $y); |
|
57 | - } |
|
50 | + /** |
|
51 | + * @inheritdoc |
|
52 | + */ |
|
53 | + public function iLike($x, $y, $type = null) { |
|
54 | + $x = $this->helper->quoteColumnName($x); |
|
55 | + $y = $this->helper->quoteColumnName($y); |
|
56 | + return $this->expressionBuilder->comparison($x, 'ILIKE', $y); |
|
57 | + } |
|
58 | 58 | |
59 | 59 | } |
@@ -39,9 +39,9 @@ |
||
39 | 39 | public function castColumn($column, $type) { |
40 | 40 | switch ($type) { |
41 | 41 | case IQueryBuilder::PARAM_INT: |
42 | - return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS INT)'); |
|
42 | + return new QueryFunction('CAST('.$this->helper->quoteColumnName($column).' AS INT)'); |
|
43 | 43 | case IQueryBuilder::PARAM_STR: |
44 | - return new QueryFunction('CAST(' . $this->helper->quoteColumnName($column) . ' AS TEXT)'); |
|
44 | + return new QueryFunction('CAST('.$this->helper->quoteColumnName($column).' AS TEXT)'); |
|
45 | 45 | default: |
46 | 46 | return parent::castColumn($column, $type); |
47 | 47 | } |
@@ -1,7 +1,7 @@ |
||
1 | 1 | <?php /** @var $l OC_L10N */ ?> |
2 | 2 | <?php |
3 | 3 | script('user_ldap', [ |
4 | - 'renewPassword', |
|
4 | + 'renewPassword', |
|
5 | 5 | ]); |
6 | 6 | style('user_ldap', 'renewPassword'); |
7 | 7 | ?> |
@@ -24,14 +24,14 @@ discard block |
||
24 | 24 | <?php endif; ?> |
25 | 25 | <div id="message" class="hidden"> |
26 | 26 | <img class="float-spinner" alt="" |
27 | - src="<?php p(image_path('core', 'loading-dark.gif'));?>"> |
|
27 | + src="<?php p(image_path('core', 'loading-dark.gif')); ?>"> |
|
28 | 28 | <span id="messageText"></span> |
29 | 29 | <!-- the following div ensures that the spinner is always inside the #message div --> |
30 | 30 | <div style="clear: both;"></div> |
31 | 31 | </div> |
32 | 32 | <p class="grouptop"> |
33 | 33 | <input type="password" id="oldPassword" name="oldPassword" |
34 | - placeholder="<?php echo $l->t('Current password');?>" |
|
34 | + placeholder="<?php echo $l->t('Current password'); ?>" |
|
35 | 35 | autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/> |
36 | 36 | <label for="oldPassword" class="infield"><?php p($l->t('Current password')); ?></label> |
37 | 37 | </p> |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | <input type="checkbox" id="personal-show" name="show" class="hidden-visually" /><label for="personal-show"></label> |
41 | 41 | <label id="newPassword-label" for="newPassword" class="infield"><?php p($l->t('New password')); ?></label> |
42 | 42 | <input type="password" id="newPassword" name="newPassword" |
43 | - placeholder="<?php echo $l->t('New password');?>" |
|
43 | + placeholder="<?php echo $l->t('New password'); ?>" |
|
44 | 44 | data-typetoggle="#personal-show" autofocus autocomplete="off" autocapitalize="off" autocorrect="off" required/> |
45 | 45 | </p> |
46 | 46 |
@@ -128,7 +128,7 @@ discard block |
||
128 | 128 | return 1; |
129 | 129 | } |
130 | 130 | if (!$storage instanceof INotifyStorage) { |
131 | - $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
131 | + $output->writeln('<error>Mount of type "'.$mount->getBackend()->getText().'" does not support active update notifications</error>'); |
|
132 | 132 | return 1; |
133 | 133 | } |
134 | 134 | |
@@ -137,7 +137,7 @@ discard block |
||
137 | 137 | $path = trim($input->getOption('path'), '/'); |
138 | 138 | $notifyHandler = $storage->notify($path); |
139 | 139 | $this->selfTest($storage, $notifyHandler, $verbose, $output); |
140 | - $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
140 | + $notifyHandler->listen(function(IChange $change) use ($mount, $verbose, $output) { |
|
141 | 141 | if ($verbose) { |
142 | 142 | $this->logUpdate($change, $output); |
143 | 143 | } |
@@ -168,14 +168,14 @@ discard block |
||
168 | 168 | $storageIds = $this->getStorageIds($mountId); |
169 | 169 | } |
170 | 170 | if (count($storageIds) === 0) { |
171 | - throw new StorageNotAvailableException('No storages found by mount ID ' . $mountId); |
|
171 | + throw new StorageNotAvailableException('No storages found by mount ID '.$mountId); |
|
172 | 172 | } |
173 | 173 | $storageIds = array_map('intval', $storageIds); |
174 | 174 | |
175 | 175 | $result = $this->updateParent($storageIds, $parent); |
176 | 176 | if ($result === 0) { |
177 | 177 | //TODO: Find existing parent further up the tree in the database and register that folder instead. |
178 | - $this->logger->info('Failed updating parent for "' . $path . '" while trying to register change. It may not exist in the filecache.'); |
|
178 | + $this->logger->info('Failed updating parent for "'.$path.'" while trying to register change. It may not exist in the filecache.'); |
|
179 | 179 | } |
180 | 180 | } |
181 | 181 | |
@@ -197,9 +197,9 @@ discard block |
||
197 | 197 | return; |
198 | 198 | } |
199 | 199 | |
200 | - $text .= ' ' . $change->getPath(); |
|
200 | + $text .= ' '.$change->getPath(); |
|
201 | 201 | if ($change instanceof IRenameChange) { |
202 | - $text .= ' to ' . $change->getTargetPath(); |
|
202 | + $text .= ' to '.$change->getTargetPath(); |
|
203 | 203 | } |
204 | 204 | |
205 | 205 | $output->writeln($text); |
@@ -45,252 +45,252 @@ |
||
45 | 45 | use Symfony\Component\Console\Output\OutputInterface; |
46 | 46 | |
47 | 47 | class Notify extends Base { |
48 | - /** @var GlobalStoragesService */ |
|
49 | - private $globalService; |
|
50 | - /** @var IDBConnection */ |
|
51 | - private $connection; |
|
52 | - /** @var ILogger */ |
|
53 | - private $logger; |
|
48 | + /** @var GlobalStoragesService */ |
|
49 | + private $globalService; |
|
50 | + /** @var IDBConnection */ |
|
51 | + private $connection; |
|
52 | + /** @var ILogger */ |
|
53 | + private $logger; |
|
54 | 54 | |
55 | - public function __construct(GlobalStoragesService $globalService, IDBConnection $connection, ILogger $logger) { |
|
56 | - parent::__construct(); |
|
57 | - $this->globalService = $globalService; |
|
58 | - $this->connection = $connection; |
|
59 | - $this->logger = $logger; |
|
60 | - } |
|
55 | + public function __construct(GlobalStoragesService $globalService, IDBConnection $connection, ILogger $logger) { |
|
56 | + parent::__construct(); |
|
57 | + $this->globalService = $globalService; |
|
58 | + $this->connection = $connection; |
|
59 | + $this->logger = $logger; |
|
60 | + } |
|
61 | 61 | |
62 | - protected function configure() { |
|
63 | - $this |
|
64 | - ->setName('files_external:notify') |
|
65 | - ->setDescription('Listen for active update notifications for a configured external mount') |
|
66 | - ->addArgument( |
|
67 | - 'mount_id', |
|
68 | - InputArgument::REQUIRED, |
|
69 | - 'the mount id of the mount to listen to' |
|
70 | - )->addOption( |
|
71 | - 'user', |
|
72 | - 'u', |
|
73 | - InputOption::VALUE_REQUIRED, |
|
74 | - 'The username for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
75 | - )->addOption( |
|
76 | - 'password', |
|
77 | - 'p', |
|
78 | - InputOption::VALUE_REQUIRED, |
|
79 | - 'The password for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
80 | - )->addOption( |
|
81 | - 'path', |
|
82 | - '', |
|
83 | - InputOption::VALUE_REQUIRED, |
|
84 | - 'The directory in the storage to listen for updates in', |
|
85 | - '/' |
|
86 | - ); |
|
87 | - parent::configure(); |
|
88 | - } |
|
62 | + protected function configure() { |
|
63 | + $this |
|
64 | + ->setName('files_external:notify') |
|
65 | + ->setDescription('Listen for active update notifications for a configured external mount') |
|
66 | + ->addArgument( |
|
67 | + 'mount_id', |
|
68 | + InputArgument::REQUIRED, |
|
69 | + 'the mount id of the mount to listen to' |
|
70 | + )->addOption( |
|
71 | + 'user', |
|
72 | + 'u', |
|
73 | + InputOption::VALUE_REQUIRED, |
|
74 | + 'The username for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
75 | + )->addOption( |
|
76 | + 'password', |
|
77 | + 'p', |
|
78 | + InputOption::VALUE_REQUIRED, |
|
79 | + 'The password for the remote mount (required only for some mount configuration that don\'t store credentials)' |
|
80 | + )->addOption( |
|
81 | + 'path', |
|
82 | + '', |
|
83 | + InputOption::VALUE_REQUIRED, |
|
84 | + 'The directory in the storage to listen for updates in', |
|
85 | + '/' |
|
86 | + ); |
|
87 | + parent::configure(); |
|
88 | + } |
|
89 | 89 | |
90 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
91 | - $mount = $this->globalService->getStorage($input->getArgument('mount_id')); |
|
92 | - if (is_null($mount)) { |
|
93 | - $output->writeln('<error>Mount not found</error>'); |
|
94 | - return 1; |
|
95 | - } |
|
96 | - $noAuth = false; |
|
97 | - try { |
|
98 | - $authBackend = $mount->getAuthMechanism(); |
|
99 | - $authBackend->manipulateStorageConfig($mount); |
|
100 | - } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
101 | - $noAuth = true; |
|
102 | - } catch (StorageNotAvailableException $e) { |
|
103 | - $noAuth = true; |
|
104 | - } |
|
90 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
91 | + $mount = $this->globalService->getStorage($input->getArgument('mount_id')); |
|
92 | + if (is_null($mount)) { |
|
93 | + $output->writeln('<error>Mount not found</error>'); |
|
94 | + return 1; |
|
95 | + } |
|
96 | + $noAuth = false; |
|
97 | + try { |
|
98 | + $authBackend = $mount->getAuthMechanism(); |
|
99 | + $authBackend->manipulateStorageConfig($mount); |
|
100 | + } catch (InsufficientDataForMeaningfulAnswerException $e) { |
|
101 | + $noAuth = true; |
|
102 | + } catch (StorageNotAvailableException $e) { |
|
103 | + $noAuth = true; |
|
104 | + } |
|
105 | 105 | |
106 | - if ($input->getOption('user')) { |
|
107 | - $mount->setBackendOption('user', $input->getOption('user')); |
|
108 | - } elseif (isset($_ENV['NOTIFY_USER'])) { |
|
109 | - $mount->setBackendOption('user', $_ENV['NOTIFY_USER']); |
|
110 | - } elseif (isset($_SERVER['NOTIFY_USER'])) { |
|
111 | - $mount->setBackendOption('user', $_SERVER['NOTIFY_USER']); |
|
112 | - } |
|
113 | - if ($input->getOption('password')) { |
|
114 | - $mount->setBackendOption('password', $input->getOption('password')); |
|
115 | - } elseif (isset($_ENV['NOTIFY_PASSWORD'])) { |
|
116 | - $mount->setBackendOption('password', $_ENV['NOTIFY_PASSWORD']); |
|
117 | - } elseif (isset($_SERVER['NOTIFY_PASSWORD'])) { |
|
118 | - $mount->setBackendOption('password', $_SERVER['NOTIFY_PASSWORD']); |
|
119 | - } |
|
106 | + if ($input->getOption('user')) { |
|
107 | + $mount->setBackendOption('user', $input->getOption('user')); |
|
108 | + } elseif (isset($_ENV['NOTIFY_USER'])) { |
|
109 | + $mount->setBackendOption('user', $_ENV['NOTIFY_USER']); |
|
110 | + } elseif (isset($_SERVER['NOTIFY_USER'])) { |
|
111 | + $mount->setBackendOption('user', $_SERVER['NOTIFY_USER']); |
|
112 | + } |
|
113 | + if ($input->getOption('password')) { |
|
114 | + $mount->setBackendOption('password', $input->getOption('password')); |
|
115 | + } elseif (isset($_ENV['NOTIFY_PASSWORD'])) { |
|
116 | + $mount->setBackendOption('password', $_ENV['NOTIFY_PASSWORD']); |
|
117 | + } elseif (isset($_SERVER['NOTIFY_PASSWORD'])) { |
|
118 | + $mount->setBackendOption('password', $_SERVER['NOTIFY_PASSWORD']); |
|
119 | + } |
|
120 | 120 | |
121 | - try { |
|
122 | - $storage = $this->createStorage($mount); |
|
123 | - } catch (\Exception $e) { |
|
124 | - $output->writeln('<error>Error while trying to create storage</error>'); |
|
125 | - if ($noAuth) { |
|
126 | - $output->writeln('<error>Username and/or password required</error>'); |
|
127 | - } |
|
128 | - return 1; |
|
129 | - } |
|
130 | - if (!$storage instanceof INotifyStorage) { |
|
131 | - $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
132 | - return 1; |
|
133 | - } |
|
121 | + try { |
|
122 | + $storage = $this->createStorage($mount); |
|
123 | + } catch (\Exception $e) { |
|
124 | + $output->writeln('<error>Error while trying to create storage</error>'); |
|
125 | + if ($noAuth) { |
|
126 | + $output->writeln('<error>Username and/or password required</error>'); |
|
127 | + } |
|
128 | + return 1; |
|
129 | + } |
|
130 | + if (!$storage instanceof INotifyStorage) { |
|
131 | + $output->writeln('<error>Mount of type "' . $mount->getBackend()->getText() . '" does not support active update notifications</error>'); |
|
132 | + return 1; |
|
133 | + } |
|
134 | 134 | |
135 | - $verbose = $input->getOption('verbose'); |
|
135 | + $verbose = $input->getOption('verbose'); |
|
136 | 136 | |
137 | - $path = trim($input->getOption('path'), '/'); |
|
138 | - $notifyHandler = $storage->notify($path); |
|
139 | - $this->selfTest($storage, $notifyHandler, $verbose, $output); |
|
140 | - $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
141 | - if ($verbose) { |
|
142 | - $this->logUpdate($change, $output); |
|
143 | - } |
|
144 | - if ($change instanceof IRenameChange) { |
|
145 | - $this->markParentAsOutdated($mount->getId(), $change->getTargetPath(), $output); |
|
146 | - } |
|
147 | - $this->markParentAsOutdated($mount->getId(), $change->getPath(), $output); |
|
148 | - }); |
|
149 | - } |
|
137 | + $path = trim($input->getOption('path'), '/'); |
|
138 | + $notifyHandler = $storage->notify($path); |
|
139 | + $this->selfTest($storage, $notifyHandler, $verbose, $output); |
|
140 | + $notifyHandler->listen(function (IChange $change) use ($mount, $verbose, $output) { |
|
141 | + if ($verbose) { |
|
142 | + $this->logUpdate($change, $output); |
|
143 | + } |
|
144 | + if ($change instanceof IRenameChange) { |
|
145 | + $this->markParentAsOutdated($mount->getId(), $change->getTargetPath(), $output); |
|
146 | + } |
|
147 | + $this->markParentAsOutdated($mount->getId(), $change->getPath(), $output); |
|
148 | + }); |
|
149 | + } |
|
150 | 150 | |
151 | - private function createStorage(StorageConfig $mount) { |
|
152 | - $class = $mount->getBackend()->getStorageClass(); |
|
153 | - return new $class($mount->getBackendOptions()); |
|
154 | - } |
|
151 | + private function createStorage(StorageConfig $mount) { |
|
152 | + $class = $mount->getBackend()->getStorageClass(); |
|
153 | + return new $class($mount->getBackendOptions()); |
|
154 | + } |
|
155 | 155 | |
156 | - private function markParentAsOutdated($mountId, $path, OutputInterface $output) { |
|
157 | - $parent = ltrim(dirname($path), '/'); |
|
158 | - if ($parent === '.') { |
|
159 | - $parent = ''; |
|
160 | - } |
|
156 | + private function markParentAsOutdated($mountId, $path, OutputInterface $output) { |
|
157 | + $parent = ltrim(dirname($path), '/'); |
|
158 | + if ($parent === '.') { |
|
159 | + $parent = ''; |
|
160 | + } |
|
161 | 161 | |
162 | - try { |
|
163 | - $storageIds = $this->getStorageIds($mountId); |
|
164 | - } catch (DriverException $ex) { |
|
165 | - $this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]); |
|
166 | - $this->connection = $this->reconnectToDatabase($this->connection, $output); |
|
167 | - $output->writeln('<info>Needed to reconnect to the database</info>'); |
|
168 | - $storageIds = $this->getStorageIds($mountId); |
|
169 | - } |
|
170 | - if (count($storageIds) === 0) { |
|
171 | - throw new StorageNotAvailableException('No storages found by mount ID ' . $mountId); |
|
172 | - } |
|
173 | - $storageIds = array_map('intval', $storageIds); |
|
162 | + try { |
|
163 | + $storageIds = $this->getStorageIds($mountId); |
|
164 | + } catch (DriverException $ex) { |
|
165 | + $this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]); |
|
166 | + $this->connection = $this->reconnectToDatabase($this->connection, $output); |
|
167 | + $output->writeln('<info>Needed to reconnect to the database</info>'); |
|
168 | + $storageIds = $this->getStorageIds($mountId); |
|
169 | + } |
|
170 | + if (count($storageIds) === 0) { |
|
171 | + throw new StorageNotAvailableException('No storages found by mount ID ' . $mountId); |
|
172 | + } |
|
173 | + $storageIds = array_map('intval', $storageIds); |
|
174 | 174 | |
175 | - $result = $this->updateParent($storageIds, $parent); |
|
176 | - if ($result === 0) { |
|
177 | - //TODO: Find existing parent further up the tree in the database and register that folder instead. |
|
178 | - $this->logger->info('Failed updating parent for "' . $path . '" while trying to register change. It may not exist in the filecache.'); |
|
179 | - } |
|
180 | - } |
|
175 | + $result = $this->updateParent($storageIds, $parent); |
|
176 | + if ($result === 0) { |
|
177 | + //TODO: Find existing parent further up the tree in the database and register that folder instead. |
|
178 | + $this->logger->info('Failed updating parent for "' . $path . '" while trying to register change. It may not exist in the filecache.'); |
|
179 | + } |
|
180 | + } |
|
181 | 181 | |
182 | - private function logUpdate(IChange $change, OutputInterface $output) { |
|
183 | - switch ($change->getType()) { |
|
184 | - case INotifyStorage::NOTIFY_ADDED: |
|
185 | - $text = 'added'; |
|
186 | - break; |
|
187 | - case INotifyStorage::NOTIFY_MODIFIED: |
|
188 | - $text = 'modified'; |
|
189 | - break; |
|
190 | - case INotifyStorage::NOTIFY_REMOVED: |
|
191 | - $text = 'removed'; |
|
192 | - break; |
|
193 | - case INotifyStorage::NOTIFY_RENAMED: |
|
194 | - $text = 'renamed'; |
|
195 | - break; |
|
196 | - default: |
|
197 | - return; |
|
198 | - } |
|
182 | + private function logUpdate(IChange $change, OutputInterface $output) { |
|
183 | + switch ($change->getType()) { |
|
184 | + case INotifyStorage::NOTIFY_ADDED: |
|
185 | + $text = 'added'; |
|
186 | + break; |
|
187 | + case INotifyStorage::NOTIFY_MODIFIED: |
|
188 | + $text = 'modified'; |
|
189 | + break; |
|
190 | + case INotifyStorage::NOTIFY_REMOVED: |
|
191 | + $text = 'removed'; |
|
192 | + break; |
|
193 | + case INotifyStorage::NOTIFY_RENAMED: |
|
194 | + $text = 'renamed'; |
|
195 | + break; |
|
196 | + default: |
|
197 | + return; |
|
198 | + } |
|
199 | 199 | |
200 | - $text .= ' ' . $change->getPath(); |
|
201 | - if ($change instanceof IRenameChange) { |
|
202 | - $text .= ' to ' . $change->getTargetPath(); |
|
203 | - } |
|
200 | + $text .= ' ' . $change->getPath(); |
|
201 | + if ($change instanceof IRenameChange) { |
|
202 | + $text .= ' to ' . $change->getTargetPath(); |
|
203 | + } |
|
204 | 204 | |
205 | - $output->writeln($text); |
|
206 | - } |
|
205 | + $output->writeln($text); |
|
206 | + } |
|
207 | 207 | |
208 | - /** |
|
209 | - * @param int $mountId |
|
210 | - * @return array |
|
211 | - */ |
|
212 | - private function getStorageIds($mountId) { |
|
213 | - $qb = $this->connection->getQueryBuilder(); |
|
214 | - return $qb |
|
215 | - ->select('storage_id') |
|
216 | - ->from('mounts') |
|
217 | - ->where($qb->expr()->eq('mount_id', $qb->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
218 | - ->execute() |
|
219 | - ->fetchAll(\PDO::FETCH_COLUMN); |
|
220 | - } |
|
208 | + /** |
|
209 | + * @param int $mountId |
|
210 | + * @return array |
|
211 | + */ |
|
212 | + private function getStorageIds($mountId) { |
|
213 | + $qb = $this->connection->getQueryBuilder(); |
|
214 | + return $qb |
|
215 | + ->select('storage_id') |
|
216 | + ->from('mounts') |
|
217 | + ->where($qb->expr()->eq('mount_id', $qb->createNamedParameter($mountId, IQueryBuilder::PARAM_INT))) |
|
218 | + ->execute() |
|
219 | + ->fetchAll(\PDO::FETCH_COLUMN); |
|
220 | + } |
|
221 | 221 | |
222 | - /** |
|
223 | - * @param array $storageIds |
|
224 | - * @param string $parent |
|
225 | - * @return int |
|
226 | - */ |
|
227 | - private function updateParent($storageIds, $parent) { |
|
228 | - $pathHash = md5(trim(\OC_Util::normalizeUnicode($parent), '/')); |
|
229 | - $qb = $this->connection->getQueryBuilder(); |
|
230 | - return $qb |
|
231 | - ->update('filecache') |
|
232 | - ->set('size', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT)) |
|
233 | - ->where($qb->expr()->in('storage', $qb->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY, ':storage_ids'))) |
|
234 | - ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash, IQueryBuilder::PARAM_STR))) |
|
235 | - ->execute(); |
|
236 | - } |
|
222 | + /** |
|
223 | + * @param array $storageIds |
|
224 | + * @param string $parent |
|
225 | + * @return int |
|
226 | + */ |
|
227 | + private function updateParent($storageIds, $parent) { |
|
228 | + $pathHash = md5(trim(\OC_Util::normalizeUnicode($parent), '/')); |
|
229 | + $qb = $this->connection->getQueryBuilder(); |
|
230 | + return $qb |
|
231 | + ->update('filecache') |
|
232 | + ->set('size', $qb->createNamedParameter(-1, IQueryBuilder::PARAM_INT)) |
|
233 | + ->where($qb->expr()->in('storage', $qb->createNamedParameter($storageIds, IQueryBuilder::PARAM_INT_ARRAY, ':storage_ids'))) |
|
234 | + ->andWhere($qb->expr()->eq('path_hash', $qb->createNamedParameter($pathHash, IQueryBuilder::PARAM_STR))) |
|
235 | + ->execute(); |
|
236 | + } |
|
237 | 237 | |
238 | - /** |
|
239 | - * @return \OCP\IDBConnection |
|
240 | - */ |
|
241 | - private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output) { |
|
242 | - try { |
|
243 | - $connection->close(); |
|
244 | - } catch (\Exception $ex) { |
|
245 | - $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]); |
|
246 | - $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
247 | - } |
|
248 | - while (!$connection->isConnected()) { |
|
249 | - try { |
|
250 | - $connection->connect(); |
|
251 | - } catch (\Exception $ex) { |
|
252 | - $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]); |
|
253 | - $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
254 | - sleep(60); |
|
255 | - } |
|
256 | - } |
|
257 | - return $connection; |
|
258 | - } |
|
238 | + /** |
|
239 | + * @return \OCP\IDBConnection |
|
240 | + */ |
|
241 | + private function reconnectToDatabase(IDBConnection $connection, OutputInterface $output) { |
|
242 | + try { |
|
243 | + $connection->close(); |
|
244 | + } catch (\Exception $ex) { |
|
245 | + $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]); |
|
246 | + $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>"); |
|
247 | + } |
|
248 | + while (!$connection->isConnected()) { |
|
249 | + try { |
|
250 | + $connection->connect(); |
|
251 | + } catch (\Exception $ex) { |
|
252 | + $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]); |
|
253 | + $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>"); |
|
254 | + sleep(60); |
|
255 | + } |
|
256 | + } |
|
257 | + return $connection; |
|
258 | + } |
|
259 | 259 | |
260 | 260 | |
261 | - private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) { |
|
262 | - usleep(100 * 1000); //give time for the notify to start |
|
263 | - $storage->file_put_contents('/.nc_test_file.txt', 'test content'); |
|
264 | - $storage->mkdir('/.nc_test_folder'); |
|
265 | - $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content'); |
|
261 | + private function selfTest(IStorage $storage, INotifyHandler $notifyHandler, $verbose, OutputInterface $output) { |
|
262 | + usleep(100 * 1000); //give time for the notify to start |
|
263 | + $storage->file_put_contents('/.nc_test_file.txt', 'test content'); |
|
264 | + $storage->mkdir('/.nc_test_folder'); |
|
265 | + $storage->file_put_contents('/.nc_test_folder/subfile.txt', 'test content'); |
|
266 | 266 | |
267 | - usleep(100 * 1000); //time for all changes to be processed |
|
268 | - $changes = $notifyHandler->getChanges(); |
|
267 | + usleep(100 * 1000); //time for all changes to be processed |
|
268 | + $changes = $notifyHandler->getChanges(); |
|
269 | 269 | |
270 | - $storage->unlink('/.nc_test_file.txt'); |
|
271 | - $storage->unlink('/.nc_test_folder/subfile.txt'); |
|
272 | - $storage->rmdir('/.nc_test_folder'); |
|
270 | + $storage->unlink('/.nc_test_file.txt'); |
|
271 | + $storage->unlink('/.nc_test_folder/subfile.txt'); |
|
272 | + $storage->rmdir('/.nc_test_folder'); |
|
273 | 273 | |
274 | - usleep(100 * 1000); //time for all changes to be processed |
|
275 | - $notifyHandler->getChanges(); // flush |
|
274 | + usleep(100 * 1000); //time for all changes to be processed |
|
275 | + $notifyHandler->getChanges(); // flush |
|
276 | 276 | |
277 | - $foundRootChange = false; |
|
278 | - $foundSubfolderChange = false; |
|
277 | + $foundRootChange = false; |
|
278 | + $foundSubfolderChange = false; |
|
279 | 279 | |
280 | - foreach ($changes as $change) { |
|
281 | - if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') { |
|
282 | - $foundRootChange = true; |
|
283 | - } elseif ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') { |
|
284 | - $foundSubfolderChange = true; |
|
285 | - } |
|
286 | - } |
|
280 | + foreach ($changes as $change) { |
|
281 | + if ($change->getPath() === '/.nc_test_file.txt' || $change->getPath() === '.nc_test_file.txt') { |
|
282 | + $foundRootChange = true; |
|
283 | + } elseif ($change->getPath() === '/.nc_test_folder/subfile.txt' || $change->getPath() === '.nc_test_folder/subfile.txt') { |
|
284 | + $foundSubfolderChange = true; |
|
285 | + } |
|
286 | + } |
|
287 | 287 | |
288 | - if ($foundRootChange && $foundSubfolderChange && $verbose) { |
|
289 | - $output->writeln('<info>Self-test successful</info>'); |
|
290 | - } elseif ($foundRootChange && !$foundSubfolderChange) { |
|
291 | - $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>'); |
|
292 | - } elseif (!$foundRootChange) { |
|
293 | - $output->writeln('<error>Error while running self-test, no changes detected</error>'); |
|
294 | - } |
|
295 | - } |
|
288 | + if ($foundRootChange && $foundSubfolderChange && $verbose) { |
|
289 | + $output->writeln('<info>Self-test successful</info>'); |
|
290 | + } elseif ($foundRootChange && !$foundSubfolderChange) { |
|
291 | + $output->writeln('<error>Error while running self-test, change is subfolder not detected</error>'); |
|
292 | + } elseif (!$foundRootChange) { |
|
293 | + $output->writeln('<error>Error while running self-test, no changes detected</error>'); |
|
294 | + } |
|
295 | + } |
|
296 | 296 | } |
@@ -31,129 +31,129 @@ |
||
31 | 31 | |
32 | 32 | class Resource implements IResource { |
33 | 33 | |
34 | - /** @var IManager */ |
|
35 | - protected $manager; |
|
36 | - |
|
37 | - /** @var IDBConnection */ |
|
38 | - protected $connection; |
|
39 | - |
|
40 | - /** @var string */ |
|
41 | - protected $type; |
|
42 | - |
|
43 | - /** @var string */ |
|
44 | - protected $id; |
|
45 | - |
|
46 | - /** @var IUser|null */ |
|
47 | - protected $userForAccess; |
|
48 | - |
|
49 | - /** @var bool|null */ |
|
50 | - protected $access; |
|
51 | - |
|
52 | - /** @var array|null */ |
|
53 | - protected $data; |
|
54 | - |
|
55 | - public function __construct( |
|
56 | - IManager $manager, |
|
57 | - IDBConnection $connection, |
|
58 | - string $type, |
|
59 | - string $id, |
|
60 | - ?IUser $userForAccess = null, |
|
61 | - ?bool $access = null |
|
62 | - ) { |
|
63 | - $this->manager = $manager; |
|
64 | - $this->connection = $connection; |
|
65 | - $this->type = $type; |
|
66 | - $this->id = $id; |
|
67 | - $this->userForAccess = $userForAccess; |
|
68 | - $this->access = $access; |
|
69 | - } |
|
70 | - |
|
71 | - /** |
|
72 | - * @return string |
|
73 | - * @since 16.0.0 |
|
74 | - */ |
|
75 | - public function getType(): string { |
|
76 | - return $this->type; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @return string |
|
81 | - * @since 16.0.0 |
|
82 | - */ |
|
83 | - public function getId(): string { |
|
84 | - return $this->id; |
|
85 | - } |
|
86 | - |
|
87 | - /** |
|
88 | - * @return array |
|
89 | - * @since 16.0.0 |
|
90 | - */ |
|
91 | - public function getRichObject(): array { |
|
92 | - if ($this->data === null) { |
|
93 | - $this->data = $this->manager->getResourceRichObject($this); |
|
94 | - } |
|
95 | - |
|
96 | - return $this->data; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Can a user/guest access the resource |
|
101 | - * |
|
102 | - * @param IUser|null $user |
|
103 | - * @return bool |
|
104 | - * @since 16.0.0 |
|
105 | - */ |
|
106 | - public function canAccess(?IUser $user): bool { |
|
107 | - if ($user instanceof IUser) { |
|
108 | - return $this->canUserAccess($user); |
|
109 | - } |
|
110 | - return $this->canGuestAccess(); |
|
111 | - } |
|
112 | - |
|
113 | - protected function canUserAccess(IUser $user): bool { |
|
114 | - if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { |
|
115 | - return $this->access; |
|
116 | - } |
|
117 | - |
|
118 | - $access = $this->manager->canAccessResource($this, $user); |
|
119 | - if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { |
|
120 | - $this->access = $access; |
|
121 | - } |
|
122 | - return $access; |
|
123 | - } |
|
124 | - |
|
125 | - protected function canGuestAccess(): bool { |
|
126 | - if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) { |
|
127 | - return $this->access; |
|
128 | - } |
|
129 | - |
|
130 | - $access = $this->manager->canAccessResource($this, null); |
|
131 | - if (!$this->userForAccess instanceof IUser) { |
|
132 | - $this->access = $access; |
|
133 | - } |
|
134 | - return $access; |
|
135 | - } |
|
136 | - |
|
137 | - /** |
|
138 | - * @return ICollection[] |
|
139 | - * @since 16.0.0 |
|
140 | - */ |
|
141 | - public function getCollections(): array { |
|
142 | - $collections = []; |
|
143 | - |
|
144 | - $query = $this->connection->getQueryBuilder(); |
|
145 | - |
|
146 | - $query->select('collection_id') |
|
147 | - ->from('collres_resources') |
|
148 | - ->where($query->expr()->eq('resource_type', $query->createNamedParameter($this->getType()))) |
|
149 | - ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($this->getId()))); |
|
150 | - |
|
151 | - $result = $query->execute(); |
|
152 | - while ($row = $result->fetch()) { |
|
153 | - $collections[] = $this->manager->getCollection((int) $row['collection_id']); |
|
154 | - } |
|
155 | - $result->closeCursor(); |
|
156 | - |
|
157 | - return $collections; |
|
158 | - } |
|
34 | + /** @var IManager */ |
|
35 | + protected $manager; |
|
36 | + |
|
37 | + /** @var IDBConnection */ |
|
38 | + protected $connection; |
|
39 | + |
|
40 | + /** @var string */ |
|
41 | + protected $type; |
|
42 | + |
|
43 | + /** @var string */ |
|
44 | + protected $id; |
|
45 | + |
|
46 | + /** @var IUser|null */ |
|
47 | + protected $userForAccess; |
|
48 | + |
|
49 | + /** @var bool|null */ |
|
50 | + protected $access; |
|
51 | + |
|
52 | + /** @var array|null */ |
|
53 | + protected $data; |
|
54 | + |
|
55 | + public function __construct( |
|
56 | + IManager $manager, |
|
57 | + IDBConnection $connection, |
|
58 | + string $type, |
|
59 | + string $id, |
|
60 | + ?IUser $userForAccess = null, |
|
61 | + ?bool $access = null |
|
62 | + ) { |
|
63 | + $this->manager = $manager; |
|
64 | + $this->connection = $connection; |
|
65 | + $this->type = $type; |
|
66 | + $this->id = $id; |
|
67 | + $this->userForAccess = $userForAccess; |
|
68 | + $this->access = $access; |
|
69 | + } |
|
70 | + |
|
71 | + /** |
|
72 | + * @return string |
|
73 | + * @since 16.0.0 |
|
74 | + */ |
|
75 | + public function getType(): string { |
|
76 | + return $this->type; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @return string |
|
81 | + * @since 16.0.0 |
|
82 | + */ |
|
83 | + public function getId(): string { |
|
84 | + return $this->id; |
|
85 | + } |
|
86 | + |
|
87 | + /** |
|
88 | + * @return array |
|
89 | + * @since 16.0.0 |
|
90 | + */ |
|
91 | + public function getRichObject(): array { |
|
92 | + if ($this->data === null) { |
|
93 | + $this->data = $this->manager->getResourceRichObject($this); |
|
94 | + } |
|
95 | + |
|
96 | + return $this->data; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Can a user/guest access the resource |
|
101 | + * |
|
102 | + * @param IUser|null $user |
|
103 | + * @return bool |
|
104 | + * @since 16.0.0 |
|
105 | + */ |
|
106 | + public function canAccess(?IUser $user): bool { |
|
107 | + if ($user instanceof IUser) { |
|
108 | + return $this->canUserAccess($user); |
|
109 | + } |
|
110 | + return $this->canGuestAccess(); |
|
111 | + } |
|
112 | + |
|
113 | + protected function canUserAccess(IUser $user): bool { |
|
114 | + if (\is_bool($this->access) && $this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { |
|
115 | + return $this->access; |
|
116 | + } |
|
117 | + |
|
118 | + $access = $this->manager->canAccessResource($this, $user); |
|
119 | + if ($this->userForAccess instanceof IUser && $user->getUID() === $this->userForAccess->getUID()) { |
|
120 | + $this->access = $access; |
|
121 | + } |
|
122 | + return $access; |
|
123 | + } |
|
124 | + |
|
125 | + protected function canGuestAccess(): bool { |
|
126 | + if (\is_bool($this->access) && !$this->userForAccess instanceof IUser) { |
|
127 | + return $this->access; |
|
128 | + } |
|
129 | + |
|
130 | + $access = $this->manager->canAccessResource($this, null); |
|
131 | + if (!$this->userForAccess instanceof IUser) { |
|
132 | + $this->access = $access; |
|
133 | + } |
|
134 | + return $access; |
|
135 | + } |
|
136 | + |
|
137 | + /** |
|
138 | + * @return ICollection[] |
|
139 | + * @since 16.0.0 |
|
140 | + */ |
|
141 | + public function getCollections(): array { |
|
142 | + $collections = []; |
|
143 | + |
|
144 | + $query = $this->connection->getQueryBuilder(); |
|
145 | + |
|
146 | + $query->select('collection_id') |
|
147 | + ->from('collres_resources') |
|
148 | + ->where($query->expr()->eq('resource_type', $query->createNamedParameter($this->getType()))) |
|
149 | + ->andWhere($query->expr()->eq('resource_id', $query->createNamedParameter($this->getId()))); |
|
150 | + |
|
151 | + $result = $query->execute(); |
|
152 | + while ($row = $result->fetch()) { |
|
153 | + $collections[] = $this->manager->getCollection((int) $row['collection_id']); |
|
154 | + } |
|
155 | + $result->closeCursor(); |
|
156 | + |
|
157 | + return $collections; |
|
158 | + } |
|
159 | 159 | } |
@@ -29,36 +29,36 @@ |
||
29 | 29 | */ |
30 | 30 | interface IResource { |
31 | 31 | |
32 | - /** |
|
33 | - * @return string |
|
34 | - * @since 16.0.0 |
|
35 | - */ |
|
36 | - public function getType(): string; |
|
32 | + /** |
|
33 | + * @return string |
|
34 | + * @since 16.0.0 |
|
35 | + */ |
|
36 | + public function getType(): string; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @return string |
|
40 | - * @since 16.0.0 |
|
41 | - */ |
|
42 | - public function getId(): string; |
|
38 | + /** |
|
39 | + * @return string |
|
40 | + * @since 16.0.0 |
|
41 | + */ |
|
42 | + public function getId(): string; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return array |
|
46 | - * @since 16.0.0 |
|
47 | - */ |
|
48 | - public function getRichObject(): array; |
|
44 | + /** |
|
45 | + * @return array |
|
46 | + * @since 16.0.0 |
|
47 | + */ |
|
48 | + public function getRichObject(): array; |
|
49 | 49 | |
50 | - /** |
|
51 | - * Can a user/guest access the resource |
|
52 | - * |
|
53 | - * @param IUser|null $user |
|
54 | - * @return bool |
|
55 | - * @since 16.0.0 |
|
56 | - */ |
|
57 | - public function canAccess(?IUser $user): bool; |
|
50 | + /** |
|
51 | + * Can a user/guest access the resource |
|
52 | + * |
|
53 | + * @param IUser|null $user |
|
54 | + * @return bool |
|
55 | + * @since 16.0.0 |
|
56 | + */ |
|
57 | + public function canAccess(?IUser $user): bool; |
|
58 | 58 | |
59 | - /** |
|
60 | - * @return ICollection[] |
|
61 | - * @since 16.0.0 |
|
62 | - */ |
|
63 | - public function getCollections(): array; |
|
59 | + /** |
|
60 | + * @return ICollection[] |
|
61 | + * @since 16.0.0 |
|
62 | + */ |
|
63 | + public function getCollections(): array; |
|
64 | 64 | } |
@@ -28,23 +28,23 @@ |
||
28 | 28 | |
29 | 29 | class Version1004Date20170924124212 extends SimpleMigrationStep { |
30 | 30 | |
31 | - /** |
|
32 | - * @param IOutput $output |
|
33 | - * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
34 | - * @param array $options |
|
35 | - * @return null|ISchemaWrapper |
|
36 | - * @since 13.0.0 |
|
37 | - */ |
|
38 | - public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
39 | - /** @var ISchemaWrapper $schema */ |
|
40 | - $schema = $schemaClosure(); |
|
31 | + /** |
|
32 | + * @param IOutput $output |
|
33 | + * @param \Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper` |
|
34 | + * @param array $options |
|
35 | + * @return null|ISchemaWrapper |
|
36 | + * @since 13.0.0 |
|
37 | + */ |
|
38 | + public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) { |
|
39 | + /** @var ISchemaWrapper $schema */ |
|
40 | + $schema = $schemaClosure(); |
|
41 | 41 | |
42 | - $table = $schema->getTable('cards'); |
|
43 | - $table->addIndex(['addressbookid'], 'cards_abid'); |
|
42 | + $table = $schema->getTable('cards'); |
|
43 | + $table->addIndex(['addressbookid'], 'cards_abid'); |
|
44 | 44 | |
45 | - $table = $schema->getTable('cards_properties'); |
|
46 | - $table->addIndex(['addressbookid'], 'cards_prop_abid'); |
|
45 | + $table = $schema->getTable('cards_properties'); |
|
46 | + $table->addIndex(['addressbookid'], 'cards_prop_abid'); |
|
47 | 47 | |
48 | - return $schema; |
|
49 | - } |
|
48 | + return $schema; |
|
49 | + } |
|
50 | 50 | } |