Completed
Push — master ( 478b01...80afc2 )
by
unknown
23:07
created
lib/public/IRequestId.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -28,12 +28,12 @@
 block discarded – undo
28 28
  * @since 24.0.0
29 29
  */
30 30
 interface IRequestId {
31
-	/**
32
-	 * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
33
-	 * If `mod_unique_id` is installed this value will be taken.
34
-	 *
35
-	 * @return string
36
-	 * @since 24.0.0
37
-	 */
38
-	public function getId(): string;
31
+    /**
32
+     * Returns an ID for the request, value is not guaranteed to be unique and is mostly meant for logging
33
+     * If `mod_unique_id` is installed this value will be taken.
34
+     *
35
+     * @return string
36
+     * @since 24.0.0
37
+     */
38
+    public function getId(): string;
39 39
 }
Please login to merge, or discard this patch.
apps/settings/lib/Controller/AuthSettingsController.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		}
147 147
 
148 148
 		if (mb_strlen($name) > 128) {
149
-			$name = mb_substr($name, 0, 120) . '…';
149
+			$name = mb_substr($name, 0, 120).'…';
150 150
 		}
151 151
 
152 152
 		$token = $this->generateRandomDeviceToken();
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 		}
247 247
 
248 248
 		if (mb_strlen($name) > 128) {
249
-			$name = mb_substr($name, 0, 120) . '…';
249
+			$name = mb_substr($name, 0, 120).'…';
250 250
 		}
251 251
 
