Passed
Push — master ( 078203...c81798 )
by Joas
14:40 queued 14s
created
lib/private/Share20/Hooks.php 1 patch
Indentation   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -23,11 +23,11 @@
 block discarded – undo
23 23
 namespace OC\Share20;
24 24
 
25 25
 class Hooks {
26
-	public static function post_deleteUser($arguments) {
27
-		\OC::$server->getShareManager()->userDeleted($arguments['uid']);
28
-	}
26
+    public static function post_deleteUser($arguments) {
27
+        \OC::$server->getShareManager()->userDeleted($arguments['uid']);
28
+    }
29 29
 
30
-	public static function post_deleteGroup($arguments) {
31
-		\OC::$server->getShareManager()->groupDeleted($arguments['gid']);
32
-	}
30
+    public static function post_deleteGroup($arguments) {
31
+        \OC::$server->getShareManager()->groupDeleted($arguments['gid']);
32
+    }
33 33
 }
Please login to merge, or discard this patch.
apps/settings/lib/SetupChecks/PhpOutputBuffering.php 1 patch
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -28,16 +28,16 @@
 block discarded – undo
28 28
 namespace OCA\Settings\SetupChecks;
29 29
 
30 30
 class PhpOutputBuffering {
31
-	public function description(): string {
32
-		return 'PHP configuration option output_buffering must be disabled';
33
-	}
31
+    public function description(): string {
32
+        return 'PHP configuration option output_buffering must be disabled';
33
+    }
34 34
 
35
-	public function severity(): string {
36
-		return 'error';
37
-	}
35
+    public function severity(): string {
36
+        return 'error';
37
+    }
38 38
 
39
-	public function run(): bool {
40
-		$value = trim(ini_get('output_buffering'));
41
-		return $value === '' || $value === '0';
42
-	}
39
+    public function run(): bool {
40
+        $value = trim(ini_get('output_buffering'));
41
+        return $value === '' || $value === '0';
42
+    }
43 43
 }
Please login to merge, or discard this patch.
apps/settings/lib/SetupChecks/PhpDefaultCharset.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -28,15 +28,15 @@
 block discarded – undo
28 28
 namespace OCA\Settings\SetupChecks;
29 29
 
30 30
 class PhpDefaultCharset {
31
-	public function description(): string {
32
-		return 'PHP configuration option default_charset should be UTF-8';
33
-	}
31
+    public function description(): string {
32
+        return 'PHP configuration option default_charset should be UTF-8';
33
+    }
34 34
 
35
-	public function severity(): string {
36
-		return 'warning';
37
-	}
35
+    public function severity(): string {
36
+        return 'warning';
37
+    }
38 38
 
39
-	public function run(): bool {
40
-		return strtoupper(trim(ini_get('default_charset'))) === 'UTF-8';
41
-	}
39
+    public function run(): bool {
40
+        return strtoupper(trim(ini_get('default_charset'))) === 'UTF-8';
41
+    }
42 42
 }
Please login to merge, or discard this patch.
apps/files/lib/Event/LoadAdditionalScriptsEvent.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -34,13 +34,13 @@
 block discarded – undo
34 34
  * @since 17.0.0
35 35
  */
36 36
 class LoadAdditionalScriptsEvent extends Event {
37
-	private $hiddenFields = [];
37
+    private $hiddenFields = [];
38 38
 
39
-	public function addHiddenField(string $name, string $value): void {
40
-		$this->hiddenFields[$name] = $value;
41
-	}
39
+    public function addHiddenField(string $name, string $value): void {
40
+        $this->hiddenFields[$name] = $value;
41
+    }
42 42
 
43
-	public function getHiddenFields(): array {
44
-		return $this->hiddenFields;
45
-	}
43
+    public function getHiddenFields(): array {
44
+        return $this->hiddenFields;
45
+    }
46 46
 }
