Passed
Push — master ( 873501...d2df81 )
by Maxence
14:59 queued 12s
created
lib/private/Files/Node/HookConnector.php 1 patch
Indentation   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -47,202 +47,202 @@
 block discarded – undo
47 47
 use Symfony\Component\EventDispatcher\EventDispatcherInterface;
48 48
 
49 49
 class HookConnector {
50
-	/** @var IRootFolder */
51
-	private $root;
52
-
53
-	/** @var View */
54
-	private $view;
55
-
56
-	/** @var FileInfo[] */
57
-	private $deleteMetaCache = [];
58
-
59
-	/** @var EventDispatcherInterface */
60
-	private $legacyDispatcher;
61
-
62
-	/** @var IEventDispatcher */
63
-	private $dispatcher;
64
-
65
-	/**
66
-	 * HookConnector constructor.
67
-	 *
68
-	 * @param Root $root
69
-	 * @param View $view
70
-	 */
71
-	public function __construct(
72
-		IRootFolder $root,
73
-		View $view,
74
-		EventDispatcherInterface $legacyDispatcher,
75
-		IEventDispatcher $dispatcher) {
76
-		$this->root = $root;
77
-		$this->view = $view;
78
-		$this->legacyDispatcher = $legacyDispatcher;
79
-		$this->dispatcher = $dispatcher;
80
-	}
81
-
82
-	public function viewToNode() {
83
-		Util::connectHook('OC_Filesystem', 'write', $this, 'write');
84
-		Util::connectHook('OC_Filesystem', 'post_write', $this, 'postWrite');
85
-
86
-		Util::connectHook('OC_Filesystem', 'create', $this, 'create');
87
-		Util::connectHook('OC_Filesystem', 'post_create', $this, 'postCreate');
88
-
89
-		Util::connectHook('OC_Filesystem', 'delete', $this, 'delete');
90
-		Util::connectHook('OC_Filesystem', 'post_delete', $this, 'postDelete');
91
-
92
-		Util::connectHook('OC_Filesystem', 'rename', $this, 'rename');
93
-		Util::connectHook('OC_Filesystem', 'post_rename', $this, 'postRename');
94
-
95
-		Util::connectHook('OC_Filesystem', 'copy', $this, 'copy');
96
-		Util::connectHook('OC_Filesystem', 'post_copy', $this, 'postCopy');
97
-
98
-		Util::connectHook('OC_Filesystem', 'touch', $this, 'touch');
99
-		Util::connectHook('OC_Filesystem', 'post_touch', $this, 'postTouch');
100
-
101
-		Util::connectHook('OC_Filesystem', 'read', $this, 'read');
102
-	}
103
-
104
-	public function write($arguments) {
105
-		$node = $this->getNodeForPath($arguments['path']);
106
-		$this->root->emit('\OC\Files', 'preWrite', [$node]);
107
-		$this->legacyDispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node));
108
-
109
-		$event = new BeforeNodeWrittenEvent($node);
110
-		$this->dispatcher->dispatchTyped($event);
111
-	}
112
-
113
-	public function postWrite($arguments) {
114
-		$node = $this->getNodeForPath($arguments['path']);
115
-		$this->root->emit('\OC\Files', 'postWrite', [$node]);
116
-		$this->legacyDispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node));
117
-
118
-		$event = new NodeWrittenEvent($node);
119
-		$this->dispatcher->dispatchTyped($event);
120
-	}
121
-
122
-	public function create($arguments) {
123
-		$node = $this->getNodeForPath($arguments['path']);
124
-		$this->root->emit('\OC\Files', 'preCreate', [$node]);
125
-		$this->legacyDispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node));
126
-
127
-		$event = new BeforeNodeCreatedEvent($node);
128
-		$this->dispatcher->dispatchTyped($event);
129
-	}
130
-
131
-	public function postCreate($arguments) {
132
-		$node = $this->getNodeForPath($arguments['path']);
133
-		$this->root->emit('\OC\Files', 'postCreate', [$node]);
134
-		$this->legacyDispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node));
135
-
136
-		$event = new NodeCreatedEvent($node);
137
-		$this->dispatcher->dispatchTyped($event);
138
-	}
139
-
140
-	public function delete($arguments) {
141
-		$node = $this->getNodeForPath($arguments['path']);
142
-		$this->deleteMetaCache[$node->getPath()] = $node->getFileInfo();
143
-		$this->root->emit('\OC\Files', 'preDelete', [$node]);
144
-		$this->legacyDispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node));
145
-
146
-		$event = new BeforeNodeDeletedEvent($node);
147
-		$this->dispatcher->dispatchTyped($event);
148
-	}
149
-
150
-	public function postDelete($arguments) {
151
-		$node = $this->getNodeForPath($arguments['path']);
152
-		unset($this->deleteMetaCache[$node->getPath()]);
153
-		$this->root->emit('\OC\Files', 'postDelete', [$node]);
154
-		$this->legacyDispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node));
155
-
156
-		$event = new NodeDeletedEvent($node);
157
-		$this->dispatcher->dispatchTyped($event);
158
-	}
159
-
160
-	public function touch($arguments) {
161
-		$node = $this->getNodeForPath($arguments['path']);
162
-		$this->root->emit('\OC\Files', 'preTouch', [$node]);
163
-		$this->legacyDispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node));
164
-
165
-		$event = new BeforeNodeTouchedEvent($node);
166
-		$this->dispatcher->dispatchTyped($event);
167
-	}
168
-
169
-	public function postTouch($arguments) {
170
-		$node = $this->getNodeForPath($arguments['path']);
171
-		$this->root->emit('\OC\Files', 'postTouch', [$node]);
172
-		$this->legacyDispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node));
173
-
174
-		$event = new NodeTouchedEvent($node);
175
-		$this->dispatcher->dispatchTyped($event);
176
-	}
177
-
178
-	public function rename($arguments) {
179
-		$source = $this->getNodeForPath($arguments['oldpath']);
180
-		$target = $this->getNodeForPath($arguments['newpath']);
181
-		$this->root->emit('\OC\Files', 'preRename', [$source, $target]);
182
-		$this->legacyDispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target]));
183
-
184
-		$event = new BeforeNodeRenamedEvent($source, $target);
185
-		$this->dispatcher->dispatchTyped($event);
186
-	}
187
-
188
-	public function postRename($arguments) {
189
-		$source = $this->getNodeForPath($arguments['oldpath']);
190
-		$target = $this->getNodeForPath($arguments['newpath']);
191
-		$this->root->emit('\OC\Files', 'postRename', [$source, $target]);
192
-		$this->legacyDispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target]));
193
-
194
-		$event = new NodeRenamedEvent($source, $target);
195
-		$this->dispatcher->dispatchTyped($event);
196
-	}
197
-
198
-	public function copy($arguments) {
199
-		$source = $this->getNodeForPath($arguments['oldpath']);
200
-		$target = $this->getNodeForPath($arguments['newpath']);
201
-		$this->root->emit('\OC\Files', 'preCopy', [$source, $target]);
202
-		$this->legacyDispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target]));
203
-
204
-		$event = new BeforeNodeCopiedEvent($source, $target);
205
-		$this->dispatcher->dispatchTyped($event);
206
-	}
207
-
208
-	public function postCopy($arguments) {
209
-		$source = $this->getNodeForPath($arguments['oldpath']);
210
-		$target = $this->getNodeForPath($arguments['newpath']);
211
-		$this->root->emit('\OC\Files', 'postCopy', [$source, $target]);
212
-		$this->legacyDispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target]));
213
-
214
-		$event = new NodeCopiedEvent($source, $target);
215
-		$this->dispatcher->dispatchTyped($event);
216
-	}
217
-
218
-	public function read($arguments) {
219
-		$node = $this->getNodeForPath($arguments['path']);
220
-		$this->root->emit('\OC\Files', 'read', [$node]);
221
-		$this->legacyDispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node]));
222
-
223
-		$event = new BeforeNodeReadEvent($node);
224
-		$this->dispatcher->dispatchTyped($event);
225
-	}
226
-
227
-	private function getNodeForPath($path) {
228
-		$info = Filesystem::getView()->getFileInfo($path);
229
-		if (!$info) {
230
-			$fullPath = Filesystem::getView()->getAbsolutePath($path);
231
-			if (isset($this->deleteMetaCache[$fullPath])) {
232
-				$info = $this->deleteMetaCache[$fullPath];
233
-			} else {
234
-				$info = null;
235
-			}
236
-			if (Filesystem::is_dir($path)) {
237
-				return new NonExistingFolder($this->root, $this->view, $fullPath, $info);
238
-			} else {
239
-				return new NonExistingFile($this->root, $this->view, $fullPath, $info);
240
-			}
241
-		}
242
-		if ($info->getType() === FileInfo::TYPE_FILE) {
243
-			return new File($this->root, $this->view, $info->getPath(), $info);
244
-		} else {
245
-			return new Folder($this->root, $this->view, $info->getPath(), $info);
246
-		}
247
-	}
50
+    /** @var IRootFolder */
51
+    private $root;
52
+
53
+    /** @var View */
54
+    private $view;
55
+
56
+    /** @var FileInfo[] */
57
+    private $deleteMetaCache = [];
58
+
59
+    /** @var EventDispatcherInterface */
60
+    private $legacyDispatcher;
61
+
62
+    /** @var IEventDispatcher */
63
+    private $dispatcher;
64
+
65
+    /**
66
+     * HookConnector constructor.
67
+     *
68
+     * @param Root $root
69
+     * @param View $view
70
+     */
71
+    public function __construct(
72
+        IRootFolder $root,
73
+        View $view,
74
+        EventDispatcherInterface $legacyDispatcher,
75
+        IEventDispatcher $dispatcher) {
76
+        $this->root = $root;
77
+        $this->view = $view;
78
+        $this->legacyDispatcher = $legacyDispatcher;
79
+        $this->dispatcher = $dispatcher;
80
+    }
81
+
82
+    public function viewToNode() {
83
+        Util::connectHook('OC_Filesystem', 'write', $this, 'write');
84
+        Util::connectHook('OC_Filesystem', 'post_write', $this, 'postWrite');
85
+
86
+        Util::connectHook('OC_Filesystem', 'create', $this, 'create');
87
+        Util::connectHook('OC_Filesystem', 'post_create', $this, 'postCreate');
88
+
89
+        Util::connectHook('OC_Filesystem', 'delete', $this, 'delete');
90
+        Util::connectHook('OC_Filesystem', 'post_delete', $this, 'postDelete');
91
+
92
+        Util::connectHook('OC_Filesystem', 'rename', $this, 'rename');
93
+        Util::connectHook('OC_Filesystem', 'post_rename', $this, 'postRename');
94
+
95
+        Util::connectHook('OC_Filesystem', 'copy', $this, 'copy');
96
+        Util::connectHook('OC_Filesystem', 'post_copy', $this, 'postCopy');
97
+
98
+        Util::connectHook('OC_Filesystem', 'touch', $this, 'touch');
99
+        Util::connectHook('OC_Filesystem', 'post_touch', $this, 'postTouch');
100
+
101
+        Util::connectHook('OC_Filesystem', 'read', $this, 'read');
102
+    }
103
+
104
+    public function write($arguments) {
105
+        $node = $this->getNodeForPath($arguments['path']);
106
+        $this->root->emit('\OC\Files', 'preWrite', [$node]);
107
+        $this->legacyDispatcher->dispatch('\OCP\Files::preWrite', new GenericEvent($node));
108
+
109
+        $event = new BeforeNodeWrittenEvent($node);
110
+        $this->dispatcher->dispatchTyped($event);
111
+    }
112
+
113
+    public function postWrite($arguments) {
114
+        $node = $this->getNodeForPath($arguments['path']);
115
+        $this->root->emit('\OC\Files', 'postWrite', [$node]);
116
+        $this->legacyDispatcher->dispatch('\OCP\Files::postWrite', new GenericEvent($node));
117
+
118
+        $event = new NodeWrittenEvent($node);
119
+        $this->dispatcher->dispatchTyped($event);
120
+    }
121
+
122
+    public function create($arguments) {
123
+        $node = $this->getNodeForPath($arguments['path']);
124
+        $this->root->emit('\OC\Files', 'preCreate', [$node]);
125
+        $this->legacyDispatcher->dispatch('\OCP\Files::preCreate', new GenericEvent($node));
126
+
127
+        $event = new BeforeNodeCreatedEvent($node);
128
+        $this->dispatcher->dispatchTyped($event);
129
+    }
130
+
131
+    public function postCreate($arguments) {
132
+        $node = $this->getNodeForPath($arguments['path']);
133
+        $this->root->emit('\OC\Files', 'postCreate', [$node]);
134
+        $this->legacyDispatcher->dispatch('\OCP\Files::postCreate', new GenericEvent($node));
135
+
136
+        $event = new NodeCreatedEvent($node);
137
+        $this->dispatcher->dispatchTyped($event);
138
+    }
139
+
140
+    public function delete($arguments) {
141
+        $node = $this->getNodeForPath($arguments['path']);
142
+        $this->deleteMetaCache[$node->getPath()] = $node->getFileInfo();
143
+        $this->root->emit('\OC\Files', 'preDelete', [$node]);
144
+        $this->legacyDispatcher->dispatch('\OCP\Files::preDelete', new GenericEvent($node));
145
+
146
+        $event = new BeforeNodeDeletedEvent($node);
147
+        $this->dispatcher->dispatchTyped($event);
148
+    }
149
+
150
+    public function postDelete($arguments) {
151
+        $node = $this->getNodeForPath($arguments['path']);
152
+        unset($this->deleteMetaCache[$node->getPath()]);
153
+        $this->root->emit('\OC\Files', 'postDelete', [$node]);
154
+        $this->legacyDispatcher->dispatch('\OCP\Files::postDelete', new GenericEvent($node));
155
+
156
+        $event = new NodeDeletedEvent($node);
157
+        $this->dispatcher->dispatchTyped($event);
158
+    }
159
+
160
+    public function touch($arguments) {
161
+        $node = $this->getNodeForPath($arguments['path']);
162
+        $this->root->emit('\OC\Files', 'preTouch', [$node]);
163
+        $this->legacyDispatcher->dispatch('\OCP\Files::preTouch', new GenericEvent($node));
164
+
165
+        $event = new BeforeNodeTouchedEvent($node);
166
+        $this->dispatcher->dispatchTyped($event);
167
+    }
168
+
169
+    public function postTouch($arguments) {
170
+        $node = $this->getNodeForPath($arguments['path']);
171
+        $this->root->emit('\OC\Files', 'postTouch', [$node]);
172
+        $this->legacyDispatcher->dispatch('\OCP\Files::postTouch', new GenericEvent($node));
173
+
174
+        $event = new NodeTouchedEvent($node);
175
+        $this->dispatcher->dispatchTyped($event);
176
+    }
177
+
178
+    public function rename($arguments) {
179
+        $source = $this->getNodeForPath($arguments['oldpath']);
180
+        $target = $this->getNodeForPath($arguments['newpath']);
181
+        $this->root->emit('\OC\Files', 'preRename', [$source, $target]);
182
+        $this->legacyDispatcher->dispatch('\OCP\Files::preRename', new GenericEvent([$source, $target]));
183
+
184
+        $event = new BeforeNodeRenamedEvent($source, $target);
185
+        $this->dispatcher->dispatchTyped($event);
186
+    }
187
+
188
+    public function postRename($arguments) {
189
+        $source = $this->getNodeForPath($arguments['oldpath']);
190
+        $target = $this->getNodeForPath($arguments['newpath']);
191
+        $this->root->emit('\OC\Files', 'postRename', [$source, $target]);
192
+        $this->legacyDispatcher->dispatch('\OCP\Files::postRename', new GenericEvent([$source, $target]));
193
+
194
+        $event = new NodeRenamedEvent($source, $target);
195
+        $this->dispatcher->dispatchTyped($event);
196
+    }
197
+
198
+    public function copy($arguments) {
199
+        $source = $this->getNodeForPath($arguments['oldpath']);
200
+        $target = $this->getNodeForPath($arguments['newpath']);
201
+        $this->root->emit('\OC\Files', 'preCopy', [$source, $target]);
202
+        $this->legacyDispatcher->dispatch('\OCP\Files::preCopy', new GenericEvent([$source, $target]));
203
+
204
+        $event = new BeforeNodeCopiedEvent($source, $target);
205
+        $this->dispatcher->dispatchTyped($event);
206
+    }
207
+
208
+    public function postCopy($arguments) {
209
+        $source = $this->getNodeForPath($arguments['oldpath']);
210
+        $target = $this->getNodeForPath($arguments['newpath']);
211
+        $this->root->emit('\OC\Files', 'postCopy', [$source, $target]);
212
+        $this->legacyDispatcher->dispatch('\OCP\Files::postCopy', new GenericEvent([$source, $target]));
213
+
214
+        $event = new NodeCopiedEvent($source, $target);
215
+        $this->dispatcher->dispatchTyped($event);
216
+    }
217
+
218
+    public function read($arguments) {
219
+        $node = $this->getNodeForPath($arguments['path']);
220
+        $this->root->emit('\OC\Files', 'read', [$node]);
221
+        $this->legacyDispatcher->dispatch('\OCP\Files::read', new GenericEvent([$node]));
222
+
223
+        $event = new BeforeNodeReadEvent($node);
224
+        $this->dispatcher->dispatchTyped($event);
225
+    }
226
+
227
+    private function getNodeForPath($path) {
228
+        $info = Filesystem::getView()->getFileInfo($path);
229
+        if (!$info) {
230
+            $fullPath = Filesystem::getView()->getAbsolutePath($path);
231
+            if (isset($this->deleteMetaCache[$fullPath])) {
232
+                $info = $this->deleteMetaCache[$fullPath];
233
+            } else {
234
+                $info = null;
235
+            }
236
+            if (Filesystem::is_dir($path)) {
237
+                return new NonExistingFolder($this->root, $this->view, $fullPath, $info);
238
+            } else {
239
+                return new NonExistingFile($this->root, $this->view, $fullPath, $info);
240
+            }
241
+        }
242
+        if ($info->getType() === FileInfo::TYPE_FILE) {
243
+            return new File($this->root, $this->view, $info->getPath(), $info);
244
+        } else {
245
+            return new Folder($this->root, $this->view, $info->getPath(), $info);
246
+        }
247
+    }
248 248
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Storage/SFTPWriteStream.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		if (isset($context[$name])) {
71 71
 			$context = $context[$name];
72 72
 		} else {
73
-			throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
73
+			throw new \BadMethodCallException('Invalid context, "'.$name.'" options not set');
74 74
 		}