252 252
 		if ($token instanceof INamedToken && $name !== $currentName) {
Please login to merge, or discard this patch.
Indentation   +250 added lines, -250 removed lines patch added patch discarded remove patch
@@ -32,254 +32,254 @@
 block discarded – undo
32 32
 use Psr\Log\LoggerInterface;
33 33
 
34 34
 class AuthSettingsController extends Controller {
35
-	/** @var IProvider */
36
-	private $tokenProvider;
37
-
38
-	/** @var RemoteWipe */
39
-	private $remoteWipe;
40
-
41
-	/**
42
-	 * @param string $appName
43
-	 * @param IRequest $request
44
-	 * @param IProvider $tokenProvider
45
-	 * @param ISession $session
46
-	 * @param ISecureRandom $random
47
-	 * @param string|null $userId
48
-	 * @param IUserSession $userSession
49
-	 * @param IManager $activityManager
50
-	 * @param RemoteWipe $remoteWipe
51
-	 * @param LoggerInterface $logger
52
-	 */
53
-	public function __construct(
54
-		string $appName,
55
-		IRequest $request,
56
-		IProvider $tokenProvider,
57
-		private ISession $session,
58
-		private ISecureRandom $random,
59
-		private ?string $userId,
60
-		private IUserSession $userSession,
61
-		private IManager $activityManager,
62
-		RemoteWipe $remoteWipe,
63
-		private LoggerInterface $logger,
64
-	) {
65
-		parent::__construct($appName, $request);
66
-		$this->tokenProvider = $tokenProvider;
67
-		$this->remoteWipe = $remoteWipe;
68
-	}
69
-
70
-	/**
71
-	 * @NoSubAdminRequired
72
-	 *
73
-	 * @param string $name
74
-	 * @return JSONResponse
75
-	 */
76
-	#[NoAdminRequired]
77
-	#[PasswordConfirmationRequired]
78
-	public function create($name) {
79
-		if ($this->checkAppToken()) {
80
-			return $this->getServiceNotAvailableResponse();
81
-		}
82
-
83
-		try {
84
-			$sessionId = $this->session->getId();
85
-		} catch (SessionNotAvailableException $ex) {
86
-			return $this->getServiceNotAvailableResponse();
87
-		}
88
-		if ($this->userSession->getImpersonatingUserID() !== null) {
89
-			return $this->getServiceNotAvailableResponse();
90
-		}
91
-
92
-		try {
93
-			$sessionToken = $this->tokenProvider->getToken($sessionId);
94
-			$loginName = $sessionToken->getLoginName();
95
-			try {
96
-				$password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
97
-			} catch (PasswordlessTokenException $ex) {
98
-				$password = null;
99
-			}
100
-		} catch (InvalidTokenException $ex) {
101
-			return $this->getServiceNotAvailableResponse();
102
-		}
103
-
104
-		if (mb_strlen($name) > 128) {
105
-			$name = mb_substr($name, 0, 120) . '…';
106
-		}
107
-
108
-		$token = $this->generateRandomDeviceToken();
109
-		$deviceToken = $this->tokenProvider->generateToken($token, $this->userId, $loginName, $password, $name, IToken::PERMANENT_TOKEN);
110
-		$tokenData = $deviceToken->jsonSerialize();
111
-		$tokenData['canDelete'] = true;
112
-		$tokenData['canRename'] = true;
113
-
114
-		$this->publishActivity(Provider::APP_TOKEN_CREATED, $deviceToken->getId(), ['name' => $deviceToken->getName()]);
115
-
116
-		return new JSONResponse([
117
-			'token' => $token,
118
-			'loginName' => $loginName,
119
-			'deviceToken' => $tokenData,
120
-		]);
121
-	}
122
-
123
-	/**
124
-	 * @return JSONResponse
125
-	 */
126
-	private function getServiceNotAvailableResponse() {
127
-		$resp = new JSONResponse();
128
-		$resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
129
-		return $resp;
130
-	}
131
-
132
-	/**
133
-	 * Return a 25 digit device password
134
-	 *
135
-	 * Example: AbCdE-fGhJk-MnPqR-sTwXy-23456
136
-	 *
137
-	 * @return string
138
-	 */
139
-	private function generateRandomDeviceToken() {
140
-		$groups = [];
141
-		for ($i = 0; $i < 5; $i++) {
142
-			$groups[] = $this->random->generate(5, ISecureRandom::CHAR_HUMAN_READABLE);
143
-		}
144
-		return implode('-', $groups);
145
-	}
146
-
147
-	private function checkAppToken(): bool {
148
-		return $this->session->exists('app_password');
149
-	}
150
-
151
-	/**
152
-	 * @NoSubAdminRequired
153
-	 *
154
-	 * @param int $id
155
-	 * @return array|JSONResponse
156
-	 */
157
-	#[NoAdminRequired]
158
-	public function destroy($id) {
159
-		if ($this->checkAppToken()) {
160
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
161
-		}
162
-
163
-		try {
164
-			$token = $this->findTokenByIdAndUser($id);
165
-		} catch (WipeTokenException $e) {
166
-			//continue as we can destroy tokens in wipe
167
-			$token = $e->getToken();
168
-		} catch (InvalidTokenException $e) {
169
-			return new JSONResponse([], Http::STATUS_NOT_FOUND);
170
-		}
171
-
172
-		$this->tokenProvider->invalidateTokenById($this->userId, $token->getId());
173
-		$this->publishActivity(Provider::APP_TOKEN_DELETED, $token->getId(), ['name' => $token->getName()]);
174
-		return [];
175
-	}
176
-
177
-	/**
178
-	 * @NoSubAdminRequired
179
-	 *
180
-	 * @param int $id
181
-	 * @param array $scope
182
-	 * @param string $name
183
-	 * @return array|JSONResponse
184
-	 */
185
-	#[NoAdminRequired]
186
-	public function update($id, array $scope, string $name) {
187
-		if ($this->checkAppToken()) {
188
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
189
-		}
190
-
191
-		try {
192
-			$token = $this->findTokenByIdAndUser($id);
193
-		} catch (InvalidTokenException $e) {
194
-			return new JSONResponse([], Http::STATUS_NOT_FOUND);
195
-		}
196
-
197
-		$currentName = $token->getName();
198
-
199
-		if ($scope !== $token->getScopeAsArray()) {
200
-			$token->setScope([IToken::SCOPE_FILESYSTEM => $scope[IToken::SCOPE_FILESYSTEM]]);
201
-			$this->publishActivity($scope[IToken::SCOPE_FILESYSTEM] ? Provider::APP_TOKEN_FILESYSTEM_GRANTED : Provider::APP_TOKEN_FILESYSTEM_REVOKED, $token->getId(), ['name' => $currentName]);
202
-		}
203
-
204
-		if (mb_strlen($name) > 128) {
205
-			$name = mb_substr($name, 0, 120) . '…';
206
-		}
207
-
208
-		if ($token instanceof INamedToken && $name !== $currentName) {
209
-			$token->setName($name);
210
-			$this->publishActivity(Provider::APP_TOKEN_RENAMED, $token->getId(), ['name' => $currentName, 'newName' => $name]);
211
-		}
212
-
213
-		$this->tokenProvider->updateToken($token);
214
-		return [];
215
-	}
216
-
217
-	/**
218
-	 * @param string $subject
219
-	 * @param int $id
220
-	 * @param array $parameters
221
-	 */
222
-	private function publishActivity(string $subject, int $id, array $parameters = []): void {
223
-		$event = $this->activityManager->generateEvent();
224
-		$event->setApp('settings')
225
-			->setType('security')
226
-			->setAffectedUser($this->userId)
227
-			->setAuthor($this->userId)
228
-			->setSubject($subject, $parameters)
229
-			->setObject('app_token', $id, 'App Password');
230
-
231
-		try {
232
-			$this->activityManager->publish($event);
233
-		} catch (BadMethodCallException $e) {
234
-			$this->logger->warning('could not publish activity', ['exception' => $e]);
235
-		}
236
-	}
237
-
238
-	/**
239
-	 * Find a token by given id and check if uid for current session belongs to this token
240
-	 *
241
-	 * @param int $id
242
-	 * @return IToken
243
-	 * @throws InvalidTokenException
244
-	 */
245
-	private function findTokenByIdAndUser(int $id): IToken {
246
-		try {
247
-			$token = $this->tokenProvider->getTokenById($id);
248
-		} catch (ExpiredTokenException $e) {
249
-			$token = $e->getToken();
250
-		}
251
-		if ($token->getUID() !== $this->userId) {
252
-			/** @psalm-suppress DeprecatedClass We have to throw the OC version so both OC and OCP catches catch it */
253
-			throw new OcInvalidTokenException('This token does not belong to you!');
254
-		}
255
-		return $token;
256
-	}
257
-
258
-	/**
259
-	 * @NoSubAdminRequired
260
-	 *
261
-	 * @param int $id
262
-	 * @return JSONResponse
263
-	 * @throws InvalidTokenException
264
-	 * @throws ExpiredTokenException
265
-	 */
266
-	#[NoAdminRequired]
267
-	#[PasswordConfirmationRequired]
268
-	public function wipe(int $id): JSONResponse {
269
-		if ($this->checkAppToken()) {
270
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
271
-		}
272
-
273
-		try {
274
-			$token = $this->findTokenByIdAndUser($id);
275
-		} catch (InvalidTokenException $e) {
276
-			return new JSONResponse([], Http::STATUS_NOT_FOUND);
277
-		}
278
-
279
-		if (!$this->remoteWipe->markTokenForWipe($token)) {
280
-			return new JSONResponse([], Http::STATUS_BAD_REQUEST);
281
-		}
282
-
283
-		return new JSONResponse([]);
284
-	}
35
+    /** @var IProvider */
36
+    private $tokenProvider;
37
+
38
+    /** @var RemoteWipe */
39
+    private $remoteWipe;
40
+
41
+    /**
42
+     * @param string $appName
43
+     * @param IRequest $request
44
+     * @param IProvider $tokenProvider
45
+     * @param ISession $session
46
+     * @param ISecureRandom $random
47
+     * @param string|null $userId
48
+     * @param IUserSession $userSession
49
+     * @param IManager $activityManager
50
+     * @param RemoteWipe $remoteWipe
51
+     * @param LoggerInterface $logger
52
+     */
53
+    public function __construct(
54
+        string $appName,
55
+        IRequest $request,
56
+        IProvider $tokenProvider,
57
+        private ISession $session,
58
+        private ISecureRandom $random,
59
+        private ?string $userId,
60
+        private IUserSession $userSession,
61
+        private IManager $activityManager,
62
+        RemoteWipe $remoteWipe,
63
+        private LoggerInterface $logger,
64
+    ) {
65
+        parent::__construct($appName, $request);
66
+        $this->tokenProvider = $tokenProvider;
67
+        $this->remoteWipe = $remoteWipe;
68
+    }
69
+
70
+    /**
71
+     * @NoSubAdminRequired
72
+     *
73
+     * @param string $name
74
+     * @return JSONResponse
75
+     */
76
+    #[NoAdminRequired]
77
+    #[PasswordConfirmationRequired]
78
+    public function create($name) {
79
+        if ($this->checkAppToken()) {
80
+            return $this->getServiceNotAvailableResponse();
81
+        }
82
+
83
+        try {
84
+            $sessionId = $this->session->getId();
85
+        } catch (SessionNotAvailableException $ex) {
86
+            return $this->getServiceNotAvailableResponse();
87
+        }
88
+        if ($this->userSession->getImpersonatingUserID() !== null) {
89
+            return $this->getServiceNotAvailableResponse();
90
+        }
91
+
92
+        try {
93
+            $sessionToken = $this->tokenProvider->getToken($sessionId);
94
+            $loginName = $sessionToken->getLoginName();
95
+            try {
96
+                $password = $this->tokenProvider->getPassword($sessionToken, $sessionId);
97
+            } catch (PasswordlessTokenException $ex) {
98
+                $password = null;
99
+            }
100
+        } catch (InvalidTokenException $ex) {
101
+            return $this->getServiceNotAvailableResponse();
102
+        }
103
+
104
+        if (mb_strlen($name) > 128) {
105
+            $name = mb_substr($name, 0, 120) . '…';
106
+        }
107
+
108
+        $token = $this->generateRandomDeviceToken();
109
+        $deviceToken = $this->tokenProvider->generateToken($token, $this->userId, $loginName, $password, $name, IToken::PERMANENT_TOKEN);
110
+        $tokenData = $deviceToken->jsonSerialize();
111
+        $tokenData['canDelete'] = true;
112
+        $tokenData['canRename'] = true;
113
+
114
+        $this->publishActivity(Provider::APP_TOKEN_CREATED, $deviceToken->getId(), ['name' => $deviceToken->getName()]);
115
+
116
+        return new JSONResponse([
117
+            'token' => $token,
118
+            'loginName' => $loginName,
119
+            'deviceToken' => $tokenData,
120
+        ]);
121
+    }
122
+
123
+    /**
124
+     * @return JSONResponse
125
+     */
126
+    private function getServiceNotAvailableResponse() {
127
+        $resp = new JSONResponse();
128
+        $resp->setStatus(Http::STATUS_SERVICE_UNAVAILABLE);
129
+        return $resp;
130
+    }
131
+
132
+    /**
133
+     * Return a 25 digit device password
134
+     *
135
+     * Example: AbCdE-fGhJk-MnPqR-sTwXy-23456
136
+     *
137
+     * @return string
138
+     */
139
+    private function generateRandomDeviceToken() {
140
+        $groups = [];
141
+        for ($i = 0; $i < 5; $i++) {
142
+            $groups[] = $this->random->generate(5, ISecureRandom::CHAR_HUMAN_READABLE);
143
+        }
144
+        return implode('-', $groups);
145
+    }
146
+
147
+    private function checkAppToken(): bool {
148
+        return $this->session->exists('app_password');
149
+    }
150
+
151
+    /**
152
+     * @NoSubAdminRequired
153
+     *
154
+     * @param int $id
155
+     * @return array|JSONResponse
156
+     */
157
+    #[NoAdminRequired]
158
+    public function destroy($id) {
159
+        if ($this->checkAppToken()) {
160
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
161
+        }
162
+
163
+        try {
164
+            $token = $this->findTokenByIdAndUser($id);
165
+        } catch (WipeTokenException $e) {
166
+            //continue as we can destroy tokens in wipe
167
+            $token = $e->getToken();
168
+        } catch (InvalidTokenException $e) {
169
+            return new JSONResponse([], Http::STATUS_NOT_FOUND);
170
+        }
171
+
172
+        $this->tokenProvider->invalidateTokenById($this->userId, $token->getId());
173
+        $this->publishActivity(Provider::APP_TOKEN_DELETED, $token->getId(), ['name' => $token->getName()]);
174
+        return [];
175
+    }
176
+
177
+    /**
178
+     * @NoSubAdminRequired
179
+     *
180
+     * @param int $id
181
+     * @param array $scope
182
+     * @param string $name
183
+     * @return array|JSONResponse
184
+     */
185
+    #[NoAdminRequired]
186
+    public function update($id, array $scope, string $name) {
187
+        if ($this->checkAppToken()) {
188
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
189
+        }
190
+
191
+        try {
192
+            $token = $this->findTokenByIdAndUser($id);
193
+        } catch (InvalidTokenException $e) {
194
+            return new JSONResponse([], Http::STATUS_NOT_FOUND);
195
+        }
196
+
197
+        $currentName = $token->getName();
198
+
199
+        if ($scope !== $token->getScopeAsArray()) {
200
+            $token->setScope([IToken::SCOPE_FILESYSTEM => $scope[IToken::SCOPE_FILESYSTEM]]);
201
+            $this->publishActivity($scope[IToken::SCOPE_FILESYSTEM] ? Provider::APP_TOKEN_FILESYSTEM_GRANTED : Provider::APP_TOKEN_FILESYSTEM_REVOKED, $token->getId(), ['name' => $currentName]);
202
+        }
203
+
204
+        if (mb_strlen($name) > 128) {
205
+            $name = mb_substr($name, 0, 120) . '…';
206
+        }
207
+
208
+        if ($token instanceof INamedToken && $name !== $currentName) {
209
+            $token->setName($name);
210
+            $this->publishActivity(Provider::APP_TOKEN_RENAMED, $token->getId(), ['name' => $currentName, 'newName' => $name]);
211
+        }
212
+
213
+        $this->tokenProvider->updateToken($token);
214
+        return [];
215
+    }
216
+
217
+    /**
218
+     * @param string $subject
219
+     * @param int $id
220
+     * @param array $parameters
221
+     */
222
+    private function publishActivity(string $subject, int $id, array $parameters = []): void {
223
+        $event = $this->activityManager->generateEvent();
224
+        $event->setApp('settings')
225
+            ->setType('security')
226
+            ->setAffectedUser($this->userId)
227
+            ->setAuthor($this->userId)
228
+            ->setSubject($subject, $parameters)
229
+            ->setObject('app_token', $id, 'App Password');
230
+
231
+        try {
232
+            $this->activityManager->publish($event);
233
+        } catch (BadMethodCallException $e) {
234
+            $this->logger->warning('could not publish activity', ['exception' => $e]);
235
+        }
236
+    }
237
+
238
+    /**
239
+     * Find a token by given id and check if uid for current session belongs to this token
240
+     *
241
+     * @param int $id
242
+     * @return IToken
243
+     * @throws InvalidTokenException
244
+     */
245
+    private function findTokenByIdAndUser(int $id): IToken {
246
+        try {
247
+            $token = $this->tokenProvider->getTokenById($id);
248
+        } catch (ExpiredTokenException $e) {
249
+            $token = $e->getToken();
250
+        }
251
+        if ($token->getUID() !== $this->userId) {
252
+            /** @psalm-suppress DeprecatedClass We have to throw the OC version so both OC and OCP catches catch it */
253
+            throw new OcInvalidTokenException('This token does not belong to you!');
254
+        }
255
+        return $token;
256
+    }
257
+
258
+    /**
259
+     * @NoSubAdminRequired
260
+     *
261
+     * @param int $id
262
+     * @return JSONResponse
263
+     * @throws InvalidTokenException
264
+     * @throws ExpiredTokenException
265
+     */
266
+    #[NoAdminRequired]
267
+    #[PasswordConfirmationRequired]
268
+    public function wipe(int $id): JSONResponse {
269
+        if ($this->checkAppToken()) {
270
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
271
+        }
272
+
273
+        try {
274
+            $token = $this->findTokenByIdAndUser($id);
275
+        } catch (InvalidTokenException $e) {
276
+            return new JSONResponse([], Http::STATUS_NOT_FOUND);
277
+        }
278
+
279
+        if (!$this->remoteWipe->markTokenForWipe($token)) {
280
+            return new JSONResponse([], Http::STATUS_BAD_REQUEST);
281
+        }
282
+
283
+        return new JSONResponse([]);
284
+    }
285 285
 }
Please login to merge, or discard this patch.
lib/public/Files/Events/InvalidateMountCacheEvent.php 1 patch
Indentation   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -32,24 +32,24 @@
 block discarded – undo
32 32
  * @since 24.0.0
33 33
  */
34 34
 class InvalidateMountCacheEvent extends Event {
35
-	private ?IUser $user;
35
+    private ?IUser $user;
36 36
 
37
-	/**
38
-	 * @param IUser|null $user user
39
-	 *
40
-	 * @since 24.0.0
41
-	 */
42
-	public function __construct(?IUser $user) {
43
-		parent::__construct();
44
-		$this->user = $user;
45
-	}
37
+    /**
38
+     * @param IUser|null $user user
39
+     *
40
+     * @since 24.0.0
41
+     */
42
+    public function __construct(?IUser $user) {
43
+        parent::__construct();
44
+        $this->user = $user;
45
+    }
46 46
 
47
-	/**
48
-	 * @return IUser|null user
49
-	 *
50
-	 * @since 24.0.0
51
-	 */
52
-	public function getUser(): ?IUser {
53
-		return $this->user;
54
-	}
47
+    /**
48
+     * @return IUser|null user
49
+     *
50
+     * @since 24.0.0
51
+     */
52
+    public function getUser(): ?IUser {
53
+        return $this->user;
54
+    }
55 55
 }
Please login to merge, or discard this patch.
apps/oauth2/lib/Migration/Version010402Date20190107124745.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -32,22 +32,22 @@
 block discarded – undo
32 32
 
33 33
 class Version010402Date20190107124745 extends SimpleMigrationStep {
34 34
 
35
-	/**
36
-	 * @param IOutput $output
37
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38
-	 * @param array $options
39
-	 * @return null|ISchemaWrapper
40
-	 */
41
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
42
-		/** @var ISchemaWrapper $schema */
43
-		$schema = $schemaClosure();
35
+    /**
36
+     * @param IOutput $output
37
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
38
+     * @param array $options
39
+     * @return null|ISchemaWrapper
40
+     */
41
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) {
42
+        /** @var ISchemaWrapper $schema */
43
+        $schema = $schemaClosure();
44 44
 
45
-		// During an ownCloud migration, the client_identifier column identifier might not exist yet.
46
-		if ($schema->getTable('oauth2_clients')->hasColumn('client_identifier')) {
47
-			$table = $schema->getTable('oauth2_clients');
48
-			$table->dropIndex('oauth2_client_id_idx');
49
-			$table->addUniqueIndex(['client_identifier'], 'oauth2_client_id_idx');
50
-			return $schema;
51
-		}
52
-	}
45
+        // During an ownCloud migration, the client_identifier column identifier might not exist yet.
46
+        if ($schema->getTable('oauth2_clients')->hasColumn('client_identifier')) {
47
+            $table = $schema->getTable('oauth2_clients');
48
+            $table->dropIndex('oauth2_client_id_idx');
49
+            $table->addUniqueIndex(['client_identifier'], 'oauth2_client_id_idx');
50
+            return $schema;
51
+        }
52
+    }
53 53
 }
