@@ -34,29 +34,29 @@ |
||
34 | 34 | * @since 15.0.0 |
35 | 35 | */ |
36 | 36 | abstract class TimedJob extends Job { |
37 | - /** @var int */ |
|
38 | - protected $interval = 0; |
|
37 | + /** @var int */ |
|
38 | + protected $interval = 0; |
|
39 | 39 | |
40 | - /** |
|
41 | - * set the interval for the job |
|
42 | - * |
|
43 | - * @since 15.0.0 |
|
44 | - */ |
|
45 | - public function setInterval(int $interval) { |
|
46 | - $this->interval = $interval; |
|
47 | - } |
|
40 | + /** |
|
41 | + * set the interval for the job |
|
42 | + * |
|
43 | + * @since 15.0.0 |
|
44 | + */ |
|
45 | + public function setInterval(int $interval) { |
|
46 | + $this->interval = $interval; |
|
47 | + } |
|
48 | 48 | |
49 | - /** |
|
50 | - * run the job if the last run is is more than the interval ago |
|
51 | - * |
|
52 | - * @param JobList $jobList |
|
53 | - * @param ILogger|null $logger |
|
54 | - * |
|
55 | - * @since 15.0.0 |
|
56 | - */ |
|
57 | - final public function execute($jobList, ILogger $logger = null) { |
|
58 | - if (($this->time->getTime() - $this->lastRun) > $this->interval) { |
|
59 | - parent::execute($jobList, $logger); |
|
60 | - } |
|
61 | - } |
|
49 | + /** |
|
50 | + * run the job if the last run is is more than the interval ago |
|
51 | + * |
|
52 | + * @param JobList $jobList |
|
53 | + * @param ILogger|null $logger |
|
54 | + * |
|
55 | + * @since 15.0.0 |
|
56 | + */ |
|
57 | + final public function execute($jobList, ILogger $logger = null) { |
|
58 | + if (($this->time->getTime() - $this->lastRun) > $this->interval) { |
|
59 | + parent::execute($jobList, $logger); |
|
60 | + } |
|
61 | + } |
|
62 | 62 | } |
@@ -72,11 +72,11 @@ discard block |
||
72 | 72 | |
73 | 73 | $nodes = $this->nodes; |
74 | 74 | // http://stackoverflow.com/a/10985500 |
75 | - @usort($nodes, function (IFile $a, IFile $b) { |
|
75 | + @usort($nodes, function(IFile $a, IFile $b) { |
|
76 | 76 | return strnatcmp($a->getName(), $b->getName()); |
77 | 77 | }); |
78 | 78 | $this->nodes = array_values($nodes); |
79 | - $this->size = array_reduce($this->nodes, function ($size, IFile $file) { |
|
79 | + $this->size = array_reduce($this->nodes, function($size, IFile $file) { |
|
80 | 80 | return $size + $file->getSize(); |
81 | 81 | }, 0); |
82 | 82 | return true; |
@@ -120,7 +120,7 @@ discard block |
||
120 | 120 | fclose($this->currentStream); |
121 | 121 | $currentNodeSize = $this->nodes[$this->currentNode]->getSize(); |
122 | 122 | if ($this->currentNodeRead < $currentNodeSize) { |
123 | - throw new \Exception('Stream from assembly node shorter than expected, got ' . $this->currentNodeRead . ' bytes, expected ' . $currentNodeSize); |
|
123 | + throw new \Exception('Stream from assembly node shorter than expected, got '.$this->currentNodeRead.' bytes, expected '.$currentNodeSize); |
|
124 | 124 | } |
125 | 125 | $this->currentNode++; |
126 | 126 | $this->currentNodeRead = 0; |
@@ -215,7 +215,7 @@ discard block |
||
215 | 215 | if (isset($context[$name])) { |
216 | 216 | $context = $context[$name]; |
217 | 217 | } else { |
218 | - throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set'); |
|
218 | + throw new \BadMethodCallException('Invalid context, "'.$name.'" options not set'); |
|
219 | 219 | } |
220 | 220 | if (isset($context['nodes']) and is_array($context['nodes'])) { |
221 | 221 | $this->nodes = $context['nodes']; |
@@ -40,264 +40,264 @@ |
||
40 | 40 | */ |
41 | 41 | class AssemblyStream implements \Icewind\Streams\File { |
42 | 42 | |
43 | - /** @var resource */ |
|
44 | - private $context; |
|
45 | - |
|
46 | - /** @var IFile[] */ |
|
47 | - private $nodes; |
|
48 | - |
|
49 | - /** @var int */ |
|
50 | - private $pos = 0; |
|
51 | - |
|
52 | - /** @var int */ |
|
53 | - private $size = 0; |
|
54 | - |
|
55 | - /** @var resource */ |
|
56 | - private $currentStream = null; |
|
57 | - |
|
58 | - /** @var int */ |
|
59 | - private $currentNode = 0; |
|
60 | - |
|
61 | - /** @var int */ |
|
62 | - private $currentNodeRead = 0; |
|
63 | - |
|
64 | - /** |
|
65 | - * @param string $path |
|
66 | - * @param string $mode |
|
67 | - * @param int $options |
|
68 | - * @param string &$opened_path |
|
69 | - * @return bool |
|
70 | - */ |
|
71 | - public function stream_open($path, $mode, $options, &$opened_path) { |
|
72 | - $this->loadContext('assembly'); |
|
73 | - |
|
74 | - $nodes = $this->nodes; |
|
75 | - // http://stackoverflow.com/a/10985500 |
|
76 | - @usort($nodes, function (IFile $a, IFile $b) { |
|
77 | - return strnatcmp($a->getName(), $b->getName()); |
|
78 | - }); |
|
79 | - $this->nodes = array_values($nodes); |
|
80 | - $this->size = array_reduce($this->nodes, function ($size, IFile $file) { |
|
81 | - return $size + $file->getSize(); |
|
82 | - }, 0); |
|
83 | - return true; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param int $offset |
|
88 | - * @param int $whence |
|
89 | - * @return bool |
|
90 | - */ |
|
91 | - public function stream_seek($offset, $whence = SEEK_SET) { |
|
92 | - if ($whence === SEEK_CUR) { |
|
93 | - $offset = $this->stream_tell() + $offset; |
|
94 | - } elseif ($whence === SEEK_END) { |
|
95 | - $offset = $this->size + $offset; |
|
96 | - } |
|
97 | - |
|
98 | - if ($offset > $this->size) { |
|
99 | - return false; |
|
100 | - } |
|
101 | - |
|
102 | - $nodeIndex = 0; |
|
103 | - $nodeStart = 0; |
|
104 | - while (true) { |
|
105 | - if (!isset($this->nodes[$nodeIndex + 1])) { |
|
106 | - break; |
|
107 | - } |
|
108 | - $node = $this->nodes[$nodeIndex]; |
|
109 | - if ($nodeStart + $node->getSize() > $offset) { |
|
110 | - break; |
|
111 | - } |
|
112 | - $nodeIndex++; |
|
113 | - $nodeStart += $node->getSize(); |
|
114 | - } |
|
115 | - |
|
116 | - $stream = $this->getStream($this->nodes[$nodeIndex]); |
|
117 | - $nodeOffset = $offset - $nodeStart; |
|
118 | - if (fseek($stream, $nodeOffset) === -1) { |
|
119 | - return false; |
|
120 | - } |
|
121 | - $this->currentNode = $nodeIndex; |
|
122 | - $this->currentNodeRead = $nodeOffset; |
|
123 | - $this->currentStream = $stream; |
|
124 | - $this->pos = $offset; |
|
125 | - |
|
126 | - return true; |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * @return int |
|
131 | - */ |
|
132 | - public function stream_tell() { |
|
133 | - return $this->pos; |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param int $count |
|
138 | - * @return string |
|
139 | - */ |
|
140 | - public function stream_read($count) { |
|
141 | - if (is_null($this->currentStream)) { |
|
142 | - if ($this->currentNode < count($this->nodes)) { |
|
143 | - $this->currentStream = $this->getStream($this->nodes[$this->currentNode]); |
|
144 | - } else { |
|
145 | - return ''; |
|
146 | - } |
|
147 | - } |
|
148 | - |
|
149 | - do { |
|
150 | - $data = fread($this->currentStream, $count); |
|
151 | - $read = strlen($data); |
|
152 | - $this->currentNodeRead += $read; |
|
153 | - |
|
154 | - if (feof($this->currentStream)) { |
|
155 | - fclose($this->currentStream); |
|
156 | - $currentNodeSize = $this->nodes[$this->currentNode]->getSize(); |
|
157 | - if ($this->currentNodeRead < $currentNodeSize) { |
|
158 | - throw new \Exception('Stream from assembly node shorter than expected, got ' . $this->currentNodeRead . ' bytes, expected ' . $currentNodeSize); |
|
159 | - } |
|
160 | - $this->currentNode++; |
|
161 | - $this->currentNodeRead = 0; |
|
162 | - if ($this->currentNode < count($this->nodes)) { |
|
163 | - $this->currentStream = $this->getStream($this->nodes[$this->currentNode]); |
|
164 | - } else { |
|
165 | - $this->currentStream = null; |
|
166 | - } |
|
167 | - } |
|
168 | - // if no data read, try again with the next node because |
|
169 | - // returning empty data can make the caller think there is no more |
|
170 | - // data left to read |
|
171 | - } while ($read === 0 && !is_null($this->currentStream)); |
|
172 | - |
|
173 | - // update position |
|
174 | - $this->pos += $read; |
|
175 | - return $data; |
|
176 | - } |
|
177 | - |
|
178 | - /** |
|
179 | - * @param string $data |
|
180 | - * @return int |
|
181 | - */ |
|
182 | - public function stream_write($data) { |
|
183 | - return false; |
|
184 | - } |
|
185 | - |
|
186 | - /** |
|
187 | - * @param int $option |
|
188 | - * @param int $arg1 |
|
189 | - * @param int $arg2 |
|
190 | - * @return bool |
|
191 | - */ |
|
192 | - public function stream_set_option($option, $arg1, $arg2) { |
|
193 | - return false; |
|
194 | - } |
|
195 | - |
|
196 | - /** |
|
197 | - * @param int $size |
|
198 | - * @return bool |
|
199 | - */ |
|
200 | - public function stream_truncate($size) { |
|
201 | - return false; |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * @return array |
|
206 | - */ |
|
207 | - public function stream_stat() { |
|
208 | - return [ |
|
209 | - 'size' => $this->size, |
|
210 | - ]; |
|
211 | - } |
|
212 | - |
|
213 | - /** |
|
214 | - * @param int $operation |
|
215 | - * @return bool |
|
216 | - */ |
|
217 | - public function stream_lock($operation) { |
|
218 | - return false; |
|
219 | - } |
|
220 | - |
|
221 | - /** |
|
222 | - * @return bool |
|
223 | - */ |
|
224 | - public function stream_flush() { |
|
225 | - return false; |
|
226 | - } |
|
227 | - |
|
228 | - /** |
|
229 | - * @return bool |
|
230 | - */ |
|
231 | - public function stream_eof() { |
|
232 | - return $this->pos >= $this->size || ($this->currentNode >= count($this->nodes) && $this->currentNode === null); |
|
233 | - } |
|
234 | - |
|
235 | - /** |
|
236 | - * @return bool |
|
237 | - */ |
|
238 | - public function stream_close() { |
|
239 | - return true; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * Load the source from the stream context and return the context options |
|
245 | - * |
|
246 | - * @param string $name |
|
247 | - * @return array |
|
248 | - * @throws \BadMethodCallException |
|
249 | - */ |
|
250 | - protected function loadContext($name) { |
|
251 | - $context = stream_context_get_options($this->context); |
|
252 | - if (isset($context[$name])) { |
|
253 | - $context = $context[$name]; |
|
254 | - } else { |
|
255 | - throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set'); |
|
256 | - } |
|
257 | - if (isset($context['nodes']) and is_array($context['nodes'])) { |
|
258 | - $this->nodes = $context['nodes']; |
|
259 | - } else { |
|
260 | - throw new \BadMethodCallException('Invalid context, nodes not set'); |
|
261 | - } |
|
262 | - return $context; |
|
263 | - } |
|
264 | - |
|
265 | - /** |
|
266 | - * @param IFile[] $nodes |
|
267 | - * @return resource |
|
268 | - * |
|
269 | - * @throws \BadMethodCallException |
|
270 | - */ |
|
271 | - public static function wrap(array $nodes) { |
|
272 | - $context = stream_context_create([ |
|
273 | - 'assembly' => [ |
|
274 | - 'nodes' => $nodes |
|
275 | - ] |
|
276 | - ]); |
|
277 | - stream_wrapper_register('assembly', self::class); |
|
278 | - try { |
|
279 | - $wrapped = fopen('assembly://', 'r', null, $context); |
|
280 | - } catch (\BadMethodCallException $e) { |
|
281 | - stream_wrapper_unregister('assembly'); |
|
282 | - throw $e; |
|
283 | - } |
|
284 | - stream_wrapper_unregister('assembly'); |
|
285 | - return $wrapped; |
|
286 | - } |
|
287 | - |
|
288 | - /** |
|
289 | - * @param IFile $node |
|
290 | - * @return resource |
|
291 | - */ |
|
292 | - private function getStream(IFile $node) { |
|
293 | - $data = $node->get(); |
|
294 | - if (is_resource($data)) { |
|
295 | - return $data; |
|
296 | - } else { |
|
297 | - $tmp = fopen('php://temp', 'w+'); |
|
298 | - fwrite($tmp, $data); |
|
299 | - rewind($tmp); |
|
300 | - return $tmp; |
|
301 | - } |
|
302 | - } |
|
43 | + /** @var resource */ |
|
44 | + private $context; |
|
45 | + |
|
46 | + /** @var IFile[] */ |
|
47 | + private $nodes; |
|
48 | + |
|
49 | + /** @var int */ |
|
50 | + private $pos = 0; |
|
51 | + |
|
52 | + /** @var int */ |
|
53 | + private $size = 0; |
|
54 | + |
|
55 | + /** @var resource */ |
|
56 | + private $currentStream = null; |
|
57 | + |
|
58 | + /** @var int */ |
|
59 | + private $currentNode = 0; |
|
60 | + |
|
61 | + /** @var int */ |
|
62 | + private $currentNodeRead = 0; |
|
63 | + |
|
64 | + /** |
|
65 | + * @param string $path |
|
66 | + * @param string $mode |
|
67 | + * @param int $options |
|
68 | + * @param string &$opened_path |
|
69 | + * @return bool |
|
70 | + */ |
|
71 | + public function stream_open($path, $mode, $options, &$opened_path) { |
|
72 | + $this->loadContext('assembly'); |
|
73 | + |
|
74 | + $nodes = $this->nodes; |
|
75 | + // http://stackoverflow.com/a/10985500 |
|
76 | + @usort($nodes, function (IFile $a, IFile $b) { |
|
77 | + return strnatcmp($a->getName(), $b->getName()); |
|
78 | + }); |
|
79 | + $this->nodes = array_values($nodes); |
|
80 | + $this->size = array_reduce($this->nodes, function ($size, IFile $file) { |
|
81 | + return $size + $file->getSize(); |
|
82 | + }, 0); |
|
83 | + return true; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param int $offset |
|
88 | + * @param int $whence |
|
89 | + * @return bool |
|
90 | + */ |
|
91 | + public function stream_seek($offset, $whence = SEEK_SET) { |
|
92 | + if ($whence === SEEK_CUR) { |
|
93 | + $offset = $this->stream_tell() + $offset; |
|
94 | + } elseif ($whence === SEEK_END) { |
|
95 | + $offset = $this->size + $offset; |
|
96 | + } |
|
97 | + |
|
98 | + if ($offset > $this->size) { |
|
99 | + return false; |
|
100 | + } |
|
101 | + |
|
102 | + $nodeIndex = 0; |
|
103 | + $nodeStart = 0; |
|
104 | + while (true) { |
|
105 | + if (!isset($this->nodes[$nodeIndex + 1])) { |
|
106 | + break; |
|
107 | + } |
|
108 | + $node = $this->nodes[$nodeIndex]; |
|
109 | + if ($nodeStart + $node->getSize() > $offset) { |
|
110 | + break; |
|
111 | + } |
|
112 | + $nodeIndex++; |
|
113 | + $nodeStart += $node->getSize(); |
|
114 | + } |
|
115 | + |
|
116 | + $stream = $this->getStream($this->nodes[$nodeIndex]); |
|
117 | + $nodeOffset = $offset - $nodeStart; |
|
118 | + if (fseek($stream, $nodeOffset) === -1) { |
|
119 | + return false; |
|
120 | + } |
|
121 | + $this->currentNode = $nodeIndex; |
|
122 | + $this->currentNodeRead = $nodeOffset; |
|
123 | + $this->currentStream = $stream; |
|
124 | + $this->pos = $offset; |
|
125 | + |
|
126 | + return true; |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * @return int |
|
131 | + */ |
|
132 | + public function stream_tell() { |
|
133 | + return $this->pos; |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param int $count |
|
138 | + * @return string |
|
139 | + */ |
|
140 | + public function stream_read($count) { |
|
141 | + if (is_null($this->currentStream)) { |
|
142 | + if ($this->currentNode < count($this->nodes)) { |
|
143 | + $this->currentStream = $this->getStream($this->nodes[$this->currentNode]); |
|
144 | + } else { |
|
145 | + return ''; |
|
146 | + } |
|
147 | + } |
|
148 | + |
|
149 | + do { |
|
150 | + $data = fread($this->currentStream, $count); |
|
151 | + $read = strlen($data); |
|
152 | + $this->currentNodeRead += $read; |
|
153 | + |
|
154 | + if (feof($this->currentStream)) { |
|
155 | + fclose($this->currentStream); |
|
156 | + $currentNodeSize = $this->nodes[$this->currentNode]->getSize(); |
|
157 | + if ($this->currentNodeRead < $currentNodeSize) { |
|
158 | + throw new \Exception('Stream from assembly node shorter than expected, got ' . $this->currentNodeRead . ' bytes, expected ' . $currentNodeSize); |
|
159 | + } |
|
160 | + $this->currentNode++; |
|
161 | + $this->currentNodeRead = 0; |
|
162 | + if ($this->currentNode < count($this->nodes)) { |
|
163 | + $this->currentStream = $this->getStream($this->nodes[$this->currentNode]); |
|
164 | + } else { |
|
165 | + $this->currentStream = null; |
|
166 | + } |
|
167 | + } |
|
168 | + // if no data read, try again with the next node because |
|
169 | + // returning empty data can make the caller think there is no more |
|
170 | + // data left to read |
|
171 | + } while ($read === 0 && !is_null($this->currentStream)); |
|
172 | + |
|
173 | + // update position |
|
174 | + $this->pos += $read; |
|
175 | + return $data; |
|
176 | + } |
|
177 | + |
|
178 | + /** |
|
179 | + * @param string $data |
|
180 | + * @return int |
|
181 | + */ |
|
182 | + public function stream_write($data) { |
|
183 | + return false; |
|
184 | + } |
|
185 | + |
|
186 | + /** |
|
187 | + * @param int $option |
|
188 | + * @param int $arg1 |
|
189 | + * @param int $arg2 |
|
190 | + * @return bool |
|
191 | + */ |
|
192 | + public function stream_set_option($option, $arg1, $arg2) { |
|
193 | + return false; |
|
194 | + } |
|
195 | + |
|
196 | + /** |
|
197 | + * @param int $size |
|
198 | + * @return bool |
|
199 | + */ |
|
200 | + public function stream_truncate($size) { |
|
201 | + return false; |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * @return array |
|
206 | + */ |
|
207 | + public function stream_stat() { |
|
208 | + return [ |
|
209 | + 'size' => $this->size, |
|
210 | + ]; |
|
211 | + } |
|
212 | + |
|
213 | + /** |
|
214 | + * @param int $operation |
|
215 | + * @return bool |
|
216 | + */ |
|
217 | + public function stream_lock($operation) { |
|
218 | + return false; |
|
219 | + } |
|
220 | + |
|
221 | + /** |
|
222 | + * @return bool |
|
223 | + */ |
|
224 | + public function stream_flush() { |
|
225 | + return false; |
|
226 | + } |
|
227 | + |
|
228 | + /** |
|
229 | + * @return bool |
|
230 | + */ |
|
231 | + public function stream_eof() { |
|
232 | + return $this->pos >= $this->size || ($this->currentNode >= count($this->nodes) && $this->currentNode === null); |
|
233 | + } |
|
234 | + |
|
235 | + /** |
|
236 | + * @return bool |
|
237 | + */ |
|
238 | + public function stream_close() { |
|
239 | + return true; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * Load the source from the stream context and return the context options |
|
245 | + * |
|
246 | + * @param string $name |
|
247 | + * @return array |
|
248 | + * @throws \BadMethodCallException |
|
249 | + */ |
|
250 | + protected function loadContext($name) { |
|
251 | + $context = stream_context_get_options($this->context); |
|
252 | + if (isset($context[$name])) { |
|
253 | + $context = $context[$name]; |
|
254 | + } else { |
|
255 | + throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set'); |
|
256 | + } |
|
257 | + if (isset($context['nodes']) and is_array($context['nodes'])) { |
|
258 | + $this->nodes = $context['nodes']; |
|
259 | + } else { |
|
260 | + throw new \BadMethodCallException('Invalid context, nodes not set'); |
|
261 | + } |
|
262 | + return $context; |
|
263 | + } |
|
264 | + |
|
265 | + /** |
|
266 | + * @param IFile[] $nodes |
|
267 | + * @return resource |
|
268 | + * |
|
269 | + * @throws \BadMethodCallException |
|
270 | + */ |
|
271 | + public static function wrap(array $nodes) { |
|
272 | + $context = stream_context_create([ |
|
273 | + 'assembly' => [ |
|
274 | + 'nodes' => $nodes |
|
275 | + ] |
|
276 | + ]); |
|
277 | + stream_wrapper_register('assembly', self::class); |
|
278 | + try { |
|
279 | + $wrapped = fopen('assembly://', 'r', null, $context); |
|
280 | + } catch (\BadMethodCallException $e) { |
|
281 | + stream_wrapper_unregister('assembly'); |
|
282 | + throw $e; |
|
283 | + } |
|
284 | + stream_wrapper_unregister('assembly'); |
|
285 | + return $wrapped; |
|
286 | + } |
|
287 | + |
|
288 | + /** |
|
289 | + * @param IFile $node |
|
290 | + * @return resource |
|
291 | + */ |
|
292 | + private function getStream(IFile $node) { |
|
293 | + $data = $node->get(); |
|
294 | + if (is_resource($data)) { |
|
295 | + return $data; |
|
296 | + } else { |
|
297 | + $tmp = fopen('php://temp', 'w+'); |
|
298 | + fwrite($tmp, $data); |
|
299 | + rewind($tmp); |
|
300 | + return $tmp; |
|
301 | + } |
|
302 | + } |
|
303 | 303 | } |
@@ -24,33 +24,33 @@ |
||
24 | 24 | use OCP\IUser; |
25 | 25 | |
26 | 26 | interface ITrashManager extends ITrashBackend { |
27 | - /** |
|
28 | - * Add a backend for the trashbin |
|
29 | - * |
|
30 | - * @param string $storageType |
|
31 | - * @param ITrashBackend $backend |
|
32 | - * @since 15.0.0 |
|
33 | - */ |
|
34 | - public function registerBackend(string $storageType, ITrashBackend $backend); |
|
27 | + /** |
|
28 | + * Add a backend for the trashbin |
|
29 | + * |
|
30 | + * @param string $storageType |
|
31 | + * @param ITrashBackend $backend |
|
32 | + * @since 15.0.0 |
|
33 | + */ |
|
34 | + public function registerBackend(string $storageType, ITrashBackend $backend); |
|
35 | 35 | |
36 | - /** |
|
37 | - * List all trash items in the root of the trashbin |
|
38 | - * |
|
39 | - * @param IUser $user |
|
40 | - * @return ITrashItem[] |
|
41 | - * @since 15.0.0 |
|
42 | - */ |
|
43 | - public function listTrashRoot(IUser $user): array; |
|
36 | + /** |
|
37 | + * List all trash items in the root of the trashbin |
|
38 | + * |
|
39 | + * @param IUser $user |
|
40 | + * @return ITrashItem[] |
|
41 | + * @since 15.0.0 |
|
42 | + */ |
|
43 | + public function listTrashRoot(IUser $user): array; |
|
44 | 44 | |
45 | - /** |
|
46 | - * Temporally prevent files from being moved to the trash |
|
47 | - * |
|
48 | - * @since 15.0.0 |
|
49 | - */ |
|
50 | - public function pauseTrash(); |
|
45 | + /** |
|
46 | + * Temporally prevent files from being moved to the trash |
|
47 | + * |
|
48 | + * @since 15.0.0 |
|
49 | + */ |
|
50 | + public function pauseTrash(); |
|
51 | 51 | |
52 | - /** |
|
53 | - * @since 15.0.0 |
|
54 | - */ |
|
55 | - public function resumeTrash(); |
|
52 | + /** |
|
53 | + * @since 15.0.0 |
|
54 | + */ |
|
55 | + public function resumeTrash(); |
|
56 | 56 | } |
@@ -31,54 +31,54 @@ |
||
31 | 31 | * @since 15.0.0 |
32 | 32 | */ |
33 | 33 | interface ITrashBackend { |
34 | - /** |
|
35 | - * List all trash items in the root of the trashbin |
|
36 | - * |
|
37 | - * @param IUser $user |
|
38 | - * @return ITrashItem[] |
|
39 | - * @since 15.0.0 |
|
40 | - */ |
|
41 | - public function listTrashRoot(IUser $user): array; |
|
34 | + /** |
|
35 | + * List all trash items in the root of the trashbin |
|
36 | + * |
|
37 | + * @param IUser $user |
|
38 | + * @return ITrashItem[] |
|
39 | + * @since 15.0.0 |
|
40 | + */ |
|
41 | + public function listTrashRoot(IUser $user): array; |
|
42 | 42 | |
43 | - /** |
|
44 | - * List all trash items in a subfolder in the trashbin |
|
45 | - * |
|
46 | - * @param ITrashItem $folder |
|
47 | - * @return ITrashItem[] |
|
48 | - * @since 15.0.0 |
|
49 | - */ |
|
50 | - public function listTrashFolder(ITrashItem $folder): array; |
|
43 | + /** |
|
44 | + * List all trash items in a subfolder in the trashbin |
|
45 | + * |
|
46 | + * @param ITrashItem $folder |
|
47 | + * @return ITrashItem[] |
|
48 | + * @since 15.0.0 |
|
49 | + */ |
|
50 | + public function listTrashFolder(ITrashItem $folder): array; |
|
51 | 51 | |
52 | - /** |
|
53 | - * Restore a trashbin item |
|
54 | - * |
|
55 | - * @param ITrashItem $item |
|
56 | - * @since 15.0.0 |
|
57 | - */ |
|
58 | - public function restoreItem(ITrashItem $item); |
|
52 | + /** |
|
53 | + * Restore a trashbin item |
|
54 | + * |
|
55 | + * @param ITrashItem $item |
|
56 | + * @since 15.0.0 |
|
57 | + */ |
|
58 | + public function restoreItem(ITrashItem $item); |
|
59 | 59 | |
60 | - /** |
|
61 | - * Permanently remove an item from trash |
|
62 | - * |
|
63 | - * @param ITrashItem $item |
|
64 | - * @since 15.0.0 |
|
65 | - */ |
|
66 | - public function removeItem(ITrashItem $item); |
|
60 | + /** |
|
61 | + * Permanently remove an item from trash |
|
62 | + * |
|
63 | + * @param ITrashItem $item |
|
64 | + * @since 15.0.0 |
|
65 | + */ |
|
66 | + public function removeItem(ITrashItem $item); |
|
67 | 67 | |
68 | - /** |
|
69 | - * Move a file or folder to trash |
|
70 | - * |
|
71 | - * @param IStorage $storage |
|
72 | - * @param string $internalPath |
|
73 | - * @return boolean whether or not the file was moved to trash, if false then the file should be deleted normally |
|
74 | - * @since 15.0.0 |
|
75 | - */ |
|
76 | - public function moveToTrash(IStorage $storage, string $internalPath): bool; |
|
68 | + /** |
|
69 | + * Move a file or folder to trash |
|
70 | + * |
|
71 | + * @param IStorage $storage |
|
72 | + * @param string $internalPath |
|
73 | + * @return boolean whether or not the file was moved to trash, if false then the file should be deleted normally |
|
74 | + * @since 15.0.0 |
|
75 | + */ |
|
76 | + public function moveToTrash(IStorage $storage, string $internalPath): bool; |
|
77 | 77 | |
78 | - /** |
|
79 | - * @param IUser $user |
|
80 | - * @param int $fileId |
|
81 | - * @return Node|null |
|
82 | - */ |
|
83 | - public function getTrashNodeById(IUser $user, int $fileId); |
|
78 | + /** |
|
79 | + * @param IUser $user |
|
80 | + * @param int $fileId |
|
81 | + * @return Node|null |
|
82 | + */ |
|
83 | + public function getTrashNodeById(IUser $user, int $fileId); |
|
84 | 84 | } |
@@ -44,10 +44,10 @@ discard block |
||
44 | 44 | } |
45 | 45 | |
46 | 46 | public function listTrashRoot(IUser $user): array { |
47 | - $items = array_reduce($this->getBackends(), function (array $items, ITrashBackend $backend) use ($user) { |
|
47 | + $items = array_reduce($this->getBackends(), function(array $items, ITrashBackend $backend) use ($user) { |
|
48 | 48 | return array_merge($items, $backend->listTrashRoot($user)); |
49 | 49 | }, []); |
50 | - usort($items, function (ITrashItem $a, ITrashItem $b) { |
|
50 | + usort($items, function(ITrashItem $a, ITrashItem $b) { |
|
51 | 51 | return $a->getDeletedTime() - $b->getDeletedTime(); |
52 | 52 | }); |
53 | 53 | return $items; |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | */ |
77 | 77 | public function getBackendForStorage(IStorage $storage): ITrashBackend { |
78 | 78 | $fullType = get_class($storage); |
79 | - $foundType = array_reduce(array_keys($this->backends), function ($type, $registeredType) use ($storage) { |
|
79 | + $foundType = array_reduce(array_keys($this->backends), function($type, $registeredType) use ($storage) { |
|
80 | 80 | if ( |
81 | 81 | $storage->instanceOfStorage($registeredType) && |
82 | 82 | ($type === '' || is_subclass_of($registeredType, $type)) |
@@ -27,102 +27,102 @@ |
||
27 | 27 | use OCP\IUser; |
28 | 28 | |
29 | 29 | class TrashManager implements ITrashManager { |
30 | - /** @var ITrashBackend[] */ |
|
31 | - private $backends = []; |
|
32 | - |
|
33 | - private $trashPaused = false; |
|
34 | - |
|
35 | - public function registerBackend(string $storageType, ITrashBackend $backend) { |
|
36 | - $this->backends[$storageType] = $backend; |
|
37 | - } |
|
38 | - |
|
39 | - /** |
|
40 | - * @return ITrashBackend[] |
|
41 | - */ |
|
42 | - private function getBackends(): array { |
|
43 | - return $this->backends; |
|
44 | - } |
|
45 | - |
|
46 | - public function listTrashRoot(IUser $user): array { |
|
47 | - $items = array_reduce($this->getBackends(), function (array $items, ITrashBackend $backend) use ($user) { |
|
48 | - return array_merge($items, $backend->listTrashRoot($user)); |
|
49 | - }, []); |
|
50 | - usort($items, function (ITrashItem $a, ITrashItem $b) { |
|
51 | - return $a->getDeletedTime() - $b->getDeletedTime(); |
|
52 | - }); |
|
53 | - return $items; |
|
54 | - } |
|
55 | - |
|
56 | - private function getBackendForItem(ITrashItem $item) { |
|
57 | - return $item->getTrashBackend(); |
|
58 | - } |
|
59 | - |
|
60 | - public function listTrashFolder(ITrashItem $folder): array { |
|
61 | - return $this->getBackendForItem($folder)->listTrashFolder($folder); |
|
62 | - } |
|
63 | - |
|
64 | - public function restoreItem(ITrashItem $item) { |
|
65 | - return $this->getBackendForItem($item)->restoreItem($item); |
|
66 | - } |
|
67 | - |
|
68 | - public function removeItem(ITrashItem $item) { |
|
69 | - $this->getBackendForItem($item)->removeItem($item); |
|
70 | - } |
|
71 | - |
|
72 | - /** |
|
73 | - * @param IStorage $storage |
|
74 | - * @return ITrashBackend |
|
75 | - * @throws BackendNotFoundException |
|
76 | - */ |
|
77 | - public function getBackendForStorage(IStorage $storage): ITrashBackend { |
|
78 | - $fullType = get_class($storage); |
|
79 | - $foundType = array_reduce(array_keys($this->backends), function ($type, $registeredType) use ($storage) { |
|
80 | - if ( |
|
81 | - $storage->instanceOfStorage($registeredType) && |
|
82 | - ($type === '' || is_subclass_of($registeredType, $type)) |
|
83 | - ) { |
|
84 | - return $registeredType; |
|
85 | - } else { |
|
86 | - return $type; |
|
87 | - } |
|
88 | - }, ''); |
|
89 | - if ($foundType === '') { |
|
90 | - throw new BackendNotFoundException("Trash backend for $fullType not found"); |
|
91 | - } else { |
|
92 | - return $this->backends[$foundType]; |
|
93 | - } |
|
94 | - } |
|
95 | - |
|
96 | - public function moveToTrash(IStorage $storage, string $internalPath): bool { |
|
97 | - if ($this->trashPaused) { |
|
98 | - return false; |
|
99 | - } |
|
100 | - try { |
|
101 | - $backend = $this->getBackendForStorage($storage); |
|
102 | - $this->trashPaused = true; |
|
103 | - $result = $backend->moveToTrash($storage, $internalPath); |
|
104 | - $this->trashPaused = false; |
|
105 | - return $result; |
|
106 | - } catch (BackendNotFoundException $e) { |
|
107 | - return false; |
|
108 | - } |
|
109 | - } |
|
110 | - |
|
111 | - public function getTrashNodeById(IUser $user, int $fileId) { |
|
112 | - foreach ($this->backends as $backend) { |
|
113 | - $item = $backend->getTrashNodeById($user, $fileId); |
|
114 | - if ($item !== null) { |
|
115 | - return $item; |
|
116 | - } |
|
117 | - } |
|
118 | - return null; |
|
119 | - } |
|
120 | - |
|
121 | - public function pauseTrash() { |
|
122 | - $this->trashPaused = true; |
|
123 | - } |
|
124 | - |
|
125 | - public function resumeTrash() { |
|
126 | - $this->trashPaused = false; |
|
127 | - } |
|
30 | + /** @var ITrashBackend[] */ |
|
31 | + private $backends = []; |
|
32 | + |
|
33 | + private $trashPaused = false; |
|
34 | + |
|
35 | + public function registerBackend(string $storageType, ITrashBackend $backend) { |
|
36 | + $this->backends[$storageType] = $backend; |
|
37 | + } |
|
38 | + |
|
39 | + /** |
|
40 | + * @return ITrashBackend[] |
|
41 | + */ |
|
42 | + private function getBackends(): array { |
|
43 | + return $this->backends; |
|
44 | + } |
|
45 | + |
|
46 | + public function listTrashRoot(IUser $user): array { |
|
47 | + $items = array_reduce($this->getBackends(), function (array $items, ITrashBackend $backend) use ($user) { |
|
48 | + return array_merge($items, $backend->listTrashRoot($user)); |
|
49 | + }, []); |
|
50 | + usort($items, function (ITrashItem $a, ITrashItem $b) { |
|
51 | + return $a->getDeletedTime() - $b->getDeletedTime(); |
|
52 | + }); |
|
53 | + return $items; |
|
54 | + } |
|
55 | + |
|
56 | + private function getBackendForItem(ITrashItem $item) { |
|
57 | + return $item->getTrashBackend(); |
|
58 | + } |
|
59 | + |
|
60 | + public function listTrashFolder(ITrashItem $folder): array { |
|
61 | + return $this->getBackendForItem($folder)->listTrashFolder($folder); |
|
62 | + } |
|
63 | + |
|
64 | + public function restoreItem(ITrashItem $item) { |
|
65 | + return $this->getBackendForItem($item)->restoreItem($item); |
|
66 | + } |
|
67 | + |
|
68 | + public function removeItem(ITrashItem $item) { |
|
69 | + $this->getBackendForItem($item)->removeItem($item); |
|
70 | + } |
|
71 | + |
|
72 | + /** |
|
73 | + * @param IStorage $storage |
|
74 | + * @return ITrashBackend |
|
75 | + * @throws BackendNotFoundException |
|
76 | + */ |
|
77 | + public function getBackendForStorage(IStorage $storage): ITrashBackend { |
|
78 | + $fullType = get_class($storage); |
|
79 | + $foundType = array_reduce(array_keys($this->backends), function ($type, $registeredType) use ($storage) { |
|
80 | + if ( |
|
81 | + $storage->instanceOfStorage($registeredType) && |
|
82 | + ($type === '' || is_subclass_of($registeredType, $type)) |
|
83 | + ) { |
|
84 | + return $registeredType; |
|
85 | + } else { |
|
86 | + return $type; |
|
87 | + } |
|
88 | + }, ''); |
|
89 | + if ($foundType === '') { |
|
90 | + throw new BackendNotFoundException("Trash backend for $fullType not found"); |
|
91 | + } else { |
|
92 | + return $this->backends[$foundType]; |
|
93 | + } |
|
94 | + } |
|
95 | + |
|
96 | + public function moveToTrash(IStorage $storage, string $internalPath): bool { |
|
97 | + if ($this->trashPaused) { |
|
98 | + return false; |
|
99 | + } |
|
100 | + try { |
|
101 | + $backend = $this->getBackendForStorage($storage); |
|
102 | + $this->trashPaused = true; |
|
103 | + $result = $backend->moveToTrash($storage, $internalPath); |
|
104 | + $this->trashPaused = false; |
|
105 | + return $result; |
|
106 | + } catch (BackendNotFoundException $e) { |
|
107 | + return false; |
|
108 | + } |
|
109 | + } |
|
110 | + |
|
111 | + public function getTrashNodeById(IUser $user, int $fileId) { |
|
112 | + foreach ($this->backends as $backend) { |
|
113 | + $item = $backend->getTrashNodeById($user, $fileId); |
|
114 | + if ($item !== null) { |
|
115 | + return $item; |
|
116 | + } |
|
117 | + } |
|
118 | + return null; |
|
119 | + } |
|
120 | + |
|
121 | + public function pauseTrash() { |
|
122 | + $this->trashPaused = true; |
|
123 | + } |
|
124 | + |
|
125 | + public function resumeTrash() { |
|
126 | + $this->trashPaused = false; |
|
127 | + } |
|
128 | 128 | } |
@@ -31,69 +31,69 @@ |
||
31 | 31 | use Sabre\DAV\ICollection; |
32 | 32 | |
33 | 33 | class TrashHome implements ICollection { |
34 | - /** @var ITrashManager */ |
|
35 | - private $trashManager; |
|
36 | - |
|
37 | - /** @var array */ |
|
38 | - private $principalInfo; |
|
39 | - |
|
40 | - /** @var IUser */ |
|
41 | - private $user; |
|
42 | - |
|
43 | - public function __construct( |
|
44 | - array $principalInfo, |
|
45 | - ITrashManager $trashManager, |
|
46 | - IUser $user |
|
47 | - ) { |
|
48 | - $this->principalInfo = $principalInfo; |
|
49 | - $this->trashManager = $trashManager; |
|
50 | - $this->user = $user; |
|
51 | - } |
|
52 | - |
|
53 | - public function delete() { |
|
54 | - throw new Forbidden(); |
|
55 | - } |
|
56 | - |
|
57 | - public function getName(): string { |
|
58 | - list(, $name) = \Sabre\Uri\split($this->principalInfo['uri']); |
|
59 | - return $name; |
|
60 | - } |
|
61 | - |
|
62 | - public function setName($name) { |
|
63 | - throw new Forbidden('Permission denied to rename this trashbin'); |
|
64 | - } |
|
65 | - |
|
66 | - public function createFile($name, $data = null) { |
|
67 | - throw new Forbidden('Not allowed to create files in the trashbin'); |
|
68 | - } |
|
69 | - |
|
70 | - public function createDirectory($name) { |
|
71 | - throw new Forbidden('Not allowed to create folders in the trashbin'); |
|
72 | - } |
|
73 | - |
|
74 | - public function getChild($name) { |
|
75 | - if ($name === 'restore') { |
|
76 | - return new RestoreFolder(); |
|
77 | - } |
|
78 | - if ($name === 'trash') { |
|
79 | - return new TrashRoot($this->user, $this->trashManager); |
|
80 | - } |
|
81 | - |
|
82 | - throw new NotFound(); |
|
83 | - } |
|
84 | - |
|
85 | - public function getChildren(): array { |
|
86 | - return [ |
|
87 | - new RestoreFolder(), |
|
88 | - new TrashRoot($this->user, $this->trashManager) |
|
89 | - ]; |
|
90 | - } |
|
91 | - |
|
92 | - public function childExists($name): bool { |
|
93 | - return $name === 'restore' || $name === 'trash'; |
|
94 | - } |
|
95 | - |
|
96 | - public function getLastModified(): int { |
|
97 | - return 0; |
|
98 | - } |
|
34 | + /** @var ITrashManager */ |
|
35 | + private $trashManager; |
|
36 | + |
|
37 | + /** @var array */ |
|
38 | + private $principalInfo; |
|
39 | + |
|
40 | + /** @var IUser */ |
|
41 | + private $user; |
|
42 | + |
|
43 | + public function __construct( |
|
44 | + array $principalInfo, |
|
45 | + ITrashManager $trashManager, |
|
46 | + IUser $user |
|
47 | + ) { |
|
48 | + $this->principalInfo = $principalInfo; |
|
49 | + $this->trashManager = $trashManager; |
|
50 | + $this->user = $user; |
|
51 | + } |
|
52 | + |
|
53 | + public function delete() { |
|
54 | + throw new Forbidden(); |
|
55 | + } |
|
56 | + |
|
57 | + public function getName(): string { |
|
58 | + list(, $name) = \Sabre\Uri\split($this->principalInfo['uri']); |
|
59 | + return $name; |
|
60 | + } |
|
61 | + |
|
62 | + public function setName($name) { |
|
63 | + throw new Forbidden('Permission denied to rename this trashbin'); |
|
64 | + } |
|
65 | + |
|
66 | + public function createFile($name, $data = null) { |
|
67 | + throw new Forbidden('Not allowed to create files in the trashbin'); |
|
68 | + } |
|
69 | + |
|
70 | + public function createDirectory($name) { |
|
71 | + throw new Forbidden('Not allowed to create folders in the trashbin'); |
|
72 | + } |
|
73 | + |
|
74 | + public function getChild($name) { |
|
75 | + if ($name === 'restore') { |
|
76 | + return new RestoreFolder(); |
|
77 | + } |
|
78 | + if ($name === 'trash') { |
|
79 | + return new TrashRoot($this->user, $this->trashManager); |
|
80 | + } |
|
81 | + |
|
82 | + throw new NotFound(); |
|
83 | + } |
|
84 | + |
|
85 | + public function getChildren(): array { |
|
86 | + return [ |
|
87 | + new RestoreFolder(), |
|
88 | + new TrashRoot($this->user, $this->trashManager) |
|
89 | + ]; |
|
90 | + } |
|
91 | + |
|
92 | + public function childExists($name): bool { |
|
93 | + return $name === 'restore' || $name === 'trash'; |
|
94 | + } |
|
95 | + |
|
96 | + public function getLastModified(): int { |
|
97 | + return 0; |
|
98 | + } |
|
99 | 99 | } |
@@ -26,6 +26,6 @@ |
||
26 | 26 | |
27 | 27 | class TrashFolder extends AbstractTrashFolder { |
28 | 28 | public function getName(): string { |
29 | - return $this->data->getName() . '.d' . $this->getLastModified(); |
|
29 | + return $this->data->getName().'.d'.$this->getLastModified(); |
|
30 | 30 | } |
31 | 31 | } |
@@ -28,7 +28,7 @@ |
||
28 | 28 | namespace OCA\Files_Trashbin\Sabre; |
29 | 29 | |
30 | 30 | class TrashFolder extends AbstractTrashFolder { |
31 | - public function getName(): string { |
|
32 | - return $this->data->getName() . '.d' . $this->getLastModified(); |
|
33 | - } |
|
31 | + public function getName(): string { |
|
32 | + return $this->data->getName() . '.d' . $this->getLastModified(); |
|
33 | + } |
|
34 | 34 | } |
@@ -33,72 +33,72 @@ |
||
33 | 33 | |
34 | 34 | class TrashRoot implements ICollection { |
35 | 35 | |
36 | - /** @var IUser */ |
|
37 | - private $user; |
|
38 | - |
|
39 | - /** @var ITrashManager */ |
|
40 | - private $trashManager; |
|
41 | - |
|
42 | - public function __construct(IUser $user, ITrashManager $trashManager) { |
|
43 | - $this->user = $user; |
|
44 | - $this->trashManager = $trashManager; |
|
45 | - } |
|
46 | - |
|
47 | - public function delete() { |
|
48 | - \OCA\Files_Trashbin\Trashbin::deleteAll(); |
|
49 | - } |
|
50 | - |
|
51 | - public function getName(): string { |
|
52 | - return 'trash'; |
|
53 | - } |
|
54 | - |
|
55 | - public function setName($name) { |
|
56 | - throw new Forbidden('Permission denied to rename this trashbin'); |
|
57 | - } |
|
58 | - |
|
59 | - public function createFile($name, $data = null) { |
|
60 | - throw new Forbidden('Not allowed to create files in the trashbin'); |
|
61 | - } |
|
62 | - |
|
63 | - public function createDirectory($name) { |
|
64 | - throw new Forbidden('Not allowed to create folders in the trashbin'); |
|
65 | - } |
|
66 | - |
|
67 | - public function getChildren(): array { |
|
68 | - $entries = $this->trashManager->listTrashRoot($this->user); |
|
69 | - |
|
70 | - $children = array_map(function (ITrashItem $entry) { |
|
71 | - if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
72 | - return new TrashFolder($this->trashManager, $entry); |
|
73 | - } |
|
74 | - return new TrashFile($this->trashManager, $entry); |
|
75 | - }, $entries); |
|
76 | - |
|
77 | - return $children; |
|
78 | - } |
|
79 | - |
|
80 | - public function getChild($name): ITrash { |
|
81 | - $entries = $this->getChildren(); |
|
82 | - |
|
83 | - foreach ($entries as $entry) { |
|
84 | - if ($entry->getName() === $name) { |
|
85 | - return $entry; |
|
86 | - } |
|
87 | - } |
|
88 | - |
|
89 | - throw new NotFound(); |
|
90 | - } |
|
91 | - |
|
92 | - public function childExists($name): bool { |
|
93 | - try { |
|
94 | - $this->getChild($name); |
|
95 | - return true; |
|
96 | - } catch (NotFound $e) { |
|
97 | - return false; |
|
98 | - } |
|
99 | - } |
|
100 | - |
|
101 | - public function getLastModified(): int { |
|
102 | - return 0; |
|
103 | - } |
|
36 | + /** @var IUser */ |
|
37 | + private $user; |
|
38 | + |
|
39 | + /** @var ITrashManager */ |
|
40 | + private $trashManager; |
|
41 | + |
|
42 | + public function __construct(IUser $user, ITrashManager $trashManager) { |
|
43 | + $this->user = $user; |
|
44 | + $this->trashManager = $trashManager; |
|
45 | + } |
|
46 | + |
|
47 | + public function delete() { |
|
48 | + \OCA\Files_Trashbin\Trashbin::deleteAll(); |
|
49 | + } |
|
50 | + |
|
51 | + public function getName(): string { |
|
52 | + return 'trash'; |
|
53 | + } |
|
54 | + |
|
55 | + public function setName($name) { |
|
56 | + throw new Forbidden('Permission denied to rename this trashbin'); |
|
57 | + } |
|
58 | + |
|
59 | + public function createFile($name, $data = null) { |
|
60 | + throw new Forbidden('Not allowed to create files in the trashbin'); |
|
61 | + } |
|
62 | + |
|
63 | + public function createDirectory($name) { |
|
64 | + throw new Forbidden('Not allowed to create folders in the trashbin'); |
|
65 | + } |
|
66 | + |
|
67 | + public function getChildren(): array { |
|
68 | + $entries = $this->trashManager->listTrashRoot($this->user); |
|
69 | + |
|
70 | + $children = array_map(function (ITrashItem $entry) { |
|
71 | + if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
72 | + return new TrashFolder($this->trashManager, $entry); |
|
73 | + } |
|
74 | + return new TrashFile($this->trashManager, $entry); |
|
75 | + }, $entries); |
|
76 | + |
|
77 | + return $children; |
|
78 | + } |
|
79 | + |
|
80 | + public function getChild($name): ITrash { |
|
81 | + $entries = $this->getChildren(); |
|
82 | + |
|
83 | + foreach ($entries as $entry) { |
|
84 | + if ($entry->getName() === $name) { |
|
85 | + return $entry; |
|
86 | + } |
|
87 | + } |
|
88 | + |
|
89 | + throw new NotFound(); |
|
90 | + } |
|
91 | + |
|
92 | + public function childExists($name): bool { |
|
93 | + try { |
|
94 | + $this->getChild($name); |
|
95 | + return true; |
|
96 | + } catch (NotFound $e) { |
|
97 | + return false; |
|
98 | + } |
|
99 | + } |
|
100 | + |
|
101 | + public function getLastModified(): int { |
|
102 | + return 0; |
|
103 | + } |
|
104 | 104 | } |
@@ -67,7 +67,7 @@ |
||
67 | 67 | public function getChildren(): array { |
68 | 68 | $entries = $this->trashManager->listTrashRoot($this->user); |
69 | 69 | |
70 | - $children = array_map(function (ITrashItem $entry) { |
|
70 | + $children = array_map(function(ITrashItem $entry) { |
|
71 | 71 | if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
72 | 72 | return new TrashFolder($this->trashManager, $entry); |
73 | 73 | } |
@@ -29,49 +29,49 @@ |
||
29 | 29 | use Sabre\DAV\ICollection; |
30 | 30 | |
31 | 31 | abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash { |
32 | - public function getChildren(): array { |
|
33 | - $entries = $this->trashManager->listTrashFolder($this->data); |
|
32 | + public function getChildren(): array { |
|
33 | + $entries = $this->trashManager->listTrashFolder($this->data); |
|
34 | 34 | |
35 | - $children = array_map(function (ITrashItem $entry) { |
|
36 | - if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
37 | - return new TrashFolderFolder($this->trashManager, $entry); |
|
38 | - } |
|
39 | - return new TrashFolderFile($this->trashManager, $entry); |
|
40 | - }, $entries); |
|
35 | + $children = array_map(function (ITrashItem $entry) { |
|
36 | + if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
|
37 | + return new TrashFolderFolder($this->trashManager, $entry); |
|
38 | + } |
|
39 | + return new TrashFolderFile($this->trashManager, $entry); |
|
40 | + }, $entries); |
|
41 | 41 | |
42 | - return $children; |
|
43 | - } |
|
42 | + return $children; |
|
43 | + } |
|
44 | 44 | |
45 | - public function getChild($name): ITrash { |
|
46 | - $entries = $this->getChildren(); |
|
45 | + public function getChild($name): ITrash { |
|
46 | + $entries = $this->getChildren(); |
|
47 | 47 | |
48 | - foreach ($entries as $entry) { |
|
49 | - if ($entry->getName() === $name) { |
|
50 | - return $entry; |
|
51 | - } |
|
52 | - } |
|
48 | + foreach ($entries as $entry) { |
|
49 | + if ($entry->getName() === $name) { |
|
50 | + return $entry; |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - throw new NotFound(); |
|
55 | - } |
|
54 | + throw new NotFound(); |
|
55 | + } |
|
56 | 56 | |
57 | - public function childExists($name): bool { |
|
58 | - try { |
|
59 | - $this->getChild($name); |
|
60 | - return true; |
|
61 | - } catch (NotFound $e) { |
|
62 | - return false; |
|
63 | - } |
|
64 | - } |
|
57 | + public function childExists($name): bool { |
|
58 | + try { |
|
59 | + $this->getChild($name); |
|
60 | + return true; |
|
61 | + } catch (NotFound $e) { |
|
62 | + return false; |
|
63 | + } |
|
64 | + } |
|
65 | 65 | |
66 | - public function setName($name) { |
|
67 | - throw new Forbidden(); |
|
68 | - } |
|
66 | + public function setName($name) { |
|
67 | + throw new Forbidden(); |
|
68 | + } |
|
69 | 69 | |
70 | - public function createFile($name, $data = null) { |
|
71 | - throw new Forbidden(); |
|
72 | - } |
|
70 | + public function createFile($name, $data = null) { |
|
71 | + throw new Forbidden(); |
|
72 | + } |
|
73 | 73 | |
74 | - public function createDirectory($name) { |
|
75 | - throw new Forbidden(); |
|
76 | - } |
|
74 | + public function createDirectory($name) { |
|
75 | + throw new Forbidden(); |
|
76 | + } |
|
77 | 77 | } |
@@ -32,7 +32,7 @@ |
||
32 | 32 | public function getChildren(): array { |
33 | 33 | $entries = $this->trashManager->listTrashFolder($this->data); |
34 | 34 | |
35 | - $children = array_map(function (ITrashItem $entry) { |
|
35 | + $children = array_map(function(ITrashItem $entry) { |
|
36 | 36 | if ($entry->getType() === FileInfo::TYPE_FOLDER) { |
37 | 37 | return new TrashFolderFolder($this->trashManager, $entry); |
38 | 38 | } |