Passed
Push — master ( a9798a...74f31b )
by John
14:36 queued 12s
created
apps/user_ldap/lib/Command/ShowRemnants.php 1 patch
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -36,73 +36,73 @@
 block discarded – undo
36 36
 use Symfony\Component\Console\Output\OutputInterface;
37 37
 
38 38
 class ShowRemnants extends Command {
39
-	/** @var \OCA\User_LDAP\User\DeletedUsersIndex */
40
-	protected $dui;
39
+    /** @var \OCA\User_LDAP\User\DeletedUsersIndex */
40
+    protected $dui;
41 41
 
42
-	/** @var \OCP\IDateTimeFormatter */
43
-	protected $dateFormatter;
42
+    /** @var \OCP\IDateTimeFormatter */
43
+    protected $dateFormatter;
44 44
 
45
-	/**
46
-	 * @param DeletedUsersIndex $dui
47
-	 * @param IDateTimeFormatter $dateFormatter
48
-	 */
49
-	public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
50
-		$this->dui = $dui;
51
-		$this->dateFormatter = $dateFormatter;
52
-		parent::__construct();
53
-	}
45
+    /**
46
+     * @param DeletedUsersIndex $dui
47
+     * @param IDateTimeFormatter $dateFormatter
48
+     */
49
+    public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) {
50
+        $this->dui = $dui;
51
+        $this->dateFormatter = $dateFormatter;
52
+        parent::__construct();
53
+    }
54 54
 
55
-	protected function configure() {
56
-		$this
57
-			->setName('ldap:show-remnants')
58
-			->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
59
-			->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.')
60
-			->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format');
61
-	}
55
+    protected function configure() {
56
+        $this
57
+            ->setName('ldap:show-remnants')
58
+            ->setDescription('shows which users are not available on LDAP anymore, but have remnants in Nextcloud.')
59
+            ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.')
60
+            ->addOption('short-date', null, InputOption::VALUE_NONE, 'show dates in Y-m-d format');
61
+    }
62 62
 
63
-	protected function formatDate(int $timestamp, string $default, bool $showShortDate) {
64
-		if (!($timestamp > 0)) {
65
-			return $default;
66
-		}
67
-		if ($showShortDate) {
68
-			return date('Y-m-d', $timestamp);
69
-		}
70
-		return $this->dateFormatter->formatDate($timestamp);
71
-	}
63
+    protected function formatDate(int $timestamp, string $default, bool $showShortDate) {
64
+        if (!($timestamp > 0)) {
65
+            return $default;
66
+        }
67
+        if ($showShortDate) {
68
+            return date('Y-m-d', $timestamp);
69
+        }
70
+        return $this->dateFormatter->formatDate($timestamp);
71
+    }
72 72
 
73
-	/**
74
-	 * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted
75
-	 *
76
-	 * {@inheritdoc}
77
-	 */
78
-	protected function execute(InputInterface $input, OutputInterface $output): int {
79
-		/** @var \Symfony\Component\Console\Helper\Table $table */
80
-		$table = new Table($output);
81
-		$table->setHeaders([
82
-			'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
83
-			'Detected on', 'Dir', 'Sharer'
84
-		]);
85
-		$rows = [];
86
-		$resultSet = $this->dui->getUsers();
87
-		foreach ($resultSet as $user) {
88
-			$rows[] = [
89
-				'ocName' => $user->getOCName(),
90
-				'displayName' => $user->getDisplayName(),
91
-				'uid' => $user->getUID(),
92
-				'dn' => $user->getDN(),
93
-				'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
94
-				'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
95
-				'homePath' => $user->getHomePath(),
96
-				'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
97
-			];
98
-		}
73
+    /**
74
+     * executes the command, i.e. creates and outputs a table of LDAP users marked as deleted
75
+     *
76
+     * {@inheritdoc}
77
+     */
78
+    protected function execute(InputInterface $input, OutputInterface $output): int {
79
+        /** @var \Symfony\Component\Console\Helper\Table $table */
80
+        $table = new Table($output);
81
+        $table->setHeaders([
82
+            'Nextcloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login',
83
+            'Detected on', 'Dir', 'Sharer'
84
+        ]);
85
+        $rows = [];
86
+        $resultSet = $this->dui->getUsers();
87
+        foreach ($resultSet as $user) {
88
+            $rows[] = [
89
+                'ocName' => $user->getOCName(),
90
+                'displayName' => $user->getDisplayName(),
91
+                'uid' => $user->getUID(),
92
+                'dn' => $user->getDN(),
93
+                'lastLogin' => $this->formatDate($user->getLastLogin(), '-', (bool)$input->getOption('short-date')),
94
+                'detectedOn' => $this->formatDate($user->getDetectedOn(), 'unknown', (bool)$input->getOption('short-date')),
95
+                'homePath' => $user->getHomePath(),
96
+                'sharer' => $user->getHasActiveShares() ? 'Y' : 'N',
97
+            ];
98
+        }
99 99
 
100
-		if ($input->getOption('json')) {
101
-			$output->writeln(json_encode($rows));
102
-		} else {
103
-			$table->setRows($rows);
104
-			$table->render();
105
-		}
106
-		return 0;
107
-	}
100
+        if ($input->getOption('json')) {
101
+            $output->writeln(json_encode($rows));
102
+        } else {
103
+            $table->setRows($rows);
104
+            $table->render();
105
+        }
106
+        return 0;
107
+    }
108 108
 }
Please login to merge, or discard this patch.
lib/private/Activity/ActivitySettingsAdapter.php 1 patch
Indentation   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -32,39 +32,39 @@
 block discarded – undo
32 32
  * class based one
33 33
  */
34 34
 class ActivitySettingsAdapter extends ActivitySettings {
35
-	private $oldSettings;
36
-	private $l10n;
35
+    private $oldSettings;
36
+    private $l10n;
37 37
 
38
-	public function __construct(ISetting $oldSettings, IL10N $l10n) {
39
-		$this->oldSettings = $oldSettings;
40
-		$this->l10n = $l10n;
41
-	}
38
+    public function __construct(ISetting $oldSettings, IL10N $l10n) {
39
+        $this->oldSettings = $oldSettings;
40
+        $this->l10n = $l10n;
41
+    }
42 42
 
43
-	public function getIdentifier() {
44
-		return $this->oldSettings->getIdentifier();
45
-	}
43
+    public function getIdentifier() {
44
+        return $this->oldSettings->getIdentifier();
45
+    }
46 46
 
47
-	public function getName() {
48
-		return $this->oldSettings->getName();
49
-	}
47
+    public function getName() {
48
+        return $this->oldSettings->getName();
49
+    }
50 50
 
51
-	public function getGroupIdentifier() {
52
-		return 'other';
53
-	}
51
+    public function getGroupIdentifier() {
52
+        return 'other';
53
+    }
54 54
 
55
-	public function getGroupName() {
56
-		return $this->l10n->t('Other activities');
57
-	}
55
+    public function getGroupName() {
56
+        return $this->l10n->t('Other activities');
57
+    }
58 58
 
59
-	public function getPriority() {
60
-		return $this->oldSettings->getPriority();
61
-	}
59
+    public function getPriority() {
60
+        return $this->oldSettings->getPriority();
61
+    }
62 62
 
63
-	public function canChangeMail() {
64
-		return $this->oldSettings->canChangeMail();
65
-	}
63
+    public function canChangeMail() {
64
+        return $this->oldSettings->canChangeMail();
65
+    }
66 66
 
67
-	public function isDefaultEnabledMail() {
68
-		return $this->oldSettings->isDefaultEnabledMail();
69
-	}
67
+    public function isDefaultEnabledMail() {
68
+        return $this->oldSettings->isDefaultEnabledMail();
69
+    }
70 70
 }