Please login to merge, or discard this patch.
lib/private/DB/QueryBuilder/FunctionBuilder/FunctionBuilder.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 	}
48 48
 
49 49
 	public function md5($input): IQueryFunction {
50
-		return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')');
50
+		return new QueryFunction('MD5('.$this->helper->quoteColumnName($input).')');
51 51
 	}
52 52
 
53 53
 	public function concat($x, ...$expr): IQueryFunction {
@@ -61,64 +61,64 @@  discard block
 block discarded – undo
61 61
 
62 62
 	public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
63 63
 		$separator = $this->connection->quote($separator);
64
-		return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ' SEPARATOR ' . $separator . ')');
64
+		return new QueryFunction('GROUP_CONCAT('.$this->helper->quoteColumnName($expr).' SEPARATOR '.$separator.')');
65 65
 	}
66 66
 
67 67
 	public function substring($input, $start, $length = null): IQueryFunction {
68 68
 		if ($length) {
69
-			return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')');
69
+			return new QueryFunction('SUBSTR('.$this->helper->quoteColumnName($input).', '.$this->helper->quoteColumnName($start).', '.$this->helper->quoteColumnName($length).')');
70 70
 		} else {
71
-			return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')');
71
+			return new QueryFunction('SUBSTR('.$this->helper->quoteColumnName($input).', '.$this->helper->quoteColumnName($start).')');
72 72
 		}
73 73
 	}
74 74
 
75 75
 	public function sum($field): IQueryFunction {
76
-		return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')');
76
+		return new QueryFunction('SUM('.$this->helper->quoteColumnName($field).')');
77 77
 	}
78 78
 
79 79
 	public function lower($field): IQueryFunction {
80
-		return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')');
80
+		return new QueryFunction('LOWER('.$this->helper->quoteColumnName($field).')');
81 81
 	}
82 82
 
83 83
 	public function add($x, $y): IQueryFunction {
84
-		return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y));
84
+		return new QueryFunction($this->helper->quoteColumnName($x).' + '.$this->helper->quoteColumnName($y));
85 85
 	}
86 86
 
87 87
 	public function subtract($x, $y): IQueryFunction {
88
-		return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
88
+		return new QueryFunction($this->helper->quoteColumnName($x).' - '.$this->helper->quoteColumnName($y));
89 89
 	}
90 90
 
91 91
 	public function count($count = '', $alias = ''): IQueryFunction {
92
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
92
+		$alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : '';
93 93
 		$quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count);
94
-		return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
94
+		return new QueryFunction('COUNT('.$quotedName.')'.$alias);
95 95
 	}
96 96
 
97 97
 	public function octetLength($field, $alias = ''): IQueryFunction {
98
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
98
+		$alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : '';
99 99
 		$quotedName = $this->helper->quoteColumnName($field);
100
-		return new QueryFunction('OCTET_LENGTH(' . $quotedName . ')' . $alias);
100
+		return new QueryFunction('OCTET_LENGTH('.$quotedName.')'.$alias);
101 101
 	}
102 102
 
103 103
 	public function charLength($field, $alias = ''): IQueryFunction {
104
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
104
+		$alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : '';
105 105
 		$quotedName = $this->helper->quoteColumnName($field);
106
-		return new QueryFunction('CHAR_LENGTH(' . $quotedName . ')' . $alias);
106
+		return new QueryFunction('CHAR_LENGTH('.$quotedName.')'.$alias);
107 107
 	}
108 108
 
109 109
 	public function max($field): IQueryFunction {
110
-		return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')');
110
+		return new QueryFunction('MAX('.$this->helper->quoteColumnName($field).')');
111 111
 	}
112 112
 
113 113
 	public function min($field): IQueryFunction {
114
-		return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')');
114
+		return new QueryFunction('MIN('.$this->helper->quoteColumnName($field).')');
115 115
 	}
116 116
 
117 117
 	public function greatest($x, $y): IQueryFunction {
118
-		return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
118
+		return new QueryFunction('GREATEST('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')');
119 119
 	}
120 120
 
121 121
 	public function least($x, $y): IQueryFunction {
122
-		return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
122
+		return new QueryFunction('LEAST('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')');
123 123
 	}
124 124
 }
Please login to merge, or discard this patch.
Indentation   +90 added lines, -90 removed lines patch added patch discarded remove patch
@@ -14,94 +14,94 @@
 block discarded – undo
14 14
 use OCP\IDBConnection;
15 15
 
