Completed
Push — master ( 247b25...4111bd )
by Thomas
26:36 queued 10s
created
apps/contactsinteraction/lib/Db/RecentContactMapper.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -116,7 +116,7 @@
 block discarded – undo
116 116
 			return null;
117 117
 		}
118 118
 
119
-		return (int)$row['last_contact'];
119
+		return (int) $row['last_contact'];
120 120
 	}
121 121
 
122 122
 	public function cleanUp(int $olderThan): void {
Please login to merge, or discard this patch.
Indentation   +95 added lines, -95 removed lines patch added patch discarded remove patch
@@ -17,99 +17,99 @@
 block discarded – undo
17 17
  * @template-extends QBMapper<RecentContact>
18 18
  */
19 19
 class RecentContactMapper extends QBMapper {
20
-	public const TABLE_NAME = 'recent_contact';
21
-
22
-	public function __construct(IDBConnection $db) {
23
-		parent::__construct($db, self::TABLE_NAME);
24
-	}
25
-
26
-	/**
27
-	 * @return RecentContact[]
28
-	 */
29
-	public function findAll(string $uid): array {
30
-		$qb = $this->db->getQueryBuilder();
31
-
32
-		$select = $qb
33
-			->select('*')
34
-			->from($this->getTableName())
35
-			->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid)));
36
-
37
-		return $this->findEntities($select);
38
-	}
39
-
40
-	/**
41
-	 * @throws DoesNotExistException
42
-	 */
43
-	public function find(string $uid, int $id): RecentContact {
44
-		$qb = $this->db->getQueryBuilder();
45
-
46
-		$select = $qb
47
-			->select('*')
48
-			->from($this->getTableName())
49
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $qb::PARAM_INT)))
50
-			->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid)));
51
-
52
-		return $this->findEntity($select);
53
-	}
54
-
55
-	/**
56
-	 * @return RecentContact[]
57
-	 */
58
-	public function findMatch(IUser $user,
59
-		?string $uid,
60
-		?string $email,
61
-		?string $cloudId): array {
62
-		$qb = $this->db->getQueryBuilder();
63
-
64
-		$additionalWheres = [];
65
-		if ($uid !== null) {
66
-			$additionalWheres[] = $qb->expr()->eq('uid', $qb->createNamedParameter($uid));
67
-		}
68
-		if ($email !== null) {
69
-			$additionalWheres[] = $qb->expr()->eq('email', $qb->createNamedParameter($email));
70
-		}
71
-		if ($cloudId !== null) {
72
-			$additionalWheres[] = $qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId));
73
-		}
74
-
75
-		$select = $qb
76
-			->select('*')
77
-			->from($this->getTableName())
78
-			->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID())));
79
-
80
-		if (!empty($additionalWheres)) {
81
-			$select->andWhere($select->expr()->orX(...$additionalWheres));
82
-		}
83
-		return $this->findEntities($select);
84
-	}
85
-
86
-	public function findLastUpdatedForUserId(string $uid): ?int {
87
-		$qb = $this->db->getQueryBuilder();
88
-
89
-		$select = $qb
90
-			->select('last_contact')
91
-			->from($this->getTableName())
92
-			->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid)))
93
-			->orderBy('last_contact', 'DESC')
94
-			->setMaxResults(1);
95
-
96
-		$cursor = $select->executeQuery();
97
-		$row = $cursor->fetch();
98
-
99
-		if ($row === false) {
100
-			return null;
101
-		}
102
-
103
-		return (int)$row['last_contact'];
104
-	}
105
-
106
-	public function cleanUp(int $olderThan): void {
107
-		$qb = $this->db->getQueryBuilder();
108
-
109
-		$delete = $qb
110
-			->delete($this->getTableName())
111
-			->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan)));
112
-
113
-		$delete->executeStatement();
114
-	}
20
+    public const TABLE_NAME = 'recent_contact';
21
+
22
+    public function __construct(IDBConnection $db) {
23
+        parent::__construct($db, self::TABLE_NAME);
24
+    }
25
+
26
+    /**
27
+     * @return RecentContact[]
28
+     */
29
+    public function findAll(string $uid): array {
30
+        $qb = $this->db->getQueryBuilder();
31
+
32
+        $select = $qb
33
+            ->select('*')
34
+            ->from($this->getTableName())
35
+            ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid)));
36
+
37
+        return $this->findEntities($select);
38
+    }
39
+
40
+    /**
41
+     * @throws DoesNotExistException
42
+     */
43
+    public function find(string $uid, int $id): RecentContact {
44
+        $qb = $this->db->getQueryBuilder();
45
+
46
+        $select = $qb
47
+            ->select('*')
48
+            ->from($this->getTableName())
49
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $qb::PARAM_INT)))
50
+            ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid)));
51
+
52
+        return $this->findEntity($select);
53
+    }
54
+
55
+    /**
56
+     * @return RecentContact[]
57
+     */
58
+    public function findMatch(IUser $user,
59
+        ?string $uid,
60
+        ?string $email,
61
+        ?string $cloudId): array {
62
+        $qb = $this->db->getQueryBuilder();
63
+
64
+        $additionalWheres = [];
65
+        if ($uid !== null) {
66
+            $additionalWheres[] = $qb->expr()->eq('uid', $qb->createNamedParameter($uid));
67
+        }
68
+        if ($email !== null) {
69
+            $additionalWheres[] = $qb->expr()->eq('email', $qb->createNamedParameter($email));
70
+        }
71
+        if ($cloudId !== null) {
72
+            $additionalWheres[] = $qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId));
73
+        }
74
+
75
+        $select = $qb
76
+            ->select('*')
77
+            ->from($this->getTableName())
78
+            ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID())));
79
+
80
+        if (!empty($additionalWheres)) {
81
+            $select->andWhere($select->expr()->orX(...$additionalWheres));
82
+        }
83
+        return $this->findEntities($select);
84
+    }
85
+
86
+    public function findLastUpdatedForUserId(string $uid): ?int {
87
+        $qb = $this->db->getQueryBuilder();
88
+
89
+        $select = $qb
90
+            ->select('last_contact')
91
+            ->from($this->getTableName())
92
+            ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid)))
93
+            ->orderBy('last_contact', 'DESC')
94
+            ->setMaxResults(1);
95
+
96
+        $cursor = $select->executeQuery();
97
+        $row = $cursor->fetch();
98
+
99
+        if ($row === false) {
100
+            return null;
101
+        }
102
+
103
+        return (int)$row['last_contact'];
104
+    }
105
+
106
+    public function cleanUp(int $olderThan): void {
107
+        $qb = $this->db->getQueryBuilder();
108
+
109
+        $delete = $qb
110
+            ->delete($this->getTableName())
111
+            ->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan)));
112
+
113
+        $delete->executeStatement();
114
+    }
115 115
 }
Please login to merge, or discard this patch.
lib/private/Authentication/Events/LoginFailed.php 1 patch
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -28,21 +28,21 @@
 block discarded – undo
28 28
 use OCP\EventDispatcher\Event;
29 29
 
30 30
 class LoginFailed extends Event {
31
-	private string $loginName;
32
-	private ?string $password;
31
+    private string $loginName;
32
+    private ?string $password;
33 33
 
34
-	public function __construct(string $loginName, ?string $password) {
35
-		parent::__construct();
34
+    public function __construct(string $loginName, ?string $password) {
35
+        parent::__construct();
36 36
 
37
-		$this->loginName = $loginName;
38
-		$this->password = $password;
39
-	}
37
+        $this->loginName = $loginName;
38
+        $this->password = $password;
39
+    }
40 40
 
41
-	public function getLoginName(): string {
42
-		return $this->loginName;
43
-	}
41
+    public function getLoginName(): string {
42
+        return $this->loginName;
43
+    }
44 44
 
45
-	public function getPassword(): ?string {
46
-		return $this->password;
47
-	}
45
+    public function getPassword(): ?string {
46
+        return $this->password;
47
+    }
48 48
 }
Please login to merge, or discard this patch.
apps/admin_audit/lib/BackgroundJobs/Rotate.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -48,7 +48,7 @@
 block discarded – undo
48 48
 	}
49 49
 
50 50
 	protected function run($argument): void {
51
-		$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
51
+		$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT.'/data').'/audit.log';
52 52
 		$this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
53 53
 