75 75
 		if (isset($context['session']) and $context['session'] instanceof \phpseclib\Net\SFTP) {
76 76
 			$this->sftp = $context['session'];
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
 	public function stream_open($path, $mode, $options, &$opened_path) {
84 84
 		[, $path] = explode('://', $path);
85
-		$path = '/' . ltrim($path);
85
+		$path = '/'.ltrim($path);
86 86
 		$path = str_replace('//', '/', $path);
87 87
 
88 88
 		$this->loadContext('sftp');
Please login to merge, or discard this patch.
Indentation   +151 added lines, -151 removed lines patch added patch discarded remove patch
@@ -30,155 +30,155 @@
 block discarded – undo
30 30
 use phpseclib\Net\SSH2;
31 31
 
32 32
 class SFTPWriteStream implements File {
33
-	/** @var resource */
34
-	public $context;
35
-
36
-	/** @var \phpseclib\Net\SFTP */
37
-	private $sftp;
38
-
39
-	/** @var string */
40
-	private $handle;
41
-
42
-	/** @var int */
43
-	private $internalPosition = 0;
44
-
45
-	/** @var int */
46
-	private $writePosition = 0;
47
-
48
-	/** @var bool */
49
-	private $eof = false;
50
-
51
-	private $buffer = '';
52
-
53
-	public static function register($protocol = 'sftpwrite') {
54
-		if (in_array($protocol, stream_get_wrappers(), true)) {
55
-			return false;
56
-		}
57
-		return stream_wrapper_register($protocol, get_called_class());
58
-	}
59
-
60
-	/**
61
-	 * Load the source from the stream context and return the context options
62
-	 *
63
-	 * @param string $name
64
-	 * @throws \BadMethodCallException
65
-	 */
66
-	protected function loadContext($name) {
67
-		$context = stream_context_get_options($this->context);
68
-		if (isset($context[$name])) {
69
-			$context = $context[$name];
70
-		} else {
71
-			throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
72
-		}
73
-		if (isset($context['session']) and $context['session'] instanceof \phpseclib\Net\SFTP) {
74
-			$this->sftp = $context['session'];
75
-		} else {
76
-			throw new \BadMethodCallException('Invalid context, session not set');
77
-		}
78
-		return $context;
79
-	}
80
-
81
-	public function stream_open($path, $mode, $options, &$opened_path) {
82
-		[, $path] = explode('://', $path);
83
-		$path = '/' . ltrim($path);
84
-		$path = str_replace('//', '/', $path);
85
-
86
-		$this->loadContext('sftp');
87
-
88
-		if (!($this->sftp->bitmap & SSH2::MASK_LOGIN)) {
89
-			return false;
90
-		}
91
-
92
-		$remote_file = $this->sftp->_realpath($path);
93
-		if ($remote_file === false) {
94
-			return false;
95
-		}
96
-
97
-		$packet = pack('Na*N2', strlen($remote_file), $remote_file, NET_SFTP_OPEN_WRITE | NET_SFTP_OPEN_CREATE | NET_SFTP_OPEN_TRUNCATE, 0);
98
-		if (!$this->sftp->_send_sftp_packet(NET_SFTP_OPEN, $packet)) {
99
-			return false;
100
-		}
101
-
102
-		$response = $this->sftp->_get_sftp_packet();
103
-		switch ($this->sftp->packet_type) {
104
-			case NET_SFTP_HANDLE:
105
-				$this->handle = substr($response, 4);
106
-				break;
107
-			case NET_SFTP_STATUS: // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
108
-				$this->sftp->_logError($response);
109
-				return false;
110
-			default:
111
-				user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
112
-				return false;
113
-		}
114
-
115
-		return true;
116
-	}
117
-
118
-	public function stream_seek($offset, $whence = SEEK_SET) {
119
-		return false;
120
-	}
121
-
122
-	public function stream_tell() {
123
-		return $this->writePosition;
124
-	}
125
-
126
-	public function stream_read($count) {
127
-		return false;
128
-	}
129
-
130
-	public function stream_write($data) {
131
-		$written = strlen($data);
132
-		$this->writePosition += $written;
133
-
134
-		$this->buffer .= $data;
135
-
136
-		if (strlen($this->buffer) > 64 * 1024) {
137
-			if (!$this->stream_flush()) {
138
-				return false;
139
-			}
140
-		}
141
-
142
-		return $written;
143
-	}
144
-
145
-	public function stream_set_option($option, $arg1, $arg2) {
146
-		return false;
147
-	}
148
-
149
-	public function stream_truncate($size) {
150
-		return false;
151
-	}
152
-
153
-	public function stream_stat() {
154
-		return false;
155
-	}
156
-
157
-	public function stream_lock($operation) {
158
-		return false;
159
-	}
160
-
161
-	public function stream_flush() {
162
-		$size = strlen($this->buffer);
163
-		$packet = pack('Na*N3a*', strlen($this->handle), $this->handle, $this->internalPosition / 4294967296, $this->internalPosition, $size, $this->buffer);
164
-		if (!$this->sftp->_send_sftp_packet(NET_SFTP_WRITE, $packet)) {
165
-			return false;
166
-		}
167
-		$this->internalPosition += $size;
168
-		$this->buffer = '';
169
-
170
-		return $this->sftp->_read_put_responses(1);
171
-	}
172
-
173
-	public function stream_eof() {
174
-		return $this->eof;
175
-	}
176
-
177
-	public function stream_close() {
178
-		$this->stream_flush();
179
-		if (!$this->sftp->_close_handle($this->handle)) {
180
-			return false;
181
-		}
182
-		return true;
183
-	}
33
+    /** @var resource */
34
+    public $context;
35
+
36
+    /** @var \phpseclib\Net\SFTP */
37
+    private $sftp;
38
+
39
+    /** @var string */
40
+    private $handle;
41
+
42
+    /** @var int */
43
+    private $internalPosition = 0;
44
+
45
+    /** @var int */
46
+    private $writePosition = 0;
47
+
48
+    /** @var bool */
49
+    private $eof = false;
50
+
51
+    private $buffer = '';
52
+
53
+    public static function register($protocol = 'sftpwrite') {
54
+        if (in_array($protocol, stream_get_wrappers(), true)) {
55
+            return false;
56
+        }
57
+        return stream_wrapper_register($protocol, get_called_class());
58
+    }
59
+
60
+    /**
61
+     * Load the source from the stream context and return the context options
62
+     *
63
+     * @param string $name
64
+     * @throws \BadMethodCallException
65
+     */
66
+    protected function loadContext($name) {
67
+        $context = stream_context_get_options($this->context);
68
+        if (isset($context[$name])) {
69
+            $context = $context[$name];
70
+        } else {
71
+            throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
72
+        }
73
+        if (isset($context['session']) and $context['session'] instanceof \phpseclib\Net\SFTP) {
74
+            $this->sftp = $context['session'];
75
+        } else {
76
+            throw new \BadMethodCallException('Invalid context, session not set');
77
+        }
78
+        return $context;
79
+    }
80
+
81
+    public function stream_open($path, $mode, $options, &$opened_path) {
82
+        [, $path] = explode('://', $path);
83
+        $path = '/' . ltrim($path);
84
+        $path = str_replace('//', '/', $path);
85
+
86
+        $this->loadContext('sftp');
87
+
88
+        if (!($this->sftp->bitmap & SSH2::MASK_LOGIN)) {
89
+            return false;
90
+        }
91
+
92
+        $remote_file = $this->sftp->_realpath($path);
93
+        if ($remote_file === false) {
94
+            return false;
95
+        }
96
+
97
+        $packet = pack('Na*N2', strlen($remote_file), $remote_file, NET_SFTP_OPEN_WRITE | NET_SFTP_OPEN_CREATE | NET_SFTP_OPEN_TRUNCATE, 0);
98
+        if (!$this->sftp->_send_sftp_packet(NET_SFTP_OPEN, $packet)) {
99
+            return false;
100
+        }
101
+
102
+        $response = $this->sftp->_get_sftp_packet();
103
+        switch ($this->sftp->packet_type) {
104
+            case NET_SFTP_HANDLE:
105
+                $this->handle = substr($response, 4);
106
+                break;
107
+            case NET_SFTP_STATUS: // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
108
+                $this->sftp->_logError($response);
109
+                return false;
110
+            default:
111
+                user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
112
+                return false;
113
+        }
114
+
115
+        return true;
116
+    }
117
+
118
+    public function stream_seek($offset, $whence = SEEK_SET) {
119
+        return false;
120
+    }
121
+
122
+    public function stream_tell() {
123
+        return $this->writePosition;
124
+    }
125
+
126
+    public function stream_read($count) {
127
+        return false;
128
+    }
129
+
130
+    public function stream_write($data) {
131
+        $written = strlen($data);
132
+        $this->writePosition += $written;
133
+
134
+        $this->buffer .= $data;
135
+
136
+        if (strlen($this->buffer) > 64 * 1024) {
137
+            if (!$this->stream_flush()) {
138
+                return false;
139
+            }
140
+        }
141
+
142
+        return $written;
143
+    }
144
+
145
+    public function stream_set_option($option, $arg1, $arg2) {
146
+        return false;
147
+    }
148
+
149
+    public function stream_truncate($size) {
150
+        return false;
151
+    }
152
+
153
+    public function stream_stat() {
154
+        return false;
155
+    }
156
+
157
+    public function stream_lock($operation) {
158
+        return false;
159
+    }
160
+
161
+    public function stream_flush() {
162
+        $size = strlen($this->buffer);
163
+        $packet = pack('Na*N3a*', strlen($this->handle), $this->handle, $this->internalPosition / 4294967296, $this->internalPosition, $size, $this->buffer);
164
+        if (!$this->sftp->_send_sftp_packet(NET_SFTP_WRITE, $packet)) {
165
+            return false;
166
+        }
167
+        $this->internalPosition += $size;
168
+        $this->buffer = '';
169
+
170
+        return $this->sftp->_read_put_responses(1);
171
+    }
172
+
173
+    public function stream_eof() {
174
+        return $this->eof;
175
+    }
176
+
177
+    public function stream_close() {
178
+        $this->stream_flush();
179
+        if (!$this->sftp->_close_handle($this->handle)) {
180
+            return false;
181
+        }
182
+        return true;
183
+    }
184 184
 }
Please login to merge, or discard this patch.
apps/files_external/lib/Lib/Storage/SFTPReadStream.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -70,7 +70,7 @@  discard block
 block discarded – undo
70 70
 		if (isset($context[$name])) {
71 71
 			$context = $context[$name];
72 72
 		} else {
73
-			throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
73
+			throw new \BadMethodCallException('Invalid context, "'.$name.'" options not set');
74 74
 		}
75 75
 		if (isset($context['session']) and $context['session'] instanceof \phpseclib\Net\SFTP) {
76 76
 			$this->sftp = $context['session'];
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 
83 83
 	public function stream_open($path, $mode, $options, &$opened_path) {
84 84
 		[, $path] = explode('://', $path);
85
-		$path = '/' . ltrim($path);
85
+		$path = '/'.ltrim($path);
86 86
 		$path = str_replace('//', '/', $path);
87 87
 
88 88
 		$this->loadContext('sftp');
Please login to merge, or discard this patch.
Indentation   +170 added lines, -170 removed lines patch added patch discarded remove patch
@@ -30,174 +30,174 @@
 block discarded – undo
30 30
 use phpseclib\Net\SSH2;
31 31
 
32 32
 class SFTPReadStream implements File {
33
-	/** @var resource */
34
-	public $context;
35
-
36
-	/** @var \phpseclib\Net\SFTP */
37
-	private $sftp;
38
-
39
-	/** @var string */
40
-	private $handle;
41
-
42
-	/** @var int */
43
-	private $internalPosition = 0;
44
-
45
-	/** @var int */
46
-	private $readPosition = 0;
47
-
48
-	/** @var bool */
49
-	private $eof = false;
50
-
51
-	private $buffer = '';
52
-
53
-	public static function register($protocol = 'sftpread') {
54
-		if (in_array($protocol, stream_get_wrappers(), true)) {
55
-			return false;
56
-		}
57
-		return stream_wrapper_register($protocol, get_called_class());
58
-	}
59
-
60
-	/**
61
-	 * Load the source from the stream context and return the context options
62
-	 *
63
-	 * @param string $name
64
-	 * @throws \BadMethodCallException
65
-	 */
66
-	protected function loadContext($name) {
67
-		$context = stream_context_get_options($this->context);
68
-		if (isset($context[$name])) {
69
-			$context = $context[$name];
70
-		} else {
71
-			throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
72
-		}
73
-		if (isset($context['session']) and $context['session'] instanceof \phpseclib\Net\SFTP) {
74
-			$this->sftp = $context['session'];
75
-		} else {
76
-			throw new \BadMethodCallException('Invalid context, session not set');
77
-		}
78
-		return $context;
79
-	}
80
-
81
-	public function stream_open($path, $mode, $options, &$opened_path) {
82
-		[, $path] = explode('://', $path);
83
-		$path = '/' . ltrim($path);
84
-		$path = str_replace('//', '/', $path);
85
-
86
-		$this->loadContext('sftp');
87
-
88
-		if (!($this->sftp->bitmap & SSH2::MASK_LOGIN)) {
89
-			return false;
90
-		}
91
-
92
-		$remote_file = $this->sftp->_realpath($path);
93
-		if ($remote_file === false) {
94
-			return false;
95
-		}
96
-
97
-		$packet = pack('Na*N2', strlen($remote_file), $remote_file, NET_SFTP_OPEN_READ, 0);
98
-		if (!$this->sftp->_send_sftp_packet(NET_SFTP_OPEN, $packet)) {
99
-			return false;
100
-		}
101
-
102
-		$response = $this->sftp->_get_sftp_packet();
103
-		switch ($this->sftp->packet_type) {
104
-			case NET_SFTP_HANDLE:
105
-				$this->handle = substr($response, 4);
106
-				break;
107
-			case NET_SFTP_STATUS: // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
108
-				$this->sftp->_logError($response);
109
-				return false;
110
-			default:
111
-				user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
112
-				return false;
113
-		}
114
-
115
-		$this->request_chunk(256 * 1024);
116
-
117
-		return true;
118
-	}
119
-
120
-	public function stream_seek($offset, $whence = SEEK_SET) {
121
-		return false;
122
-	}
123
-
124
-	public function stream_tell() {
125
-		return $this->readPosition;
126
-	}
127
-
128
-	public function stream_read($count) {
129
-		if (!$this->eof && strlen($this->buffer) < $count) {
130
-			$chunk = $this->read_chunk();
131
-			$this->buffer .= $chunk;
132
-			if (!$this->eof) {
133
-				$this->request_chunk(256 * 1024);
134
-			}
135
-		}
136
-
137
-		$data = substr($this->buffer, 0, $count);
138
-		$this->buffer = substr($this->buffer, $count);
139
-		$this->readPosition += strlen($data);
140
-
141
-		return $data;
142
-	}
143
-
144
-	private function request_chunk($size) {
145
-		$packet = pack('Na*N3', strlen($this->handle), $this->handle, $this->internalPosition / 4294967296, $this->internalPosition, $size);
146
-		return $this->sftp->_send_sftp_packet(NET_SFTP_READ, $packet);
147
-	}
148
-
149
-	private function read_chunk() {
150
-		$response = $this->sftp->_get_sftp_packet();
151
-
152
-		switch ($this->sftp->packet_type) {
153
-			case NET_SFTP_DATA:
154
-				$temp = substr($response, 4);
155
-				$len = strlen($temp);
156
-				$this->internalPosition += $len;
157
-				return $temp;
158
-			case NET_SFTP_STATUS:
159
-				[1 => $status] = unpack('N', substr($response, 0, 4));
160
-				if ($status == NET_SFTP_STATUS_EOF) {
161
-					$this->eof = true;
162
-				}
163
-				return '';
164
-			default:
165
-				return '';
166
-		}
167
-	}
168
-
169
-	public function stream_write($data) {
170
-		return false;
171
-	}
172
-
173
-	public function stream_set_option($option, $arg1, $arg2) {
174
-		return false;
175
-	}
176
-
177
-	public function stream_truncate($size) {
178
-		return false;
179
-	}
180
-
181
-	public function stream_stat() {
182
-		return false;
183
-	}
184
-
185
-	public function stream_lock($operation) {
186
-		return false;
187
-	}
188
-
189
-	public function stream_flush() {
190
-		return false;
191
-	}
192
-
193
-	public function stream_eof() {
194
-		return $this->eof;
195
-	}
196
-
197
-	public function stream_close() {
198
-		if (!$this->sftp->_close_handle($this->handle)) {
199
-			return false;
200
-		}
201
-		return true;
202
-	}
33
+    /** @var resource */
34
+    public $context;
35
+
36
+    /** @var \phpseclib\Net\SFTP */
37
+    private $sftp;
38
+
39
+    /** @var string */
40
+    private $handle;
41
+
42
+    /** @var int */
43
+    private $internalPosition = 0;
44
+
45
+    /** @var int */
46
+    private $readPosition = 0;
47
+
48
+    /** @var bool */
49
+    private $eof = false;
50
+
51
+    private $buffer = '';
52
+
53
+    public static function register($protocol = 'sftpread') {
54
+        if (in_array($protocol, stream_get_wrappers(), true)) {
55
+            return false;
56
+        }
57
+        return stream_wrapper_register($protocol, get_called_class());
58
+    }
59
+
60
+    /**
61
+     * Load the source from the stream context and return the context options
62
+     *
63
+     * @param string $name
64
+     * @throws \BadMethodCallException
65
+     */
66
+    protected function loadContext($name) {
67
+        $context = stream_context_get_options($this->context);
68
+        if (isset($context[$name])) {
69
+            $context = $context[$name];
70
+        } else {
71
+            throw new \BadMethodCallException('Invalid context, "' . $name . '" options not set');
72
+        }
73
+        if (isset($context['session']) and $context['session'] instanceof \phpseclib\Net\SFTP) {
74
+            $this->sftp = $context['session'];
75
+        } else {
76
+            throw new \BadMethodCallException('Invalid context, session not set');
77
+        }
78
+        return $context;
79
+    }
80
+
81
+    public function stream_open($path, $mode, $options, &$opened_path) {
82
+        [, $path] = explode('://', $path);
83
+        $path = '/' . ltrim($path);
84
+        $path = str_replace('//', '/', $path);
85
+
86
+        $this->loadContext('sftp');
87
+
88
+        if (!($this->sftp->bitmap & SSH2::MASK_LOGIN)) {
89
+            return false;
90
+        }
91
+
92
+        $remote_file = $this->sftp->_realpath($path);
93
+        if ($remote_file === false) {
94
+            return false;
95
+        }
96
+
97
+        $packet = pack('Na*N2', strlen($remote_file), $remote_file, NET_SFTP_OPEN_READ, 0);
98
+        if (!$this->sftp->_send_sftp_packet(NET_SFTP_OPEN, $packet)) {
99
+            return false;
100
+        }
101
+
102
+        $response = $this->sftp->_get_sftp_packet();
103
+        switch ($this->sftp->packet_type) {
104
+            case NET_SFTP_HANDLE:
105
+                $this->handle = substr($response, 4);
106
+                break;
107
+            case NET_SFTP_STATUS: // presumably SSH_FX_NO_SUCH_FILE or SSH_FX_PERMISSION_DENIED
108
+                $this->sftp->_logError($response);
109
+                return false;
110
+            default:
111
+                user_error('Expected SSH_FXP_HANDLE or SSH_FXP_STATUS');
112
+                return false;
113
+        }
114
+
115
+        $this->request_chunk(256 * 1024);
116
+
117
+        return true;
118
+    }
119
+
120
+    public function stream_seek($offset, $whence = SEEK_SET) {
121
+        return false;
122
+    }
123
+
124
+    public function stream_tell() {
125
+        return $this->readPosition;
126
+    }
127
+
128
+    public function stream_read($count) {
129
+        if (!$this->eof && strlen($this->buffer) < $count) {
130
+            $chunk = $this->read_chunk();
131
+            $this->buffer .= $chunk;
132
+            if (!$this->eof) {
133
+                $this->request_chunk(256 * 1024);
134
+            }
135
+        }
136
+
137
+        $data = substr($this->buffer, 0, $count);
138
+        $this->buffer = substr($this->buffer, $count);
139
+        $this->readPosition += strlen($data);
140
+
141
+        return $data;
142
+    }
143
+
144
+    private function request_chunk($size) {
145
+        $packet = pack('Na*N3', strlen($this->handle), $this->handle, $this->internalPosition / 4294967296, $this->internalPosition, $size);
146
+        return $this->sftp->_send_sftp_packet(NET_SFTP_READ, $packet);
147
+    }
148
+
149
+    private function read_chunk() {
150
+        $response = $this->sftp->_get_sftp_packet();
151
+
152
+        switch ($this->sftp->packet_type) {
153
+            case NET_SFTP_DATA:
154
+                $temp = substr($response, 4);
155
+                $len = strlen($temp);
156
+                $this->internalPosition += $len;
157
+                return $temp;
158
+            case NET_SFTP_STATUS:
159
+                [1 => $status] = unpack('N', substr($response, 0, 4));
160
+                if ($status == NET_SFTP_STATUS_EOF) {
161
+                    $this->eof = true;
162
+                }
163
+                return '';
164
+            default:
165
+                return '';
166
+        }
167
+    }
168
+
169
+    public function stream_write($data) {
170
+        return false;
171
+    }
172
+
173
+    public function stream_set_option($option, $arg1, $arg2) {
174
+        return false;
175
+    }
176
+
177
+    public function stream_truncate($size) {
178
+        return false;
179
+    }
180
+
181
+    public function stream_stat() {
182
+        return false;
183
+    }
184
+
185
+    public function stream_lock($operation) {
186
+        return false;
187
+    }
188
+
189
+    public function stream_flush() {
190
+        return false;
191
+    }
192
+
193
+    public function stream_eof() {
194
+        return $this->eof;
195
+    }
196
+
197
+    public function stream_close() {
198
+        if (!$this->sftp->_close_handle($this->handle)) {
199
+            return false;
200
+        }
201
+        return true;
202
+    }
203 203
 }
Please login to merge, or discard this patch.
apps/dav/lib/Connector/Sabre/PropfindCompressionPlugin.php 1 patch
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -31,44 +31,44 @@
 block discarded – undo
31 31
 
32 32
 class PropfindCompressionPlugin extends ServerPlugin {
33 33
 
34
-	/**
35
-	 * Reference to main server object
36
-	 *
37
-	 * @var Server
38
-	 */
39
-	private $server;
34
+    /**
35
+     * Reference to main server object
36
+     *
37
+     * @var Server
38
+     */
39
+    private $server;
40 40
 
41
-	/**
42
-	 * This initializes the plugin.
43
-	 *
44
-	 * This function is called by \Sabre\DAV\Server, after
45
-	 * addPlugin is called.
46
-	 *
47
-	 * This method should set up the required event subscriptions.
48
-	 *
49
-	 * @param \Sabre\DAV\Server $server
50
-	 * @return void
51
-	 */
52
-	public function initialize(\Sabre\DAV\Server $server) {
53
-		$this->server = $server;
54
-		$this->server->on('afterMethod:PROPFIND', [$this, 'compressResponse'], 100);
55
-	}
41
+    /**
42
+     * This initializes the plugin.
43
+     *
44
+     * This function is called by \Sabre\DAV\Server, after
45
+     * addPlugin is called.
46
+     *
47
+     * This method should set up the required event subscriptions.
48
+     *
49
+     * @param \Sabre\DAV\Server $server
50
+     * @return void
51
+     */
52
+    public function initialize(\Sabre\DAV\Server $server) {
53
+        $this->server = $server;
54
+        $this->server->on('afterMethod:PROPFIND', [$this, 'compressResponse'], 100);
55
+    }
56 56
 
57
-	public function compressResponse(Request $request, Response $response) {
58
-		$header = $request->getHeader('Accept-Encoding');
57
+    public function compressResponse(Request $request, Response $response) {
58
+        $header = $request->getHeader('Accept-Encoding');
59 59
 
60
-		if ($header === null) {
61
-			return $response;
62
-		}
60
+        if ($header === null) {
61
+            return $response;
62
+        }
63 63
 
64
-		if (strpos($header, 'gzip') !== false) {
65
-			$body = $response->getBody();
66
-			if (is_string($body)) {
67
-				$response->setHeader('Content-Encoding', 'gzip');
68
-				$response->setBody(gzencode($body));
69
-			}
70
-		}
64
+        if (strpos($header, 'gzip') !== false) {
65
+            $body = $response->getBody();
66
+            if (is_string($body)) {
67
+                $response->setHeader('Content-Encoding', 'gzip');
68
+                $response->setBody(gzencode($body));
69
+            }
70
+        }
71 71
 
72
-		return $response;
73
-	}
72
+        return $response;
73
+    }
74 74
 }
Please login to merge, or discard this patch.
apps/comments/lib/Listener/CommentsEntityEventListener.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -30,15 +30,15 @@
 block discarded – undo
30 30
 use OCP\EventDispatcher\IEventListener;
31 31
 
32 32
 class CommentsEntityEventListener implements IEventListener {
33
-	public function handle(Event $event): void {
34
-		if (!($event instanceof CommentsEntityEvent)) {
35
-			// Unrelated
36
-			return;
37
-		}
33
+    public function handle(Event $event): void {
34
+        if (!($event instanceof CommentsEntityEvent)) {
35
+            // Unrelated
36
+            return;
37
+        }
38 38
 
39
-		$event->addEntityCollection('files', function ($name) {
40
-			$nodes = \OC::$server->getUserFolder()->getById((int)$name);
41
-			return !empty($nodes);
42
-		});
43
-	}
39
+        $event->addEntityCollection('files', function ($name) {
40
+            $nodes = \OC::$server->getUserFolder()->getById((int)$name);
41
+            return !empty($nodes);
42
+        });
43
+    }
44 44
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@
 block discarded – undo
36 36
 			return;
37 37
 		}
38 38
 
39
-		$event->addEntityCollection('files', function ($name) {
40
-			$nodes = \OC::$server->getUserFolder()->getById((int)$name);
39
+		$event->addEntityCollection('files', function($name) {
40
+			$nodes = \OC::$server->getUserFolder()->getById((int) $name);
41 41
 			return !empty($nodes);
42 42
 		});
43 43
 	}
Please login to merge, or discard this patch.
apps/settings/lib/Controller/WebAuthnController.php 1 patch
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -38,81 +38,81 @@
 block discarded – undo
38 38
 use Webauthn\PublicKeyCredentialCreationOptions;
39 39
 
40 40
 class WebAuthnController extends Controller {
41
-	private const WEBAUTHN_REGISTRATION = 'webauthn_registration';
42
-
43
-	/** @var Manager */
44
-	private $manager;
45
-
46
-	/** @var IUserSession */
47
-	private $userSession;
48
-	/**
49
-	 * @var ISession
50
-	 */
51
-	private $session;
52
-	/**
53
-	 * @var ILogger
54
-	 */
55
-	private $logger;
56
-
57
-	public function __construct(IRequest $request, ILogger $logger, Manager $webAuthnManager, IUserSession $userSession, ISession $session) {
58
-		parent::__construct(Application::APP_ID, $request);
59
-
60
-		$this->manager = $webAuthnManager;
61
-		$this->userSession = $userSession;
62
-		$this->session = $session;
63
-		$this->logger = $logger;
64
-	}
65
-
66
-	/**
67
-	 * @NoAdminRequired
68
-	 * @NoSubAdminRequired
69
-	 * @PasswordConfirmationRequired
70
-	 * @UseSession
71
-	 * @NoCSRFRequired
72
-	 */
73
-	public function startRegistration(): JSONResponse {
74
-		$this->logger->debug('Starting WebAuthn registration');
75
-
76
-		$credentialOptions = $this->manager->startRegistration($this->userSession->getUser(), $this->request->getServerHost());
77
-
78
-		// Set this in the session since we need it on finish
79
-		$this->session->set(self::WEBAUTHN_REGISTRATION, $credentialOptions);
80
-
81
-		return new JSONResponse($credentialOptions);
82
-	}
83
-
84
-	/**
85
-	 * @NoAdminRequired
86
-	 * @NoSubAdminRequired
87
-	 * @PasswordConfirmationRequired
88
-	 * @UseSession
89
-	 */
90
-	public function finishRegistration(string $name, string $data): JSONResponse {
91
-		$this->logger->debug('Finishing WebAuthn registration');
92
-
93
-		if (!$this->session->exists(self::WEBAUTHN_REGISTRATION)) {
94
-			$this->logger->debug('Trying to finish WebAuthn registration without session data');
95
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
96
-		}
97
-
98
-		// Obtain the publicKeyCredentialOptions from when we started the registration
99
-		$publicKeyCredentialCreationOptions = PublicKeyCredentialCreationOptions::createFromArray($this->session->get(self::WEBAUTHN_REGISTRATION));
100
-
101
-		$this->session->remove(self::WEBAUTHN_REGISTRATION);
102
-
103
-		return new JSONResponse($this->manager->finishRegister($publicKeyCredentialCreationOptions, $name, $data));
104
-	}
105
-
106
-	/**
107
-	 * @NoAdminRequired
108
-	 * @NoSubAdminRequired
109
-	 * @PasswordConfirmationRequired
110
-	 */
111
-	public function deleteRegistration(int $id): JSONResponse {
112
-		$this->logger->debug('Finishing WebAuthn registration');
113
-
114
-		$this->manager->deleteRegistration($this->userSession->getUser(), $id);
115
-
116
-		return new JSONResponse([]);
117
-	}
41
+    private const WEBAUTHN_REGISTRATION = 'webauthn_registration';
42
+
43
+    /** @var Manager */
44
+    private $manager;
45
+
46
+    /** @var IUserSession */
47
+    private $userSession;
48
+    /**
49
+     * @var ISession
50
+     */
51
+    private $session;
52
+    /**
53
+     * @var ILogger
54
+     */
55
+    private $logger;
56
+
57
+    public function __construct(IRequest $request, ILogger $logger, Manager $webAuthnManager, IUserSession $userSession, ISession $session) {
58
+        parent::__construct(Application::APP_ID, $request);
59
+
60
+        $this->manager = $webAuthnManager;
61
+        $this->userSession = $userSession;
62
+        $this->session = $session;
63
+        $this->logger = $logger;
64
+    }
65
+
66
+    /**
67
+     * @NoAdminRequired
68
+     * @NoSubAdminRequired
69
+     * @PasswordConfirmationRequired
70
+     * @UseSession
71
+     * @NoCSRFRequired
72
+     */
73
+    public function startRegistration(): JSONResponse {
74
+        $this->logger->debug('Starting WebAuthn registration');
75
+
76
+        $credentialOptions = $this->manager->startRegistration($this->userSession->getUser(), $this->request->getServerHost());
77
+
78
+        // Set this in the session since we need it on finish
79
+        $this->session->set(self::WEBAUTHN_REGISTRATION, $credentialOptions);
80
+
81
+        return new JSONResponse($credentialOptions);
82
+    }
83
+
84
+    /**
85
+     * @NoAdminRequired
86
+     * @NoSubAdminRequired
87
+     * @PasswordConfirmationRequired
88
+     * @UseSession
89
+     */
90
+    public function finishRegistration(string $name, string $data): JSONResponse {
91
+        $this->logger->debug('Finishing WebAuthn registration');
92
+
93
+        if (!$this->session->exists(self::WEBAUTHN_REGISTRATION)) {
94
+            $this->logger->debug('Trying to finish WebAuthn registration without session data');
95
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
96
+        }
97
+
98
+        // Obtain the publicKeyCredentialOptions from when we started the registration
99
+        $publicKeyCredentialCreationOptions = PublicKeyCredentialCreationOptions::createFromArray($this->session->get(self::WEBAUTHN_REGISTRATION));
100
+
101
+        $this->session->remove(self::WEBAUTHN_REGISTRATION);
102
+
103
+        return new JSONResponse($this->manager->finishRegister($publicKeyCredentialCreationOptions, $name, $data));
104
+    }
105
+
106
+    /**
107
+     * @NoAdminRequired
108
+     * @NoSubAdminRequired
109
+     * @PasswordConfirmationRequired
110
+     */
111
+    public function deleteRegistration(int $id): JSONResponse {
112
+        $this->logger->debug('Finishing WebAuthn registration');
113
+
114
+        $this->manager->deleteRegistration($this->userSession->getUser(), $id);
115
+
116
+        return new JSONResponse([]);
117
+    }
118 118
 }
Please login to merge, or discard this patch.
lib/private/Federation/CloudFederationShare.php 1 patch
Indentation   +302 added lines, -302 removed lines patch added patch discarded remove patch
@@ -27,331 +27,331 @@
 block discarded – undo
27 27
 use OCP\Share\IShare;
28 28
 
29 29
 class CloudFederationShare implements ICloudFederationShare {
30
-	private $share = [
31
-		'shareWith' => '',
32
-		'shareType' => '',
33
-		'name' => '',
34
-		'resourceType' => '',
35
-		'description' => '',
36
-		'providerId' => '',
37
-		'owner' => '',
38
-		'ownerDisplayName' => '',
39
-		'sharedBy' => '',
40
-		'sharedByDisplayName' => '',
41
-		'protocol' => []
42
-	];
30
+    private $share = [
31
+        'shareWith' => '',
32
+        'shareType' => '',
33
+        'name' => '',
34
+        'resourceType' => '',
35
+        'description' => '',
36
+        'providerId' => '',
37
+        'owner' => '',
38
+        'ownerDisplayName' => '',
39
+        'sharedBy' => '',
40
+        'sharedByDisplayName' => '',
41
+        'protocol' => []
42
+    ];
43 43
 
44
-	/**
45
-	 * get a CloudFederationShare Object to prepare a share you want to send
46
-	 *
47
-	 * @param string $shareWith
48
-	 * @param string $name resource name (e.g. document.odt)
49
-	 * @param string $description share description (optional)
50
-	 * @param string $providerId resource UID on the provider side
51
-	 * @param string $owner provider specific UID of the user who owns the resource
52
-	 * @param string $ownerDisplayName display name of the user who shared the item
53
-	 * @param string $sharedBy provider specific UID of the user who shared the resource
54
-	 * @param string $sharedByDisplayName display name of the user who shared the resource
55
-	 * @param string $shareType ('group' or 'user' share)
56
-	 * @param string $resourceType ('file', 'calendar',...)
57
-	 * @param string $sharedSecret
58
-	 */
59
-	public function __construct($shareWith = '',
60
-								$name = '',
61
-								$description = '',
62
-								$providerId = '',
63
-								$owner = '',
64
-								$ownerDisplayName = '',
65
-								$sharedBy = '',
66
-								$sharedByDisplayName = '',
67
-								$shareType = '',
68
-								$resourceType = '',
69
-								$sharedSecret = ''
70
-	) {
71
-		$this->setShareWith($shareWith);
72
-		$this->setResourceName($name);
73
-		$this->setDescription($description);
74
-		$this->setProviderId($providerId);
75
-		$this->setOwner($owner);
76
-		$this->setOwnerDisplayName($ownerDisplayName);
77
-		$this->setSharedBy($sharedBy);
78
-		$this->setSharedByDisplayName($sharedByDisplayName);
79
-		$this->setProtocol([
80
-			'name' => 'webdav',
81
-			'options' => [
82
-				'sharedSecret' => $sharedSecret,
83
-				'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions'
84
-			]
85
-		]);
86
-		$this->setShareType($shareType);
87
-		$this->setResourceType($resourceType);
88
-	}
44
+    /**
45
+     * get a CloudFederationShare Object to prepare a share you want to send
46
+     *
47
+     * @param string $shareWith
48
+     * @param string $name resource name (e.g. document.odt)
49
+     * @param string $description share description (optional)
50
+     * @param string $providerId resource UID on the provider side
51
+     * @param string $owner provider specific UID of the user who owns the resource
52
+     * @param string $ownerDisplayName display name of the user who shared the item
53
+     * @param string $sharedBy provider specific UID of the user who shared the resource
54
+     * @param string $sharedByDisplayName display name of the user who shared the resource
55
+     * @param string $shareType ('group' or 'user' share)
56
+     * @param string $resourceType ('file', 'calendar',...)
57
+     * @param string $sharedSecret
58
+     */
59
+    public function __construct($shareWith = '',
60
+                                $name = '',
61
+                                $description = '',
62
+                                $providerId = '',
63
+                                $owner = '',
64
+                                $ownerDisplayName = '',
65
+                                $sharedBy = '',
66
+                                $sharedByDisplayName = '',
67
+                                $shareType = '',
68
+                                $resourceType = '',
69
+                                $sharedSecret = ''
70
+    ) {
71
+        $this->setShareWith($shareWith);
72
+        $this->setResourceName($name);
73
+        $this->setDescription($description);
74
+        $this->setProviderId($providerId);
75
+        $this->setOwner($owner);
76
+        $this->setOwnerDisplayName($ownerDisplayName);
77
+        $this->setSharedBy($sharedBy);
78
+        $this->setSharedByDisplayName($sharedByDisplayName);
79
+        $this->setProtocol([
80
+            'name' => 'webdav',
81
+            'options' => [
82
+                'sharedSecret' => $sharedSecret,
83
+                'permissions' => '{http://open-cloud-mesh.org/ns}share-permissions'
84
+            ]
85
+        ]);
86
+        $this->setShareType($shareType);
87
+        $this->setResourceType($resourceType);
88
+    }
89 89
 
90
-	/**
91
-	 * set uid of the recipient
92
-	 *
93
-	 * @param string $user
94
-	 *
95
-	 * @since 14.0.0
96
-	 */
97
-	public function setShareWith($user) {
98
-		$this->share['shareWith'] = $user;
99
-	}
90
+    /**
91
+     * set uid of the recipient
92
+     *
93
+     * @param string $user
94
+     *
95
+     * @since 14.0.0
96
+     */
97
+    public function setShareWith($user) {
98
+        $this->share['shareWith'] = $user;
99
+    }
100 100
 
101
-	/**
102
-	 * set resource name (e.g. document.odt)
103
-	 *
104
-	 * @param string $name
105
-	 *
106
-	 * @since 14.0.0
107
-	 */
108
-	public function setResourceName($name) {
109
-		$this->share['name'] = $name;
110
-	}
101
+    /**
102
+     * set resource name (e.g. document.odt)
103
+     *
104
+     * @param string $name
105
+     *
106
+     * @since 14.0.0
107
+     */
108
+    public function setResourceName($name) {
109
+        $this->share['name'] = $name;
110
+    }
111 111
 
112
-	/**
113
-	 * set resource type (e.g. file, calendar, contact,...)
114
-	 *
115
-	 * @param string $resourceType
116
-	 *
117
-	 * @since 14.0.0
118
-	 */
119
-	public function setResourceType($resourceType) {
120
-		$this->share['resourceType'] = $resourceType;
121
-	}
112
+    /**
113
+     * set resource type (e.g. file, calendar, contact,...)
114
+     *
115
+     * @param string $resourceType
116
+     *
117
+     * @since 14.0.0
118
+     */
119
+    public function setResourceType($resourceType) {
120
+        $this->share['resourceType'] = $resourceType;
121
+    }
122 122
 
123
-	/**
124
-	 * set resource description (optional)
125
-	 *
126
-	 * @param string $description
127
-	 *
128
-	 * @since 14.0.0
129
-	 */
130
-	public function setDescription($description) {
131
-		$this->share['description'] = $description;
132
-	}
123
+    /**
124
+     * set resource description (optional)
125
+     *
126
+     * @param string $description
127
+     *
128
+     * @since 14.0.0
129
+     */
130
+    public function setDescription($description) {
131
+        $this->share['description'] = $description;
132
+    }
133 133
 
134
-	/**
135
-	 * set provider ID (e.g. file ID)
136
-	 *
137
-	 * @param string $providerId
138
-	 *
139
-	 * @since 14.0.0
140
-	 */
141
-	public function setProviderId($providerId) {
142
-		$this->share['providerId'] = $providerId;
143
-	}
134
+    /**
135
+     * set provider ID (e.g. file ID)
136
+     *
137
+     * @param string $providerId
138
+     *
139
+     * @since 14.0.0
140
+     */
141
+    public function setProviderId($providerId) {
142
+        $this->share['providerId'] = $providerId;
143
+    }
144 144
 
145
-	/**
146
-	 * set owner UID
147
-	 *
148
-	 * @param string $owner
149
-	 *
150
-	 * @since 14.0.0
151
-	 */
152
-	public function setOwner($owner) {
153
-		$this->share['owner'] = $owner;
154
-	}
145
+    /**
146
+     * set owner UID
147
+     *
148
+     * @param string $owner
149
+     *
150
+     * @since 14.0.0
151
+     */
152
+    public function setOwner($owner) {
153
+        $this->share['owner'] = $owner;
154
+    }
155 155
 
156
-	/**
157
-	 * set owner display name
158
-	 *
159
-	 * @param string $ownerDisplayName
160
-	 *
161
-	 * @since 14.0.0
162
-	 */
163
-	public function setOwnerDisplayName($ownerDisplayName) {
164
-		$this->share['ownerDisplayName'] = $ownerDisplayName;
165
-	}
156
+    /**
157
+     * set owner display name
158
+     *
159
+     * @param string $ownerDisplayName
160
+     *
161
+     * @since 14.0.0
162
+     */
163
+    public function setOwnerDisplayName($ownerDisplayName) {
164
+        $this->share['ownerDisplayName'] = $ownerDisplayName;
165
+    }
166 166
 
167
-	/**
168
-	 * set UID of the user who sends the share
169
-	 *
170
-	 * @param string $sharedBy
171
-	 *
172
-	 * @since 14.0.0
173
-	 */
174
-	public function setSharedBy($sharedBy) {
175
-		$this->share['sharedBy'] = $sharedBy;
176
-	}
167
+    /**
168
+     * set UID of the user who sends the share
169
+     *
170
+     * @param string $sharedBy
171
+     *
172
+     * @since 14.0.0
173
+     */
174
+    public function setSharedBy($sharedBy) {
175
+        $this->share['sharedBy'] = $sharedBy;
176
+    }
177 177
 
178
-	/**
179
-	 * set display name of the user who sends the share
180
-	 *
181
-	 * @param $sharedByDisplayName
182
-	 *
183
-	 * @since 14.0.0
184
-	 */
185
-	public function setSharedByDisplayName($sharedByDisplayName) {
186
-		$this->share['sharedByDisplayName'] = $sharedByDisplayName;
187
-	}
178
+    /**
179
+     * set display name of the user who sends the share
180
+     *
181
+     * @param $sharedByDisplayName
182
+     *
183
+     * @since 14.0.0
184
+     */
185
+    public function setSharedByDisplayName($sharedByDisplayName) {
186
+        $this->share['sharedByDisplayName'] = $sharedByDisplayName;
187
+    }
188 188
 
189
-	/**
190
-	 * set protocol specification
191
-	 *
192
-	 * @param array $protocol
193
-	 *
194
-	 * @since 14.0.0
195
-	 */
196
-	public function setProtocol(array $protocol) {
197
-		$this->share['protocol'] = $protocol;
198
-	}
189
+    /**
190
+     * set protocol specification
191
+     *
192
+     * @param array $protocol
193
+     *
194
+     * @since 14.0.0
195
+     */
196
+    public function setProtocol(array $protocol) {
197
+        $this->share['protocol'] = $protocol;
198
+    }
199 199
 
200
-	/**
201
-	 * share type (group or user)
202
-	 *
203
-	 * @param string $shareType
204
-	 *
205
-	 * @since 14.0.0
206
-	 */
207
-	public function setShareType($shareType) {
208
-		if ($shareType === 'group' || $shareType === IShare::TYPE_REMOTE_GROUP) {
209
-			$this->share['shareType'] = 'group';
210
-		} else {
211
-			$this->share['shareType'] = 'user';
212
-		}
213
-	}
200
+    /**
201
+     * share type (group or user)
202
+     *
203
+     * @param string $shareType
204
+     *
205
+     * @since 14.0.0
206
+     */
207
+    public function setShareType($shareType) {
208
+        if ($shareType === 'group' || $shareType === IShare::TYPE_REMOTE_GROUP) {
209
+            $this->share['shareType'] = 'group';
210
+        } else {
211
+            $this->share['shareType'] = 'user';
212
+        }
213
+    }
214 214
 
215
-	/**
216
-	 * get the whole share, ready to send out
217
-	 *
218
-	 * @return array
219
-	 *
220
-	 * @since 14.0.0
221
-	 */
222
-	public function getShare() {
223
-		return $this->share;
224
-	}
215
+    /**
216
+     * get the whole share, ready to send out
217
+     *
218
+     * @return array
219
+     *
220
+     * @since 14.0.0
221
+     */
222
+    public function getShare() {
223
+        return $this->share;
224
+    }
225 225
 
226
-	/**
227
-	 * get uid of the recipient
228
-	 *
229
-	 * @return string
230
-	 *
231
-	 * @since 14.0.0
232
-	 */
233
-	public function getShareWith() {
234
-		return $this->share['shareWith'];
235
-	}
226
+    /**
227
+     * get uid of the recipient
228
+     *
229
+     * @return string
230
+     *
231
+     * @since 14.0.0
232
+     */
233
+    public function getShareWith() {
234
+        return $this->share['shareWith'];
235
+    }
236 236
 
237
-	/**
238
-	 * get resource name (e.g. file, calendar, contact,...)
239
-	 *
240
-	 * @return string
241
-	 *
242
-	 * @since 14.0.0
243
-	 */
244
-	public function getResourceName() {
245
-		return $this->share['name'];
246
-	}
237
+    /**
238
+     * get resource name (e.g. file, calendar, contact,...)
239
+     *
240
+     * @return string
241
+     *
242
+     * @since 14.0.0
243
+     */
244
+    public function getResourceName() {
245
+        return $this->share['name'];
246
+    }
247 247
 
248
-	/**
249
-	 * get resource type (e.g. file, calendar, contact,...)
250
-	 *
251
-	 * @return string
252
-	 *
253
-	 * @since 14.0.0
254
-	 */
255
-	public function getResourceType() {
256
-		return $this->share['resourceType'];
257
-	}
248
+    /**
249
+     * get resource type (e.g. file, calendar, contact,...)
250
+     *
251
+     * @return string
252
+     *
253
+     * @since 14.0.0
254
+     */
255
+    public function getResourceType() {
256
+        return $this->share['resourceType'];
257
+    }
258 258
 
259
-	/**
260
-	 * get resource description (optional)
261
-	 *
262
-	 * @return string
263
-	 *
264
-	 * @since 14.0.0
265
-	 */
266
-	public function getDescription() {
267
-		return $this->share['description'];
268
-	}
259
+    /**
260
+     * get resource description (optional)
261
+     *
262
+     * @return string
263
+     *
264
+     * @since 14.0.0
265
+     */
266
+    public function getDescription() {
267
+        return $this->share['description'];
268
+    }
269 269
 
270
-	/**
271
-	 * get provider ID (e.g. file ID)
272
-	 *
273
-	 * @return string
274
-	 *
275
-	 * @since 14.0.0
276
-	 */
277
-	public function getProviderId() {
278
-		return $this->share['providerId'];
279
-	}
270
+    /**
271
+     * get provider ID (e.g. file ID)
272
+     *
273
+     * @return string
274
+     *
275
+     * @since 14.0.0
276
+     */
277
+    public function getProviderId() {
278
+        return $this->share['providerId'];
279
+    }
280 280
 
281
-	/**
282
-	 * get owner UID
283
-	 *
284
-	 * @return string
285
-	 *
286
-	 * @since 14.0.0
287
-	 */
288
-	public function getOwner() {
289
-		return $this->share['owner'];
290
-	}
281
+    /**
282
+     * get owner UID
283
+     *
284
+     * @return string
285
+     *
286
+     * @since 14.0.0
287
+     */
288
+    public function getOwner() {
289
+        return $this->share['owner'];
290
+    }
291 291
 
292
-	/**
293
-	 * get owner display name
294
-	 *
295
-	 * @return string
296
-	 *
297
-	 * @since 14.0.0
298
-	 */
299
-	public function getOwnerDisplayName() {
300
-		return $this->share['ownerDisplayName'];
301
-	}
292
+    /**
293
+     * get owner display name
294
+     *
295
+     * @return string
296
+     *
297
+     * @since 14.0.0
298
+     */
299
+    public function getOwnerDisplayName() {
300
+        return $this->share['ownerDisplayName'];
301
+    }
302 302
 
303
-	/**
304
-	 * get UID of the user who sends the share
305
-	 *
306
-	 * @return string
307
-	 *
308
-	 * @since 14.0.0
309
-	 */
310
-	public function getSharedBy() {
311
-		return $this->share['sharedBy'];
312
-	}
303
+    /**
304
+     * get UID of the user who sends the share
305
+     *
306
+     * @return string
307
+     *
308
+     * @since 14.0.0
309
+     */
310
+    public function getSharedBy() {
311
+        return $this->share['sharedBy'];
312
+    }
313 313
 
314
-	/**
315
-	 * get display name of the user who sends the share
316
-	 *
317
-	 * @return string
318
-	 *
319
-	 * @since 14.0.0
320
-	 */
321
-	public function getSharedByDisplayName() {
322
-		return $this->share['sharedByDisplayName'];
323
-	}
314
+    /**
315
+     * get display name of the user who sends the share
316
+     *
317
+     * @return string
318
+     *
319
+     * @since 14.0.0
320
+     */
321
+    public function getSharedByDisplayName() {
322
+        return $this->share['sharedByDisplayName'];
323
+    }
324 324
 
325
-	/**
326
-	 * get share type (group or user)
327
-	 *
328
-	 * @return string
329
-	 *
330
-	 * @since 14.0.0
331
-	 */
332
-	public function getShareType() {
333
-		return $this->share['shareType'];
334
-	}
325
+    /**
326
+     * get share type (group or user)
327
+     *
328
+     * @return string
329
+     *
330
+     * @since 14.0.0
331
+     */
332
+    public function getShareType() {
333
+        return $this->share['shareType'];
334
+    }
335 335
 
336
-	/**
337
-	 * get share Secret
338
-	 *
339
-	 * @return string
340
-	 *
341
-	 * @since 14.0.0
342
-	 */
343
-	public function getShareSecret() {
344
-		return $this->share['protocol']['options']['sharedSecret'];
345
-	}
336
+    /**
337
+     * get share Secret
338
+     *
339
+     * @return string
340
+     *
341
+     * @since 14.0.0
342
+     */
343
+    public function getShareSecret() {
344
+        return $this->share['protocol']['options']['sharedSecret'];
345
+    }
346 346
 
347
-	/**
348
-	 * get protocol specification
349
-	 *
350
-	 * @return array
351
-	 *
352
-	 * @since 14.0.0
353
-	 */
354
-	public function getProtocol() {
355
-		return $this->share['protocol'];
356
-	}
347
+    /**
348
+     * get protocol specification
349
+     *
350
+     * @return array
351
+     *
352
+     * @since 14.0.0
353
+     */
354
+    public function getProtocol() {
355
+        return $this->share['protocol'];
356
+    }
357 357
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Migration/SetPasswordColumn.php 1 patch
Indentation   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -36,60 +36,60 @@
 block discarded – undo
36 36
  */
37 37
 class SetPasswordColumn implements IRepairStep {
38 38
 
39
-	/** @var IDBConnection */
40
-	private $connection;
39
+    /** @var IDBConnection */
40
+    private $connection;
41 41
 
42
-	/** @var  IConfig */
43
-	private $config;
42
+    /** @var  IConfig */
43
+    private $config;
44 44
 
45 45
 
46
-	public function __construct(IDBConnection $connection, IConfig $config) {
47
-		$this->connection = $connection;
48
-		$this->config = $config;
49
-	}
46
+    public function __construct(IDBConnection $connection, IConfig $config) {
47
+        $this->connection = $connection;
48
+        $this->config = $config;
49
+    }
50 50
 
51
-	/**
52
-	 * Returns the step's name
53
-	 *
54
-	 * @return string
55
-	 * @since 9.1.0
56
-	 */
57
-	public function getName() {
58
-		return 'Copy the share password into the dedicated column';
59
-	}
51
+    /**
52
+     * Returns the step's name
53
+     *
54
+     * @return string
55
+     * @since 9.1.0
56
+     */
57
+    public function getName() {
58
+        return 'Copy the share password into the dedicated column';
59
+    }
60 60
 
61
-	/**
62
-	 * @param IOutput $output
63
-	 */
64
-	public function run(IOutput $output) {
65
-		if (!$this->shouldRun()) {
66
-			return;
67
-		}
61
+    /**
62
+     * @param IOutput $output
63
+     */
64
+    public function run(IOutput $output) {
65
+        if (!$this->shouldRun()) {
66
+            return;
67
+        }
68 68
 
69
-		$query = $this->connection->getQueryBuilder();
70
-		$query
71
-			->update('share')
72
-			->set('password', 'share_with')
73
-			->where($query->expr()->eq('share_type', $query->createNamedParameter(IShare::TYPE_LINK)))
74
-			->andWhere($query->expr()->isNotNull('share_with'));
75
-		$result = $query->execute();
69
+        $query = $this->connection->getQueryBuilder();
70
+        $query
71
+            ->update('share')
72
+            ->set('password', 'share_with')
73
+            ->where($query->expr()->eq('share_type', $query->createNamedParameter(IShare::TYPE_LINK)))
74
+            ->andWhere($query->expr()->isNotNull('share_with'));
75
+        $result = $query->execute();
76 76
 
77
-		if ($result === 0) {
78
-			// No link updated, no need to run the second query
79
-			return;
80
-		}
77
+        if ($result === 0) {
78
+            // No link updated, no need to run the second query
79
+            return;
80
+        }
81 81
 
82
-		$clearQuery = $this->connection->getQueryBuilder();
83
-		$clearQuery
84
-			->update('share')
85
-			->set('share_with', $clearQuery->createNamedParameter(null))
86
-			->where($clearQuery->expr()->eq('share_type', $clearQuery->createNamedParameter(IShare::TYPE_LINK)));
82
+        $clearQuery = $this->connection->getQueryBuilder();
83
+        $clearQuery
84
+            ->update('share')
85
+            ->set('share_with', $clearQuery->createNamedParameter(null))
86
+            ->where($clearQuery->expr()->eq('share_type', $clearQuery->createNamedParameter(IShare::TYPE_LINK)));
87 87
 
88
-		$clearQuery->execute();
89
-	}
88
+        $clearQuery->execute();
89
+    }
90 90
 
91
-	protected function shouldRun() {
92
-		$appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0');
93
-		return version_compare($appVersion, '1.4.0', '<');
94
-	}
91
+    protected function shouldRun() {
92
+        $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0');
93
+        return version_compare($appVersion, '1.4.0', '<');
94
+    }
95 95
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Migration/OwncloudGuestShareType.php 2 patches
Indentation   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -37,46 +37,46 @@
 block discarded – undo
37 37
  */
38 38
 class OwncloudGuestShareType implements IRepairStep {
39 39
 
40
-	/** @var IDBConnection */
41
-	private $connection;
40
+    /** @var IDBConnection */
41
+    private $connection;
42 42
 
43
-	/** @var  IConfig */
44
-	private $config;
43
+    /** @var  IConfig */
44
+    private $config;
45 45
 
46 46
 
47
-	public function __construct(IDBConnection $connection, IConfig $config) {
48
-		$this->connection = $connection;
49
-		$this->config = $config;
50
-	}
47
+    public function __construct(IDBConnection $connection, IConfig $config) {
48
+        $this->connection = $connection;
49
+        $this->config = $config;
50
+    }
51 51
 
52
-	/**
53
-	 * Returns the step's name
54
-	 *
55
-	 * @return string
56
-	 * @since 9.1.0
57
-	 */
58
-	public function getName() {
59
-		return 'Fix the share type of guest shares when migrating from ownCloud';
60
-	}
52
+    /**
53
+     * Returns the step's name
54
+     *
55
+     * @return string
56
+     * @since 9.1.0
57
+     */
58
+    public function getName() {
59
+        return 'Fix the share type of guest shares when migrating from ownCloud';
60
+    }
61 61
 
62
-	/**
63
-	 * @param IOutput $output
64
-	 */
65
-	public function run(IOutput $output) {
66
-		if (!$this->shouldRun()) {
67
-			return;
68
-		}
62
+    /**
63
+     * @param IOutput $output
64
+     */
65
+    public function run(IOutput $output) {
66
+        if (!$this->shouldRun()) {
67
+            return;
68
+        }
69 69
 
70
-		$query = $this->connection->getQueryBuilder();
71
-		$query->update('share')
72
-			->set('share_type',  $query->createNamedParameter(IShare::TYPE_GUEST))
73
-			->where($query->expr()->eq('share_type', $query->createNamedParameter(IShare::TYPE_EMAIL)));
74
-		$query->execute();
75
-	}
70
+        $query = $this->connection->getQueryBuilder();
71
+        $query->update('share')
72
+            ->set('share_type',  $query->createNamedParameter(IShare::TYPE_GUEST))
73
+            ->where($query->expr()->eq('share_type', $query->createNamedParameter(IShare::TYPE_EMAIL)));
74
+        $query->execute();
75
+    }
76 76
 
77
-	protected function shouldRun() {
78
-		$appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0');
79
-		return $appVersion === '0.10.0' ||
80
-			$this->config->getAppValue('core', 'vendor', '') === 'owncloud';
81
-	}
77
+    protected function shouldRun() {
78
+        $appVersion = $this->config->getAppValue('files_sharing', 'installed_version', '0.0.0');
79
+        return $appVersion === '0.10.0' ||
80
+            $this->config->getAppValue('core', 'vendor', '') === 'owncloud';
81
+    }
82 82
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -69,7 +69,7 @@
 block discarded – undo
69 69
 
70 70
 		$query = $this->connection->getQueryBuilder();
71 71
 		$query->update('share')
72
-			->set('share_type',  $query->createNamedParameter(IShare::TYPE_GUEST))
72
+			->set('share_type', $query->createNamedParameter(IShare::TYPE_GUEST))
73 73
 			->where($query->expr()->eq('share_type', $query->createNamedParameter(IShare::TYPE_EMAIL)));
74 74
 		$query->execute();
75 75
 	}
Please login to merge, or discard this patch.