16 16
 class FunctionBuilder implements IFunctionBuilder {
17
-	/** @var IDBConnection|Connection */
18
-	protected $connection;
19
-
20
-	/** @var IQueryBuilder */
21
-	protected $queryBuilder;
22
-
23
-	/** @var QuoteHelper */
24
-	protected $helper;
25
-
26
-	public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder, QuoteHelper $helper) {
27
-		$this->connection = $connection;
28
-		$this->queryBuilder = $queryBuilder;
29
-		$this->helper = $helper;
30
-	}
31
-
32
-	public function md5($input): IQueryFunction {
33
-		return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')');
34
-	}
35
-
36
-	public function concat($x, ...$expr): IQueryFunction {
37
-		$args = func_get_args();
38
-		$list = [];
39
-		foreach ($args as $item) {
40
-			$list[] = $this->helper->quoteColumnName($item);
41
-		}
42
-		return new QueryFunction(sprintf('CONCAT(%s)', implode(', ', $list)));
43
-	}
44
-
45
-	public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
46
-		$separator = $this->connection->quote($separator);
47
-		return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ' SEPARATOR ' . $separator . ')');
48
-	}
49
-
50
-	public function substring($input, $start, $length = null): IQueryFunction {
51
-		if ($length) {
52
-			return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')');
53
-		} else {
54
-			return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')');
55
-		}
56
-	}
57
-
58
-	public function sum($field): IQueryFunction {
59
-		return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')');
60
-	}
61
-
62
-	public function lower($field): IQueryFunction {
63
-		return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')');
64
-	}
65
-
66
-	public function add($x, $y): IQueryFunction {
67
-		return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y));
68
-	}
69
-
70
-	public function subtract($x, $y): IQueryFunction {
71
-		return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
72
-	}
73
-
74
-	public function count($count = '', $alias = ''): IQueryFunction {
75
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
76
-		$quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count);
77
-		return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
78
-	}
79
-
80
-	public function octetLength($field, $alias = ''): IQueryFunction {
81
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
82
-		$quotedName = $this->helper->quoteColumnName($field);
83
-		return new QueryFunction('OCTET_LENGTH(' . $quotedName . ')' . $alias);
84
-	}
85
-
86
-	public function charLength($field, $alias = ''): IQueryFunction {
87
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
88
-		$quotedName = $this->helper->quoteColumnName($field);
89
-		return new QueryFunction('CHAR_LENGTH(' . $quotedName . ')' . $alias);
90
-	}
91
-
92
-	public function max($field): IQueryFunction {
93
-		return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')');
94
-	}
95
-
96
-	public function min($field): IQueryFunction {
97
-		return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')');
98
-	}
99
-
100
-	public function greatest($x, $y): IQueryFunction {
101
-		return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
102
-	}
103
-
104
-	public function least($x, $y): IQueryFunction {
105
-		return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
106
-	}
17
+    /** @var IDBConnection|Connection */
18
+    protected $connection;
19
+
20
+    /** @var IQueryBuilder */
21
+    protected $queryBuilder;
22
+
23
+    /** @var QuoteHelper */
24
+    protected $helper;
25
+
26
+    public function __construct(IDBConnection $connection, IQueryBuilder $queryBuilder, QuoteHelper $helper) {
27
+        $this->connection = $connection;
28
+        $this->queryBuilder = $queryBuilder;
29
+        $this->helper = $helper;
30
+    }
31
+
32
+    public function md5($input): IQueryFunction {
33
+        return new QueryFunction('MD5(' . $this->helper->quoteColumnName($input) . ')');
34
+    }
35
+
36
+    public function concat($x, ...$expr): IQueryFunction {
37
+        $args = func_get_args();
38
+        $list = [];
39
+        foreach ($args as $item) {
40
+            $list[] = $this->helper->quoteColumnName($item);
41
+        }
42
+        return new QueryFunction(sprintf('CONCAT(%s)', implode(', ', $list)));
43
+    }
44
+
45
+    public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
46
+        $separator = $this->connection->quote($separator);
47
+        return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ' SEPARATOR ' . $separator . ')');
48
+    }
49
+
50
+    public function substring($input, $start, $length = null): IQueryFunction {
51
+        if ($length) {
52
+            return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ', ' . $this->helper->quoteColumnName($length) . ')');
53
+        } else {
54
+            return new QueryFunction('SUBSTR(' . $this->helper->quoteColumnName($input) . ', ' . $this->helper->quoteColumnName($start) . ')');
55
+        }
56
+    }
57
+
58
+    public function sum($field): IQueryFunction {
59
+        return new QueryFunction('SUM(' . $this->helper->quoteColumnName($field) . ')');
60
+    }
61
+
62
+    public function lower($field): IQueryFunction {
63
+        return new QueryFunction('LOWER(' . $this->helper->quoteColumnName($field) . ')');
64
+    }
65
+
66
+    public function add($x, $y): IQueryFunction {
67
+        return new QueryFunction($this->helper->quoteColumnName($x) . ' + ' . $this->helper->quoteColumnName($y));
68
+    }
69
+
70
+    public function subtract($x, $y): IQueryFunction {
71
+        return new QueryFunction($this->helper->quoteColumnName($x) . ' - ' . $this->helper->quoteColumnName($y));
72
+    }
73
+
74
+    public function count($count = '', $alias = ''): IQueryFunction {
75
+        $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
76
+        $quotedName = $count === '' ? '*' : $this->helper->quoteColumnName($count);
77
+        return new QueryFunction('COUNT(' . $quotedName . ')' . $alias);
78
+    }
79
+
80
+    public function octetLength($field, $alias = ''): IQueryFunction {
81
+        $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
82
+        $quotedName = $this->helper->quoteColumnName($field);
83
+        return new QueryFunction('OCTET_LENGTH(' . $quotedName . ')' . $alias);
84
+    }
85
+
86
+    public function charLength($field, $alias = ''): IQueryFunction {
87
+        $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
88
+        $quotedName = $this->helper->quoteColumnName($field);
89
+        return new QueryFunction('CHAR_LENGTH(' . $quotedName . ')' . $alias);
90
+    }
91
+
92
+    public function max($field): IQueryFunction {
93
+        return new QueryFunction('MAX(' . $this->helper->quoteColumnName($field) . ')');
94
+    }
95
+
96
+    public function min($field): IQueryFunction {
97
+        return new QueryFunction('MIN(' . $this->helper->quoteColumnName($field) . ')');
98
+    }
99
+
100
+    public function greatest($x, $y): IQueryFunction {
101
+        return new QueryFunction('GREATEST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
102
+    }
103
+
104
+    public function least($x, $y): IQueryFunction {
105
+        return new QueryFunction('LEAST(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
106
+    }
107 107
 }
Please login to merge, or discard this patch.
lib/private/DB/QueryBuilder/FunctionBuilder/SqliteFunctionBuilder.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -38,26 +38,26 @@
 block discarded – undo
38 38
 
39 39
 	public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
40 40
 		$separator = $this->connection->quote($separator);
41
-		return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ', ' . $separator . ')');
41
+		return new QueryFunction('GROUP_CONCAT('.$this->helper->quoteColumnName($expr).', '.$separator.')');
42 42
 	}
43 43
 
44 44
 	public function greatest($x, $y): IQueryFunction {
45
-		return new QueryFunction('MAX(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
45
+		return new QueryFunction('MAX('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')');
46 46
 	}
47 47
 
48 48
 	public function least($x, $y): IQueryFunction {
49
-		return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
49
+		return new QueryFunction('MIN('.$this->helper->quoteColumnName($x).', '.$this->helper->quoteColumnName($y).')');
50 50
 	}
51 51
 
52 52
 	public function octetLength($field, $alias = ''): IQueryFunction {
53
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
53
+		$alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : '';
54 54
 		$quotedName = $this->helper->quoteColumnName($field);
55
-		return new QueryFunction('LENGTH(CAST(' . $quotedName . ' as BLOB))' . $alias);
55
+		return new QueryFunction('LENGTH(CAST('.$quotedName.' as BLOB))'.$alias);
56 56
 	}
57 57
 
58 58
 	public function charLength($field, $alias = ''): IQueryFunction {
59
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
59
+		$alias = $alias ? (' AS '.$this->helper->quoteColumnName($alias)) : '';
60 60
 		$quotedName = $this->helper->quoteColumnName($field);
61
-		return new QueryFunction('LENGTH(' . $quotedName . ')' . $alias);
61
+		return new QueryFunction('LENGTH('.$quotedName.')'.$alias);
62 62
 	}
63 63
 }
Please login to merge, or discard this patch.
Indentation   +33 added lines, -33 removed lines patch added patch discarded remove patch
@@ -10,37 +10,37 @@
 block discarded – undo
10 10
 use OCP\DB\QueryBuilder\IQueryFunction;
11 11
 
