Passed
Push — master ( fd284f...fa2878 )
by Morris
13:09 queued 12s
created
apps/federation/lib/DAV/FedAuth.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,40 +29,40 @@
 block discarded – undo
29 29
 
30 30
 class FedAuth extends AbstractBasic {
31 31
 
32
-	/** @var DbHandler */
33
-	private $db;
32
+    /** @var DbHandler */
33
+    private $db;
34 34
 
35
-	/**
36
-	 * FedAuth constructor.
37
-	 *
38
-	 * @param DbHandler $db
39
-	 */
40
-	public function __construct(DbHandler $db) {
41
-		$this->db = $db;
42
-		$this->principalPrefix = 'principals/system/';
35
+    /**
36
+     * FedAuth constructor.
37
+     *
38
+     * @param DbHandler $db
39
+     */
40
+    public function __construct(DbHandler $db) {
41
+        $this->db = $db;
42
+        $this->principalPrefix = 'principals/system/';
43 43
 
44
-		// setup realm
45
-		$defaults = new \OCP\Defaults();
46
-		$this->realm = $defaults->getName();
47
-	}
44
+        // setup realm
45
+        $defaults = new \OCP\Defaults();
46
+        $this->realm = $defaults->getName();
47
+    }
48 48
 
49
-	/**
50
-	 * Validates a username and password
51
-	 *
52
-	 * This method should return true or false depending on if login
53
-	 * succeeded.
54
-	 *
55
-	 * @param string $username
56
-	 * @param string $password
57
-	 * @return bool
58
-	 */
59
-	protected function validateUserPass($username, $password) {
60
-		return $this->db->auth($username, $password);
61
-	}
49
+    /**
50
+     * Validates a username and password
51
+     *
52
+     * This method should return true or false depending on if login
53
+     * succeeded.
54
+     *
55
+     * @param string $username
56
+     * @param string $password
57
+     * @return bool
58
+     */
59
+    protected function validateUserPass($username, $password) {
60
+        return $this->db->auth($username, $password);
61
+    }
62 62
 
63
-	/**
64
-	 * @inheritdoc
65
-	 */
66
-	public function challenge(RequestInterface $request, ResponseInterface $response) {
67
-	}
63
+    /**
64
+     * @inheritdoc
65
+     */
66
+    public function challenge(RequestInterface $request, ResponseInterface $response) {
67
+    }
68 68
 }
