@@ -41,129 +41,129 @@ |
||
41 | 41 | * @since 18.0.0 |
42 | 42 | */ |
43 | 43 | class GenericEvent extends Event implements ArrayAccess, IteratorAggregate { |
44 | - protected $subject; |
|
45 | - protected $arguments; |
|
46 | - |
|
47 | - /** |
|
48 | - * Encapsulate an event with $subject and $args. |
|
49 | - * |
|
50 | - * @since 18.0.0 |
|
51 | - */ |
|
52 | - public function __construct($subject = null, array $arguments = []) { |
|
53 | - $this->subject = $subject; |
|
54 | - $this->arguments = $arguments; |
|
55 | - } |
|
56 | - |
|
57 | - /** |
|
58 | - * Getter for subject property. |
|
59 | - * |
|
60 | - * @since 18.0.0 |
|
61 | - */ |
|
62 | - public function getSubject() { |
|
63 | - return $this->subject; |
|
64 | - } |
|
65 | - |
|
66 | - /** |
|
67 | - * Get argument by key. |
|
68 | - * |
|
69 | - * @throws InvalidArgumentException if key is not found |
|
70 | - * @since 18.0.0 |
|
71 | - */ |
|
72 | - public function getArgument(string $key) { |
|
73 | - if ($this->hasArgument($key)) { |
|
74 | - return $this->arguments[$key]; |
|
75 | - } |
|
76 | - |
|
77 | - throw new InvalidArgumentException(sprintf('Argument "%s" not found.', $key)); |
|
78 | - } |
|
79 | - |
|
80 | - /** |
|
81 | - * Add argument to event. |
|
82 | - * |
|
83 | - * @since 18.0.0 |
|
84 | - */ |
|
85 | - public function setArgument($key, $value): GenericEvent { |
|
86 | - $this->arguments[$key] = $value; |
|
87 | - return $this; |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * Getter for all arguments. |
|
92 | - * |
|
93 | - * @since 18.0.0 |
|
94 | - */ |
|
95 | - public function getArguments(): array { |
|
96 | - return $this->arguments; |
|
97 | - } |
|
98 | - |
|
99 | - /** |
|
100 | - * Set args property. |
|
101 | - * |
|
102 | - * @since 18.0.0 |
|
103 | - */ |
|
104 | - public function setArguments(array $args = []): GenericEvent { |
|
105 | - $this->arguments = $args; |
|
106 | - return $this; |
|
107 | - } |
|
108 | - |
|
109 | - /** |
|
110 | - * Has argument. |
|
111 | - * |
|
112 | - * @since 18.0.0 |
|
113 | - */ |
|
114 | - public function hasArgument($key): bool { |
|
115 | - return array_key_exists($key, $this->arguments); |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * Retrieve an external iterator |
|
120 | - * |
|
121 | - * @link https://php.net/manual/en/iteratoraggregate.getiterator.php |
|
122 | - * @since 18.0.0 |
|
123 | - */ |
|
124 | - public function getIterator(): Traversable { |
|
125 | - return new ArrayIterator($this->arguments); |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * Whether a offset exists |
|
130 | - * |
|
131 | - * @link https://php.net/manual/en/arrayaccess.offsetexists.php |
|
132 | - * @since 18.0.0 |
|
133 | - */ |
|
134 | - public function offsetExists($offset): bool { |
|
135 | - return $this->hasArgument($offset); |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * Offset to retrieve |
|
140 | - * |
|
141 | - * @link https://php.net/manual/en/arrayaccess.offsetget.php |
|
142 | - * @since 18.0.0 |
|
143 | - */ |
|
144 | - public function offsetGet($offset) { |
|
145 | - return $this->arguments[$offset]; |
|
146 | - } |
|
147 | - |
|
148 | - /** |
|
149 | - * Offset to set |
|
150 | - * |
|
151 | - * @link https://php.net/manual/en/arrayaccess.offsetset.php |
|
152 | - * @since 18.0.0 |
|
153 | - */ |
|
154 | - public function offsetSet($offset, $value): void { |
|
155 | - $this->setArgument($offset, $value); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * Offset to unset |
|
160 | - * |
|
161 | - * @link https://php.net/manual/en/arrayaccess.offsetunset.php |
|
162 | - * @since 18.0.0 |
|
163 | - */ |
|
164 | - public function offsetUnset($offset): void { |
|
165 | - if ($this->hasArgument($offset)) { |
|
166 | - unset($this->arguments[$offset]); |
|
167 | - } |
|
168 | - } |
|
44 | + protected $subject; |
|
45 | + protected $arguments; |
|
46 | + |
|
47 | + /** |
|
48 | + * Encapsulate an event with $subject and $args. |
|
49 | + * |
|
50 | + * @since 18.0.0 |
|
51 | + */ |
|
52 | + public function __construct($subject = null, array $arguments = []) { |
|
53 | + $this->subject = $subject; |
|
54 | + $this->arguments = $arguments; |
|
55 | + } |
|
56 | + |
|
57 | + /** |
|
58 | + * Getter for subject property. |
|
59 | + * |
|
60 | + * @since 18.0.0 |
|
61 | + */ |
|
62 | + public function getSubject() { |
|
63 | + return $this->subject; |
|
64 | + } |
|
65 | + |
|
66 | + /** |
|
67 | + * Get argument by key. |
|
68 | + * |
|
69 | + * @throws InvalidArgumentException if key is not found |
|
70 | + * @since 18.0.0 |
|
71 | + */ |
|
72 | + public function getArgument(string $key) { |
|
73 | + if ($this->hasArgument($key)) { |
|
74 | + return $this->arguments[$key]; |
|
75 | + } |
|
76 | + |
|
77 | + throw new InvalidArgumentException(sprintf('Argument "%s" not found.', $key)); |
|
78 | + } |
|
79 | + |
|
80 | + /** |
|
81 | + * Add argument to event. |
|
82 | + * |
|
83 | + * @since 18.0.0 |
|
84 | + */ |
|
85 | + public function setArgument($key, $value): GenericEvent { |
|
86 | + $this->arguments[$key] = $value; |
|
87 | + return $this; |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * Getter for all arguments. |
|
92 | + * |
|
93 | + * @since 18.0.0 |
|
94 | + */ |
|
95 | + public function getArguments(): array { |
|
96 | + return $this->arguments; |
|
97 | + } |
|
98 | + |
|
99 | + /** |
|
100 | + * Set args property. |
|
101 | + * |
|
102 | + * @since 18.0.0 |
|
103 | + */ |
|
104 | + public function setArguments(array $args = []): GenericEvent { |
|
105 | + $this->arguments = $args; |
|
106 | + return $this; |
|
107 | + } |
|
108 | + |
|
109 | + /** |
|
110 | + * Has argument. |
|
111 | + * |
|
112 | + * @since 18.0.0 |
|
113 | + */ |
|
114 | + public function hasArgument($key): bool { |
|
115 | + return array_key_exists($key, $this->arguments); |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * Retrieve an external iterator |
|
120 | + * |
|
121 | + * @link https://php.net/manual/en/iteratoraggregate.getiterator.php |
|
122 | + * @since 18.0.0 |
|
123 | + */ |
|
124 | + public function getIterator(): Traversable { |
|
125 | + return new ArrayIterator($this->arguments); |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * Whether a offset exists |
|
130 | + * |
|
131 | + * @link https://php.net/manual/en/arrayaccess.offsetexists.php |
|
132 | + * @since 18.0.0 |
|
133 | + */ |
|
134 | + public function offsetExists($offset): bool { |
|
135 | + return $this->hasArgument($offset); |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * Offset to retrieve |
|
140 | + * |
|
141 | + * @link https://php.net/manual/en/arrayaccess.offsetget.php |
|
142 | + * @since 18.0.0 |
|
143 | + */ |
|
144 | + public function offsetGet($offset) { |
|
145 | + return $this->arguments[$offset]; |
|
146 | + } |
|
147 | + |
|
148 | + /** |
|
149 | + * Offset to set |
|
150 | + * |
|
151 | + * @link https://php.net/manual/en/arrayaccess.offsetset.php |
|
152 | + * @since 18.0.0 |
|
153 | + */ |
|
154 | + public function offsetSet($offset, $value): void { |
|
155 | + $this->setArgument($offset, $value); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * Offset to unset |
|
160 | + * |
|
161 | + * @link https://php.net/manual/en/arrayaccess.offsetunset.php |
|
162 | + * @since 18.0.0 |
|
163 | + */ |
|
164 | + public function offsetUnset($offset): void { |
|
165 | + if ($this->hasArgument($offset)) { |
|
166 | + unset($this->arguments[$offset]); |
|
167 | + } |
|
168 | + } |
|
169 | 169 | } |
@@ -30,161 +30,161 @@ |
||
30 | 30 | use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
31 | 31 | |
32 | 32 | class HookConnector { |
33 | - /** |
|
34 | - * @var Root |
|
35 | - */ |
|
36 | - private $root; |
|
37 | - |
|
38 | - /** |
|
39 | - * @var View |
|
40 | - */ |
|
41 | - private $view; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var FileInfo[] |
|
45 | - */ |
|
46 | - private $deleteMetaCache = []; |
|
47 | - /** @var EventDispatcherInterface */ |
|
48 | - private $dispatcher; |
|
49 | - |
|
50 | - /** |
|
51 | - * HookConnector constructor. |
|
52 | - * |
|
53 | - * @param Root $root |
|
54 | - * @param View $view |
|
55 | - */ |
|
56 | - public function __construct(Root $root, View $view, EventDispatcherInterface $dispatcher) { |
|
57 | - $this->root = $root; |
|
58 | - $this->view = $view; |
|
59 | - $this->dispatcher = $dispatcher; |
|
60 | - } |
|
61 | - |
|
62 | - public function viewToNode() { |
|
63 | - Util::connectHook('OC_Filesystem', 'write', $this, 'write'); |
|
64 | - Util::connectHook('OC_Filesystem', 'post_write', $this, 'postWrite'); |
|
65 | - |
|
66 | - Util::connectHook('OC_Filesystem', 'create', $this, 'create'); |
|
67 | - Util::connectHook('OC_Filesystem', 'post_create', $this, 'postCreate'); |
|
68 | - |
|
69 | - Util::connectHook('OC_Filesystem', 'delete', $this, 'delete'); |
|
70 | - Util::connectHook('OC_Filesystem', 'post_delete', $this, 'postDelete'); |
|
71 | - |
|
72 | - Util::connectHook('OC_Filesystem', 'rename', $this, 'rename'); |
|
73 | - Util::connectHook('OC_Filesystem', 'post_rename', $this, 'postRename'); |
|
74 | - |
|
75 | - Util::connectHook('OC_Filesystem', 'copy', $this, 'copy'); |
|
76 | - Util::connectHook('OC_Filesystem', 'post_copy', $this, 'postCopy'); |
|
77 | - |
|
78 | - Util::connectHook('OC_Filesystem', 'touch', $this, 'touch'); |
|
79 | - Util::connectHook('OC_Filesystem', 'post_touch', $this, 'postTouch'); |
|
80 | - |
|
81 | - Util::connectHook('OC_Filesystem', 'read', $this, 'read'); |
|
82 | - } |
|
83 | - |
|
84 | - public function write($arguments) { |
|
85 | - $node = $this->getNodeForPath($arguments['path']); |
|
86 | - $this->root->emit('\OC\Files', 'preWrite', [$node]); |
|
87 | - $this->dispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node)); |
|
88 | - } |
|
89 | - |
|
90 | - public function postWrite($arguments) { |
|
91 | - $node = $this->getNodeForPath($arguments['path']); |
|
92 | - $this->root->emit('\OC\Files', 'postWrite', [$node]); |
|
93 | - $this->dispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node)); |
|
94 | - } |
|
95 | - |
|
96 | - public function create($arguments) { |
|
97 | - $node = $this->getNodeForPath($arguments['path']); |
|
98 | - $this->root->emit('\OC\Files', 'preCreate', [$node]); |
|
99 | - $this->dispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node)); |
|
100 | - } |
|
101 | - |
|
102 | - public function postCreate($arguments) { |
|
103 | - $node = $this->getNodeForPath($arguments['path']); |
|
104 | - $this->root->emit('\OC\Files', 'postCreate', [$node]); |
|
105 | - $this->dispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node)); |
|
106 | - } |
|
107 | - |
|
108 | - public function delete($arguments) { |
|
109 | - $node = $this->getNodeForPath($arguments['path']); |
|
110 | - $this->deleteMetaCache[$node->getPath()] = $node->getFileInfo(); |
|
111 | - $this->root->emit('\OC\Files', 'preDelete', [$node]); |
|
112 | - $this->dispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node)); |
|
113 | - } |
|
114 | - |
|
115 | - public function postDelete($arguments) { |
|
116 | - $node = $this->getNodeForPath($arguments['path']); |
|
117 | - unset($this->deleteMetaCache[$node->getPath()]); |
|
118 | - $this->root->emit('\OC\Files', 'postDelete', [$node]); |
|
119 | - $this->dispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node)); |
|
120 | - } |
|
121 | - |
|
122 | - public function touch($arguments) { |
|
123 | - $node = $this->getNodeForPath($arguments['path']); |
|
124 | - $this->root->emit('\OC\Files', 'preTouch', [$node]); |
|
125 | - $this->dispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node)); |
|
126 | - } |
|
127 | - |
|
128 | - public function postTouch($arguments) { |
|
129 | - $node = $this->getNodeForPath($arguments['path']); |
|
130 | - $this->root->emit('\OC\Files', 'postTouch', [$node]); |
|
131 | - $this->dispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node)); |
|
132 | - } |
|
133 | - |
|
134 | - public function rename($arguments) { |
|
135 | - $source = $this->getNodeForPath($arguments['oldpath']); |
|
136 | - $target = $this->getNodeForPath($arguments['newpath']); |
|
137 | - $this->root->emit('\OC\Files', 'preRename', [$source, $target]); |
|
138 | - $this->dispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target])); |
|
139 | - } |
|
140 | - |
|
141 | - public function postRename($arguments) { |
|
142 | - $source = $this->getNodeForPath($arguments['oldpath']); |
|
143 | - $target = $this->getNodeForPath($arguments['newpath']); |
|
144 | - $this->root->emit('\OC\Files', 'postRename', [$source, $target]); |
|
145 | - $this->dispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target])); |
|
146 | - } |
|
147 | - |
|
148 | - public function copy($arguments) { |
|
149 | - $source = $this->getNodeForPath($arguments['oldpath']); |
|
150 | - $target = $this->getNodeForPath($arguments['newpath']); |
|
151 | - $this->root->emit('\OC\Files', 'preCopy', [$source, $target]); |
|
152 | - $this->dispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target])); |
|
153 | - } |
|
154 | - |
|
155 | - public function postCopy($arguments) { |
|
156 | - $source = $this->getNodeForPath($arguments['oldpath']); |
|
157 | - $target = $this->getNodeForPath($arguments['newpath']); |
|
158 | - $this->root->emit('\OC\Files', 'postCopy', [$source, $target]); |
|
159 | - $this->dispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target])); |
|
160 | - } |
|
161 | - |
|
162 | - public function read($arguments) { |
|
163 | - $node = $this->getNodeForPath($arguments['path']); |
|
164 | - $this->root->emit('\OC\Files', 'read', [$node]); |
|
165 | - $this->dispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node])); |
|
166 | - } |
|
167 | - |
|
168 | - private function getNodeForPath($path) { |
|
169 | - $info = Filesystem::getView()->getFileInfo($path); |
|
170 | - if (!$info) { |
|
171 | - |
|
172 | - $fullPath = Filesystem::getView()->getAbsolutePath($path); |
|
173 | - if (isset($this->deleteMetaCache[$fullPath])) { |
|
174 | - $info = $this->deleteMetaCache[$fullPath]; |
|
175 | - } else { |
|
176 | - $info = null; |
|
177 | - } |
|
178 | - if (Filesystem::is_dir($path)) { |
|
179 | - return new NonExistingFolder($this->root, $this->view, $fullPath, $info); |
|
180 | - } else { |
|
181 | - return new NonExistingFile($this->root, $this->view, $fullPath, $info); |
|
182 | - } |
|
183 | - } |
|
184 | - if ($info->getType() === FileInfo::TYPE_FILE) { |
|
185 | - return new File($this->root, $this->view, $info->getPath(), $info); |
|
186 | - } else { |
|
187 | - return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
188 | - } |
|
189 | - } |
|
33 | + /** |
|
34 | + * @var Root |
|
35 | + */ |
|
36 | + private $root; |
|
37 | + |
|
38 | + /** |
|
39 | + * @var View |
|
40 | + */ |
|
41 | + private $view; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var FileInfo[] |
|
45 | + */ |
|
46 | + private $deleteMetaCache = []; |
|
47 | + /** @var EventDispatcherInterface */ |
|
48 | + private $dispatcher; |
|
49 | + |
|
50 | + /** |
|
51 | + * HookConnector constructor. |
|
52 | + * |
|
53 | + * @param Root $root |
|
54 | + * @param View $view |
|
55 | + */ |
|
56 | + public function __construct(Root $root, View $view, EventDispatcherInterface $dispatcher) { |
|
57 | + $this->root = $root; |
|
58 | + $this->view = $view; |
|
59 | + $this->dispatcher = $dispatcher; |
|
60 | + } |
|
61 | + |
|
62 | + public function viewToNode() { |
|
63 | + Util::connectHook('OC_Filesystem', 'write', $this, 'write'); |
|
64 | + Util::connectHook('OC_Filesystem', 'post_write', $this, 'postWrite'); |
|
65 | + |
|
66 | + Util::connectHook('OC_Filesystem', 'create', $this, 'create'); |
|
67 | + Util::connectHook('OC_Filesystem', 'post_create', $this, 'postCreate'); |
|
68 | + |
|
69 | + Util::connectHook('OC_Filesystem', 'delete', $this, 'delete'); |
|
70 | + Util::connectHook('OC_Filesystem', 'post_delete', $this, 'postDelete'); |
|
71 | + |
|
72 | + Util::connectHook('OC_Filesystem', 'rename', $this, 'rename'); |
|
73 | + Util::connectHook('OC_Filesystem', 'post_rename', $this, 'postRename'); |
|
74 | + |
|
75 | + Util::connectHook('OC_Filesystem', 'copy', $this, 'copy'); |
|
76 | + Util::connectHook('OC_Filesystem', 'post_copy', $this, 'postCopy'); |
|
77 | + |
|
78 | + Util::connectHook('OC_Filesystem', 'touch', $this, 'touch'); |
|
79 | + Util::connectHook('OC_Filesystem', 'post_touch', $this, 'postTouch'); |
|
80 | + |
|
81 | + Util::connectHook('OC_Filesystem', 'read', $this, 'read'); |
|
82 | + } |
|
83 | + |
|
84 | + public function write($arguments) { |
|
85 | + $node = $this->getNodeForPath($arguments['path']); |
|
86 | + $this->root->emit('\OC\Files', 'preWrite', [$node]); |
|
87 | + $this->dispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node)); |
|
88 | + } |
|
89 | + |
|
90 | + public function postWrite($arguments) { |
|
91 | + $node = $this->getNodeForPath($arguments['path']); |
|
92 | + $this->root->emit('\OC\Files', 'postWrite', [$node]); |
|
93 | + $this->dispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node)); |
|
94 | + } |
|
95 | + |
|
96 | + public function create($arguments) { |
|
97 | + $node = $this->getNodeForPath($arguments['path']); |
|
98 | + $this->root->emit('\OC\Files', 'preCreate', [$node]); |
|
99 | + $this->dispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node)); |
|
100 | + } |
|
101 | + |
|
102 | + public function postCreate($arguments) { |
|
103 | + $node = $this->getNodeForPath($arguments['path']); |
|
104 | + $this->root->emit('\OC\Files', 'postCreate', [$node]); |
|
105 | + $this->dispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node)); |
|
106 | + } |
|
107 | + |
|
108 | + public function delete($arguments) { |
|
109 | + $node = $this->getNodeForPath($arguments['path']); |
|
110 | + $this->deleteMetaCache[$node->getPath()] = $node->getFileInfo(); |
|
111 | + $this->root->emit('\OC\Files', 'preDelete', [$node]); |
|
112 | + $this->dispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node)); |
|
113 | + } |
|
114 | + |
|
115 | + public function postDelete($arguments) { |
|
116 | + $node = $this->getNodeForPath($arguments['path']); |
|
117 | + unset($this->deleteMetaCache[$node->getPath()]); |
|
118 | + $this->root->emit('\OC\Files', 'postDelete', [$node]); |
|
119 | + $this->dispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node)); |
|
120 | + } |
|
121 | + |
|
122 | + public function touch($arguments) { |
|
123 | + $node = $this->getNodeForPath($arguments['path']); |
|
124 | + $this->root->emit('\OC\Files', 'preTouch', [$node]); |
|
125 | + $this->dispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node)); |
|
126 | + } |
|
127 | + |
|
128 | + public function postTouch($arguments) { |
|
129 | + $node = $this->getNodeForPath($arguments['path']); |
|
130 | + $this->root->emit('\OC\Files', 'postTouch', [$node]); |
|
131 | + $this->dispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node)); |
|
132 | + } |
|
133 | + |
|
134 | + public function rename($arguments) { |
|
135 | + $source = $this->getNodeForPath($arguments['oldpath']); |
|
136 | + $target = $this->getNodeForPath($arguments['newpath']); |
|
137 | + $this->root->emit('\OC\Files', 'preRename', [$source, $target]); |
|
138 | + $this->dispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target])); |
|
139 | + } |
|
140 | + |
|
141 | + public function postRename($arguments) { |
|
142 | + $source = $this->getNodeForPath($arguments['oldpath']); |
|
143 | + $target = $this->getNodeForPath($arguments['newpath']); |
|
144 | + $this->root->emit('\OC\Files', 'postRename', [$source, $target]); |
|
145 | + $this->dispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target])); |
|
146 | + } |
|
147 | + |
|
148 | + public function copy($arguments) { |
|
149 | + $source = $this->getNodeForPath($arguments['oldpath']); |
|
150 | + $target = $this->getNodeForPath($arguments['newpath']); |
|
151 | + $this->root->emit('\OC\Files', 'preCopy', [$source, $target]); |
|
152 | + $this->dispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target])); |
|
153 | + } |
|
154 | + |
|
155 | + public function postCopy($arguments) { |
|
156 | + $source = $this->getNodeForPath($arguments['oldpath']); |
|
157 | + $target = $this->getNodeForPath($arguments['newpath']); |
|
158 | + $this->root->emit('\OC\Files', 'postCopy', [$source, $target]); |
|
159 | + $this->dispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target])); |
|
160 | + } |
|
161 | + |
|
162 | + public function read($arguments) { |
|
163 | + $node = $this->getNodeForPath($arguments['path']); |
|
164 | + $this->root->emit('\OC\Files', 'read', [$node]); |
|
165 | + $this->dispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node])); |
|
166 | + } |
|
167 | + |
|
168 | + private function getNodeForPath($path) { |
|
169 | + $info = Filesystem::getView()->getFileInfo($path); |
|
170 | + if (!$info) { |
|
171 | + |
|
172 | + $fullPath = Filesystem::getView()->getAbsolutePath($path); |
|
173 | + if (isset($this->deleteMetaCache[$fullPath])) { |
|
174 | + $info = $this->deleteMetaCache[$fullPath]; |
|
175 | + } else { |
|
176 | + $info = null; |
|
177 | + } |
|
178 | + if (Filesystem::is_dir($path)) { |
|
179 | + return new NonExistingFolder($this->root, $this->view, $fullPath, $info); |
|
180 | + } else { |
|
181 | + return new NonExistingFile($this->root, $this->view, $fullPath, $info); |
|
182 | + } |
|
183 | + } |
|
184 | + if ($info->getType() === FileInfo::TYPE_FILE) { |
|
185 | + return new File($this->root, $this->view, $info->getPath(), $info); |
|
186 | + } else { |
|
187 | + return new Folder($this->root, $this->view, $info->getPath(), $info); |
|
188 | + } |
|
189 | + } |
|
190 | 190 | } |