12 12
 class SqliteFunctionBuilder extends FunctionBuilder {
13
-	public function concat($x, ...$expr): IQueryFunction {
14
-		$args = func_get_args();
15
-		$list = [];
16
-		foreach ($args as $item) {
17
-			$list[] = $this->helper->quoteColumnName($item);
18
-		}
19
-		return new QueryFunction(sprintf('(%s)', implode(' || ', $list)));
20
-	}
21
-
22
-	public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
23
-		$separator = $this->connection->quote($separator);
24
-		return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ', ' . $separator . ')');
25
-	}
26
-
27
-	public function greatest($x, $y): IQueryFunction {
28
-		return new QueryFunction('MAX(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
29
-	}
30
-
31
-	public function least($x, $y): IQueryFunction {
32
-		return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
33
-	}
34
-
35
-	public function octetLength($field, $alias = ''): IQueryFunction {
36
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
37
-		$quotedName = $this->helper->quoteColumnName($field);
38
-		return new QueryFunction('LENGTH(CAST(' . $quotedName . ' as BLOB))' . $alias);
39
-	}
40
-
41
-	public function charLength($field, $alias = ''): IQueryFunction {
42
-		$alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
43
-		$quotedName = $this->helper->quoteColumnName($field);
44
-		return new QueryFunction('LENGTH(' . $quotedName . ')' . $alias);
45
-	}
13
+    public function concat($x, ...$expr): IQueryFunction {
14
+        $args = func_get_args();
15
+        $list = [];
16
+        foreach ($args as $item) {
17
+            $list[] = $this->helper->quoteColumnName($item);
18
+        }
19
+        return new QueryFunction(sprintf('(%s)', implode(' || ', $list)));
20
+    }
21
+
22
+    public function groupConcat($expr, ?string $separator = ','): IQueryFunction {
23
+        $separator = $this->connection->quote($separator);
24
+        return new QueryFunction('GROUP_CONCAT(' . $this->helper->quoteColumnName($expr) . ', ' . $separator . ')');
25
+    }
26
+
27
+    public function greatest($x, $y): IQueryFunction {
28
+        return new QueryFunction('MAX(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
29
+    }
30
+
31
+    public function least($x, $y): IQueryFunction {
32
+        return new QueryFunction('MIN(' . $this->helper->quoteColumnName($x) . ', ' . $this->helper->quoteColumnName($y) . ')');
33
+    }
34
+
35
+    public function octetLength($field, $alias = ''): IQueryFunction {
36
+        $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
37
+        $quotedName = $this->helper->quoteColumnName($field);
38
+        return new QueryFunction('LENGTH(CAST(' . $quotedName . ' as BLOB))' . $alias);
39
+    }
40
+
41
+    public function charLength($field, $alias = ''): IQueryFunction {
42
+        $alias = $alias ? (' AS ' . $this->helper->quoteColumnName($alias)) : '';
43
+        $quotedName = $this->helper->quoteColumnName($field);
44
+        return new QueryFunction('LENGTH(' . $quotedName . ')' . $alias);
45
+    }
46 46
 }
Please login to merge, or discard this patch.
apps/user_ldap/lib/Migration/Version1120Date20210917155206.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -143,7 +143,7 @@
 block discarded – undo
143 143
 
144 144
 	protected function emitUnassign(string $oldId, bool $pre): void {
145 145
 		if ($this->userManager instanceof PublicEmitter) {
146
-			$this->userManager->emit('\OC\User', $pre ? 'pre' : 'post' . 'UnassignedUserId', [$oldId]);
146
+			$this->userManager->emit('\OC\User', $pre ? 'pre' : 'post'.'UnassignedUserId', [$oldId]);
147 147
 		}
148 148
 	}
149 149
 
Please login to merge, or discard this patch.
Indentation   +106 added lines, -106 removed lines patch added patch discarded remove patch
@@ -22,110 +22,110 @@
 block discarded – undo
22 22
 
23 23
 class Version1120Date20210917155206 extends SimpleMigrationStep {
24 24
 
25
-	public function __construct(
26
-		private IDBConnection $dbc,
27
-		private IUserManager $userManager,
28
-		private LoggerInterface $logger,
29
-	) {
30
-	}
31
-
32
-	public function getName() {
33
-		return 'Adjust LDAP user and group id column lengths to match server lengths';
34
-	}
35
-
36
-	/**
37
-	 * @param IOutput $output
38
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
-	 * @param array $options
40
-	 */
41
-	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
42
-		// ensure that there is no user or group id longer than 64char in LDAP table
43
-		$this->handleIDs('ldap_group_mapping', false);
44
-		$this->handleIDs('ldap_user_mapping', true);
45
-	}
46
-
47
-	/**
48
-	 * @param IOutput $output
49
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
50
-	 * @param array $options
51
-	 * @return null|ISchemaWrapper
52
-	 */
53
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
54
-		/** @var ISchemaWrapper $schema */
55
-		$schema = $schemaClosure();
56
-
57
-		$changeSchema = false;
58
-		foreach (['ldap_user_mapping', 'ldap_group_mapping'] as $tableName) {
59
-			$table = $schema->getTable($tableName);
60
-			$column = $table->getColumn('owncloud_name');
61
-			if ($column->getLength() > 64) {
62
-				$column->setLength(64);
63
-				$changeSchema = true;
64
-			}
65
-		}
66
-
67
-		return $changeSchema ? $schema : null;
68
-	}
69
-
70
-	protected function handleIDs(string $table, bool $emitHooks) {
71
-		$select = $this->getSelectQuery($table);
72
-		$update = $this->getUpdateQuery($table);
73
-
74
-		$result = $select->executeQuery();
75
-		while ($row = $result->fetch()) {
76
-			$newId = hash('sha256', $row['owncloud_name'], false);
77
-			if ($emitHooks) {
78
-				$this->emitUnassign($row['owncloud_name'], true);
79
-			}
80
-			$update->setParameter('uuid', $row['directory_uuid']);
81
-			$update->setParameter('newId', $newId);
82
-			try {
83
-				$update->executeStatement();
84
-				if ($emitHooks) {
85
-					$this->emitUnassign($row['owncloud_name'], false);
86
-					$this->emitAssign($newId);
87
-				}
88
-			} catch (Exception $e) {
89
-				$this->logger->error('Failed to shorten owncloud_name "{oldId}" to "{newId}" (UUID: "{uuid}" of {table})',
90
-					[
91
-						'app' => 'user_ldap',
92
-						'oldId' => $row['owncloud_name'],
93
-						'newId' => $newId,
94
-						'uuid' => $row['directory_uuid'],
95
-						'table' => $table,
96
-						'exception' => $e,
97
-					]
98
-				);
99
-			}
100
-		}
101
-		$result->closeCursor();
102
-	}
103
-
104
-	protected function getSelectQuery(string $table): IQueryBuilder {
105
-		$qb = $this->dbc->getQueryBuilder();
106
-		$qb->select('owncloud_name', 'directory_uuid')
107
-			->from($table)
108
-			->where($qb->expr()->gt($qb->func()->octetLength('owncloud_name'), $qb->createNamedParameter('64'), IQueryBuilder::PARAM_INT));
109
-		return $qb;
110
-	}
111
-
112
-	protected function getUpdateQuery(string $table): IQueryBuilder {
113
-		$qb = $this->dbc->getQueryBuilder();
114
-		$qb->update($table)
115
-			->set('owncloud_name', $qb->createParameter('newId'))
116
-			->where($qb->expr()->eq('directory_uuid', $qb->createParameter('uuid')));
117
-		return $qb;
118
-	}
119
-
120
-	protected function emitUnassign(string $oldId, bool $pre): void {
121
-		if ($this->userManager instanceof PublicEmitter) {
122
-			$this->userManager->emit('\OC\User', $pre ? 'pre' : 'post' . 'UnassignedUserId', [$oldId]);
123
-		}
124
-	}
125
-
126
-	protected function emitAssign(string $newId): void {
127
-		if ($this->userManager instanceof PublicEmitter) {
128
-			$this->userManager->emit('\OC\User', 'assignedUserId', [$newId]);
129
-		}
130
-	}
25
+    public function __construct(
26
+        private IDBConnection $dbc,
27
+        private IUserManager $userManager,
28
+        private LoggerInterface $logger,
29
+    ) {
30
+    }
31
+
32
+    public function getName() {
33
+        return 'Adjust LDAP user and group id column lengths to match server lengths';
34
+    }
35
+
36
+    /**
37
+     * @param IOutput $output
38
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
39
+     * @param array $options
40
+     */
41
+    public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
42
+        // ensure that there is no user or group id longer than 64char in LDAP table
43
+        $this->handleIDs('ldap_group_mapping', false);
44
+        $this->handleIDs('ldap_user_mapping', true);
45
+    }
46
+
47
+    /**
48
+     * @param IOutput $output
49
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
50
+     * @param array $options
51
+     * @return null|ISchemaWrapper
52
+     */
53
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
54
+        /** @var ISchemaWrapper $schema */
55
+        $schema = $schemaClosure();
56
+
57
+        $changeSchema = false;
58
+        foreach (['ldap_user_mapping', 'ldap_group_mapping'] as $tableName) {
59
+            $table = $schema->getTable($tableName);
60
+            $column = $table->getColumn('owncloud_name');
61
+            if ($column->getLength() > 64) {
62
+                $column->setLength(64);
63
+                $changeSchema = true;
64
+            }
65
+        }
66
+
67
+        return $changeSchema ? $schema : null;
68
+    }
69
+
70
+    protected function handleIDs(string $table, bool $emitHooks) {
71
+        $select = $this->getSelectQuery($table);
72
+        $update = $this->getUpdateQuery($table);
73
+
74
+        $result = $select->executeQuery();
75
+        while ($row = $result->fetch()) {
76
+            $newId = hash('sha256', $row['owncloud_name'], false);
77
+            if ($emitHooks) {
78
+                $this->emitUnassign($row['owncloud_name'], true);
79
+            }
80
+            $update->setParameter('uuid', $row['directory_uuid']);
81
+            $update->setParameter('newId', $newId);
82
+            try {
83
+                $update->executeStatement();
84
+                if ($emitHooks) {
85
+                    $this->emitUnassign($row['owncloud_name'], false);
86
+                    $this->emitAssign($newId);
87
+                }
88
+            } catch (Exception $e) {
89
+                $this->logger->error('Failed to shorten owncloud_name "{oldId}" to "{newId}" (UUID: "{uuid}" of {table})',
90
+                    [
91
+                        'app' => 'user_ldap',
92
+                        'oldId' => $row['owncloud_name'],
93
+                        'newId' => $newId,
94
+                        'uuid' => $row['directory_uuid'],
95
+                        'table' => $table,
96
+                        'exception' => $e,
97
+                    ]
98
+                );
99
+            }
100
+        }
101
+        $result->closeCursor();
102
+    }
103
+
104
+    protected function getSelectQuery(string $table): IQueryBuilder {
105
+        $qb = $this->dbc->getQueryBuilder();
106
+        $qb->select('owncloud_name', 'directory_uuid')
107
+            ->from($table)
108
+            ->where($qb->expr()->gt($qb->func()->octetLength('owncloud_name'), $qb->createNamedParameter('64'), IQueryBuilder::PARAM_INT));
109
+        return $qb;
110
+    }
111
+
112
+    protected function getUpdateQuery(string $table): IQueryBuilder {
113
+        $qb = $this->dbc->getQueryBuilder();
114
+        $qb->update($table)
115
+            ->set('owncloud_name', $qb->createParameter('newId'))
116
+            ->where($qb->expr()->eq('directory_uuid', $qb->createParameter('uuid')));
117
+        return $qb;
118
+    }
119
+
120
+    protected function emitUnassign(string $oldId, bool $pre): void {
121
+        if ($this->userManager instanceof PublicEmitter) {
122
+            $this->userManager->emit('\OC\User', $pre ? 'pre' : 'post' . 'UnassignedUserId', [$oldId]);
123
+        }
124
+    }
125
+
126
+    protected function emitAssign(string $newId): void {
127
+        if ($this->userManager instanceof PublicEmitter) {
128
+            $this->userManager->emit('\OC\User', 'assignedUserId', [$newId]);
129
+        }
130
+    }
131 131
 }