Please login to merge, or discard this patch.
lib/private/Activity/Manager.php 1 patch
Indentation   +354 added lines, -354 removed lines patch added patch discarded remove patch
@@ -43,358 +43,358 @@
 block discarded – undo
43 43
 use OCP\RichObjectStrings\IValidator;
44 44
 
45 45
 class Manager implements IManager {
46
-	/** @var IRequest */
47
-	protected $request;
48
-
49
-	/** @var IUserSession */
50
-	protected $session;
51
-
52
-	/** @var IConfig */
53
-	protected $config;
54
-
55
-	/** @var IValidator */
56
-	protected $validator;
57
-
58
-	/** @var string */
59
-	protected $formattingObjectType;
60
-
61
-	/** @var int */
62
-	protected $formattingObjectId;
63
-
64
-	/** @var bool */
65
-	protected $requirePNG = false;
66
-
67
-	/** @var string */
68
-	protected $currentUserId;
69
-
70
-	protected $l10n;
71
-
72
-	public function __construct(
73
-			IRequest $request,
74
-			IUserSession $session,
75
-			IConfig $config,
76
-			IValidator $validator,
77
-			IL10N $l10n
78
-	) {
79
-		$this->request = $request;
80
-		$this->session = $session;
81
-		$this->config = $config;
82
-		$this->validator = $validator;
83
-		$this->l10n = $l10n;
84
-	}
85
-
86
-	/** @var \Closure[] */
87
-	private $consumersClosures = [];
88
-
89
-	/** @var IConsumer[] */
90
-	private $consumers = [];
91
-
92
-	/**
93
-	 * @return \OCP\Activity\IConsumer[]
94
-	 */
95
-	protected function getConsumers(): array {
96
-		if (!empty($this->consumers)) {
97
-			return $this->consumers;
98
-		}
99
-
100
-		$this->consumers = [];
101
-		foreach ($this->consumersClosures as $consumer) {
102
-			$c = $consumer();
103
-			if ($c instanceof IConsumer) {
104
-				$this->consumers[] = $c;
105
-			} else {
106
-				throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface');
107
-			}
108
-		}
109
-
110
-		return $this->consumers;
111
-	}
112
-
113
-	/**
114
-	 * Generates a new IEvent object
115
-	 *
116
-	 * Make sure to call at least the following methods before sending it to the
117
-	 * app with via the publish() method:
118
-	 *  - setApp()
119
-	 *  - setType()
120
-	 *  - setAffectedUser()
121
-	 *  - setSubject()
122
-	 *
123
-	 * @return IEvent
124
-	 */
125
-	public function generateEvent(): IEvent {
126
-		return new Event($this->validator);
127
-	}
128
-
129
-	/**
130
-	 * Publish an event to the activity consumers
131
-	 *
132
-	 * Make sure to call at least the following methods before sending an Event:
133
-	 *  - setApp()
134
-	 *  - setType()
135
-	 *  - setAffectedUser()
136
-	 *  - setSubject()
137
-	 *
138
-	 * @param IEvent $event
139
-	 * @throws \BadMethodCallException if required values have not been set
140
-	 */
141
-	public function publish(IEvent $event): void {
142
-		if ($event->getAuthor() === '') {
143
-			if ($this->session->getUser() instanceof IUser) {
144
-				$event->setAuthor($this->session->getUser()->getUID());
145
-			}
146
-		}
147
-
148
-		if (!$event->getTimestamp()) {
149
-			$event->setTimestamp(time());
150
-		}
151
-
152
-		if (!$event->isValid()) {
153
-			throw new \BadMethodCallException('The given event is invalid');
154
-		}
155
-
156
-		foreach ($this->getConsumers() as $c) {
157
-			$c->receive($event);
158
-		}
159
-	}
160
-
161
-	/**
162
-	 * In order to improve lazy loading a closure can be registered which will be called in case
163
-	 * activity consumers are actually requested
164
-	 *
165
-	 * $callable has to return an instance of OCA\Activity\IConsumer
166
-	 *
167
-	 * @param \Closure $callable
168
-	 */
169
-	public function registerConsumer(\Closure $callable): void {
170
-		$this->consumersClosures[] = $callable;
171
-		$this->consumers = [];
172
-	}
173
-
174
-	/** @var string[] */
175
-	protected $filterClasses = [];
176
-
177
-	/** @var IFilter[] */
178
-	protected $filters = [];
179
-
180
-	/**
181
-	 * @param string $filter Class must implement OCA\Activity\IFilter
182
-	 * @return void
183
-	 */
184
-	public function registerFilter(string $filter): void {
185
-		$this->filterClasses[$filter] = false;
186
-	}
187
-
188
-	/**
189
-	 * @return IFilter[]
190
-	 * @throws \InvalidArgumentException
191
-	 */
192
-	public function getFilters(): array {
193
-		foreach ($this->filterClasses as $class => $false) {
194
-			/** @var IFilter $filter */
195
-			$filter = \OC::$server->query($class);
196
-
197
-			if (!$filter instanceof IFilter) {
198
-				throw new \InvalidArgumentException('Invalid activity filter registered');
199
-			}
200
-
201
-			$this->filters[$filter->getIdentifier()] = $filter;
202
-
203
-			unset($this->filterClasses[$class]);
204
-		}
205
-		return $this->filters;
206
-	}
207
-
208
-	/**
209
-	 * @param string $id
210
-	 * @return IFilter
211
-	 * @throws \InvalidArgumentException when the filter was not found
212
-	 * @since 11.0.0
213
-	 */
214
-	public function getFilterById(string $id): IFilter {
215
-		$filters = $this->getFilters();
216
-
217
-		if (isset($filters[$id])) {
218
-			return $filters[$id];
219
-		}
220
-
221
-		throw new \InvalidArgumentException('Requested filter does not exist');
222
-	}
223
-
224
-	/** @var string[] */
225
-	protected $providerClasses = [];
226
-
227
-	/** @var IProvider[] */
228
-	protected $providers = [];
229
-
230
-	/**
231
-	 * @param string $provider Class must implement OCA\Activity\IProvider
232
-	 * @return void
233
-	 */
234
-	public function registerProvider(string $provider): void {
235
-		$this->providerClasses[$provider] = false;
236
-	}
237
-
238
-	/**
239
-	 * @return IProvider[]
240
-	 * @throws \InvalidArgumentException
241
-	 */
242
-	public function getProviders(): array {
243
-		foreach ($this->providerClasses as $class => $false) {
244
-			/** @var IProvider $provider */
245
-			$provider = \OC::$server->query($class);
246
-
247
-			if (!$provider instanceof IProvider) {
248
-				throw new \InvalidArgumentException('Invalid activity provider registered');
249
-			}
250
-
251
-			$this->providers[] = $provider;
252
-
253
-			unset($this->providerClasses[$class]);
254
-		}
255
-		return $this->providers;
256
-	}
257
-
258
-	/** @var string[] */
259
-	protected $settingsClasses = [];
260
-
261
-	/** @var ISetting[] */
262
-	protected $settings = [];
263
-
264
-	/**
265
-	 * @param string $setting Class must implement OCA\Activity\ISetting
266
-	 * @return void
267
-	 */
268
-	public function registerSetting(string $setting): void {
269
-		$this->settingsClasses[$setting] = false;
270
-	}
271
-
272
-	/**
273
-	 * @return ActivitySettings[]
274
-	 * @throws \InvalidArgumentException
275
-	 */
276
-	public function getSettings(): array {
277
-		foreach ($this->settingsClasses as $class => $false) {
278
-			/** @var ISetting $setting */
279
-			$setting = \OC::$server->query($class);
280
-
281
-			if ($setting instanceof ISetting) {
282
-				if (!$setting instanceof ActivitySettings) {
283
-					$setting = new ActivitySettingsAdapter($setting, $this->l10n);
284
-				}
285
-			} else {
286
-				throw new \InvalidArgumentException('Invalid activity filter registered');
287
-			}
288
-
289
-			$this->settings[$setting->getIdentifier()] = $setting;
290
-
291
-			unset($this->settingsClasses[$class]);
292
-		}
293
-		return $this->settings;
294
-	}
295
-
296
-	/**
297
-	 * @param string $id
298
-	 * @return ActivitySettings
299
-	 * @throws \InvalidArgumentException when the setting was not found
300
-	 * @since 11.0.0
301
-	 */
302
-	public function getSettingById(string $id): ActivitySettings {
303
-		$settings = $this->getSettings();
304
-
305
-		if (isset($settings[$id])) {
306
-			return $settings[$id];
307
-		}
308
-
309
-		throw new \InvalidArgumentException('Requested setting does not exist');
310
-	}
311
-
312
-
313
-	/**
314
-	 * @param string $type
315
-	 * @param int $id
316
-	 */
317
-	public function setFormattingObject(string $type, int $id): void {
318
-		$this->formattingObjectType = $type;
319
-		$this->formattingObjectId = $id;
320
-	}
321
-
322
-	/**
323
-	 * @return bool
324
-	 */
325
-	public function isFormattingFilteredObject(): bool {
326
-		return $this->formattingObjectType !== null && $this->formattingObjectId !== null
327
-			&& $this->formattingObjectType === $this->request->getParam('object_type')
328
-			&& $this->formattingObjectId === (int) $this->request->getParam('object_id');
329
-	}
330
-
331
-	/**
332
-	 * @param bool $status Set to true, when parsing events should not use SVG icons
333
-	 */
334
-	public function setRequirePNG(bool $status): void {
335
-		$this->requirePNG = $status;
336
-	}
337
-
338
-	/**
339
-	 * @return bool
340
-	 */
341
-	public function getRequirePNG(): bool {
342
-		return $this->requirePNG;
343
-	}
344
-
345
-	/**
346
-	 * Set the user we need to use
347
-	 *
348
-	 * @param string|null $currentUserId
349
-	 * @throws \UnexpectedValueException If the user is invalid
350
-	 */
351
-	public function setCurrentUserId(string $currentUserId = null): void {
352
-		if (!is_string($currentUserId) && $currentUserId !== null) {
353
-			throw new \UnexpectedValueException('The given current user is invalid');
354
-		}
355
-		$this->currentUserId = $currentUserId;
356
-	}
357
-
358
-	/**
359
-	 * Get the user we need to use
360
-	 *
361
-	 * Either the user is logged in, or we try to get it from the token
362
-	 *
363
-	 * @return string
364
-	 * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
365
-	 */
366
-	public function getCurrentUserId(): string {
367
-		if ($this->currentUserId !== null) {
368
-			return $this->currentUserId;
369
-		}
370
-
371
-		if (!$this->session->isLoggedIn()) {
372
-			return $this->getUserFromToken();
373
-		}
374
-
375
-		return $this->session->getUser()->getUID();
376
-	}
377
-
378
-	/**
379
-	 * Get the user for the token
380
-	 *
381
-	 * @return string
382
-	 * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
383
-	 */
384
-	protected function getUserFromToken(): string {
385
-		$token = (string) $this->request->getParam('token', '');
386
-		if (strlen($token) !== 30) {
387
-			throw new \UnexpectedValueException('The token is invalid');
388
-		}
389
-
390
-		$users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
391
-
392
-		if (count($users) !== 1) {
393
-			// No unique user found
394
-			throw new \UnexpectedValueException('The token is invalid');
395
-		}
396
-
397
-		// Token found login as that user
398
-		return array_shift($users);
399
-	}
46
+    /** @var IRequest */
47
+    protected $request;
48
+
49
+    /** @var IUserSession */
50
+    protected $session;
51
+
52
+    /** @var IConfig */
53
+    protected $config;
54
+
55
+    /** @var IValidator */
56
+    protected $validator;
57
+
58
+    /** @var string */
59
+    protected $formattingObjectType;
60
+
61
+    /** @var int */
62
+    protected $formattingObjectId;
63
+
64
+    /** @var bool */
65
+    protected $requirePNG = false;
66
+
67
+    /** @var string */
68
+    protected $currentUserId;
69
+
70
+    protected $l10n;
71
+
72
+    public function __construct(
73
+            IRequest $request,
74
+            IUserSession $session,
75
+            IConfig $config,
76
+            IValidator $validator,
77
+            IL10N $l10n
78
+    ) {
79
+        $this->request = $request;
80
+        $this->session = $session;
81
+        $this->config = $config;
82
+        $this->validator = $validator;
83
+        $this->l10n = $l10n;
84
+    }
85
+
86
+    /** @var \Closure[] */
87
+    private $consumersClosures = [];
88
+
89
+    /** @var IConsumer[] */
90
+    private $consumers = [];
91
+
92
+    /**
93
+     * @return \OCP\Activity\IConsumer[]
94
+     */
95
+    protected function getConsumers(): array {
96
+        if (!empty($this->consumers)) {
97
+            return $this->consumers;
98
+        }
99
+
100
+        $this->consumers = [];
101
+        foreach ($this->consumersClosures as $consumer) {
102
+            $c = $consumer();
103
+            if ($c instanceof IConsumer) {
104
+                $this->consumers[] = $c;
105
+            } else {
106
+                throw new \InvalidArgumentException('The given consumer does not implement the \OCP\Activity\IConsumer interface');
107
+            }
108
+        }
109
+
110
+        return $this->consumers;
111
+    }
112
+
113
+    /**
114
+     * Generates a new IEvent object
115
+     *
116
+     * Make sure to call at least the following methods before sending it to the
117
+     * app with via the publish() method:
118
+     *  - setApp()
119
+     *  - setType()
120
+     *  - setAffectedUser()
121
+     *  - setSubject()
122
+     *
123
+     * @return IEvent
124
+     */
125
+    public function generateEvent(): IEvent {
126
+        return new Event($this->validator);
127
+    }
128
+
129
+    /**
130
+     * Publish an event to the activity consumers
131
+     *
132
+     * Make sure to call at least the following methods before sending an Event:
133
+     *  - setApp()
134
+     *  - setType()
135
+     *  - setAffectedUser()
136
+     *  - setSubject()
137
+     *
138
+     * @param IEvent $event
139
+     * @throws \BadMethodCallException if required values have not been set
140
+     */
141
+    public function publish(IEvent $event): void {
142
+        if ($event->getAuthor() === '') {
143
+            if ($this->session->getUser() instanceof IUser) {
144
+                $event->setAuthor($this->session->getUser()->getUID());
145
+            }
146
+        }
147
+
148
+        if (!$event->getTimestamp()) {
149
+            $event->setTimestamp(time());
150
+        }
151
+
152
+        if (!$event->isValid()) {
153
+            throw new \BadMethodCallException('The given event is invalid');
154
+        }
155
+
156
+        foreach ($this->getConsumers() as $c) {
157
+            $c->receive($event);
158
+        }
159
+    }
160
+
161
+    /**
162
+     * In order to improve lazy loading a closure can be registered which will be called in case
163
+     * activity consumers are actually requested
164
+     *
165
+     * $callable has to return an instance of OCA\Activity\IConsumer
166
+     *
167
+     * @param \Closure $callable
168
+     */
169
+    public function registerConsumer(\Closure $callable): void {
170
+        $this->consumersClosures[] = $callable;
171
+        $this->consumers = [];
172
+    }
173
+
174
+    /** @var string[] */
175
+    protected $filterClasses = [];
176
+
177
+    /** @var IFilter[] */
178
+    protected $filters = [];
179
+
180
+    /**
181
+     * @param string $filter Class must implement OCA\Activity\IFilter
182
+     * @return void
183
+     */
184
+    public function registerFilter(string $filter): void {
185
+        $this->filterClasses[$filter] = false;
186
+    }
187
+
188
+    /**
189
+     * @return IFilter[]
190
+     * @throws \InvalidArgumentException
191
+     */
192
+    public function getFilters(): array {
193
+        foreach ($this->filterClasses as $class => $false) {
194
+            /** @var IFilter $filter */
195
+            $filter = \OC::$server->query($class);
196
+
197
+            if (!$filter instanceof IFilter) {
198
+                throw new \InvalidArgumentException('Invalid activity filter registered');
199
+            }
200
+
201
+            $this->filters[$filter->getIdentifier()] = $filter;
202
+
203
+            unset($this->filterClasses[$class]);
204
+        }
205
+        return $this->filters;
206
+    }
207
+
208
+    /**
209
+     * @param string $id
210
+     * @return IFilter
211
+     * @throws \InvalidArgumentException when the filter was not found
212
+     * @since 11.0.0
213
+     */
214
+    public function getFilterById(string $id): IFilter {
215
+        $filters = $this->getFilters();
216
+
217
+        if (isset($filters[$id])) {
218
+            return $filters[$id];
219
+        }
220
+
221
+        throw new \InvalidArgumentException('Requested filter does not exist');
222
+    }
223
+
224
+    /** @var string[] */
225
+    protected $providerClasses = [];
226
+
227
+    /** @var IProvider[] */
228
+    protected $providers = [];
229
+
230
+    /**
231
+     * @param string $provider Class must implement OCA\Activity\IProvider
232
+     * @return void
233
+     */
234
+    public function registerProvider(string $provider): void {
235
+        $this->providerClasses[$provider] = false;
236
+    }
237
+
238
+    /**
239
+     * @return IProvider[]
240
+     * @throws \InvalidArgumentException
241
+     */
242
+    public function getProviders(): array {
243
+        foreach ($this->providerClasses as $class => $false) {
244
+            /** @var IProvider $provider */
245
+            $provider = \OC::$server->query($class);
246
+
247
+            if (!$provider instanceof IProvider) {
248
+                throw new \InvalidArgumentException('Invalid activity provider registered');
249
+            }
250
+
251
+            $this->providers[] = $provider;
252
+
253
+            unset($this->providerClasses[$class]);
254
+        }
255
+        return $this->providers;
256
+    }
257
+
258
+    /** @var string[] */
259
+    protected $settingsClasses = [];
260
+
261
+    /** @var ISetting[] */
262
+    protected $settings = [];
263
+
264
+    /**
265
+     * @param string $setting Class must implement OCA\Activity\ISetting
266
+     * @return void
267
+     */
268
+    public function registerSetting(string $setting): void {
269
+        $this->settingsClasses[$setting] = false;
270
+    }
271
+
272
+    /**
273
+     * @return ActivitySettings[]
274
+     * @throws \InvalidArgumentException
275
+     */
276
+    public function getSettings(): array {
277
+        foreach ($this->settingsClasses as $class => $false) {
278
+            /** @var ISetting $setting */
279
+            $setting = \OC::$server->query($class);
280
+
281
+            if ($setting instanceof ISetting) {
282
+                if (!$setting instanceof ActivitySettings) {
283
+                    $setting = new ActivitySettingsAdapter($setting, $this->l10n);
284
+                }
285
+            } else {
286
+                throw new \InvalidArgumentException('Invalid activity filter registered');
287
+            }
288
+
289
+            $this->settings[$setting->getIdentifier()] = $setting;
290
+
291
+            unset($this->settingsClasses[$class]);
292
+        }
293
+        return $this->settings;
294
+    }
295
+
296
+    /**
297
+     * @param string $id
298
+     * @return ActivitySettings
299
+     * @throws \InvalidArgumentException when the setting was not found
300
+     * @since 11.0.0
301
+     */
302
+    public function getSettingById(string $id): ActivitySettings {
303
+        $settings = $this->getSettings();
304
+
305
+        if (isset($settings[$id])) {
306
+            return $settings[$id];
307
+        }
308
+
309
+        throw new \InvalidArgumentException('Requested setting does not exist');
310
+    }
311
+
312
+
313
+    /**
314
+     * @param string $type
315
+     * @param int $id
316
+     */
317
+    public function setFormattingObject(string $type, int $id): void {
318
+        $this->formattingObjectType = $type;
319
+        $this->formattingObjectId = $id;
320
+    }
321
+
322
+    /**
323
+     * @return bool
324
+     */
325
+    public function isFormattingFilteredObject(): bool {
326
+        return $this->formattingObjectType !== null && $this->formattingObjectId !== null
327
+            && $this->formattingObjectType === $this->request->getParam('object_type')
328
+            && $this->formattingObjectId === (int) $this->request->getParam('object_id');
329
+    }
330
+
331
+    /**
332
+     * @param bool $status Set to true, when parsing events should not use SVG icons
333
+     */
334
+    public function setRequirePNG(bool $status): void {
335
+        $this->requirePNG = $status;
336
+    }
337
+
338
+    /**
339
+     * @return bool
340
+     */
341
+    public function getRequirePNG(): bool {
342
+        return $this->requirePNG;
343
+    }
344
+
345
+    /**
346
+     * Set the user we need to use
347
+     *
348
+     * @param string|null $currentUserId
349
+     * @throws \UnexpectedValueException If the user is invalid
350
+     */
351
+    public function setCurrentUserId(string $currentUserId = null): void {
352
+        if (!is_string($currentUserId) && $currentUserId !== null) {
353
+            throw new \UnexpectedValueException('The given current user is invalid');
354
+        }
355
+        $this->currentUserId = $currentUserId;
356
+    }
357
+
358
+    /**
359
+     * Get the user we need to use
360
+     *
361
+     * Either the user is logged in, or we try to get it from the token
362
+     *
363
+     * @return string
364
+     * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
365
+     */
366
+    public function getCurrentUserId(): string {
367
+        if ($this->currentUserId !== null) {
368
+            return $this->currentUserId;
369
+        }
370
+
371
+        if (!$this->session->isLoggedIn()) {
372
+            return $this->getUserFromToken();
373
+        }
374
+
375
+        return $this->session->getUser()->getUID();
376
+    }
377
+
378
+    /**
379
+     * Get the user for the token
380
+     *
381
+     * @return string
382
+     * @throws \UnexpectedValueException If the token is invalid, does not exist or is not unique
383
+     */
384
+    protected function getUserFromToken(): string {
385
+        $token = (string) $this->request->getParam('token', '');
386
+        if (strlen($token) !== 30) {
387
+            throw new \UnexpectedValueException('The token is invalid');
388
+        }
389
+
390
+        $users = $this->config->getUsersForUserValue('activity', 'rsstoken', $token);
391
+
392
+        if (count($users) !== 1) {
393
+            // No unique user found
394
+            throw new \UnexpectedValueException('The token is invalid');
395
+        }
396
+
397
+        // Token found login as that user
398
+        return array_shift($users);
399
+    }
400 400
 }