54 54
 		if ($this->filePath === '') {
Please login to merge, or discard this patch.
Indentation   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@
 block discarded – undo
13 13
 use OCP\Log\RotationTrait;
14 14
 
15 15
 class Rotate extends TimedJob {
16
-	use RotationTrait;
16
+    use RotationTrait;
17 17
 
18
-	public function __construct(
19
-		ITimeFactory $time,
20
-		private IConfig $config,
21
-	) {
22
-		parent::__construct($time);
18
+    public function __construct(
19
+        ITimeFactory $time,
20
+        private IConfig $config,
21
+    ) {
22
+        parent::__construct($time);
23 23
 
24
-		$this->setInterval(60 * 60 * 3);
25
-	}
24
+        $this->setInterval(60 * 60 * 3);
25
+    }
26 26
 
27
-	protected function run($argument): void {
28
-		$default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
29
-		$this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
27
+    protected function run($argument): void {
28
+        $default = $this->config->getSystemValue('datadirectory', \OC::$SERVERROOT . '/data') . '/audit.log';
29
+        $this->filePath = $this->config->getAppValue('admin_audit', 'logfile', $default);
30 30
 
31
-		if ($this->filePath === '') {
32
-			// default log file, nothing to do
33
-			return;
34
-		}
31
+        if ($this->filePath === '') {
32
+            // default log file, nothing to do
33
+            return;
34
+        }
35 35
 
36
-		$this->maxSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
36
+        $this->maxSize = $this->config->getSystemValue('log_rotate_size', 100 * 1024 * 1024);
37 37
 
38
-		if ($this->shouldRotateBySize()) {
39
-			$this->rotate();
40
-		}
41
-	}
38
+        if ($this->shouldRotateBySize()) {
39
+            $this->rotate();
40
+        }
41
+    }
42 42
 }
Please login to merge, or discard this patch.
lib/public/Migration/IMigrationStep.php 1 patch
Indentation   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -34,47 +34,47 @@
 block discarded – undo
34 34
  * @since 13.0.0
35 35
  */
36 36
 interface IMigrationStep {
37
-	/**
38
-	 * Human-readable name of the migration step
39
-	 *
40
-	 * @return string
41
-	 * @since 14.0.0
42
-	 */
43
-	public function name(): string;
37
+    /**
38
+     * Human-readable name of the migration step
39
+     *
40
+     * @return string
41
+     * @since 14.0.0
42
+     */
43
+    public function name(): string;
44 44
 
45
-	/**
46
-	 * Human-readable description of the migration step
47
-	 *
48
-	 * @return string
49
-	 * @since 14.0.0
50
-	 */
51
-	public function description(): string;
45
+    /**
46
+     * Human-readable description of the migration step
47
+     *
48
+     * @return string
49
+     * @since 14.0.0
50
+     */
51
+    public function description(): string;
52 52
 
53
-	/**
54
-	 * @param IOutput $output
55
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
56
-	 * @psalm-param Closure():ISchemaWrapper $schemaClosure
57
-	 * @param array $options
58
-	 * @since 13.0.0
59
-	 */
60
-	public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options);
53
+    /**
54
+     * @param IOutput $output
55
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
56
+     * @psalm-param Closure():ISchemaWrapper $schemaClosure
57
+     * @param array $options
58
+     * @since 13.0.0
59
+     */
60
+    public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options);
61 61
 
62
-	/**
63
-	 * @param IOutput $output
64
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
65
-	 * @psalm-param Closure():ISchemaWrapper $schemaClosure
66
-	 * @param array $options
67
-	 * @return null|ISchemaWrapper
68
-	 * @since 13.0.0
69
-	 */
70
-	public function changeSchema(IOutput $output, Closure $schemaClosure, array $options);
62
+    /**
63
+     * @param IOutput $output
64
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
65
+     * @psalm-param Closure():ISchemaWrapper $schemaClosure
66
+     * @param array $options
67
+     * @return null|ISchemaWrapper
68
+     * @since 13.0.0
69
+     */
70
+    public function changeSchema(IOutput $output, Closure $schemaClosure, array $options);
71 71
 
72
-	/**
73
-	 * @param IOutput $output
74
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
75
-	 * @psalm-param Closure():ISchemaWrapper $schemaClosure
76
-	 * @param array $options
77
-	 * @since 13.0.0
78
-	 */
79
-	public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options);
72
+    /**
73
+     * @param IOutput $output
74
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
75
+     * @psalm-param Closure():ISchemaWrapper $schemaClosure
76
+     * @param array $options
77
+     * @since 13.0.0
78
+     */
79
+    public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options);
80 80
 }
Please login to merge, or discard this patch.
lib/public/Migration/SimpleMigrationStep.php 1 patch
Indentation   +47 added lines, -47 removed lines patch added patch discarded remove patch
@@ -35,55 +35,55 @@
 block discarded – undo
35 35
  * @since 13.0.0
36 36
  */
37 37
 abstract class SimpleMigrationStep implements IMigrationStep {
38
-	/**
39
-	 * Human-readable name of the migration step
40
-	 *
41
-	 * @return string
42
-	 * @since 14.0.0
43
-	 */
44
-	public function name(): string {
45
-		return '';
46
-	}
38
+    /**
39
+     * Human-readable name of the migration step
40
+     *
41
+     * @return string
42
+     * @since 14.0.0
43
+     */
44
+    public function name(): string {
45
+        return '';
46
+    }
47 47
 
48
-	/**
49
-	 * Human-readable description of the migration step
50
-	 *
51
-	 * @return string
52
-	 * @since 14.0.0
53
-	 */
54
-	public function description(): string {
55
-		return '';
56
-	}
48
+    /**
49
+     * Human-readable description of the migration step
50
+     *
51
+     * @return string
52
+     * @since 14.0.0
53
+     */
54
+    public function description(): string {
55
+        return '';
56
+    }
57 57
 
58
-	/**
59
-	 * @param IOutput $output
60
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
61
-	 * @psalm-param Closure():ISchemaWrapper $schemaClosure
62
-	 * @param array $options
63
-	 * @since 13.0.0
64
-	 */
65
-	public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
66
-	}
58
+    /**
59
+     * @param IOutput $output
60
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
61
+     * @psalm-param Closure():ISchemaWrapper $schemaClosure
62
+     * @param array $options
63
+     * @since 13.0.0
64
+     */
65
+    public function preSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
66
+    }
67 67
 
68
-	/**
69
-	 * @param IOutput $output
70
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
71
-	 * @psalm-param Closure():ISchemaWrapper $schemaClosure
72
-	 * @param array $options
73
-	 * @return null|ISchemaWrapper
74
-	 * @since 13.0.0
75
-	 */
76
-	public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
77
-		return null;
78
-	}
68
+    /**
69
+     * @param IOutput $output
70
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
71
+     * @psalm-param Closure():ISchemaWrapper $schemaClosure
72
+     * @param array $options
73
+     * @return null|ISchemaWrapper
74
+     * @since 13.0.0
75
+     */
76
+    public function changeSchema(IOutput $output, \Closure $schemaClosure, array $options) {
77
+        return null;
78
+    }
79 79
 
80
-	/**
81
-	 * @param IOutput $output
82
-	 * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
83
-	 * @psalm-param Closure():ISchemaWrapper $schemaClosure
84
-	 * @param array $options
85
-	 * @since 13.0.0
86
-	 */
87
-	public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
88
-	}
80
+    /**
81
+     * @param IOutput $output
82
+     * @param Closure $schemaClosure The `\Closure` returns a `ISchemaWrapper`
83
+     * @psalm-param Closure():ISchemaWrapper $schemaClosure
84
+     * @param array $options
85
+     * @since 13.0.0
86
+     */
87
+    public function postSchemaChange(IOutput $output, \Closure $schemaClosure, array $options) {
88
+    }
89 89
 }
Please login to merge, or discard this patch.
lib/private/AppFramework/Middleware/PublicShare/PublicShareMiddleware.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -62,7 +62,7 @@
 block discarded – undo
62 62
 
63 63
 		$controllerClassPath = explode('\\', get_class($controller));
64 64
 		$controllerShortClass = end($controllerClassPath);
65
-		$bruteforceProtectionAction = $controllerShortClass . '::' . $methodName;
65
+		$bruteforceProtectionAction = $controllerShortClass.'::'.$methodName;
66 66
 		$this->throttler->sleepDelayOrThrowOnMax($this->request->getRemoteAddress(), $bruteforceProtectionAction);
67 67
 