Please login to merge, or discard this patch.
lib/private/Files/ObjectStore/SwiftFactory.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 	}
92 92
 
93 93
 	private function getCachedToken(string $cacheKey) {
94
-		$cachedTokenString = $this->cache->get($cacheKey . '/token');
94
+		$cachedTokenString = $this->cache->get($cacheKey.'/token');
95 95
 		if ($cachedTokenString) {
96 96
 			return json_decode($cachedTokenString, true);
97 97
 		} else {
@@ -117,7 +117,7 @@  discard block
 block discarded – undo
117 117
 		}
118 118
 
119 119
 		$this->params['cachedToken'] = $value;
120
-		$this->cache->set($cacheKey . '/token', json_encode($value));
120
+		$this->cache->set($cacheKey.'/token', json_encode($value));
121 121
 	}
122 122
 
123 123
 	/**
@@ -148,7 +148,7 @@  discard block
 block discarded – undo
148 148
 		}
149 149
 		$this->params = array_merge(self::DEFAULT_OPTIONS, $this->params);
150 150
 
151
-		$cacheKey = $userName . '@' . $this->params['url'] . '/' . $this->params['container'];
151
+		$cacheKey = $userName.'@'.$this->params['url'].'/'.$this->params['container'];
152 152
 		$token = $this->getCachedToken($cacheKey);
153 153
 		$this->params['cachedToken'] = $token;
154 154
 
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
 			if ($authService instanceof IdentityV3Service) {
185 185
 				$token = $authService->generateTokenFromCache($cachedToken);
186 186
 				if (\is_null($token->catalog)) {
187
-					$this->logger->warning('Invalid cached token for swift, no catalog set: ' . json_encode($cachedToken));
187
+					$this->logger->warning('Invalid cached token for swift, no catalog set: '.json_encode($cachedToken));
188 188
 				} elseif ($token->hasExpired()) {
189 189
 					$this->logger->debug('Cached token for swift expired');
190 190
 				} else {
@@ -278,7 +278,7 @@  discard block
 block discarded – undo
278 278
 		} catch (ConnectException $e) {
279 279
 			/** @var RequestInterface $request */
280 280
 			$request = $e->getRequest();
281
-			$host = $request->getUri()->getHost() . ':' . $request->getUri()->getPort();
281
+			$host = $request->getUri()->getHost().':'.$request->getUri()->getPort();
282 282
 			$this->logger->error("Can't connect to object storage server at $host", ['exception' => $e]);
283 283
 			throw new StorageNotAvailableException("Can't connect to object storage server at $host", StorageNotAvailableException::STATUS_ERROR, $e);
284 284
 		}
Please login to merge, or discard this patch.
Indentation   +208 added lines, -208 removed lines patch added patch discarded remove patch
@@ -28,235 +28,235 @@
 block discarded – undo
28 28
 use Psr\Log\LoggerInterface;
29 29
 