Please login to merge, or discard this patch.
lib/private/Security/FeaturePolicy/FeaturePolicyManager.php 1 patch
Indentation   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -31,48 +31,48 @@
 block discarded – undo
31 31
 use OCP\Security\FeaturePolicy\AddFeaturePolicyEvent;
32 32
 
33 33
 class FeaturePolicyManager {
34
-	/** @var EmptyFeaturePolicy[] */
35
-	private $policies = [];
34
+    /** @var EmptyFeaturePolicy[] */
35
+    private $policies = [];
36 36
 
37
-	/** @var IEventDispatcher */
38
-	private $dispatcher;
37
+    /** @var IEventDispatcher */
38
+    private $dispatcher;
39 39
 
40
-	public function __construct(IEventDispatcher $dispatcher) {
41
-		$this->dispatcher = $dispatcher;
42
-	}
40
+    public function __construct(IEventDispatcher $dispatcher) {
41
+        $this->dispatcher = $dispatcher;
42
+    }
43 43
 
44
-	public function addDefaultPolicy(EmptyFeaturePolicy $policy): void {
45
-		$this->policies[] = $policy;
46
-	}
44
+    public function addDefaultPolicy(EmptyFeaturePolicy $policy): void {
45
+        $this->policies[] = $policy;
46
+    }
47 47
 
48
-	public function getDefaultPolicy(): FeaturePolicy {
49
-		$event = new AddFeaturePolicyEvent($this);
50
-		$this->dispatcher->dispatchTyped($event);
48
+    public function getDefaultPolicy(): FeaturePolicy {
49
+        $event = new AddFeaturePolicyEvent($this);
50
+        $this->dispatcher->dispatchTyped($event);
51 51
 
52
-		$defaultPolicy = new FeaturePolicy();
53
-		foreach ($this->policies as $policy) {
54
-			$defaultPolicy = $this->mergePolicies($defaultPolicy, $policy);
55
-		}
56
-		return $defaultPolicy;
57
-	}
52
+        $defaultPolicy = new FeaturePolicy();
53
+        foreach ($this->policies as $policy) {
54
+            $defaultPolicy = $this->mergePolicies($defaultPolicy, $policy);
55
+        }
56
+        return $defaultPolicy;
57
+    }
58 58
 
59
-	/**
60
-	 * Merges the first given policy with the second one
61
-	 *
62
-	 */
63
-	public function mergePolicies(FeaturePolicy $defaultPolicy,
64
-								  EmptyFeaturePolicy $originalPolicy): FeaturePolicy {
65
-		foreach ((object)(array)$originalPolicy as $name => $value) {
66
-			$setter = 'set' . ucfirst($name);
67
-			if (\is_array($value)) {
68
-				$getter = 'get' . ucfirst($name);
69
-				$currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : [];
70
-				$defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value))));
71
-			} elseif (\is_bool($value)) {
72
-				$defaultPolicy->$setter($value);
73
-			}
74
-		}
59
+    /**
60
+     * Merges the first given policy with the second one
61
+     *
62
+     */
63
+    public function mergePolicies(FeaturePolicy $defaultPolicy,
64
+                                    EmptyFeaturePolicy $originalPolicy): FeaturePolicy {
65
+        foreach ((object)(array)$originalPolicy as $name => $value) {
66
+            $setter = 'set' . ucfirst($name);
67
+            if (\is_array($value)) {
68
+                $getter = 'get' . ucfirst($name);
69
+                $currentValues = \is_array($defaultPolicy->$getter()) ? $defaultPolicy->$getter() : [];
70
+                $defaultPolicy->$setter(\array_values(\array_unique(\array_merge($currentValues, $value))));
71
+            } elseif (\is_bool($value)) {
72
+                $defaultPolicy->$setter($value);
73
+            }
74
+        }
75 75
 
76
-		return $defaultPolicy;
77
-	}
76
+        return $defaultPolicy;
77
+    }
78 78
 }
Please login to merge, or discard this patch.
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.