Please login to merge, or discard this patch.
apps/federation/lib/Controller/OCSAuthAPIController.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 */
135 135
 	public function requestSharedSecret($url, $token) {
136 136
 		if ($this->trustedServers->isTrustedServer($url) === false) {
137
-			$this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']);
137
+			$this->logger->error('remote server not trusted ('.$url.') while requesting shared secret', ['app' => 'federation']);
138 138
 			throw new OCSForbiddenException();
139 139
 		}
140 140
 
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
 		$localToken = $this->dbHandler->getToken($url);
144 144
 		if (strcmp($localToken, $token) > 0) {
145 145
 			$this->logger->info(
146
-				'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.',
146
+				'remote server ('.$url.') presented lower token. We will initiate the exchange of the shared secret.',
147 147
 				['app' => 'federation']
148 148
 			);
149 149
 			throw new OCSForbiddenException();
@@ -183,14 +183,14 @@  discard block
 block discarded – undo
183 183
 	 */
184 184
 	public function getSharedSecret($url, $token) {
185 185
 		if ($this->trustedServers->isTrustedServer($url) === false) {
186
-			$this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']);
186
+			$this->logger->error('remote server not trusted ('.$url.') while getting shared secret', ['app' => 'federation']);
187 187
 			throw new OCSForbiddenException();
188 188
 		}
189 189
 
190 190
 		if ($this->isValidToken($url, $token) === false) {
191 191
 			$expectedToken = $this->dbHandler->getToken($url);
192 192
 			$this->logger->error(
193
-				'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret',
193
+				'remote server ('.$url.') didn\'t send a valid token (got "'.$token.'" but expected "'.$expectedToken.'") while getting shared secret',
194 194
 				['app' => 'federation']
195 195
 			);
196 196
 			throw new OCSForbiddenException();
Please login to merge, or discard this patch.
Indentation   +160 added lines, -160 removed lines patch added patch discarded remove patch
@@ -48,164 +48,164 @@
 block discarded – undo
48 48
  */
49 49
 class OCSAuthAPIController extends OCSController {
50 50
 
51
-	/** @var ISecureRandom  */
52
-	private $secureRandom;
53
-
54
-	/** @var IJobList */
55
-	private $jobList;
56
-
57
-	/** @var TrustedServers */
58
-	private $trustedServers;
59
-
60
-	/** @var DbHandler */
61
-	private $dbHandler;
62
-
63
-	/** @var ILogger */
64
-	private $logger;
65
-
66
-	/** @var ITimeFactory */
67
-	private $timeFactory;
68
-
69
-	/**
70
-	 * OCSAuthAPI constructor.
71
-	 *
72
-	 * @param string $appName
73
-	 * @param IRequest $request
74
-	 * @param ISecureRandom $secureRandom
75
-	 * @param IJobList $jobList
76
-	 * @param TrustedServers $trustedServers
77
-	 * @param DbHandler $dbHandler
78
-	 * @param ILogger $logger
79
-	 * @param ITimeFactory $timeFactory
80
-	 */
81
-	public function __construct(
82
-		$appName,
83
-		IRequest $request,
84
-		ISecureRandom $secureRandom,
85
-		IJobList $jobList,
86
-		TrustedServers $trustedServers,
87
-		DbHandler $dbHandler,
88
-		ILogger $logger,
89
-		ITimeFactory $timeFactory
90
-	) {
91
-		parent::__construct($appName, $request);
92
-
93
-		$this->secureRandom = $secureRandom;
94
-		$this->jobList = $jobList;
95
-		$this->trustedServers = $trustedServers;
96
-		$this->dbHandler = $dbHandler;
97
-		$this->logger = $logger;
98
-		$this->timeFactory = $timeFactory;
99
-	}
100
-
101
-	/**
102
-	 * @NoCSRFRequired
103
-	 * @PublicPage
104
-	 *
105
-	 * request received to ask remote server for a shared secret, for legacy end-points
106
-	 *
107
-	 * @param string $url
108
-	 * @param string $token
109
-	 * @return Http\DataResponse
110
-	 * @throws OCSForbiddenException
111
-	 */
112
-	public function requestSharedSecretLegacy($url, $token) {
113
-		return $this->requestSharedSecret($url, $token);
114
-	}
115
-
116
-
117
-	/**
118
-	 * @NoCSRFRequired
119
-	 * @PublicPage
120
-	 *
121
-	 * create shared secret and return it, for legacy end-points
122
-	 *
123
-	 * @param string $url
124
-	 * @param string $token
125
-	 * @return Http\DataResponse
126
-	 * @throws OCSForbiddenException
127
-	 */
128
-	public function getSharedSecretLegacy($url, $token) {
129
-		return $this->getSharedSecret($url, $token);
130
-	}
131
-
132
-	/**
133
-	 * @NoCSRFRequired
134
-	 * @PublicPage
135
-	 *
136
-	 * request received to ask remote server for a shared secret
137
-	 *
138
-	 * @param string $url
139
-	 * @param string $token
140
-	 * @return Http\DataResponse
141
-	 * @throws OCSForbiddenException
142
-	 */
143
-	public function requestSharedSecret($url, $token) {
144
-		if ($this->trustedServers->isTrustedServer($url) === false) {
145
-			$this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']);
146
-			throw new OCSForbiddenException();
147
-		}
148
-
149
-		// if both server initiated the exchange of the shared secret the greater
150
-		// token wins
151
-		$localToken = $this->dbHandler->getToken($url);
152
-		if (strcmp($localToken, $token) > 0) {
153
-			$this->logger->info(
154
-				'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.',
155
-				['app' => 'federation']
156
-			);
157
-			throw new OCSForbiddenException();
158
-		}
159
-
160
-		$this->jobList->add(
161
-			'OCA\Federation\BackgroundJob\GetSharedSecret',
162
-			[
163
-				'url' => $url,
164
-				'token' => $token,
165
-				'created' => $this->timeFactory->getTime()
166
-			]
167
-		);
168
-
169
-		return new Http\DataResponse();
170
-	}
171
-
172
-	/**
173
-	 * @NoCSRFRequired
174
-	 * @PublicPage
175
-	 *
176
-	 * create shared secret and return it
177
-	 *
178
-	 * @param string $url
179
-	 * @param string $token
180
-	 * @return Http\DataResponse
181
-	 * @throws OCSForbiddenException
182
-	 */
183
-	public function getSharedSecret($url, $token) {
184
-		if ($this->trustedServers->isTrustedServer($url) === false) {
185
-			$this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']);
186
-			throw new OCSForbiddenException();
187
-		}
188
-
189
-		if ($this->isValidToken($url, $token) === false) {
190
-			$expectedToken = $this->dbHandler->getToken($url);
191
-			$this->logger->error(
192
-				'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret',
193
-				['app' => 'federation']
194
-			);
195
-			throw new OCSForbiddenException();
196
-		}
197
-
198
-		$sharedSecret = $this->secureRandom->generate(32);
199
-
200
-		$this->trustedServers->addSharedSecret($url, $sharedSecret);
201
-
202
-		return new Http\DataResponse([
203
-			'sharedSecret' => $sharedSecret
204
-		]);
205
-	}
206
-
207
-	protected function isValidToken($url, $token) {
208
-		$storedToken = $this->dbHandler->getToken($url);
209
-		return hash_equals($storedToken, $token);
210
-	}
51
+    /** @var ISecureRandom  */
52
+    private $secureRandom;
53
+
54
+    /** @var IJobList */
55
+    private $jobList;
56
+
57
+    /** @var TrustedServers */
58
+    private $trustedServers;
59
+
60
+    /** @var DbHandler */
61
+    private $dbHandler;
62
+
63
+    /** @var ILogger */
64
+    private $logger;
65
+
66
+    /** @var ITimeFactory */
67
+    private $timeFactory;
68
+
69
+    /**
70
+     * OCSAuthAPI constructor.
71
+     *
72
+     * @param string $appName
73
+     * @param IRequest $request
74
+     * @param ISecureRandom $secureRandom
75
+     * @param IJobList $jobList
76
+     * @param TrustedServers $trustedServers
77
+     * @param DbHandler $dbHandler
78
+     * @param ILogger $logger
79
+     * @param ITimeFactory $timeFactory
80
+     */
81
+    public function __construct(
82
+        $appName,
83
+        IRequest $request,
84
+        ISecureRandom $secureRandom,
85
+        IJobList $jobList,
86
+        TrustedServers $trustedServers,
87
+        DbHandler $dbHandler,
88
+        ILogger $logger,
89
+        ITimeFactory $timeFactory
90
+    ) {
91
+        parent::__construct($appName, $request);
92
+
93
+        $this->secureRandom = $secureRandom;
94
+        $this->jobList = $jobList;
95
+        $this->trustedServers = $trustedServers;
96
+        $this->dbHandler = $dbHandler;
97
+        $this->logger = $logger;
98
+        $this->timeFactory = $timeFactory;
99
+    }
100
+
101
+    /**
102
+     * @NoCSRFRequired
103
+     * @PublicPage
104
+     *
105
+     * request received to ask remote server for a shared secret, for legacy end-points
106
+     *
107
+     * @param string $url
108
+     * @param string $token
109
+     * @return Http\DataResponse
110
+     * @throws OCSForbiddenException
111
+     */
112
+    public function requestSharedSecretLegacy($url, $token) {
113
+        return $this->requestSharedSecret($url, $token);
114
+    }
115
+
116
+
117
+    /**
118
+     * @NoCSRFRequired
119
+     * @PublicPage
120
+     *
121
+     * create shared secret and return it, for legacy end-points
122
+     *
123
+     * @param string $url
124
+     * @param string $token
125
+     * @return Http\DataResponse
126
+     * @throws OCSForbiddenException
127
+     */
128
+    public function getSharedSecretLegacy($url, $token) {
129
+        return $this->getSharedSecret($url, $token);
130
+    }
131
+
132
+    /**
133
+     * @NoCSRFRequired
134
+     * @PublicPage
135
+     *
136
+     * request received to ask remote server for a shared secret
137
+     *
138
+     * @param string $url
139
+     * @param string $token
140
+     * @return Http\DataResponse
141
+     * @throws OCSForbiddenException
142
+     */
143
+    public function requestSharedSecret($url, $token) {
144
+        if ($this->trustedServers->isTrustedServer($url) === false) {
145
+            $this->logger->error('remote server not trusted (' . $url . ') while requesting shared secret', ['app' => 'federation']);
146
+            throw new OCSForbiddenException();
147
+        }
148
+
149
+        // if both server initiated the exchange of the shared secret the greater
150
+        // token wins
151
+        $localToken = $this->dbHandler->getToken($url);
152
+        if (strcmp($localToken, $token) > 0) {
153
+            $this->logger->info(
154
+                'remote server (' . $url . ') presented lower token. We will initiate the exchange of the shared secret.',
155
+                ['app' => 'federation']
156
+            );
157
+            throw new OCSForbiddenException();
158
+        }
159
+
160
+        $this->jobList->add(
161
+            'OCA\Federation\BackgroundJob\GetSharedSecret',
162
+            [
163
+                'url' => $url,
164
+                'token' => $token,
165
+                'created' => $this->timeFactory->getTime()
166
+            ]
167
+        );
168
+
169
+        return new Http\DataResponse();
170
+    }
171
+
172
+    /**
173
+     * @NoCSRFRequired
174
+     * @PublicPage
175
+     *
176
+     * create shared secret and return it
177
+     *
178
+     * @param string $url
179
+     * @param string $token
180
+     * @return Http\DataResponse
181
+     * @throws OCSForbiddenException
182
+     */
183
+    public function getSharedSecret($url, $token) {
184
+        if ($this->trustedServers->isTrustedServer($url) === false) {
185
+            $this->logger->error('remote server not trusted (' . $url . ') while getting shared secret', ['app' => 'federation']);
186
+            throw new OCSForbiddenException();
187
+        }
188
+
189
+        if ($this->isValidToken($url, $token) === false) {
190
+            $expectedToken = $this->dbHandler->getToken($url);
191
+            $this->logger->error(
192
+                'remote server (' . $url . ') didn\'t send a valid token (got "' . $token . '" but expected "'. $expectedToken . '") while getting shared secret',
193
+                ['app' => 'federation']
194
+            );
195
+            throw new OCSForbiddenException();
196
+        }
197
+
198
+        $sharedSecret = $this->secureRandom->generate(32);
199
+
200
+        $this->trustedServers->addSharedSecret($url, $sharedSecret);
201
+
202
+        return new Http\DataResponse([
203
+            'sharedSecret' => $sharedSecret
204
+        ]);
205
+    }
206
+
207
+    protected function isValidToken($url, $token) {
208
+        $storedToken = $this->dbHandler->getToken($url);
209
+        return hash_equals($storedToken, $token);
210
+    }
211 211
 }
Please login to merge, or discard this patch.
apps/systemtags/lib/Controller/LastUsedController.php 2 patches
Indentation   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -29,32 +29,32 @@
 block discarded – undo
29 29
 
30 30
 class LastUsedController extends Controller {
31 31
 
32
-	/** @var IConfig */
33
-	protected $config;
32
+    /** @var IConfig */
33
+    protected $config;
34 34
 
35
-	/** @var IUserSession */
36
-	protected $userSession;
35
+    /** @var IUserSession */
36
+    protected $userSession;
37 37
 
38
-	/**
39
-	 * @param string $appName
40
-	 * @param IRequest $request
41
-	 * @param IConfig $config
42
-	 * @param IUserSession $userSession
43
-	 */
44
-	public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) {
45
-		parent::__construct($appName, $request);
46
-		$this->config = $config;
47
-		$this->userSession = $userSession;
48
-	}
38
+    /**
39
+     * @param string $appName
40
+     * @param IRequest $request
41
+     * @param IConfig $config
42
+     * @param IUserSession $userSession
43
+     */
44
+    public function __construct($appName, IRequest $request, IConfig $config, IUserSession $userSession) {
45
+        parent::__construct($appName, $request);
46
+        $this->config = $config;
47
+        $this->userSession = $userSession;
48
+    }
49 49
 
50
-	/**
51
-	 * @NoAdminRequired
52
-	 */
53
-	public function getLastUsedTagIds() {
54
-		$lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]');
55
-		$tagIds = json_decode($lastUsed, true);
56
-		return new DataResponse(array_map(function ($id) {
57
-			return (string) $id;
58
-		}, $tagIds));
59
-	}
50
+    /**
51
+     * @NoAdminRequired
52
+     */
53
+    public function getLastUsedTagIds() {
54
+        $lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]');
55
+        $tagIds = json_decode($lastUsed, true);
56
+        return new DataResponse(array_map(function ($id) {
57
+            return (string) $id;
58
+        }, $tagIds));
59
+    }
60 60
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 	public function getLastUsedTagIds() {
54 54
 		$lastUsed = $this->config->getUserValue($this->userSession->getUser()->getUID(), 'systemtags', 'last_used', '[]');
55 55
 		$tagIds = json_decode($lastUsed, true);
56
-		return new DataResponse(array_map(function ($id) {
56
+		return new DataResponse(array_map(function($id) {
57 57
 			return (string) $id;
58 58
 		}, $tagIds));
59 59
 	}
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Command/Expire.php 1 patch
Indentation   +22 added lines, -22 removed lines patch added patch discarded remove patch
@@ -31,30 +31,30 @@
 block discarded – undo
31 31
 use OCP\Command\ICommand;
32 32
 
33 33
 class Expire implements ICommand {
34
-	use FileAccess;
34
+    use FileAccess;
35 35
 
36
-	/**
37
-	 * @var string
38
-	 */
39
-	private $user;
36
+    /**
37
+     * @var string
38
+     */
39
+    private $user;
40 40
 
41
-	/**
42
-	 * @param string $user
43
-	 */
44
-	public function __construct($user) {
45
-		$this->user = $user;
46
-	}
41
+    /**
42
+     * @param string $user
43
+     */
44
+    public function __construct($user) {
45
+        $this->user = $user;
46
+    }
47 47
 
48
-	public function handle() {
49
-		$userManager = \OC::$server->getUserManager();
50
-		if (!$userManager->userExists($this->user)) {
51
-			// User has been deleted already
52
-			return;
53
-		}
48
+    public function handle() {
49
+        $userManager = \OC::$server->getUserManager();
50
+        if (!$userManager->userExists($this->user)) {
51
+            // User has been deleted already
52
+            return;
53
+        }
54 54
 
55
-		\OC_Util::tearDownFS();
56
-		\OC_Util::setupFS($this->user);
57
-		Trashbin::expire($this->user);
58
-		\OC_Util::tearDownFS();
59
-	}
55
+        \OC_Util::tearDownFS();
56
+        \OC_Util::setupFS($this->user);
57
+        Trashbin::expire($this->user);
58
+        \OC_Util::tearDownFS();
59
+    }
60 60
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Command/ExpireTrash.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@  discard block
 block discarded – undo
90 90
 		} else {
91 91
 			$p = new ProgressBar($output);
92 92
 			$p->start();
93
-			$this->userManager->callForSeenUsers(function (IUser $user) use ($p) {
93
+			$this->userManager->callForSeenUsers(function(IUser $user) use ($p) {
94 94
 				$p->advance();
95 95
 				$this->expireTrashForUser($user);
96 96
 			});
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		\OC_Util::setupFS($user);
119 119
 
120 120
 		// Check if this user has a trashbin directory
121
-		$view = new \OC\Files\View('/' . $user);
121
+		$view = new \OC\Files\View('/'.$user);
122 122
 		if (!$view->is_dir('/files_trashbin/files')) {
123 123
 			return false;
124 124
 		}
Please login to merge, or discard this patch.
Indentation   +81 added lines, -81 removed lines patch added patch discarded remove patch
@@ -38,95 +38,95 @@
 block discarded – undo
38 38
 
39 39
 class ExpireTrash extends Command {
40 40
 
41
-	/**
42
-	 * @var Expiration
43
-	 */
44
-	private $expiration;
41
+    /**
42
+     * @var Expiration
43
+     */
44
+    private $expiration;
45 45
 
46
-	/**
47
-	 * @var IUserManager
48
-	 */
49
-	private $userManager;
46
+    /**
47
+     * @var IUserManager
48
+     */
49
+    private $userManager;
50 50
 
51
-	/**
52
-	 * @param IUserManager|null $userManager
53
-	 * @param Expiration|null $expiration
54
-	 */
55
-	public function __construct(IUserManager $userManager = null,
56
-								Expiration $expiration = null) {
57
-		parent::__construct();
51
+    /**
52
+     * @param IUserManager|null $userManager
53
+     * @param Expiration|null $expiration
54
+     */
55
+    public function __construct(IUserManager $userManager = null,
56
+                                Expiration $expiration = null) {
57
+        parent::__construct();
58 58
 
59
-		$this->userManager = $userManager;
60
-		$this->expiration = $expiration;
61
-	}
59
+        $this->userManager = $userManager;
60
+        $this->expiration = $expiration;
61
+    }
62 62
 
63
-	protected function configure() {
64
-		$this
65
-			->setName('trashbin:expire')
66
-			->setDescription('Expires the users trashbin')
67
-			->addArgument(
68
-				'user_id',
69
-				InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
70
-				'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired'
71
-			);
72
-	}
63
+    protected function configure() {
64
+        $this
65
+            ->setName('trashbin:expire')
66
+            ->setDescription('Expires the users trashbin')
67
+            ->addArgument(
68
+                'user_id',
69
+                InputArgument::OPTIONAL | InputArgument::IS_ARRAY,
70
+                'expires the trashbin of the given user(s), if no user is given the trash for all users will be expired'
71
+            );
72
+    }
73 73
 
74
-	protected function execute(InputInterface $input, OutputInterface $output): int {
75
-		$maxAge = $this->expiration->getMaxAgeAsTimestamp();
76
-		if (!$maxAge) {
77
-			$output->writeln("No expiry configured.");
78
-			return 1;
79
-		}
74
+    protected function execute(InputInterface $input, OutputInterface $output): int {
75
+        $maxAge = $this->expiration->getMaxAgeAsTimestamp();
76
+        if (!$maxAge) {
77
+            $output->writeln("No expiry configured.");
78
+            return 1;
79
+        }
80 80
 
81
-		$users = $input->getArgument('user_id');
82
-		if (!empty($users)) {
83
-			foreach ($users as $user) {
84
-				if ($this->userManager->userExists($user)) {
85
-					$output->writeln("Remove deleted files of   <info>$user</info>");
86
-					$userObject = $this->userManager->get($user);
87
-					$this->expireTrashForUser($userObject);
88
-				} else {
89
-					$output->writeln("<error>Unknown user $user</error>");
90
-					return 1;
91
-				}
92
-			}
93
-		} else {
94
-			$p = new ProgressBar($output);
95
-			$p->start();
96
-			$this->userManager->callForSeenUsers(function (IUser $user) use ($p) {
97
-				$p->advance();
98
-				$this->expireTrashForUser($user);
99
-			});
100
-			$p->finish();
101
-			$output->writeln('');
102
-		}
103
-		return 0;
104
-	}
81
+        $users = $input->getArgument('user_id');
82
+        if (!empty($users)) {
83
+            foreach ($users as $user) {
84
+                if ($this->userManager->userExists($user)) {
85
+                    $output->writeln("Remove deleted files of   <info>$user</info>");
86
+                    $userObject = $this->userManager->get($user);
87
+                    $this->expireTrashForUser($userObject);
88
+                } else {
89
+                    $output->writeln("<error>Unknown user $user</error>");
90
+                    return 1;
91
+                }
92
+            }
93
+        } else {
94
+            $p = new ProgressBar($output);
95
+            $p->start();
96
+            $this->userManager->callForSeenUsers(function (IUser $user) use ($p) {
97
+                $p->advance();
98
+                $this->expireTrashForUser($user);
99
+            });
100
+            $p->finish();
101
+            $output->writeln('');
102
+        }
103
+        return 0;
104
+    }
105 105
 
106
-	public function expireTrashForUser(IUser $user) {
107
-		$uid = $user->getUID();
108
-		if (!$this->setupFS($uid)) {
109
-			return;
110
-		}
111
-		$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
112
-		Trashbin::deleteExpiredFiles($dirContent, $uid);
113
-	}
106
+    public function expireTrashForUser(IUser $user) {
107
+        $uid = $user->getUID();
108
+        if (!$this->setupFS($uid)) {
109
+            return;
110
+        }
111
+        $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
112
+        Trashbin::deleteExpiredFiles($dirContent, $uid);
113
+    }
114 114
 
115
-	/**
116
-	 * Act on behalf on trash item owner
117
-	 * @param string $user
118
-	 * @return boolean
119
-	 */
120
-	protected function setupFS($user) {
121
-		\OC_Util::tearDownFS();
122
-		\OC_Util::setupFS($user);
115
+    /**
116
+     * Act on behalf on trash item owner
117
+     * @param string $user
118
+     * @return boolean
119
+     */
120
+    protected function setupFS($user) {
121
+        \OC_Util::tearDownFS();
122
+        \OC_Util::setupFS($user);
123 123
 
124
-		// Check if this user has a trashbin directory
125
-		$view = new \OC\Files\View('/' . $user);
126
-		if (!$view->is_dir('/files_trashbin/files')) {
127
-			return false;
128
-		}
124
+        // Check if this user has a trashbin directory
125
+        $view = new \OC\Files\View('/' . $user);
126
+        if (!$view->is_dir('/files_trashbin/files')) {
127
+            return false;
128
+        }
129 129
 
130
-		return true;
131
-	}
130
+        return true;
131
+    }
132 132
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/BackgroundJob/ExpireTrash.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -78,7 +78,7 @@  discard block
 block discarded – undo
78 78
 			return;
79 79
 		}
80 80
 
81
-		$this->userManager->callForSeenUsers(function (IUser $user) {
81
+		$this->userManager->callForSeenUsers(function(IUser $user) {
82 82
 			$uid = $user->getUID();
83 83
 			if (!$this->setupFS($uid)) {
84 84
 				return;
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		\OC_Util::setupFS($user);
101 101
 
102 102
 		// Check if this user has a trashbin directory
103
-		$view = new \OC\Files\View('/' . $user);
103
+		$view = new \OC\Files\View('/'.$user);
104 104
 		if (!$view->is_dir('/files_trashbin/files')) {
105 105
 			return false;
106 106
 		}
Please login to merge, or discard this patch.
Indentation   +63 added lines, -63 removed lines patch added patch discarded remove patch
@@ -36,77 +36,77 @@
 block discarded – undo
36 36
 
37 37
 class ExpireTrash extends \OC\BackgroundJob\TimedJob {
38 38
 
39
-	/**
40
-	 * @var Expiration
41
-	 */
42
-	private $expiration;
39
+    /**
40
+     * @var Expiration
41
+     */
42
+    private $expiration;
43 43
 	
44
-	/**
45
-	 * @var IUserManager
46
-	 */
47
-	private $userManager;
44
+    /**
45
+     * @var IUserManager
46
+     */
47
+    private $userManager;
48 48
 
49
-	/**
50
-	 * @param IUserManager|null $userManager
51
-	 * @param Expiration|null $expiration
52
-	 */
53
-	public function __construct(IUserManager $userManager = null,
54
-								Expiration $expiration = null) {
55
-		// Run once per 30 minutes
56
-		$this->setInterval(60 * 30);
49
+    /**
50
+     * @param IUserManager|null $userManager
51
+     * @param Expiration|null $expiration
52
+     */
53
+    public function __construct(IUserManager $userManager = null,
54
+                                Expiration $expiration = null) {
55
+        // Run once per 30 minutes
56
+        $this->setInterval(60 * 30);
57 57
 
58
-		if (is_null($expiration) || is_null($userManager)) {
59
-			$this->fixDIForJobs();
60
-		} else {
61
-			$this->userManager = $userManager;
62
-			$this->expiration = $expiration;
63
-		}
64
-	}
58
+        if (is_null($expiration) || is_null($userManager)) {
59
+            $this->fixDIForJobs();
60
+        } else {
61
+            $this->userManager = $userManager;
62
+            $this->expiration = $expiration;
63
+        }
64
+    }
65 65
 
66
-	protected function fixDIForJobs() {
67
-		/** @var Application $application */
68
-		$application = \OC::$server->query(Application::class);
69
-		$this->userManager = \OC::$server->getUserManager();
70
-		$this->expiration = $application->getContainer()->query('Expiration');
71
-	}
66
+    protected function fixDIForJobs() {
67
+        /** @var Application $application */
68
+        $application = \OC::$server->query(Application::class);
69
+        $this->userManager = \OC::$server->getUserManager();
70
+        $this->expiration = $application->getContainer()->query('Expiration');
71
+    }
72 72
 
73
-	/**
74
-	 * @param $argument
75
-	 * @throws \Exception
76
-	 */
77
-	protected function run($argument) {
78
-		$maxAge = $this->expiration->getMaxAgeAsTimestamp();
79
-		if (!$maxAge) {
80
-			return;
81
-		}
73
+    /**
74
+     * @param $argument
75
+     * @throws \Exception
76
+     */
77
+    protected function run($argument) {
78
+        $maxAge = $this->expiration->getMaxAgeAsTimestamp();
79
+        if (!$maxAge) {
80
+            return;
81
+        }
82 82
 
83
-		$this->userManager->callForSeenUsers(function (IUser $user) {
84
-			$uid = $user->getUID();
85
-			if (!$this->setupFS($uid)) {
86
-				return;
87
-			}
88
-			$dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
89
-			Trashbin::deleteExpiredFiles($dirContent, $uid);
90
-		});
83
+        $this->userManager->callForSeenUsers(function (IUser $user) {
84
+            $uid = $user->getUID();
85
+            if (!$this->setupFS($uid)) {
86
+                return;
87
+            }
88
+            $dirContent = Helper::getTrashFiles('/', $uid, 'mtime');
89
+            Trashbin::deleteExpiredFiles($dirContent, $uid);
90
+        });
91 91
 		
92
-		\OC_Util::tearDownFS();
93
-	}
92
+        \OC_Util::tearDownFS();
93
+    }
94 94
 
95
-	/**
96
-	 * Act on behalf on trash item owner
97
-	 * @param string $user
98
-	 * @return boolean
99
-	 */
100
-	protected function setupFS($user) {
101
-		\OC_Util::tearDownFS();
102
-		\OC_Util::setupFS($user);
95
+    /**
96
+     * Act on behalf on trash item owner
97
+     * @param string $user
98
+     * @return boolean
99
+     */
100
+    protected function setupFS($user) {
101
+        \OC_Util::tearDownFS();
102
+        \OC_Util::setupFS($user);
103 103
 
104
-		// Check if this user has a trashbin directory
105
-		$view = new \OC\Files\View('/' . $user);
106
-		if (!$view->is_dir('/files_trashbin/files')) {
107
-			return false;
108
-		}
104
+        // Check if this user has a trashbin directory
105
+        $view = new \OC\Files\View('/' . $user);
106
+        if (!$view->is_dir('/files_trashbin/files')) {
107
+            return false;
108
+        }
109 109
 
110
-		return true;
111
-	}
110
+        return true;
111
+    }
112 112
 }
Please login to merge, or discard this patch.
apps/files_trashbin/lib/Helper.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -44,7 +44,7 @@  discard block
 block discarded – undo
44 44
 		$result = [];
45 45
 		$timestamp = null;
46 46
 
47
-		$view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
47
+		$view = new \OC\Files\View('/'.$user.'/files_trashbin/files');
48 48
 
49 49
 		if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
50 50
 			throw new \Exception('Directory does not exists');
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
 			];
92 92
 			if ($originalPath) {
93 93
 				if ($originalPath !== '.') {
94
-					$i['extraData'] = $originalPath . '/' . $originalName;
94
+					$i['extraData'] = $originalPath.'/'.$originalName;
95 95
 				} else {
96 96
 					$i['extraData'] = $originalName;
97 97
 				}
98 98
 			}
99
-			$result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
99
+			$result[] = new FileInfo($absoluteDir.'/'.$i['name'], $storage, $internalPath.'/'.$i['name'], $i, $mount);
100 100
 		}
101 101
 
102 102
 		if ($sortAttribute !== '') {
Please login to merge, or discard this patch.
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -36,95 +36,95 @@
 block discarded – undo
36 36
 use OCP\Files\Cache\ICacheEntry;
37 37
 
38 38
 class Helper {
39
-	/**
40
-	 * Retrieves the contents of a trash bin directory.
41
-	 *
42
-	 * @param string $dir path to the directory inside the trashbin
43
-	 * or empty to retrieve the root of the trashbin
44
-	 * @param string $user
45
-	 * @param string $sortAttribute attribute to sort on or empty to disable sorting
46
-	 * @param bool $sortDescending true for descending sort, false otherwise
47
-	 * @return \OCP\Files\FileInfo[]
48
-	 */
49
-	public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) {
50
-		$result = [];
51
-		$timestamp = null;
39
+    /**
40
+     * Retrieves the contents of a trash bin directory.
41
+     *
42
+     * @param string $dir path to the directory inside the trashbin
43
+     * or empty to retrieve the root of the trashbin
44
+     * @param string $user
45
+     * @param string $sortAttribute attribute to sort on or empty to disable sorting
46
+     * @param bool $sortDescending true for descending sort, false otherwise
47
+     * @return \OCP\Files\FileInfo[]
48
+     */
49
+    public static function getTrashFiles($dir, $user, $sortAttribute = '', $sortDescending = false) {
50
+        $result = [];
51
+        $timestamp = null;
52 52
 
53
-		$view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
53
+        $view = new \OC\Files\View('/' . $user . '/files_trashbin/files');
54 54
 
55
-		if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
56
-			throw new \Exception('Directory does not exists');
57
-		}
55
+        if (ltrim($dir, '/') !== '' && !$view->is_dir($dir)) {
56
+            throw new \Exception('Directory does not exists');
57
+        }
58 58
 
59
-		$mount = $view->getMount($dir);
60
-		$storage = $mount->getStorage();
61
-		$absoluteDir = $view->getAbsolutePath($dir);
62
-		$internalPath = $mount->getInternalPath($absoluteDir);
59
+        $mount = $view->getMount($dir);
60
+        $storage = $mount->getStorage();
61
+        $absoluteDir = $view->getAbsolutePath($dir);
62
+        $internalPath = $mount->getInternalPath($absoluteDir);
63 63
 
64
-		$originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
65
-		$dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
66
-		foreach ($dirContent as $entry) {
67
-			$entryName = $entry->getName();
68
-			$name = $entryName;
69
-			if ($dir === '' || $dir === '/') {
70
-				$pathparts = pathinfo($entryName);
71
-				$timestamp = substr($pathparts['extension'], 1);
72
-				$name = $pathparts['filename'];
73
-			} elseif ($timestamp === null) {
74
-				// for subfolders we need to calculate the timestamp only once
75
-				$parts = explode('/', ltrim($dir, '/'));
76
-				$timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
77
-			}
78
-			$originalPath = '';
79
-			$originalName = substr($entryName, 0, -strlen($timestamp) - 2);
80
-			if (isset($originalLocations[$originalName][$timestamp])) {
81
-				$originalPath = $originalLocations[$originalName][$timestamp];
82
-				if (substr($originalPath, -1) === '/') {
83
-					$originalPath = substr($originalPath, 0, -1);
84
-				}
85
-			}
86
-			$type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file';
87
-			$i = [
88
-				'name' => $name,
89
-				'mtime' => $timestamp,
90
-				'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name),
91
-				'type' => $type,
92
-				'directory' => ($dir === '/') ? '' : $dir,
93
-				'size' => $entry->getSize(),
94
-				'etag' => '',
95
-				'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
96
-				'fileid' => $entry->getId(),
97
-			];
98
-			if ($originalPath) {
99
-				if ($originalPath !== '.') {
100
-					$i['extraData'] = $originalPath . '/' . $originalName;
101
-				} else {
102
-					$i['extraData'] = $originalName;
103
-				}
104
-			}
105
-			$result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
106
-		}
64
+        $originalLocations = \OCA\Files_Trashbin\Trashbin::getLocations($user);
65
+        $dirContent = $storage->getCache()->getFolderContents($mount->getInternalPath($view->getAbsolutePath($dir)));
66
+        foreach ($dirContent as $entry) {
67
+            $entryName = $entry->getName();
68
+            $name = $entryName;
69
+            if ($dir === '' || $dir === '/') {
70
+                $pathparts = pathinfo($entryName);
71
+                $timestamp = substr($pathparts['extension'], 1);
72
+                $name = $pathparts['filename'];
73
+            } elseif ($timestamp === null) {
74
+                // for subfolders we need to calculate the timestamp only once
75
+                $parts = explode('/', ltrim($dir, '/'));
76
+                $timestamp = substr(pathinfo($parts[0], PATHINFO_EXTENSION), 1);
77
+            }
78
+            $originalPath = '';
79
+            $originalName = substr($entryName, 0, -strlen($timestamp) - 2);
80
+            if (isset($originalLocations[$originalName][$timestamp])) {
81
+                $originalPath = $originalLocations[$originalName][$timestamp];
82
+                if (substr($originalPath, -1) === '/') {
83
+                    $originalPath = substr($originalPath, 0, -1);
84
+                }
85
+            }
86
+            $type = $entry->getMimeType() === ICacheEntry::DIRECTORY_MIMETYPE ? 'dir' : 'file';
87
+            $i = [
88
+                'name' => $name,
89
+                'mtime' => $timestamp,
90
+                'mimetype' => $type === 'dir' ? 'httpd/unix-directory' : \OC::$server->getMimeTypeDetector()->detectPath($name),
91
+                'type' => $type,
92
+                'directory' => ($dir === '/') ? '' : $dir,
93
+                'size' => $entry->getSize(),
94
+                'etag' => '',
95
+                'permissions' => Constants::PERMISSION_ALL - Constants::PERMISSION_SHARE,
96
+                'fileid' => $entry->getId(),
97
+            ];
98
+            if ($originalPath) {
99
+                if ($originalPath !== '.') {
100
+                    $i['extraData'] = $originalPath . '/' . $originalName;
101
+                } else {
102
+                    $i['extraData'] = $originalName;
103
+                }
104
+            }
105
+            $result[] = new FileInfo($absoluteDir . '/' . $i['name'], $storage, $internalPath . '/' . $i['name'], $i, $mount);
106
+        }
107 107
 
108
-		if ($sortAttribute !== '') {
109
-			return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
110
-		}
111
-		return $result;
112
-	}
108
+        if ($sortAttribute !== '') {
109
+            return \OCA\Files\Helper::sortFiles($result, $sortAttribute, $sortDescending);
110
+        }
111
+        return $result;
112
+    }
113 113
 
114
-	/**
115
-	 * Format file infos for JSON
116
-	 *
117
-	 * @param \OCP\Files\FileInfo[] $fileInfos file infos
118
-	 */
119
-	public static function formatFileInfos($fileInfos) {
120
-		$files = [];
121
-		foreach ($fileInfos as $i) {
122
-			$entry = \OCA\Files\Helper::formatFileInfo($i);
123
-			$entry['id'] = $i->getId();
124
-			$entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
125
-			$entry['permissions'] = \OCP\Constants::PERMISSION_READ;
126
-			$files[] = $entry;
127
-		}
128
-		return $files;
129
-	}
114
+    /**
115
+     * Format file infos for JSON
116
+     *
117
+     * @param \OCP\Files\FileInfo[] $fileInfos file infos
118
+     */
119
+    public static function formatFileInfos($fileInfos) {
120
+        $files = [];
121
+        foreach ($fileInfos as $i) {
122
+            $entry = \OCA\Files\Helper::formatFileInfo($i);
123
+            $entry['id'] = $i->getId();
124
+            $entry['etag'] = $entry['mtime']; // add fake etag, it is only needed to identify the preview image
125
+            $entry['permissions'] = \OCP\Constants::PERMISSION_READ;
126
+            $files[] = $entry;
127
+        }
128
+        return $files;
129
+    }
130 130
 }
Please login to merge, or discard this patch.
apps/comments/lib/Notification/Listener.php 2 patches
Indentation   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -27,91 +27,91 @@
 block discarded – undo
27 27
 use OCP\Notification\IManager;
28 28
 
29 29
 class Listener {
30
-	/** @var IManager */
31
-	protected $notificationManager;
30
+    /** @var IManager */
31
+    protected $notificationManager;
32 32
 
33
-	/** @var IUserManager */
34
-	protected $userManager;
33
+    /** @var IUserManager */
34
+    protected $userManager;
35 35
 
36
-	/**
37
-	 * Listener constructor.
38
-	 *
39
-	 * @param IManager $notificationManager
40
-	 * @param IUserManager $userManager
41
-	 */
42
-	public function __construct(
43
-		IManager $notificationManager,
44
-		IUserManager $userManager
45
-	) {
46
-		$this->notificationManager = $notificationManager;
47
-		$this->userManager = $userManager;
48
-	}
36
+    /**
37
+     * Listener constructor.
38
+     *
39
+     * @param IManager $notificationManager
40
+     * @param IUserManager $userManager
41
+     */
42
+    public function __construct(
43
+        IManager $notificationManager,
44
+        IUserManager $userManager
45
+    ) {
46
+        $this->notificationManager = $notificationManager;
47
+        $this->userManager = $userManager;
48
+    }
49 49
 
50
-	/**
51
-	 * @param CommentsEvent $event
52
-	 */
53
-	public function evaluate(CommentsEvent $event) {
54
-		$comment = $event->getComment();
50
+    /**
51
+     * @param CommentsEvent $event
52
+     */
53
+    public function evaluate(CommentsEvent $event) {
54
+        $comment = $event->getComment();
55 55
 
56
-		$mentions = $this->extractMentions($comment->getMentions());
57
-		if (empty($mentions)) {
58
-			// no one to notify
59
-			return;
60
-		}
56
+        $mentions = $this->extractMentions($comment->getMentions());
57
+        if (empty($mentions)) {
58
+            // no one to notify
59
+            return;
60
+        }
61 61
 
62
-		$notification = $this->instantiateNotification($comment);
62
+        $notification = $this->instantiateNotification($comment);
63 63
 
64
-		foreach ($mentions as $uid) {
65
-			if (($comment->getActorType() === 'users' && $uid === $comment->getActorId())
66
-				|| !$this->userManager->userExists($uid)
67
-			) {
68
-				// do not notify unknown users or yourself
69
-				continue;
70
-			}
64
+        foreach ($mentions as $uid) {
65
+            if (($comment->getActorType() === 'users' && $uid === $comment->getActorId())
66
+                || !$this->userManager->userExists($uid)
67
+            ) {
68
+                // do not notify unknown users or yourself
69
+                continue;
70
+            }
71 71
 
72
-			$notification->setUser($uid);
73
-			if ($event->getEvent() === CommentsEvent::EVENT_DELETE
74
-				|| $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) {
75
-				$this->notificationManager->markProcessed($notification);
76
-			} else {
77
-				$this->notificationManager->notify($notification);
78
-			}
79
-		}
80
-	}
72
+            $notification->setUser($uid);
73
+            if ($event->getEvent() === CommentsEvent::EVENT_DELETE
74
+                || $event->getEvent() === CommentsEvent::EVENT_PRE_UPDATE) {
75
+                $this->notificationManager->markProcessed($notification);
76
+            } else {
77
+                $this->notificationManager->notify($notification);
78
+            }
79
+        }
80
+    }
81 81
 
82
-	/**
83
-	 * creates a notification instance and fills it with comment data
84
-	 *
85
-	 * @param IComment $comment
86
-	 * @return \OCP\Notification\INotification
87
-	 */
88
-	public function instantiateNotification(IComment $comment) {
89
-		$notification = $this->notificationManager->createNotification();
90
-		$notification
91
-			->setApp('comments')
92
-			->setObject('comment', $comment->getId())
93
-			->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ])
94
-			->setDateTime($comment->getCreationDateTime());
82
+    /**
83
+     * creates a notification instance and fills it with comment data
84
+     *
85
+     * @param IComment $comment
86
+     * @return \OCP\Notification\INotification
87
+     */
88
+    public function instantiateNotification(IComment $comment) {
89
+        $notification = $this->notificationManager->createNotification();
90
+        $notification
91
+            ->setApp('comments')
92
+            ->setObject('comment', $comment->getId())
93
+            ->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ])
94
+            ->setDateTime($comment->getCreationDateTime());
95 95
 
96
-		return $notification;
97
-	}
96
+        return $notification;
97
+    }
98 98
 
99
-	/**
100
-	 * flattens the mention array returned from comments to a list of user ids.
101
-	 *
102
-	 * @param array $mentions
103
-	 * @return string[] containing the mentions, e.g. ['alice', 'bob']
104
-	 */
105
-	public function extractMentions(array $mentions) {
106
-		if (empty($mentions)) {
107
-			return [];
108
-		}
109
-		$uids = [];
110
-		foreach ($mentions as $mention) {
111
-			if ($mention['type'] === 'user') {
112
-				$uids[] = $mention['id'];
113
-			}
114
-		}
115
-		return $uids;
116
-	}
99
+    /**
100
+     * flattens the mention array returned from comments to a list of user ids.
101
+     *
102
+     * @param array $mentions
103
+     * @return string[] containing the mentions, e.g. ['alice', 'bob']
104
+     */
105
+    public function extractMentions(array $mentions) {
106
+        if (empty($mentions)) {
107
+            return [];
108
+        }
109
+        $uids = [];
110
+        foreach ($mentions as $mention) {
111
+            if ($mention['type'] === 'user') {
112
+                $uids[] = $mention['id'];
113
+            }
114
+        }
115
+        return $uids;
116
+    }
117 117
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -90,7 +90,7 @@
 block discarded – undo
90 90
 		$notification
91 91
 			->setApp('comments')
92 92
 			->setObject('comment', $comment->getId())
93
-			->setSubject('mention', [ $comment->getObjectType(), $comment->getObjectId() ])
93
+			->setSubject('mention', [$comment->getObjectType(), $comment->getObjectId()])
94 94
 			->setDateTime($comment->getCreationDateTime());
95 95
 
96 96
 		return $notification;
Please login to merge, or discard this patch.
apps/comments/lib/EventHandler.php 1 patch
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -36,56 +36,56 @@
 block discarded – undo
36 36
  * @package OCA\Comments
37 37
  */
38 38
 class EventHandler implements ICommentsEventHandler {
39
-	/** @var ActivityListener */
40
-	private $activityListener;
39
+    /** @var ActivityListener */
40
+    private $activityListener;
41 41
 
42
-	/** @var NotificationListener */
43
-	private $notificationListener;
42
+    /** @var NotificationListener */
43
+    private $notificationListener;
44 44
 
45
-	public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) {
46
-		$this->activityListener = $activityListener;
47
-		$this->notificationListener = $notificationListener;
48
-	}
45
+    public function __construct(ActivityListener $activityListener, NotificationListener $notificationListener) {
46
+        $this->activityListener = $activityListener;
47
+        $this->notificationListener = $notificationListener;
48
+    }
49 49
 
50
-	/**
51
-	 * @param CommentsEvent $event
52
-	 */
53
-	public function handle(CommentsEvent $event) {
54
-		if ($event->getComment()->getObjectType() !== 'files') {
55
-			// this is a 'files'-specific Handler
56
-			return;
57
-		}
50
+    /**
51
+     * @param CommentsEvent $event
52
+     */
53
+    public function handle(CommentsEvent $event) {
54
+        if ($event->getComment()->getObjectType() !== 'files') {
55
+            // this is a 'files'-specific Handler
56
+            return;
57
+        }
58 58
 
59
-		$eventType = $event->getEvent();
60
-		if ($eventType === CommentsEvent::EVENT_ADD
61
-		) {
62
-			$this->notificationHandler($event);
63
-			$this->activityHandler($event);
64
-			return;
65
-		}
59
+        $eventType = $event->getEvent();
60
+        if ($eventType === CommentsEvent::EVENT_ADD
61
+        ) {
62
+            $this->notificationHandler($event);
63
+            $this->activityHandler($event);
64
+            return;
65
+        }
66 66
 
67
-		$applicableEvents = [
68
-			CommentsEvent::EVENT_PRE_UPDATE,
69
-			CommentsEvent::EVENT_UPDATE,
70
-			CommentsEvent::EVENT_DELETE,
71
-		];
72
-		if (in_array($eventType, $applicableEvents)) {
73
-			$this->notificationHandler($event);
74
-			return;
75
-		}
76
-	}
67
+        $applicableEvents = [
68
+            CommentsEvent::EVENT_PRE_UPDATE,
69
+            CommentsEvent::EVENT_UPDATE,
70
+            CommentsEvent::EVENT_DELETE,
71
+        ];
72
+        if (in_array($eventType, $applicableEvents)) {
73
+            $this->notificationHandler($event);
74
+            return;
75
+        }
76
+    }
77 77
 
78
-	/**
79
-	 * @param CommentsEvent $event
80
-	 */
81
-	private function activityHandler(CommentsEvent $event) {
82
-		$this->activityListener->commentEvent($event);
83
-	}
78
+    /**
79
+     * @param CommentsEvent $event
80
+     */
81
+    private function activityHandler(CommentsEvent $event) {
82
+        $this->activityListener->commentEvent($event);
83
+    }
84 84
 
85
-	/**
86
-	 * @param CommentsEvent $event
87
-	 */
88
-	private function notificationHandler(CommentsEvent $event) {
89
-		$this->notificationListener->evaluate($event);
90
-	}
85
+    /**
86
+     * @param CommentsEvent $event
87
+     */
88
+    private function notificationHandler(CommentsEvent $event) {
89
+        $this->notificationListener->evaluate($event);
90
+    }
91 91
 }
Please login to merge, or discard this patch.