30 30
 class SwiftFactory {
31
-	private $cache;
32
-	private $params;
33
-	/** @var Container|null */
34
-	private $container = null;
35
-	private LoggerInterface $logger;
31
+    private $cache;
32
+    private $params;
33
+    /** @var Container|null */
34
+    private $container = null;
35
+    private LoggerInterface $logger;
36 36
 
37
-	public const DEFAULT_OPTIONS = [
38
-		'autocreate' => false,
39
-		'urlType' => 'publicURL',
40
-		'catalogName' => 'swift',
41
-		'catalogType' => 'object-store'
42
-	];
37
+    public const DEFAULT_OPTIONS = [
38
+        'autocreate' => false,
39
+        'urlType' => 'publicURL',
40
+        'catalogName' => 'swift',
41
+        'catalogType' => 'object-store'
42
+    ];
43 43
 
44
-	public function __construct(ICache $cache, array $params, LoggerInterface $logger) {
45
-		$this->cache = $cache;
46
-		$this->params = $params;
47
-		$this->logger = $logger;
48
-	}
44
+    public function __construct(ICache $cache, array $params, LoggerInterface $logger) {
45
+        $this->cache = $cache;
46
+        $this->params = $params;
47
+        $this->logger = $logger;
48
+    }
49 49
 
50
-	/**
51
-	 * Gets currently cached token id
52
-	 *
53
-	 * @return string
54
-	 * @throws StorageAuthException
55
-	 */
56
-	public function getCachedTokenId() {
57
-		if (!isset($this->params['cachedToken'])) {
58
-			throw new StorageAuthException('Unauthenticated ObjectStore connection');
59
-		}
50
+    /**
51
+     * Gets currently cached token id
52
+     *
53
+     * @return string
54
+     * @throws StorageAuthException
55
+     */
56
+    public function getCachedTokenId() {
57
+        if (!isset($this->params['cachedToken'])) {
58
+            throw new StorageAuthException('Unauthenticated ObjectStore connection');
59
+        }
60 60
 
61
-		// Is it V2 token?
62
-		if (isset($this->params['cachedToken']['token'])) {
63
-			return $this->params['cachedToken']['token']['id'];
64
-		}
61
+        // Is it V2 token?
62
+        if (isset($this->params['cachedToken']['token'])) {
63
+            return $this->params['cachedToken']['token']['id'];
64
+        }
65 65
 
66
-		return $this->params['cachedToken']['id'];
67
-	}
66
+        return $this->params['cachedToken']['id'];
67
+    }
68 68
 
69
-	private function getCachedToken(string $cacheKey) {
70
-		$cachedTokenString = $this->cache->get($cacheKey . '/token');
71
-		if ($cachedTokenString) {
72
-			return json_decode($cachedTokenString, true);
73
-		} else {
74
-			return null;
75
-		}
76
-	}
69
+    private function getCachedToken(string $cacheKey) {
70
+        $cachedTokenString = $this->cache->get($cacheKey . '/token');
71
+        if ($cachedTokenString) {
72
+            return json_decode($cachedTokenString, true);
73
+        } else {
74
+            return null;
75
+        }
76
+    }
77 77
 
78
-	private function cacheToken(Token $token, string $serviceUrl, string $cacheKey) {
79
-		if ($token instanceof \OpenStack\Identity\v3\Models\Token) {
80
-			// for v3 the catalog is cached as part of the token, so no need to cache $serviceUrl separately
81
-			$value = $token->export();
82
-		} else {
83
-			/** @var \OpenStack\Identity\v2\Models\Token $token */
84
-			$value = [
85
-				'serviceUrl' => $serviceUrl,
86
-				'token' => [
87
-					'issued_at' => $token->issuedAt->format('c'),
88
-					'expires' => $token->expires->format('c'),
89
-					'id' => $token->id,
90
-					'tenant' => $token->tenant
91
-				]
92
-			];
93
-		}
78
+    private function cacheToken(Token $token, string $serviceUrl, string $cacheKey) {
79
+        if ($token instanceof \OpenStack\Identity\v3\Models\Token) {
80
+            // for v3 the catalog is cached as part of the token, so no need to cache $serviceUrl separately
81
+            $value = $token->export();
82
+        } else {
83
+            /** @var \OpenStack\Identity\v2\Models\Token $token */
84
+            $value = [
85
+                'serviceUrl' => $serviceUrl,
86
+                'token' => [
87
+                    'issued_at' => $token->issuedAt->format('c'),
88
+                    'expires' => $token->expires->format('c'),
89
+                    'id' => $token->id,
90
+                    'tenant' => $token->tenant
91
+                ]
92
+            ];
93
+        }
94 94
 
95
-		$this->params['cachedToken'] = $value;
96
-		$this->cache->set($cacheKey . '/token', json_encode($value));
97
-	}
95
+        $this->params['cachedToken'] = $value;
96
+        $this->cache->set($cacheKey . '/token', json_encode($value));
97
+    }
98 98
 
99
-	/**
100
-	 * @return OpenStack
101
-	 * @throws StorageAuthException
102
-	 */
103
-	private function getClient() {
104
-		if (isset($this->params['bucket'])) {
105
-			$this->params['container'] = $this->params['bucket'];
106
-		}
107
-		if (!isset($this->params['container'])) {
108
-			$this->params['container'] = 'nextcloud';
109
-		}
110
-		if (isset($this->params['user']) && is_array($this->params['user'])) {
111
-			$userName = $this->params['user']['name'];
112
-		} else {
113
-			if (!isset($this->params['username']) && isset($this->params['user'])) {
114
-				$this->params['username'] = $this->params['user'];
115
-			}
116
-			$userName = $this->params['username'];
117
-		}
118
-		if (!isset($this->params['tenantName']) && isset($this->params['tenant'])) {
119
-			$this->params['tenantName'] = $this->params['tenant'];
120
-		}
121
-		if (isset($this->params['domain'])) {
122
-			$this->params['scope']['project']['name'] = $this->params['tenant'];
123
-			$this->params['scope']['project']['domain']['name'] = $this->params['domain'];
124
-		}
125
-		$this->params = array_merge(self::DEFAULT_OPTIONS, $this->params);
99
+    /**
100
+     * @return OpenStack
101
+     * @throws StorageAuthException
102
+     */
103
+    private function getClient() {
104
+        if (isset($this->params['bucket'])) {
105
+            $this->params['container'] = $this->params['bucket'];
106
+        }
107
+        if (!isset($this->params['container'])) {
108
+            $this->params['container'] = 'nextcloud';
109
+        }
110
+        if (isset($this->params['user']) && is_array($this->params['user'])) {
111
+            $userName = $this->params['user']['name'];
112
+        } else {
113
+            if (!isset($this->params['username']) && isset($this->params['user'])) {
114
+                $this->params['username'] = $this->params['user'];
115
+            }
116
+            $userName = $this->params['username'];
117
+        }
118
+        if (!isset($this->params['tenantName']) && isset($this->params['tenant'])) {
119
+            $this->params['tenantName'] = $this->params['tenant'];
120
+        }
121
+        if (isset($this->params['domain'])) {
122
+            $this->params['scope']['project']['name'] = $this->params['tenant'];
123
+            $this->params['scope']['project']['domain']['name'] = $this->params['domain'];
124
+        }
125
+        $this->params = array_merge(self::DEFAULT_OPTIONS, $this->params);
126 126
 
127
-		$cacheKey = $userName . '@' . $this->params['url'] . '/' . $this->params['container'];
128
-		$token = $this->getCachedToken($cacheKey);
129
-		$this->params['cachedToken'] = $token;
127
+        $cacheKey = $userName . '@' . $this->params['url'] . '/' . $this->params['container'];
128
+        $token = $this->getCachedToken($cacheKey);
129
+        $this->params['cachedToken'] = $token;
130 130
 
131
-		$httpClient = new Client([
132
-			'base_uri' => TransportUtils::normalizeUrl($this->params['url']),
133
-			'handler' => HandlerStack::create()
134
-		]);
131
+        $httpClient = new Client([
132
+            'base_uri' => TransportUtils::normalizeUrl($this->params['url']),
133
+            'handler' => HandlerStack::create()
134
+        ]);
135 135
 
136
-		if (isset($this->params['user']) && is_array($this->params['user']) && isset($this->params['user']['name'])) {
137
-			if (!isset($this->params['scope'])) {
138
-				throw new StorageAuthException('Scope has to be defined for V3 requests');
139
-			}
136
+        if (isset($this->params['user']) && is_array($this->params['user']) && isset($this->params['user']['name'])) {
137
+            if (!isset($this->params['scope'])) {
138
+                throw new StorageAuthException('Scope has to be defined for V3 requests');
139
+            }
140 140
 
141
-			return $this->auth(IdentityV3Service::factory($httpClient), $cacheKey);
142
-		} else {
143
-			return $this->auth(SwiftV2CachingAuthService::factory($httpClient), $cacheKey);
144
-		}
145
-	}
141
+            return $this->auth(IdentityV3Service::factory($httpClient), $cacheKey);
142
+        } else {
143
+            return $this->auth(SwiftV2CachingAuthService::factory($httpClient), $cacheKey);
144
+        }
145
+    }
146 146
 
147
-	/**
148
-	 * @param IdentityV2Service|IdentityV3Service $authService
149
-	 * @param string $cacheKey
150
-	 * @return OpenStack
151
-	 * @throws StorageAuthException
152
-	 */
153
-	private function auth($authService, string $cacheKey) {
154
-		$this->params['identityService'] = $authService;
155
-		$this->params['authUrl'] = $this->params['url'];
147
+    /**
148
+     * @param IdentityV2Service|IdentityV3Service $authService
149
+     * @param string $cacheKey
150
+     * @return OpenStack
151
+     * @throws StorageAuthException
152
+     */
153
+    private function auth($authService, string $cacheKey) {
154
+        $this->params['identityService'] = $authService;
155
+        $this->params['authUrl'] = $this->params['url'];
156 156
 
157
-		$cachedToken = $this->params['cachedToken'];
158
-		$hasValidCachedToken = false;
159
-		if (\is_array($cachedToken)) {
160
-			if ($authService instanceof IdentityV3Service) {
161
-				$token = $authService->generateTokenFromCache($cachedToken);
162
-				if (\is_null($token->catalog)) {
163
-					$this->logger->warning('Invalid cached token for swift, no catalog set: ' . json_encode($cachedToken));
164
-				} elseif ($token->hasExpired()) {
165
-					$this->logger->debug('Cached token for swift expired');
166
-				} else {
167
-					$hasValidCachedToken = true;
168
-				}
169
-			} else {
170
-				try {
171
-					/** @var \OpenStack\Identity\v2\Models\Token $token */
172
-					$token = $authService->model(\OpenStack\Identity\v2\Models\Token::class, $cachedToken['token']);
173
-					$now = new \DateTimeImmutable('now');
174
-					if ($token->expires > $now) {
175
-						$hasValidCachedToken = true;
176
-						$this->params['v2cachedToken'] = $token;
177
-						$this->params['v2serviceUrl'] = $cachedToken['serviceUrl'];
178
-					} else {
179
-						$this->logger->debug('Cached token for swift expired');
180
-					}
181
-				} catch (\Exception $e) {
182
-					$this->logger->error($e->getMessage(), ['exception' => $e]);
183
-				}
184
-			}
185
-		}
157
+        $cachedToken = $this->params['cachedToken'];
158
+        $hasValidCachedToken = false;
159
+        if (\is_array($cachedToken)) {
160
+            if ($authService instanceof IdentityV3Service) {
161
+                $token = $authService->generateTokenFromCache($cachedToken);
162
+                if (\is_null($token->catalog)) {
163
+                    $this->logger->warning('Invalid cached token for swift, no catalog set: ' . json_encode($cachedToken));
164
+                } elseif ($token->hasExpired()) {
165
+                    $this->logger->debug('Cached token for swift expired');
166
+                } else {
167
+                    $hasValidCachedToken = true;
168
+                }
169
+            } else {
170
+                try {
171
+                    /** @var \OpenStack\Identity\v2\Models\Token $token */
172
+                    $token = $authService->model(\OpenStack\Identity\v2\Models\Token::class, $cachedToken['token']);
173
+                    $now = new \DateTimeImmutable('now');
174
+                    if ($token->expires > $now) {
175
+                        $hasValidCachedToken = true;
176
+                        $this->params['v2cachedToken'] = $token;
177
+                        $this->params['v2serviceUrl'] = $cachedToken['serviceUrl'];
178
+                    } else {
179
+                        $this->logger->debug('Cached token for swift expired');
180
+                    }
181
+                } catch (\Exception $e) {
182
+                    $this->logger->error($e->getMessage(), ['exception' => $e]);
183
+                }
184
+            }
185
+        }
186 186
 
187
-		if (!$hasValidCachedToken) {
188
-			unset($this->params['cachedToken']);
189
-			try {
190
-				[$token, $serviceUrl] = $authService->authenticate($this->params);
191
-				$this->cacheToken($token, $serviceUrl, $cacheKey);
192
-			} catch (ConnectException $e) {
193
-				throw new StorageAuthException('Failed to connect to keystone, verify the keystone url', $e);
194
-			} catch (ClientException $e) {
195
-				$statusCode = $e->getResponse()->getStatusCode();
196
-				if ($statusCode === 404) {
197
-					throw new StorageAuthException('Keystone not found while connecting to object storage, verify the keystone url', $e);
198
-				} elseif ($statusCode === 412) {
199
-					throw new StorageAuthException('Precondition failed while connecting to object storage, verify the keystone url', $e);
200
-				} elseif ($statusCode === 401) {
201
-					throw new StorageAuthException('Authentication failed while connecting to object storage, verify the username, password and possibly tenant', $e);
202
-				} else {
203
-					throw new StorageAuthException('Unknown error while connecting to object storage', $e);
204
-				}
205
-			} catch (RequestException $e) {
206
-				throw new StorageAuthException('Connection reset while connecting to keystone, verify the keystone url', $e);
207
-			}
208
-		}
187
+        if (!$hasValidCachedToken) {
188
+            unset($this->params['cachedToken']);
189
+            try {
190
+                [$token, $serviceUrl] = $authService->authenticate($this->params);
191
+                $this->cacheToken($token, $serviceUrl, $cacheKey);
192
+            } catch (ConnectException $e) {
193
+                throw new StorageAuthException('Failed to connect to keystone, verify the keystone url', $e);
194
+            } catch (ClientException $e) {
195
+                $statusCode = $e->getResponse()->getStatusCode();
196
+                if ($statusCode === 404) {
197
+                    throw new StorageAuthException('Keystone not found while connecting to object storage, verify the keystone url', $e);
198
+                } elseif ($statusCode === 412) {
199
+                    throw new StorageAuthException('Precondition failed while connecting to object storage, verify the keystone url', $e);
200
+                } elseif ($statusCode === 401) {
201
+                    throw new StorageAuthException('Authentication failed while connecting to object storage, verify the username, password and possibly tenant', $e);
202
+                } else {
203
+                    throw new StorageAuthException('Unknown error while connecting to object storage', $e);
204
+                }
205
+            } catch (RequestException $e) {
206
+                throw new StorageAuthException('Connection reset while connecting to keystone, verify the keystone url', $e);
207
+            }
208
+        }
209 209
 
210 210
 
211
-		$client = new OpenStack($this->params);
211
+        $client = new OpenStack($this->params);
212 212
 
213
-		return $client;
214
-	}
213
+        return $client;
214
+    }
215 215
 
216
-	/**
217
-	 * @return \OpenStack\ObjectStore\v1\Models\Container
218
-	 * @throws StorageAuthException
219
-	 * @throws StorageNotAvailableException
220
-	 */
221
-	public function getContainer() {
222
-		if (is_null($this->container)) {
223
-			$this->container = $this->createContainer();
224
-		}
216
+    /**
217
+     * @return \OpenStack\ObjectStore\v1\Models\Container
218
+     * @throws StorageAuthException
219
+     * @throws StorageNotAvailableException
220
+     */
221
+    public function getContainer() {
222
+        if (is_null($this->container)) {
223
+            $this->container = $this->createContainer();
224
+        }
225 225
 
226
-		return $this->container;
227
-	}
226
+        return $this->container;
227
+    }
228 228
 
229
-	/**
230
-	 * @return \OpenStack\ObjectStore\v1\Models\Container
231
-	 * @throws StorageAuthException
232
-	 * @throws StorageNotAvailableException
233
-	 */
234
-	private function createContainer() {
235
-		$client = $this->getClient();
236
-		$objectStoreService = $client->objectStoreV1();
229
+    /**
230
+     * @return \OpenStack\ObjectStore\v1\Models\Container
231
+     * @throws StorageAuthException
232
+     * @throws StorageNotAvailableException
233
+     */
234
+    private function createContainer() {
235
+        $client = $this->getClient();
236
+        $objectStoreService = $client->objectStoreV1();
237 237
 
238
-		$autoCreate = isset($this->params['autocreate']) && $this->params['autocreate'] === true;
239
-		try {
240
-			$container = $objectStoreService->getContainer($this->params['container']);
241
-			if ($autoCreate) {
242
-				$container->getMetadata();
243
-			}
244
-			return $container;
245
-		} catch (BadResponseError $ex) {
246
-			// if the container does not exist and autocreate is true try to create the container on the fly
247
-			if ($ex->getResponse()->getStatusCode() === 404 && $autoCreate) {
248
-				return $objectStoreService->createContainer([
249
-					'name' => $this->params['container']
250
-				]);
251
-			} else {
252
-				throw new StorageNotAvailableException('Invalid response while trying to get container info', StorageNotAvailableException::STATUS_ERROR, $ex);
253
-			}
254
-		} catch (ConnectException $e) {
255
-			/** @var RequestInterface $request */
256
-			$request = $e->getRequest();
257
-			$host = $request->getUri()->getHost() . ':' . $request->getUri()->getPort();
258
-			$this->logger->error("Can't connect to object storage server at $host", ['exception' => $e]);
259
-			throw new StorageNotAvailableException("Can't connect to object storage server at $host", StorageNotAvailableException::STATUS_ERROR, $e);
260
-		}
261
-	}
238
+        $autoCreate = isset($this->params['autocreate']) && $this->params['autocreate'] === true;
239
+        try {
240
+            $container = $objectStoreService->getContainer($this->params['container']);
241
+            if ($autoCreate) {
242
+                $container->getMetadata();
243
+            }
244
+            return $container;
245
+        } catch (BadResponseError $ex) {
246
+            // if the container does not exist and autocreate is true try to create the container on the fly
247
+            if ($ex->getResponse()->getStatusCode() === 404 && $autoCreate) {
248
+                return $objectStoreService->createContainer([
249
+                    'name' => $this->params['container']
250
+                ]);
251
+            } else {
252
+                throw new StorageNotAvailableException('Invalid response while trying to get container info', StorageNotAvailableException::STATUS_ERROR, $ex);
253
+            }
254
+        } catch (ConnectException $e) {
255
+            /** @var RequestInterface $request */
256
+            $request = $e->getRequest();
257
+            $host = $request->getUri()->getHost() . ':' . $request->getUri()->getPort();
258
+            $this->logger->error("Can't connect to object storage server at $host", ['exception' => $e]);
259
+            throw new StorageNotAvailableException("Can't connect to object storage server at $host", StorageNotAvailableException::STATUS_ERROR, $e);
260
+        }
261
+    }
262 262
 }