68 68
 		if (!$this->isLinkSharingEnabled()) {
Please login to merge, or discard this patch.
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -20,107 +20,107 @@
 block discarded – undo
20 20
 
21 21
 class PublicShareMiddleware extends Middleware {
22 22
 
23
-	public function __construct(
24
-		private IRequest $request,
25
-		private ISession $session,
26
-		private IConfig $config,
27
-		private IThrottler $throttler,
28
-	) {
29
-	}
30
-
31
-	public function beforeController($controller, $methodName) {
32
-		if (!($controller instanceof PublicShareController)) {
33
-			return;
34
-		}
35
-
36
-		$controllerClassPath = explode('\\', get_class($controller));
37
-		$controllerShortClass = end($controllerClassPath);
38
-		$bruteforceProtectionAction = $controllerShortClass . '::' . $methodName;
39
-		$this->throttler->sleepDelayOrThrowOnMax($this->request->getRemoteAddress(), $bruteforceProtectionAction);
40
-
41
-		if (!$this->isLinkSharingEnabled()) {
42
-			throw new NotFoundException('Link sharing is disabled');
43
-		}
44
-
45
-		// We require the token parameter to be set
46
-		$token = $this->request->getParam('token');
47
-		if ($token === null) {
48
-			throw new NotFoundException();
49
-		}
50
-
51
-		// Set the token
52
-		$controller->setToken($token);
53
-
54
-		if (!$controller->isValidToken()) {
55
-			$this->throttle($bruteforceProtectionAction, $token);
56
-
57
-			$controller->shareNotFound();
58
-			throw new NotFoundException();
59
-		}
60
-
61
-		// No need to check for authentication when we try to authenticate
62
-		if ($methodName === 'authenticate' || $methodName === 'showAuthenticate') {
63
-			return;
64
-		}
65
-
66
-		// If authentication succeeds just continue
67
-		if ($controller->isAuthenticated()) {
68
-			return;
69
-		}
70
-
71
-		// If we can authenticate to this controller do it else we throw a 404 to not leak any info
72
-		if ($controller instanceof AuthPublicShareController) {
73
-			$this->session->set('public_link_authenticate_redirect', json_encode($this->request->getParams()));
74
-			throw new NeedAuthenticationException();
75
-		}
76
-
77
-		$this->throttle($bruteforceProtectionAction, $token);
78
-		throw new NotFoundException();
79
-	}
80
-
81
-	public function afterException($controller, $methodName, \Exception $exception) {
82
-		if (!($controller instanceof PublicShareController)) {
83
-			throw $exception;
84
-		}
85
-
86
-		if ($exception instanceof NotFoundException) {
87
-			return new TemplateResponse(Application::APP_ID, 'sharenotfound', [
88
-				'message' => $exception->getMessage(),
89
-			], 'guest', Http::STATUS_NOT_FOUND);
90
-		}
91
-
92
-		if ($controller instanceof AuthPublicShareController && $exception instanceof NeedAuthenticationException) {
93
-			return $controller->getAuthenticationRedirect($this->getFunctionForRoute($this->request->getParam('_route')));
94
-		}
95
-
96
-		throw $exception;
97
-	}
98
-
99
-	private function getFunctionForRoute(string $route): string {
100
-		$tmp = explode('.', $route);
101
-		return array_pop($tmp);
102
-	}
103
-
104
-	/**
105
-	 * Check if link sharing is allowed
106
-	 */
107
-	private function isLinkSharingEnabled(): bool {
108
-		// Check if the shareAPI is enabled
109
-		if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') {
110
-			return false;
111
-		}
112
-
113
-		// Check whether public sharing is enabled
114
-		if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
115
-			return false;
116
-		}
117
-
118
-		return true;
119
-	}
120
-
121
-	private function throttle($bruteforceProtectionAction, $token): void {
122
-		$ip = $this->request->getRemoteAddress();
123
-		$this->throttler->sleepDelayOrThrowOnMax($ip, $bruteforceProtectionAction);
124
-		$this->throttler->registerAttempt($bruteforceProtectionAction, $ip, ['token' => $token]);
125
-	}
23
+    public function __construct(
24
+        private IRequest $request,
25
+        private ISession $session,
26
+        private IConfig $config,
27
+        private IThrottler $throttler,
28
+    ) {
29
+    }
30
+
31
+    public function beforeController($controller, $methodName) {
32
+        if (!($controller instanceof PublicShareController)) {
33
+            return;
34
+        }
35
+
36
+        $controllerClassPath = explode('\\', get_class($controller));
37
+        $controllerShortClass = end($controllerClassPath);
38
+        $bruteforceProtectionAction = $controllerShortClass . '::' . $methodName;
39
+        $this->throttler->sleepDelayOrThrowOnMax($this->request->getRemoteAddress(), $bruteforceProtectionAction);
40
+
41
+        if (!$this->isLinkSharingEnabled()) {
42
+            throw new NotFoundException('Link sharing is disabled');
43
+        }
44
+
45
+        // We require the token parameter to be set
46
+        $token = $this->request->getParam('token');
47
+        if ($token === null) {
48
+            throw new NotFoundException();
49
+        }
50
+
51
+        // Set the token
52
+        $controller->setToken($token);
53
+
54
+        if (!$controller->isValidToken()) {
55
+            $this->throttle($bruteforceProtectionAction, $token);
56
+
57
+            $controller->shareNotFound();
58
+            throw new NotFoundException();
59
+        }
60
+
61
+        // No need to check for authentication when we try to authenticate
62
+        if ($methodName === 'authenticate' || $methodName === 'showAuthenticate') {
63
+            return;
64
+        }
65
+
66
+        // If authentication succeeds just continue
67
+        if ($controller->isAuthenticated()) {
68
+            return;
69
+        }
70
+
71
+        // If we can authenticate to this controller do it else we throw a 404 to not leak any info
72
+        if ($controller instanceof AuthPublicShareController) {
73
+            $this->session->set('public_link_authenticate_redirect', json_encode($this->request->getParams()));
74
+            throw new NeedAuthenticationException();
75
+        }
76
+
77
+        $this->throttle($bruteforceProtectionAction, $token);
78
+        throw new NotFoundException();
79
+    }
80
+
81
+    public function afterException($controller, $methodName, \Exception $exception) {
82
+        if (!($controller instanceof PublicShareController)) {
83
+            throw $exception;
84
+        }
85
+
86
+        if ($exception instanceof NotFoundException) {
87
+            return new TemplateResponse(Application::APP_ID, 'sharenotfound', [
88
+                'message' => $exception->getMessage(),
89
+            ], 'guest', Http::STATUS_NOT_FOUND);
90
+        }
91
+
92
+        if ($controller instanceof AuthPublicShareController && $exception instanceof NeedAuthenticationException) {
93
+            return $controller->getAuthenticationRedirect($this->getFunctionForRoute($this->request->getParam('_route')));
94
+        }
95
+
96
+        throw $exception;
97
+    }
98
+
99
+    private function getFunctionForRoute(string $route): string {
100
+        $tmp = explode('.', $route);
101
+        return array_pop($tmp);
102
+    }
103
+
104
+    /**
105
+     * Check if link sharing is allowed
106
+     */
107
+    private function isLinkSharingEnabled(): bool {
108
+        // Check if the shareAPI is enabled
109
+        if ($this->config->getAppValue('core', 'shareapi_enabled', 'yes') !== 'yes') {
110
+            return false;
111
+        }
112
+
113
+        // Check whether public sharing is enabled
114
+        if ($this->config->getAppValue('core', 'shareapi_allow_links', 'yes') !== 'yes') {
115
+            return false;
116
+        }
117
+
118
+        return true;
119
+    }
120
+
121
+    private function throttle($bruteforceProtectionAction, $token): void {
122
+        $ip = $this->request->getRemoteAddress();
123
+        $this->throttler->sleepDelayOrThrowOnMax($ip, $bruteforceProtectionAction);
124
+        $this->throttler->registerAttempt($bruteforceProtectionAction, $ip, ['token' => $token]);
125
+    }
126 126
 }
Please login to merge, or discard this patch.
lib/private/Template/JSCombiner.php 2 patches
Spacing   +18 added lines, -18 removed lines patch added patch discarded remove patch
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 		$this->appData = $appData;
64 64
 		$this->urlGenerator = $urlGenerator;
65 65
 		$this->cacheFactory = $cacheFactory;
66
-		$this->depsCache = $this->cacheFactory->createDistributed('JS-' . md5($this->urlGenerator->getBaseUrl()));
66
+		$this->depsCache = $this->cacheFactory->createDistributed('JS-'.md5($this->urlGenerator->getBaseUrl()));
67 67
 		$this->config = $config;