Please login to merge, or discard this patch.
lib/public/Activity/ActivitySettings.php 1 patch
Indentation   +73 added lines, -73 removed lines patch added patch discarded remove patch
@@ -27,87 +27,87 @@
 block discarded – undo
27 27
  * @since 20.0.0
28 28
  */
29 29
 abstract class ActivitySettings implements ISetting {
30
-	/**
31
-	 * @return string Lowercase a-z and underscore only identifier
32
-	 * @since 20.0.0
33
-	 */
34
-	abstract public function getIdentifier();
30
+    /**
31
+     * @return string Lowercase a-z and underscore only identifier
32
+     * @since 20.0.0
33
+     */
34
+    abstract public function getIdentifier();
35 35
 
36
-	/**
37
-	 * @return string A translated string
38
-	 * @since 20.0.0
39
-	 */
40
-	abstract public function getName();
36
+    /**
37
+     * @return string A translated string
38
+     * @since 20.0.0
39
+     */
40
+    abstract public function getName();
41 41
 
42
-	/**
43
-	 * @return string Lowercase a-z and underscore only group identifier
44
-	 * @since 20.0.0
45
-	 */
46
-	abstract public function getGroupIdentifier();
42
+    /**
43
+     * @return string Lowercase a-z and underscore only group identifier
44
+     * @since 20.0.0
45
+     */
46
+    abstract public function getGroupIdentifier();
47 47
 
48
-	/**
49
-	 * @return string A translated string for the settings group
50
-	 * @since 20.0.0
51
-	 */
52
-	abstract public function getGroupName();
48
+    /**
49
+     * @return string A translated string for the settings group
50
+     * @since 20.0.0
51
+     */
52
+    abstract public function getGroupName();
53 53
 
54
-	/**
55
-	 * @return int whether the filter should be rather on the top or bottom of
56
-	 * the admin section. The filters are arranged in ascending order of the
57
-	 * priority values. It is required to return a value between 0 and 100.
58
-	 * @since 20.0.0
59
-	 */
60
-	abstract public function getPriority();
54
+    /**
55
+     * @return int whether the filter should be rather on the top or bottom of
56
+     * the admin section. The filters are arranged in ascending order of the
57
+     * priority values. It is required to return a value between 0 and 100.
58
+     * @since 20.0.0
59
+     */
60
+    abstract public function getPriority();
61 61
 
62
-	/**
63
-	 * @return bool True when the option can be changed for the mail
64
-	 * @since 20.0.0
65
-	 */
66
-	public function canChangeMail() {
67
-		return true;
68
-	}
62
+    /**
63
+     * @return bool True when the option can be changed for the mail
64
+     * @since 20.0.0
65
+     */
66
+    public function canChangeMail() {
67
+        return true;
68
+    }
69 69
 
70
-	/**
71
-	 * @return bool True when the option can be changed for the notification
72
-	 * @since 20.0.0
73
-	 */
74
-	public function canChangeNotification() {
75
-		return true;
76
-	}
70
+    /**
71
+     * @return bool True when the option can be changed for the notification
72
+     * @since 20.0.0
73
+     */
74
+    public function canChangeNotification() {
75
+        return true;
76
+    }
77 77
 
78
-	/**
79
-	 * @return bool Whether or not an activity email should be send by default
80
-	 * @since 20.0.0
81
-	 */
82
-	public function isDefaultEnabledMail() {
83
-		return false;
84
-	}
78
+    /**
79
+     * @return bool Whether or not an activity email should be send by default
80
+     * @since 20.0.0
81
+     */
82
+    public function isDefaultEnabledMail() {
83
+        return false;
84
+    }
85 85
 
86
-	/**
87
-	 * @return bool Whether or not an activity notification should be send by default
88
-	 * @since 20.0.0
89
-	 */
90
-	public function isDefaultEnabledNotification() {
91
-		return $this->isDefaultEnabledMail() && !$this->canChangeMail();
92
-	}
86
+    /**
87
+     * @return bool Whether or not an activity notification should be send by default
88
+     * @since 20.0.0
89
+     */
90
+    public function isDefaultEnabledNotification() {
91
+        return $this->isDefaultEnabledMail() && !$this->canChangeMail();
92
+    }
93 93
 
94
-	/**
95
-	 * Left in for backwards compatibility
96
-	 *
97
-	 * @return bool
98
-	 * @since 20.0.0
99
-	 */
100
-	public function canChangeStream() {
101
-		return false;
102
-	}
94
+    /**
95
+     * Left in for backwards compatibility
96
+     *
97
+     * @return bool
98
+     * @since 20.0.0
99
+     */
100
+    public function canChangeStream() {
101
+        return false;
102
+    }
103 103
 
104
-	/**
105
-	 * Left in for backwards compatibility
106
-	 *
107
-	 * @return bool
108
-	 * @since 20.0.0
109
-	 */
110
-	public function isDefaultEnabledStream() {
111
-		return true;
112
-	}
104
+    /**
105
+     * Left in for backwards compatibility
106
+     *
107
+     * @return bool
108
+     * @since 20.0.0
109
+     */
110
+    public function isDefaultEnabledStream() {
111
+        return true;
112
+    }
113 113
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Activity/Settings/PublicLinks.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -24,61 +24,61 @@
 block discarded – undo
24 24
 namespace OCA\Files_Sharing\Activity\Settings;
25 25
 
26 26
 class PublicLinks extends ShareActivitySettings {
27
-	/**
28
-	 * @return string Lowercase a-z and underscore only identifier
29
-	 * @since 11.0.0
30
-	 */
31
-	public function getIdentifier() {
32
-		return 'public_links';
33
-	}
27
+    /**
28
+     * @return string Lowercase a-z and underscore only identifier
29
+     * @since 11.0.0
30
+     */
31
+    public function getIdentifier() {
32
+        return 'public_links';
33
+    }
34 34
 
35
-	/**
36
-	 * @return string A translated string
37
-	 * @since 11.0.0
38
-	 */
39
-	public function getName() {
40
-		return $this->l->t('A file or folder shared by mail or by public link was <strong>downloaded</strong>');
41
-	}
35
+    /**
36
+     * @return string A translated string
37
+     * @since 11.0.0
38
+     */
39
+    public function getName() {
40
+        return $this->l->t('A file or folder shared by mail or by public link was <strong>downloaded</strong>');
41
+    }
42 42
 
43
-	/**
44
-	 * @return int whether the filter should be rather on the top or bottom of
45
-	 * the admin section. The filters are arranged in ascending order of the
46
-	 * priority values. It is required to return a value between 0 and 100.
47
-	 * @since 11.0.0
48
-	 */
49
-	public function getPriority() {
50
-		return 20;
51
-	}
43
+    /**
44
+     * @return int whether the filter should be rather on the top or bottom of
45
+     * the admin section. The filters are arranged in ascending order of the
46
+     * priority values. It is required to return a value between 0 and 100.
47
+     * @since 11.0.0
48
+     */
49
+    public function getPriority() {
50
+        return 20;
51
+    }
52 52
 
53
-	/**
54
-	 * @return bool True when the option can be changed for the stream
55
-	 * @since 11.0.0
56
-	 */
57
-	public function canChangeStream() {
58
-		return true;
59
-	}
53
+    /**
54
+     * @return bool True when the option can be changed for the stream
55
+     * @since 11.0.0
56
+     */
57
+    public function canChangeStream() {
58
+        return true;
59
+    }
60 60
 
61
-	/**
62
-	 * @return bool True when the option can be changed for the stream
63
-	 * @since 11.0.0
64
-	 */
65
-	public function isDefaultEnabledStream() {
66
-		return true;
67
-	}
61
+    /**
62
+     * @return bool True when the option can be changed for the stream
63
+     * @since 11.0.0
64
+     */
65
+    public function isDefaultEnabledStream() {
66
+        return true;
67
+    }
68 68
 
69
-	/**
70
-	 * @return bool True when the option can be changed for the mail
71
-	 * @since 11.0.0
72
-	 */
73
-	public function canChangeMail() {
74
-		return true;
75
-	}
69
+    /**
70
+     * @return bool True when the option can be changed for the mail
71
+     * @since 11.0.0
72
+     */
73
+    public function canChangeMail() {
74
+        return true;
75
+    }
76 76
 
77
-	/**
78
-	 * @return bool True when the option can be changed for the stream
79
-	 * @since 11.0.0
80
-	 */
81
-	public function isDefaultEnabledMail() {
82
-		return false;
83
-	}
77
+    /**
78
+     * @return bool True when the option can be changed for the stream
79
+     * @since 11.0.0
80
+     */
81
+    public function isDefaultEnabledMail() {
82
+        return false;
83
+    }
84 84
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Activity/Settings/Shared.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -25,61 +25,61 @@
 block discarded – undo
25 25
 namespace OCA\Files_Sharing\Activity\Settings;
26 26
 
27 27
 class Shared extends ShareActivitySettings {
28
-	/**
29
-	 * @return string Lowercase a-z and underscore only identifier
30
-	 * @since 11.0.0
31
-	 */
32
-	public function getIdentifier() {
33
-		return 'shared';
34
-	}
28
+    /**
29
+     * @return string Lowercase a-z and underscore only identifier
30
+     * @since 11.0.0
31
+     */
32
+    public function getIdentifier() {
33
+        return 'shared';
34
+    }
35 35
 
36
-	/**
37
-	 * @return string A translated string
38
-	 * @since 11.0.0
39
-	 */
40
-	public function getName() {
41
-		return $this->l->t('A file or folder has been <strong>shared</strong>');
42
-	}
36
+    /**
37
+     * @return string A translated string
38
+     * @since 11.0.0
39
+     */
40
+    public function getName() {
41
+        return $this->l->t('A file or folder has been <strong>shared</strong>');
42
+    }
43 43
 
44
-	/**
45
-	 * @return int whether the filter should be rather on the top or bottom of
46
-	 * the admin section. The filters are arranged in ascending order of the
47
-	 * priority values. It is required to return a value between 0 and 100.
48
-	 * @since 11.0.0
49
-	 */
50
-	public function getPriority() {
51
-		return 10;
52
-	}
44
+    /**
45
+     * @return int whether the filter should be rather on the top or bottom of
46
+     * the admin section. The filters are arranged in ascending order of the
47
+     * priority values. It is required to return a value between 0 and 100.
48
+     * @since 11.0.0
49
+     */
50
+    public function getPriority() {
51
+        return 10;
52
+    }
53 53
 
54
-	/**
55
-	 * @return bool True when the option can be changed for the stream
56
-	 * @since 11.0.0
57
-	 */
58
-	public function canChangeStream() {
59
-		return true;
60
-	}
54
+    /**
55
+     * @return bool True when the option can be changed for the stream
56
+     * @since 11.0.0
57
+     */
58
+    public function canChangeStream() {
59
+        return true;
60
+    }
61 61
 
62
-	/**
63
-	 * @return bool True when the option can be changed for the stream
64
-	 * @since 11.0.0
65
-	 */
66
-	public function isDefaultEnabledStream() {
67
-		return true;
68
-	}
62
+    /**
63
+     * @return bool True when the option can be changed for the stream
64
+     * @since 11.0.0
65
+     */
66
+    public function isDefaultEnabledStream() {
67
+        return true;
68
+    }
69 69
 
70
-	/**
71
-	 * @return bool True when the option can be changed for the mail
72
-	 * @since 11.0.0
73
-	 */
74
-	public function canChangeMail() {
75
-		return true;
76
-	}
70
+    /**
71
+     * @return bool True when the option can be changed for the mail
72
+     * @since 11.0.0
73
+     */
74
+    public function canChangeMail() {
75
+        return true;
76
+    }
77 77
 
78
-	/**
79
-	 * @return bool True when the option can be changed for the stream
80
-	 * @since 11.0.0
81
-	 */
82
-	public function isDefaultEnabledMail() {
83
-		return false;
84
-	}
78
+    /**
79
+     * @return bool True when the option can be changed for the stream
80
+     * @since 11.0.0
81
+     */
82
+    public function isDefaultEnabledMail() {
83
+        return false;
84
+    }
85 85
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Activity/Settings/RemoteShare.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -25,61 +25,61 @@
 block discarded – undo
25 25
 namespace OCA\Files_Sharing\Activity\Settings;
26 26
 
27 27
 class RemoteShare extends ShareActivitySettings {
28
-	/**
29
-	 * @return string Lowercase a-z and underscore only identifier
30
-	 * @since 11.0.0
31
-	 */
32
-	public function getIdentifier() {
33
-		return 'remote_share';
34
-	}
28
+    /**
29
+     * @return string Lowercase a-z and underscore only identifier
30
+     * @since 11.0.0
31
+     */
32
+    public function getIdentifier() {
33
+        return 'remote_share';
34
+    }
35 35
 
36
-	/**
37
-	 * @return string A translated string
38
-	 * @since 11.0.0
39
-	 */
40
-	public function getName() {
41
-		return $this->l->t('A file or folder was shared from <strong>another server</strong>');
42
-	}
36
+    /**
37
+     * @return string A translated string
38
+     * @since 11.0.0
39
+     */
40
+    public function getName() {
41
+        return $this->l->t('A file or folder was shared from <strong>another server</strong>');
42
+    }
43 43
 
44
-	/**
45
-	 * @return int whether the filter should be rather on the top or bottom of
46
-	 * the admin section. The filters are arranged in ascending order of the
47
-	 * priority values. It is required to return a value between 0 and 100.
48
-	 * @since 11.0.0
49
-	 */
50
-	public function getPriority() {
51
-		return 11;
52
-	}
44
+    /**
45
+     * @return int whether the filter should be rather on the top or bottom of
46
+     * the admin section. The filters are arranged in ascending order of the
47
+     * priority values. It is required to return a value between 0 and 100.
48
+     * @since 11.0.0
49
+     */
50
+    public function getPriority() {
51
+        return 11;
52
+    }
53 53
 
54
-	/**
55
-	 * @return bool True when the option can be changed for the stream
56
-	 * @since 11.0.0
57
-	 */
58
-	public function canChangeStream() {
59
-		return true;
60
-	}
54
+    /**
55
+     * @return bool True when the option can be changed for the stream
56
+     * @since 11.0.0
57
+     */
58
+    public function canChangeStream() {
59
+        return true;
60
+    }
61 61
 
62
-	/**
63
-	 * @return bool True when the option can be changed for the stream
64
-	 * @since 11.0.0
65
-	 */
66
-	public function isDefaultEnabledStream() {
67
-		return true;
68
-	}
62
+    /**
63
+     * @return bool True when the option can be changed for the stream
64
+     * @since 11.0.0
65
+     */
66
+    public function isDefaultEnabledStream() {
67
+        return true;
68
+    }
69 69
 
70
-	/**
71
-	 * @return bool True when the option can be changed for the mail
72
-	 * @since 11.0.0
73
-	 */
74
-	public function canChangeMail() {
75
-		return true;
76
-	}
70
+    /**
71
+     * @return bool True when the option can be changed for the mail
72
+     * @since 11.0.0
73
+     */
74
+    public function canChangeMail() {
75
+        return true;
76
+    }
77 77
 
78
-	/**
79
-	 * @return bool True when the option can be changed for the stream
80
-	 * @since 11.0.0
81
-	 */
82
-	public function isDefaultEnabledMail() {
83
-		return false;
84
-	}
78
+    /**
79
+     * @return bool True when the option can be changed for the stream
80
+     * @since 11.0.0
81
+     */
82
+    public function isDefaultEnabledMail() {
83
+        return false;
84
+    }
85 85
 }
Please login to merge, or discard this patch.
apps/files_sharing/lib/Activity/Settings/ShareActivitySettings.php 1 patch
Indentation   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -27,21 +27,21 @@
 block discarded – undo
27 27
 use OCP\IL10N;
28 28
 
29 29
 abstract class ShareActivitySettings extends ActivitySettings {
30
-	/** @var IL10N */
31
-	protected $l;
30
+    /** @var IL10N */
31
+    protected $l;
32 32
 
33
-	/**
34
-	 * @param IL10N $l
35
-	 */
36
-	public function __construct(IL10N $l) {
37
-		$this->l = $l;
38
-	}
33
+    /**
34
+     * @param IL10N $l
35
+     */
36
+    public function __construct(IL10N $l) {
37
+        $this->l = $l;
38
+    }
39 39
 
40
-	public function getGroupIdentifier() {
41
-		return 'files';
42
-	}
40
+    public function getGroupIdentifier() {
41
+        return 'files';
42
+    }
43 43
 
44
-	public function getGroupName() {
45
-		return $this->l->t('Files');
46
-	}
44
+    public function getGroupName() {
45
+        return $this->l->t('Files');
46
+    }
47 47
 }
Please login to merge, or discard this patch.
apps/dav/lib/Upload/ChunkingPlugin.php 1 patch
Indentation   +83 added lines, -83 removed lines patch added patch discarded remove patch
@@ -35,97 +35,97 @@
 block discarded – undo
35 35
 
36 36
 class ChunkingPlugin extends ServerPlugin {
37 37
 
38
-	/** @var Server */
39
-	private $server;
40
-	/** @var FutureFile */
41
-	private $sourceNode;
38
+    /** @var Server */
39
+    private $server;
40
+    /** @var FutureFile */
41
+    private $sourceNode;
42 42
 
43
-	/**
44
-	 * @inheritdoc
45
-	 */
46
-	public function initialize(Server $server) {
47
-		$server->on('beforeMove', [$this, 'beforeMove']);
48
-		$this->server = $server;
49
-	}
43
+    /**
44
+     * @inheritdoc
45
+     */
46
+    public function initialize(Server $server) {
47
+        $server->on('beforeMove', [$this, 'beforeMove']);
48
+        $this->server = $server;
49
+    }
50 50
 
51
-	/**
52
-	 * @param string $sourcePath source path
53
-	 * @param string $destination destination path
54
-	 * @return bool|void
55
-	 * @throws BadRequest
56
-	 * @throws NotFound
57
-	 */
58
-	public function beforeMove($sourcePath, $destination) {
59
-		$this->sourceNode = $this->server->tree->getNodeForPath($sourcePath);
60
-		if (!$this->sourceNode instanceof FutureFile) {
61
-			// skip handling as the source is not a chunked FutureFile
62
-			return;
63
-		}
51
+    /**
52
+     * @param string $sourcePath source path
53
+     * @param string $destination destination path
54
+     * @return bool|void
55
+     * @throws BadRequest
56
+     * @throws NotFound
57
+     */
58
+    public function beforeMove($sourcePath, $destination) {
59
+        $this->sourceNode = $this->server->tree->getNodeForPath($sourcePath);
60
+        if (!$this->sourceNode instanceof FutureFile) {
61
+            // skip handling as the source is not a chunked FutureFile
62
+            return;
63
+        }
64 64
 
65
-		try {
66
-			/** @var INode $destinationNode */
67
-			$destinationNode = $this->server->tree->getNodeForPath($destination);
68
-			if ($destinationNode instanceof Directory) {
69
-				throw new BadRequest("The given destination $destination is a directory.");
70
-			}
71
-		} catch (NotFound $e) {
72
-			// If the destination does not exist yet it's not a directory either ;)
73
-		}
65
+        try {
66
+            /** @var INode $destinationNode */
67
+            $destinationNode = $this->server->tree->getNodeForPath($destination);
68
+            if ($destinationNode instanceof Directory) {
69
+                throw new BadRequest("The given destination $destination is a directory.");
70
+            }
71
+        } catch (NotFound $e) {
72
+            // If the destination does not exist yet it's not a directory either ;)
73
+        }
74 74
 
75
-		$this->verifySize();
76
-		return $this->performMove($sourcePath, $destination);
77
-	}
75
+        $this->verifySize();
76
+        return $this->performMove($sourcePath, $destination);
77
+    }
78 78
 
79
-	/**
80
-	 * Move handler for future file.
81
-	 *
82
-	 * This overrides the default move behavior to prevent Sabre
83
-	 * to delete the target file before moving. Because deleting would
84
-	 * lose the file id and metadata.
85
-	 *
86
-	 * @param string $path source path
87
-	 * @param string $destination destination path
88
-	 * @return bool|void false to stop handling, void to skip this handler
89
-	 */
90
-	public function performMove($path, $destination) {
91
-		$fileExists = $this->server->tree->nodeExists($destination);
92
-		// do a move manually, skipping Sabre's default "delete" for existing nodes
93
-		try {
94
-			$this->server->tree->move($path, $destination);
95
-		} catch (Forbidden $e) {
96
-			$sourceNode = $this->server->tree->getNodeForPath($path);
97
-			if ($sourceNode instanceof FutureFile) {
98
-				$sourceNode->delete();
99
-			}
100
-			throw $e;
101
-		}
79
+    /**
80
+     * Move handler for future file.
81
+     *
82
+     * This overrides the default move behavior to prevent Sabre
83
+     * to delete the target file before moving. Because deleting would
84
+     * lose the file id and metadata.
85
+     *
86
+     * @param string $path source path
87
+     * @param string $destination destination path
88
+     * @return bool|void false to stop handling, void to skip this handler
89
+     */
90
+    public function performMove($path, $destination) {
91
+        $fileExists = $this->server->tree->nodeExists($destination);
92
+        // do a move manually, skipping Sabre's default "delete" for existing nodes
93
+        try {
94
+            $this->server->tree->move($path, $destination);
95
+        } catch (Forbidden $e) {
96
+            $sourceNode = $this->server->tree->getNodeForPath($path);
97
+            if ($sourceNode instanceof FutureFile) {
98
+                $sourceNode->delete();
99
+            }
100
+            throw $e;
101
+        }
102 102
 
103
-		// trigger all default events (copied from CorePlugin::move)
104
-		$this->server->emit('afterMove', [$path, $destination]);
105
-		$this->server->emit('afterUnbind', [$path]);
106
-		$this->server->emit('afterBind', [$destination]);
103
+        // trigger all default events (copied from CorePlugin::move)
104
+        $this->server->emit('afterMove', [$path, $destination]);
105
+        $this->server->emit('afterUnbind', [$path]);
106
+        $this->server->emit('afterBind', [$destination]);
107 107
 
108
-		$response = $this->server->httpResponse;
109
-		$response->setHeader('Content-Length', '0');
110
-		$response->setStatus($fileExists ? 204 : 201);
108
+        $response = $this->server->httpResponse;
109
+        $response->setHeader('Content-Length', '0');
110
+        $response->setStatus($fileExists ? 204 : 201);
111 111
 
112
-		return false;
113
-	}
112
+        return false;
113
+    }
114 114
 
115
-	/**
116
-	 * @throws BadRequest
117
-	 */
118
-	private function verifySize() {
119
-		$expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length');
120
-		if ($expectedSize === null) {
121
-			return;
122
-		}
123
-		$actualSize = $this->sourceNode->getSize();
115
+    /**
116
+     * @throws BadRequest
117
+     */
118
+    private function verifySize() {
119
+        $expectedSize = $this->server->httpRequest->getHeader('OC-Total-Length');
120
+        if ($expectedSize === null) {
121
+            return;
122
+        }
123
+        $actualSize = $this->sourceNode->getSize();
124 124
 
125
-		// casted to string because cast to float cause equality for non equal numbers
126
-		// and integer has the problem of limited size on 32 bit systems
127
-		if ((string)$expectedSize !== (string)$actualSize) {
128
-			throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes");
129
-		}
130
-	}
125
+        // casted to string because cast to float cause equality for non equal numbers
126
+        // and integer has the problem of limited size on 32 bit systems
127
+        if ((string)$expectedSize !== (string)$actualSize) {
128
+            throw new BadRequest("Chunks on server do not sum up to $expectedSize but to $actualSize bytes");
129
+        }
130
+    }
131 131
 }
Please login to merge, or discard this patch.