Please login to merge, or discard this patch.
lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
 			return;
75 75
 		}
76 76
 
77
-		$folders = array_filter($folders, function (ISimpleFolder $folder) {
77
+		$folders = array_filter($folders, function(ISimpleFolder $folder) {
78 78
 			return $folder->fileExists('photo.');
79 79
 		});
80 80
 
@@ -82,7 +82,7 @@  discard block
 block discarded – undo
82 82
 			return;
83 83
 		}
84 84
 
85
-		$output->info('Delete ' . count($folders) . ' "photo." files');
85
+		$output->info('Delete '.count($folders).' "photo." files');
86 86
 
87 87
 		foreach ($folders as $folder) {
88 88
 			try {
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 				$folder->getFile('photo.')->delete();
91 91
 			} catch (\Exception $e) {
92 92
 				$this->logger->error($e->getMessage(), ['exception' => $e]);
93
-				$output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."');
93
+				$output->warning('Could not delete file "dav-photocache/'.$folder->getName().'/photo."');
94 94
 			}
95 95
 		}
96 96
 	}
Please login to merge, or discard this patch.
Indentation   +48 added lines, -48 removed lines patch added patch discarded remove patch
@@ -28,61 +28,61 @@
 block discarded – undo
28 28
  * photo could be returned for this vcard. These invalid files are removed by this migration step.
29 29
  */
30 30
 class CleanupCardDAVPhotoCache implements IRepairStep {
31
-	public function __construct(
32
-		private IConfig $config,
33
-		private IAppDataFactory $appDataFactory,
34
-		private LoggerInterface $logger,
35
-	) {
36
-	}
31
+    public function __construct(
32
+        private IConfig $config,
33
+        private IAppDataFactory $appDataFactory,
34
+        private LoggerInterface $logger,
35
+    ) {
36
+    }
37 37
 
38
-	public function getName(): string {
39
-		return 'Cleanup invalid photocache files for carddav';
40
-	}
38
+    public function getName(): string {
39
+        return 'Cleanup invalid photocache files for carddav';
40
+    }
41 41
 
42
-	private function repair(IOutput $output): void {
43
-		$photoCacheAppData = $this->appDataFactory->get('dav-photocache');
42
+    private function repair(IOutput $output): void {
43
+        $photoCacheAppData = $this->appDataFactory->get('dav-photocache');
44 44
 
45
-		try {
46
-			$folders = $photoCacheAppData->getDirectoryListing();
47
-		} catch (NotFoundException $e) {
48
-			return;
49
-		} catch (RuntimeException $e) {
50
-			$this->logger->error('Failed to fetch directory listing in CleanupCardDAVPhotoCache', ['exception' => $e]);
51
-			return;
52
-		}
45
+        try {
46
+            $folders = $photoCacheAppData->getDirectoryListing();
47
+        } catch (NotFoundException $e) {
48
+            return;
49
+        } catch (RuntimeException $e) {
50
+            $this->logger->error('Failed to fetch directory listing in CleanupCardDAVPhotoCache', ['exception' => $e]);
51
+            return;
52
+        }
53 53
 
54
-		$folders = array_filter($folders, function (ISimpleFolder $folder) {
55
-			return $folder->fileExists('photo.');
56
-		});
54
+        $folders = array_filter($folders, function (ISimpleFolder $folder) {
55
+            return $folder->fileExists('photo.');
56
+        });
57 57
 
58
-		if (empty($folders)) {
59
-			return;
60
-		}
58
+        if (empty($folders)) {
59
+            return;
60
+        }
61 61
 
62
-		$output->info('Delete ' . count($folders) . ' "photo." files');
62
+        $output->info('Delete ' . count($folders) . ' "photo." files');
63 63
 
64
-		foreach ($folders as $folder) {
65
-			try {
66
-				/** @var ISimpleFolder $folder */
67
-				$folder->getFile('photo.')->delete();
68
-			} catch (\Exception $e) {
69
-				$this->logger->error($e->getMessage(), ['exception' => $e]);
70
-				$output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."');
71
-			}
72
-		}
73
-	}
64
+        foreach ($folders as $folder) {
65
+            try {
66
+                /** @var ISimpleFolder $folder */
67
+                $folder->getFile('photo.')->delete();
68
+            } catch (\Exception $e) {
69
+                $this->logger->error($e->getMessage(), ['exception' => $e]);
70
+                $output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."');
71
+            }
72
+        }
73
+    }
74 74
 
75
-	private function shouldRun(): bool {
76
-		return version_compare(
77
-			$this->config->getSystemValueString('version', '0.0.0.0'),
78
-			'16.0.0.0',
79
-			'<='
80
-		);
81
-	}
75
+    private function shouldRun(): bool {
76
+        return version_compare(
77
+            $this->config->getSystemValueString('version', '0.0.0.0'),
78
+            '16.0.0.0',
79
+            '<='
80
+        );
81
+    }
82 82
 
83
-	public function run(IOutput $output): void {
84
-		if ($this->shouldRun()) {
85
-			$this->repair($output);
86
-		}
87
-	}
83
+    public function run(IOutput $output): void {
84
+        if ($this->shouldRun()) {
85
+            $this->repair($output);
86
+        }
87
+    }
88 88
 }
Please login to merge, or discard this patch.