68 68
 		$this->logger = $logger;
69 69
 	}
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 			return false;
80 80
 		}
81 81
 
82
-		$path = explode('/', $root . '/' . $file);
82
+		$path = explode('/', $root.'/'.$file);
83 83
 
84 84
 		$fileName = array_pop($path);
85 85
 		$path = implode('/', $path);
@@ -109,9 +109,9 @@  discard block
 block discarded – undo
109 109
 			return false;
110 110
 		}
111 111
 
112
-		$fileName = $fileName . '.deps';
112
+		$fileName = $fileName.'.deps';
113 113
 		try {
114
-			$deps = $this->depsCache->get($folder->getName() . '-' . $fileName);
114
+			$deps = $this->depsCache->get($folder->getName().'-'.$fileName);
115 115
 			$fromCache = true;
116 116
 			if ($deps === null || $deps === '') {
117 117
 				$fromCache = false;
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 
122 122
 			// check again
123 123
 			if ($deps === null || $deps === '') {
124
-				$this->logger->info('JSCombiner: deps file empty: ' . $fileName);
124
+				$this->logger->info('JSCombiner: deps file empty: '.$fileName);
125 125
 				return false;
126 126
 			}
127 127
 
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
 			}
139 139
 
140 140
 			if ($fromCache === false) {
141
-				$this->depsCache->set($folder->getName() . '-' . $fileName, json_encode($deps));
141
+				$this->depsCache->set($folder->getName().'-'.$fileName, json_encode($deps));
142 142
 			}
143 143
 
144 144
 			return true;
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
 	 */
156 156
 	protected function cache($path, $fileName, ISimpleFolder $folder) {
157 157
 		$deps = [];
158
-		$fullPath = $path . '/' . $fileName;
158
+		$fullPath = $path.'/'.$fileName;
159 159
 		$data = json_decode(file_get_contents($fullPath));
160 160
 		$deps[$fullPath] = filemtime($fullPath);
161 161
 
162 162
 		$res = '';
163 163
 		foreach ($data as $file) {
164
-			$filePath = $path . '/' . $file;
164
+			$filePath = $path.'/'.$file;
165 165
 
166 166
 			if (is_file($filePath)) {
167 167
 				$res .= file_get_contents($filePath);
168
-				$res .= PHP_EOL . PHP_EOL;
168
+				$res .= PHP_EOL.PHP_EOL;
169 169
 				$deps[$filePath] = filemtime($filePath);
170 170
 			}
171 171
 		}
@@ -177,7 +177,7 @@  discard block
 block discarded – undo
177 177
 			$cachedfile = $folder->newFile($fileName);
178 178
 		}
179 179
 
180
-		$depFileName = $fileName . '.deps';
180
+		$depFileName = $fileName.'.deps';
181 181
 		try {
182 182
 			$depFile = $folder->getFile($depFileName);
183 183
 		} catch (NotFoundException $e) {
@@ -185,21 +185,21 @@  discard block
 block discarded – undo
185 185
 		}
186 186
 
187 187
 		try {
188
-			$gzipFile = $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz
188
+			$gzipFile = $folder->getFile($fileName.'.gzip'); # Safari doesn't like .gz
189 189
 		} catch (NotFoundException $e) {
190
-			$gzipFile = $folder->newFile($fileName . '.gzip'); # Safari doesn't like .gz
190
+			$gzipFile = $folder->newFile($fileName.'.gzip'); # Safari doesn't like .gz
191 191
 		}
192 192
 
193 193
 		try {
194 194
 			$cachedfile->putContent($res);
195 195
 			$deps = json_encode($deps);
196 196
 			$depFile->putContent($deps);
197
-			$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
197
+			$this->depsCache->set($folder->getName().'-'.$depFileName, $deps);
198 198
 			$gzipFile->putContent(gzencode($res, 9));
199
-			$this->logger->debug('JSCombiner: successfully cached: ' . $fileName);
199
+			$this->logger->debug('JSCombiner: successfully cached: '.$fileName);
200 200
 			return true;
201
-		} catch (NotPermittedException|NotFoundException $e) {
202
-			$this->logger->error('JSCombiner: unable to cache: ' . $fileName);
201
+		} catch (NotPermittedException | NotFoundException $e) {
202
+			$this->logger->error('JSCombiner: unable to cache: '.$fileName);
203 203
 			return false;
204 204
 		}
205 205
 	}
@@ -224,7 +224,7 @@  discard block
 block discarded – undo
224 224
 	 */
225 225
 	public function getContent($root, $file) {
226 226
 		/** @var array $data */
227
-		$data = json_decode(file_get_contents($root . '/' . $file));
227
+		$data = json_decode(file_get_contents($root.'/'.$file));
228 228
 		if (!is_array($data)) {
229 229
 			return [];
230 230
 		}
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
 
236 236
 		$result = [];
237 237
 		foreach ($data as $f) {
238
-			$result[] = $path . '/' . $f;
238
+			$result[] = $path.'/'.$f;
239 239
 		}
240 240
 
241 241
 		return $result;
Please login to merge, or discard this patch.
Indentation   +218 added lines, -218 removed lines patch added patch discarded remove patch
@@ -16,222 +16,222 @@
 block discarded – undo
16 16
 use Psr\Log\LoggerInterface;
17 17
 
18 18
 class JSCombiner {
19
-	/** @var IAppData */
20
-	protected $appData;
21
-
22
-	/** @var IURLGenerator */
23
-	protected $urlGenerator;
24
-
25
-	/** @var ICache */
26
-	protected $depsCache;
27
-
28
-	/** @var SystemConfig */
29
-	protected $config;
30
-
31
-	protected LoggerInterface $logger;
32
-
33
-	/** @var ICacheFactory */
34
-	private $cacheFactory;
35
-
36
-	public function __construct(IAppData $appData,
37
-		IURLGenerator $urlGenerator,
38
-		ICacheFactory $cacheFactory,
39
-		SystemConfig $config,
40
-		LoggerInterface $logger) {
41
-		$this->appData = $appData;
42
-		$this->urlGenerator = $urlGenerator;
43
-		$this->cacheFactory = $cacheFactory;
44
-		$this->depsCache = $this->cacheFactory->createDistributed('JS-' . md5($this->urlGenerator->getBaseUrl()));
45
-		$this->config = $config;
46
-		$this->logger = $logger;
47
-	}
48
-
49
-	/**
50
-	 * @param string $root
51
-	 * @param string $file
52
-	 * @param string $app
53
-	 * @return bool
54
-	 */
55
-	public function process($root, $file, $app) {
56
-		if ($this->config->getValue('debug') || !$this->config->getValue('installed')) {
57
-			return false;
58
-		}
59
-
60
-		$path = explode('/', $root . '/' . $file);
61
-
62
-		$fileName = array_pop($path);
63
-		$path = implode('/', $path);
64
-
65
-		try {
66
-			$folder = $this->appData->getFolder($app);
67
-		} catch (NotFoundException $e) {
68
-			// creating css appdata folder
69
-			$folder = $this->appData->newFolder($app);
70
-		}
71
-
72
-		if ($this->isCached($fileName, $folder)) {
73
-			return true;
74
-		}
75
-		return $this->cache($path, $fileName, $folder);
76
-	}
77
-
78
-	/**
79
-	 * @param string $fileName
80
-	 * @param ISimpleFolder $folder
81
-	 * @return bool
82
-	 */
83
-	protected function isCached($fileName, ISimpleFolder $folder) {
84
-		$fileName = str_replace('.json', '.js', $fileName);
85
-
86
-		if (!$folder->fileExists($fileName)) {
87
-			return false;
88
-		}
89
-
90
-		$fileName = $fileName . '.deps';
91
-		try {
92
-			$deps = $this->depsCache->get($folder->getName() . '-' . $fileName);
93
-			$fromCache = true;
94
-			if ($deps === null || $deps === '') {
95
-				$fromCache = false;
96
-				$depFile = $folder->getFile($fileName);
97
-				$deps = $depFile->getContent();
98
-			}
99
-
100
-			// check again
101
-			if ($deps === null || $deps === '') {
102
-				$this->logger->info('JSCombiner: deps file empty: ' . $fileName);
103
-				return false;
104
-			}
105
-
106
-			$deps = json_decode($deps, true);
107
-
108
-			if ($deps === null) {
109
-				return false;
110
-			}
111
-
112
-			foreach ($deps as $file => $mtime) {
113
-				if (!file_exists($file) || filemtime($file) > $mtime) {
114
-					return false;
115
-				}
116
-			}
117
-
118
-			if ($fromCache === false) {
119
-				$this->depsCache->set($folder->getName() . '-' . $fileName, json_encode($deps));
120
-			}
121
-
122
-			return true;
123
-		} catch (NotFoundException $e) {
124
-			return false;
125
-		}
126
-	}
127
-
128
-	/**
129
-	 * @param string $path
130
-	 * @param string $fileName
131
-	 * @param ISimpleFolder $folder
132
-	 * @return bool
133
-	 */
134
-	protected function cache($path, $fileName, ISimpleFolder $folder) {
135
-		$deps = [];
136
-		$fullPath = $path . '/' . $fileName;
137
-		$data = json_decode(file_get_contents($fullPath));
138
-		$deps[$fullPath] = filemtime($fullPath);
139
-
140
-		$res = '';
141
-		foreach ($data as $file) {
142
-			$filePath = $path . '/' . $file;
143
-
144
-			if (is_file($filePath)) {
145
-				$res .= file_get_contents($filePath);
146
-				$res .= PHP_EOL . PHP_EOL;
147
-				$deps[$filePath] = filemtime($filePath);
148
-			}
149
-		}
150
-
151
-		$fileName = str_replace('.json', '.js', $fileName);
152
-		try {
153
-			$cachedfile = $folder->getFile($fileName);
154
-		} catch (NotFoundException $e) {
155
-			$cachedfile = $folder->newFile($fileName);
156
-		}
157
-
158
-		$depFileName = $fileName . '.deps';
159
-		try {
160
-			$depFile = $folder->getFile($depFileName);
161
-		} catch (NotFoundException $e) {
162
-			$depFile = $folder->newFile($depFileName);
163
-		}
164
-
165
-		try {
166
-			$gzipFile = $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz
167
-		} catch (NotFoundException $e) {
168
-			$gzipFile = $folder->newFile($fileName . '.gzip'); # Safari doesn't like .gz
169
-		}
170
-
171
-		try {
172
-			$cachedfile->putContent($res);
173
-			$deps = json_encode($deps);
174
-			$depFile->putContent($deps);
175
-			$this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
176
-			$gzipFile->putContent(gzencode($res, 9));
177
-			$this->logger->debug('JSCombiner: successfully cached: ' . $fileName);
178
-			return true;
179
-		} catch (NotPermittedException|NotFoundException $e) {
180
-			$this->logger->error('JSCombiner: unable to cache: ' . $fileName);
181
-			return false;
182
-		}
183
-	}
184
-
185
-	/**
186
-	 * @param string $appName
187
-	 * @param string $fileName
188
-	 * @return string
189
-	 */
190
-	public function getCachedJS($appName, $fileName) {
191
-		$tmpfileLoc = explode('/', $fileName);
192
-		$fileName = array_pop($tmpfileLoc);
193
-		$fileName = str_replace('.json', '.js', $fileName);
194
-
195
-		return substr($this->urlGenerator->linkToRoute('core.Js.getJs', ['fileName' => $fileName, 'appName' => $appName]), strlen(\OC::$WEBROOT) + 1);
196
-	}
197
-
198
-	/**
199
-	 * @param string $root
200
-	 * @param string $file
201
-	 * @return string[]
202
-	 */
203
-	public function getContent($root, $file) {
204
-		/** @var array $data */
205
-		$data = json_decode(file_get_contents($root . '/' . $file));
206
-		if (!is_array($data)) {
207
-			return [];
208
-		}
209
-
210
-		$path = explode('/', $file);
211
-		array_pop($path);
212
-		$path = implode('/', $path);
213
-
214
-		$result = [];
215
-		foreach ($data as $f) {
216
-			$result[] = $path . '/' . $f;
217
-		}
218
-
219
-		return $result;
220
-	}
221
-
222
-
223
-	/**
224
-	 * Clear cache with combined javascript files
225
-	 *
226
-	 * @throws NotFoundException
227
-	 */
228
-	public function resetCache() {
229
-		$this->cacheFactory->createDistributed('JS-')->clear();
230
-		$appDirectory = $this->appData->getDirectoryListing();
231
-		foreach ($appDirectory as $folder) {
232
-			foreach ($folder->getDirectoryListing() as $file) {
233
-				$file->delete();
234
-			}
235
-		}
236
-	}
19
+    /** @var IAppData */
20
+    protected $appData;
21
+
22
+    /** @var IURLGenerator */
23
+    protected $urlGenerator;
24
+
25
+    /** @var ICache */
26
+    protected $depsCache;
27
+
28
+    /** @var SystemConfig */
29
+    protected $config;
30
+
31
+    protected LoggerInterface $logger;
32
+
33
+    /** @var ICacheFactory */
34
+    private $cacheFactory;
35
+
36
+    public function __construct(IAppData $appData,
37
+        IURLGenerator $urlGenerator,
38
+        ICacheFactory $cacheFactory,
39
+        SystemConfig $config,
40
+        LoggerInterface $logger) {
41
+        $this->appData = $appData;
42
+        $this->urlGenerator = $urlGenerator;
43
+        $this->cacheFactory = $cacheFactory;
44
+        $this->depsCache = $this->cacheFactory->createDistributed('JS-' . md5($this->urlGenerator->getBaseUrl()));
45
+        $this->config = $config;
46
+        $this->logger = $logger;
47
+    }
48
+
49
+    /**
50
+     * @param string $root
51
+     * @param string $file
52
+     * @param string $app
53
+     * @return bool
54
+     */
55
+    public function process($root, $file, $app) {
56
+        if ($this->config->getValue('debug') || !$this->config->getValue('installed')) {
57
+            return false;
58
+        }
59
+
60
+        $path = explode('/', $root . '/' . $file);
61
+
62
+        $fileName = array_pop($path);
63
+        $path = implode('/', $path);
64
+
65
+        try {
66
+            $folder = $this->appData->getFolder($app);
67
+        } catch (NotFoundException $e) {
68
+            // creating css appdata folder
69
+            $folder = $this->appData->newFolder($app);
70
+        }
71
+
72
+        if ($this->isCached($fileName, $folder)) {
73
+            return true;
74
+        }
75
+        return $this->cache($path, $fileName, $folder);
76
+    }
77
+
78
+    /**
79
+     * @param string $fileName
80
+     * @param ISimpleFolder $folder
81
+     * @return bool
82
+     */
83
+    protected function isCached($fileName, ISimpleFolder $folder) {
84
+        $fileName = str_replace('.json', '.js', $fileName);
85
+
86
+        if (!$folder->fileExists($fileName)) {
87
+            return false;
88
+        }
89
+
90
+        $fileName = $fileName . '.deps';
91
+        try {
92
+            $deps = $this->depsCache->get($folder->getName() . '-' . $fileName);
93
+            $fromCache = true;
94
+            if ($deps === null || $deps === '') {
95
+                $fromCache = false;
96
+                $depFile = $folder->getFile($fileName);
97
+                $deps = $depFile->getContent();
98
+            }
99
+
100
+            // check again
101
+            if ($deps === null || $deps === '') {
102
+                $this->logger->info('JSCombiner: deps file empty: ' . $fileName);
103
+                return false;
104
+            }
105
+
106
+            $deps = json_decode($deps, true);
107
+
108
+            if ($deps === null) {
109
+                return false;
110
+            }
111
+
112
+            foreach ($deps as $file => $mtime) {
113
+                if (!file_exists($file) || filemtime($file) > $mtime) {
114
+                    return false;
115
+                }
116
+            }
117
+
118
+            if ($fromCache === false) {
119
+                $this->depsCache->set($folder->getName() . '-' . $fileName, json_encode($deps));
120
+            }
121
+
122
+            return true;
123
+        } catch (NotFoundException $e) {
124
+            return false;
125
+        }
126
+    }
127
+
128
+    /**
129
+     * @param string $path
130
+     * @param string $fileName
131
+     * @param ISimpleFolder $folder
132
+     * @return bool
133
+     */
134
+    protected function cache($path, $fileName, ISimpleFolder $folder) {
135
+        $deps = [];
136
+        $fullPath = $path . '/' . $fileName;
137
+        $data = json_decode(file_get_contents($fullPath));
138
+        $deps[$fullPath] = filemtime($fullPath);
139
+
140
+        $res = '';
141
+        foreach ($data as $file) {
142
+            $filePath = $path . '/' . $file;
143
+
144
+            if (is_file($filePath)) {
145
+                $res .= file_get_contents($filePath);
146
+                $res .= PHP_EOL . PHP_EOL;
147
+                $deps[$filePath] = filemtime($filePath);
148
+            }
149
+        }
150
+
151
+        $fileName = str_replace('.json', '.js', $fileName);
152
+        try {
153
+            $cachedfile = $folder->getFile($fileName);
154
+        } catch (NotFoundException $e) {
155
+            $cachedfile = $folder->newFile($fileName);
156
+        }
157
+
158
+        $depFileName = $fileName . '.deps';
159
+        try {
160
+            $depFile = $folder->getFile($depFileName);
161
+        } catch (NotFoundException $e) {
162
+            $depFile = $folder->newFile($depFileName);
163
+        }
164
+
165
+        try {
166
+            $gzipFile = $folder->getFile($fileName . '.gzip'); # Safari doesn't like .gz
167
+        } catch (NotFoundException $e) {
168
+            $gzipFile = $folder->newFile($fileName . '.gzip'); # Safari doesn't like .gz
169
+        }
170
+
171
+        try {
172
+            $cachedfile->putContent($res);
173
+            $deps = json_encode($deps);
174
+            $depFile->putContent($deps);
175
+            $this->depsCache->set($folder->getName() . '-' . $depFileName, $deps);
176
+            $gzipFile->putContent(gzencode($res, 9));
177
+            $this->logger->debug('JSCombiner: successfully cached: ' . $fileName);
178
+            return true;
179
+        } catch (NotPermittedException|NotFoundException $e) {
180
+            $this->logger->error('JSCombiner: unable to cache: ' . $fileName);
181
+            return false;
182
+        }
183
+    }
184
+
185
+    /**
186
+     * @param string $appName
187
+     * @param string $fileName
188
+     * @return string
189
+     */
190
+    public function getCachedJS($appName, $fileName) {
191
+        $tmpfileLoc = explode('/', $fileName);
192
+        $fileName = array_pop($tmpfileLoc);
193
+        $fileName = str_replace('.json', '.js', $fileName);
194
+
195
+        return substr($this->urlGenerator->linkToRoute('core.Js.getJs', ['fileName' => $fileName, 'appName' => $appName]), strlen(\OC::$WEBROOT) + 1);
196
+    }
197
+
198
+    /**
199
+     * @param string $root
200
+     * @param string $file
201
+     * @return string[]
202
+     */
203
+    public function getContent($root, $file) {
204
+        /** @var array $data */
205
+        $data = json_decode(file_get_contents($root . '/' . $file));
206
+        if (!is_array($data)) {
207
+            return [];
208
+        }
209
+
210
+        $path = explode('/', $file);
211
+        array_pop($path);
212
+        $path = implode('/', $path);
213
+
214
+        $result = [];
215
+        foreach ($data as $f) {
216
+            $result[] = $path . '/' . $f;
217
+        }
218
+
219
+        return $result;
220
+    }
221
+
222
+
223
+    /**
224
+     * Clear cache with combined javascript files
225
+     *
226
+     * @throws NotFoundException
227
+     */
228
+    public function resetCache() {
229
+        $this->cacheFactory->createDistributed('JS-')->clear();
230
+        $appDirectory = $this->appData->getDirectoryListing();
231
+        foreach ($appDirectory as $folder) {
232
+            foreach ($folder->getDirectoryListing() as $file) {
233
+                $file->delete();
234
+            }
235
+        }
236
+    }
237 237
 }
Please login to merge, or discard this patch.
lib/private/Files/Cache/Wrapper/CacheJail.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 		if ($path === '') {
80 80
 			return $this->getRoot();
81 81
 		} else {
82
-			return $this->getRoot() . '/' . ltrim($path, '/');
82
+			return $this->getRoot().'/'.ltrim($path, '/');
83 83
 		}
84 84
 	}
85 85
 
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 		$rootLength = strlen($root) + 1;
99 99
 		if ($path === $root) {
100 100
 			return '';
101
-		} elseif (substr($path, 0, $rootLength) === $root . '/') {
101
+		} elseif (substr($path, 0, $rootLength) === $root.'/') {
102 102
 			return substr($path, $rootLength);
103 103
 		} else {
104 104
 			return null;
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 					new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR,
318 318
 						[
319 319
 							new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()),
320
-							new SearchComparison(ISearchComparison::COMPARE_LIKE_CASE_SENSITIVE, 'path', SearchComparison::escapeLikeParameter($this->getGetUnjailedRoot()) . '/%'),
320
+							new SearchComparison(ISearchComparison::COMPARE_LIKE_CASE_SENSITIVE, 'path', SearchComparison::escapeLikeParameter($this->getGetUnjailedRoot()).'/%'),
321 321
 						],
322 322
 					)
323 323
 				]
Please login to merge, or discard this patch.
Indentation   +304 added lines, -304 removed lines patch added patch discarded remove patch
@@ -22,308 +22,308 @@
 block discarded – undo
22 22
  */
23 23
 class CacheJail extends CacheWrapper {
24 24
 
25
-	protected string $unjailedRoot;
26
-
27
-	public function __construct(
28
-		?ICache $cache,
29
-		protected string $root,
30
-		?CacheDependencies $dependencies = null,
31
-	) {
32
-		parent::__construct($cache, $dependencies);
33
-
34
-		$this->unjailedRoot = $root;
35
-		$parent = $cache;
36
-		while ($parent instanceof CacheWrapper) {
37
-			if ($parent instanceof CacheJail) {
38
-				$this->unjailedRoot = $parent->getSourcePath($this->unjailedRoot);
39
-			}
40
-			$parent = $parent->getCache();
41
-		}
42
-	}
43
-
44
-	/**
45
-	 * @return string
46
-	 */
47
-	protected function getRoot() {
48
-		return $this->root;
49
-	}
50
-
51
-	/**
52
-	 * Get the root path with any nested jails resolved
53
-	 *
54
-	 * @return string
55
-	 */
56
-	public function getGetUnjailedRoot() {
57
-		return $this->unjailedRoot;
58
-	}
59
-
60
-	/**
61
-	 * @return string
62
-	 */
63
-	protected function getSourcePath(string $path) {
64
-		if ($path === '') {
65
-			return $this->getRoot();
66
-		} else {
67
-			return $this->getRoot() . '/' . ltrim($path, '/');
68
-		}
69
-	}
70
-
71
-	/**
72
-	 * @param string $path
73
-	 * @param null|string $root
74
-	 * @return null|string the jailed path or null if the path is outside the jail
75
-	 */
76
-	protected function getJailedPath(string $path, ?string $root = null) {
77
-		if ($root === null) {
78
-			$root = $this->getRoot();
79
-		}
80
-		if ($root === '') {
81
-			return $path;
82
-		}
83
-		$rootLength = strlen($root) + 1;
84
-		if ($path === $root) {
85
-			return '';
86
-		} elseif (substr($path, 0, $rootLength) === $root . '/') {
87
-			return substr($path, $rootLength);
88
-		} else {
89
-			return null;
90
-		}
91
-	}
92
-
93
-	protected function formatCacheEntry($entry) {
94
-		if (isset($entry['path'])) {
95
-			$entry['path'] = $this->getJailedPath($entry['path']);
96
-		}
97
-		return $entry;
98
-	}
99
-
100
-	/**
101
-	 * get the stored metadata of a file or folder
102
-	 *
103
-	 * @param string|int $file
104
-	 * @return ICacheEntry|false
105
-	 */
106
-	public function get($file) {
107
-		if (is_string($file) or $file == '') {
108
-			$file = $this->getSourcePath($file);
109
-		}
110
-		return parent::get($file);
111
-	}
112
-
113
-	/**
114
-	 * insert meta data for a new file or folder
115
-	 *
116
-	 * @param string $file
117
-	 * @param array $data
118
-	 *
119
-	 * @return int file id
120
-	 * @throws \RuntimeException
121
-	 */
122
-	public function insert($file, array $data) {
123
-		return $this->getCache()->insert($this->getSourcePath($file), $data);
124
-	}
125
-
126
-	/**
127
-	 * update the metadata in the cache
128
-	 *
129
-	 * @param int $id
130
-	 * @param array $data
131
-	 */
132
-	public function update($id, array $data) {
133
-		$this->getCache()->update($id, $data);
134
-	}
135
-
136
-	/**
137
-	 * get the file id for a file
138
-	 *
139
-	 * @param string $file
140
-	 * @return int
141
-	 */
142
-	public function getId($file) {
143
-		return $this->getCache()->getId($this->getSourcePath($file));
144
-	}
145
-
146
-	/**
147
-	 * get the id of the parent folder of a file
148
-	 *
149
-	 * @param string $file
150
-	 * @return int
151
-	 */
152
-	public function getParentId($file) {
153
-		return $this->getCache()->getParentId($this->getSourcePath($file));
154
-	}
155
-
156
-	/**
157
-	 * check if a file is available in the cache
158
-	 *
159
-	 * @param string $file
160
-	 * @return bool
161
-	 */
162
-	public function inCache($file) {
163
-		return $this->getCache()->inCache($this->getSourcePath($file));
164
-	}
165
-
166
-	/**
167
-	 * remove a file or folder from the cache
168
-	 *
169
-	 * @param string $file
170
-	 */
171
-	public function remove($file) {
172
-		$this->getCache()->remove($this->getSourcePath($file));
173
-	}
174
-
175
-	/**
176
-	 * Move a file or folder in the cache
177
-	 *
178
-	 * @param string $source
179
-	 * @param string $target
180
-	 */
181
-	public function move($source, $target) {
182
-		$this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
183
-	}
184
-
185
-	/**
186
-	 * Get the storage id and path needed for a move
187
-	 *
188
-	 * @param string $path
189
-	 * @return array [$storageId, $internalPath]
190
-	 */
191
-	protected function getMoveInfo($path) {
192
-		return [$this->getNumericStorageId(), $this->getSourcePath($path)];
193
-	}
194
-
195
-	/**
196
-	 * remove all entries for files that are stored on the storage from the cache
197
-	 */
198
-	public function clear() {
199
-		$this->getCache()->remove($this->getRoot());
200
-	}
201
-
202
-	/**
203
-	 * @param string $file
204
-	 *
205
-	 * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
206
-	 */
207
-	public function getStatus($file) {
208
-		return $this->getCache()->getStatus($this->getSourcePath($file));
209
-	}
210
-
211
-	/**
212
-	 * update the folder size and the size of all parent folders
213
-	 *
214
-	 * @param array|ICacheEntry|null $data (optional) meta data of the folder
215
-	 */
216
-	public function correctFolderSize(string $path, $data = null, bool $isBackgroundScan = false): void {
217
-		$cache = $this->getCache();
218
-		if ($cache instanceof Cache) {
219
-			$cache->correctFolderSize($this->getSourcePath($path), $data, $isBackgroundScan);
220
-		}
221
-	}
222
-
223
-	/**
224
-	 * get the size of a folder and set it in the cache
225
-	 *
226
-	 * @param string $path
227
-	 * @param array|null|ICacheEntry $entry (optional) meta data of the folder
228
-	 * @return int|float
229
-	 */
230
-	public function calculateFolderSize($path, $entry = null) {
231
-		$cache = $this->getCache();
232
-		if ($cache instanceof Cache) {
233
-			return $cache->calculateFolderSize($this->getSourcePath($path), $entry);
234
-		} else {
235
-			return 0;
236
-		}
237
-	}
238
-
239
-	/**
240
-	 * get all file ids on the files on the storage
241
-	 *
242
-	 * @return int[]
243
-	 */
244
-	public function getAll() {
245
-		// not supported
246
-		return [];
247
-	}
248
-
249
-	/**
250
-	 * find a folder in the cache which has not been fully scanned
251
-	 *
252
-	 * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
253
-	 * use the one with the highest id gives the best result with the background scanner, since that is most
254
-	 * likely the folder where we stopped scanning previously
255
-	 *
256
-	 * @return string|false the path of the folder or false when no folder matched
257
-	 */
258
-	public function getIncomplete() {
259
-		// not supported
260
-		return false;
261
-	}
262
-
263
-	/**
264
-	 * get the path of a file on this storage by it's id
265
-	 *
266
-	 * @param int $id
267
-	 * @return string|null
268
-	 */
269
-	public function getPathById($id) {
270
-		$path = $this->getCache()->getPathById($id);
271
-		if ($path === null) {
272
-			return null;
273
-		}
274
-
275
-		return $this->getJailedPath($path);
276
-	}
277
-
278
-	/**
279
-	 * Move a file or folder in the cache
280
-	 *
281
-	 * Note that this should make sure the entries are removed from the source cache
282
-	 *
283
-	 * @param \OCP\Files\Cache\ICache $sourceCache
284
-	 * @param string $sourcePath
285
-	 * @param string $targetPath
286
-	 */
287
-	public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
288
-		if ($sourceCache === $this) {
289
-			return $this->move($sourcePath, $targetPath);
290
-		}
291
-		return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath));
292
-	}
293
-
294
-	public function getQueryFilterForStorage(): ISearchOperator {
295
-		return $this->addJailFilterQuery($this->getCache()->getQueryFilterForStorage());
296
-	}
297
-
298
-	protected function addJailFilterQuery(ISearchOperator $filter): ISearchOperator {
299
-		if ($this->getGetUnjailedRoot() !== '' && $this->getGetUnjailedRoot() !== '/') {
300
-			return new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND,
301
-				[
302
-					$filter,
303
-					new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR,
304
-						[
305
-							new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()),
306
-							new SearchComparison(ISearchComparison::COMPARE_LIKE_CASE_SENSITIVE, 'path', SearchComparison::escapeLikeParameter($this->getGetUnjailedRoot()) . '/%'),
307
-						],
308
-					)
309
-				]
310
-			);
311
-		} else {
312
-			return $filter;
313
-		}
314
-	}
315
-
316
-	public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {
317
-		if ($this->getGetUnjailedRoot() === '' || str_starts_with($rawEntry->getPath(), $this->getGetUnjailedRoot())) {
318
-			$rawEntry = $this->getCache()->getCacheEntryFromSearchResult($rawEntry);
319
-			if ($rawEntry) {
320
-				$jailedPath = $this->getJailedPath($rawEntry->getPath());
321
-				if ($jailedPath !== null) {
322
-					return $this->formatCacheEntry(clone $rawEntry) ?: null;
323
-				}
324
-			}
325
-		}
326
-
327
-		return null;
328
-	}
25
+    protected string $unjailedRoot;
26
+
27
+    public function __construct(
28
+        ?ICache $cache,
29
+        protected string $root,
30
+        ?CacheDependencies $dependencies = null,
31
+    ) {
32
+        parent::__construct($cache, $dependencies);
33
+
34
+        $this->unjailedRoot = $root;
35
+        $parent = $cache;
36
+        while ($parent instanceof CacheWrapper) {
37
+            if ($parent instanceof CacheJail) {
38
+                $this->unjailedRoot = $parent->getSourcePath($this->unjailedRoot);
39
+            }
40
+            $parent = $parent->getCache();
41
+        }
42
+    }
43
+
44
+    /**
45
+     * @return string
46
+     */
47
+    protected function getRoot() {
48
+        return $this->root;
49
+    }
50
+
51
+    /**
52
+     * Get the root path with any nested jails resolved
53
+     *
54
+     * @return string
55
+     */
56
+    public function getGetUnjailedRoot() {
57
+        return $this->unjailedRoot;
58
+    }
59
+
60
+    /**
61
+     * @return string
62
+     */
63
+    protected function getSourcePath(string $path) {
64
+        if ($path === '') {
65
+            return $this->getRoot();
66
+        } else {
67
+            return $this->getRoot() . '/' . ltrim($path, '/');
68
+        }
69
+    }
70
+
71
+    /**
72
+     * @param string $path
73
+     * @param null|string $root
74
+     * @return null|string the jailed path or null if the path is outside the jail
75
+     */
76
+    protected function getJailedPath(string $path, ?string $root = null) {
77
+        if ($root === null) {
78
+            $root = $this->getRoot();
79
+        }
80
+        if ($root === '') {
81
+            return $path;
82
+        }
83
+        $rootLength = strlen($root) + 1;
84
+        if ($path === $root) {
85
+            return '';
86
+        } elseif (substr($path, 0, $rootLength) === $root . '/') {
87
+            return substr($path, $rootLength);
88
+        } else {
89
+            return null;
90
+        }
91
+    }
92
+
93
+    protected function formatCacheEntry($entry) {
94
+        if (isset($entry['path'])) {
95
+            $entry['path'] = $this->getJailedPath($entry['path']);
96
+        }
97
+        return $entry;
98
+    }
99
+
100
+    /**
101
+     * get the stored metadata of a file or folder
102
+     *
103
+     * @param string|int $file
104
+     * @return ICacheEntry|false
105
+     */
106
+    public function get($file) {
107
+        if (is_string($file) or $file == '') {
108
+            $file = $this->getSourcePath($file);
109
+        }
110
+        return parent::get($file);
111
+    }
112
+
113
+    /**
114
+     * insert meta data for a new file or folder
115
+     *
116
+     * @param string $file
117
+     * @param array $data
118
+     *
119
+     * @return int file id
120
+     * @throws \RuntimeException
121
+     */
122
+    public function insert($file, array $data) {
123
+        return $this->getCache()->insert($this->getSourcePath($file), $data);
124
+    }
125
+
126
+    /**
127
+     * update the metadata in the cache
128
+     *
129
+     * @param int $id
130
+     * @param array $data
131
+     */
132
+    public function update($id, array $data) {
133
+        $this->getCache()->update($id, $data);
134
+    }
135
+
136
+    /**
137
+     * get the file id for a file
138
+     *
139
+     * @param string $file
140
+     * @return int
141
+     */
142
+    public function getId($file) {
143
+        return $this->getCache()->getId($this->getSourcePath($file));
144
+    }
145
+
146
+    /**
147
+     * get the id of the parent folder of a file
148
+     *
149
+     * @param string $file
150
+     * @return int
151
+     */
152
+    public function getParentId($file) {
153
+        return $this->getCache()->getParentId($this->getSourcePath($file));
154
+    }
155
+
156
+    /**
157
+     * check if a file is available in the cache
158
+     *
159
+     * @param string $file
160
+     * @return bool
161
+     */
162
+    public function inCache($file) {
163
+        return $this->getCache()->inCache($this->getSourcePath($file));
164
+    }
165
+
166
+    /**
167
+     * remove a file or folder from the cache
168
+     *
169
+     * @param string $file
170
+     */
171
+    public function remove($file) {
172
+        $this->getCache()->remove($this->getSourcePath($file));
173
+    }
174
+
175
+    /**
176
+     * Move a file or folder in the cache
177
+     *
178
+     * @param string $source
179
+     * @param string $target
180
+     */
181
+    public function move($source, $target) {
182
+        $this->getCache()->move($this->getSourcePath($source), $this->getSourcePath($target));
183
+    }
184
+
185
+    /**
186
+     * Get the storage id and path needed for a move
187
+     *
188
+     * @param string $path
189
+     * @return array [$storageId, $internalPath]
190
+     */
191
+    protected function getMoveInfo($path) {
192
+        return [$this->getNumericStorageId(), $this->getSourcePath($path)];
193
+    }
194
+
195
+    /**
196
+     * remove all entries for files that are stored on the storage from the cache
197
+     */
198
+    public function clear() {
199
+        $this->getCache()->remove($this->getRoot());
200
+    }
201
+
202
+    /**
203
+     * @param string $file
204
+     *
205
+     * @return int Cache::NOT_FOUND, Cache::PARTIAL, Cache::SHALLOW or Cache::COMPLETE
206
+     */
207
+    public function getStatus($file) {
208
+        return $this->getCache()->getStatus($this->getSourcePath($file));
209
+    }
210
+
211
+    /**
212
+     * update the folder size and the size of all parent folders
213
+     *
214
+     * @param array|ICacheEntry|null $data (optional) meta data of the folder
215
+     */
216
+    public function correctFolderSize(string $path, $data = null, bool $isBackgroundScan = false): void {
217
+        $cache = $this->getCache();
218
+        if ($cache instanceof Cache) {
219
+            $cache->correctFolderSize($this->getSourcePath($path), $data, $isBackgroundScan);
220
+        }
221
+    }
222
+
223
+    /**
224
+     * get the size of a folder and set it in the cache
225
+     *
226
+     * @param string $path
227
+     * @param array|null|ICacheEntry $entry (optional) meta data of the folder
228
+     * @return int|float
229
+     */
230
+    public function calculateFolderSize($path, $entry = null) {
231
+        $cache = $this->getCache();
232
+        if ($cache instanceof Cache) {
233
+            return $cache->calculateFolderSize($this->getSourcePath($path), $entry);
234
+        } else {
235
+            return 0;
236
+        }
237
+    }
238
+
239
+    /**
240
+     * get all file ids on the files on the storage
241
+     *
242
+     * @return int[]
243
+     */
244
+    public function getAll() {
245
+        // not supported
246
+        return [];
247
+    }
248
+
249
+    /**
250
+     * find a folder in the cache which has not been fully scanned
251
+     *
252
+     * If multiply incomplete folders are in the cache, the one with the highest id will be returned,
253
+     * use the one with the highest id gives the best result with the background scanner, since that is most
254
+     * likely the folder where we stopped scanning previously
255
+     *
256
+     * @return string|false the path of the folder or false when no folder matched
257
+     */
258
+    public function getIncomplete() {
259
+        // not supported
260
+        return false;
261
+    }
262
+
263
+    /**
264
+     * get the path of a file on this storage by it's id
265
+     *
266
+     * @param int $id
267
+     * @return string|null
268
+     */
269
+    public function getPathById($id) {
270
+        $path = $this->getCache()->getPathById($id);
271
+        if ($path === null) {
272
+            return null;
273
+        }
274
+
275
+        return $this->getJailedPath($path);
276
+    }
277
+
278
+    /**
279
+     * Move a file or folder in the cache
280
+     *
281
+     * Note that this should make sure the entries are removed from the source cache
282
+     *
283
+     * @param \OCP\Files\Cache\ICache $sourceCache
284
+     * @param string $sourcePath
285
+     * @param string $targetPath
286
+     */
287
+    public function moveFromCache(\OCP\Files\Cache\ICache $sourceCache, $sourcePath, $targetPath) {
288
+        if ($sourceCache === $this) {
289
+            return $this->move($sourcePath, $targetPath);
290
+        }
291
+        return $this->getCache()->moveFromCache($sourceCache, $sourcePath, $this->getSourcePath($targetPath));
292
+    }
293
+
294
+    public function getQueryFilterForStorage(): ISearchOperator {
295
+        return $this->addJailFilterQuery($this->getCache()->getQueryFilterForStorage());
296
+    }
297
+
298
+    protected function addJailFilterQuery(ISearchOperator $filter): ISearchOperator {
299
+        if ($this->getGetUnjailedRoot() !== '' && $this->getGetUnjailedRoot() !== '/') {
300
+            return new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_AND,
301
+                [
302
+                    $filter,
303
+                    new SearchBinaryOperator(ISearchBinaryOperator::OPERATOR_OR,
304
+                        [
305
+                            new SearchComparison(ISearchComparison::COMPARE_EQUAL, 'path', $this->getGetUnjailedRoot()),
306
+                            new SearchComparison(ISearchComparison::COMPARE_LIKE_CASE_SENSITIVE, 'path', SearchComparison::escapeLikeParameter($this->getGetUnjailedRoot()) . '/%'),
307
+                        ],
308
+                    )
309
+                ]
310
+            );
311
+        } else {
312
+            return $filter;
313
+        }
314
+    }
315
+
316
+    public function getCacheEntryFromSearchResult(ICacheEntry $rawEntry): ?ICacheEntry {
317
+        if ($this->getGetUnjailedRoot() === '' || str_starts_with($rawEntry->getPath(), $this->getGetUnjailedRoot())) {
318
+            $rawEntry = $this->getCache()->getCacheEntryFromSearchResult($rawEntry);
319
+            if ($rawEntry) {
320
+                $jailedPath = $this->getJailedPath($rawEntry->getPath());
321
+                if ($jailedPath !== null) {
322
+                    return $this->formatCacheEntry(clone $rawEntry) ?: null;
323
+                }
324
+            }
325
+        }
326
+
327
+        return null;
328
+    }
329 329
 }
Please login to merge, or discard this patch.
lib/public/Log/IWriter.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 14.0.0
29 29
  */
30 30
 interface IWriter {
31
-	/**
32
-	 * @since 14.0.0
33
-	 *
34
-	 * @param string $app
35
-	 * @param string|array $message
36
-	 * @param int $level
37
-	 */
38
-	public function write(string $app, $message, int $level);
31
+    /**
32
+     * @since 14.0.0
33
+     *
34
+     * @param string $app
35
+     * @param string|array $message
36
+     * @param int $level
37
+     */
38
+    public function write(string $app, $message, int $level);
39 39
 }
Please login to merge, or discard this patch.