Completed
Pull Request — stable9 (#4226)
by Lukas
11:11
created
lib/private/subadmin.php 2 patches
Indentation   +247 added lines, -247 removed lines patch added patch discarded remove patch
@@ -36,253 +36,253 @@
 block discarded – undo
36 36
 
37 37
 class SubAdmin extends PublicEmitter {
38 38
 
39
-	/** @var IUserManager */
40
-	private $userManager;
41
-
42
-	/** @var IGroupManager */
43
-	private $groupManager;
44
-
45
-	/** @var IDBConnection */
46
-	private $dbConn;
47
-
48
-	/**
49
-	 * @param IUserManager $userManager
50
-	 * @param IGroupManager $groupManager
51
-	 * @param IDBConnection $dbConn
52
-	 */
53
-	public function __construct(IUserManager $userManager,
54
-	                            IGroupManager $groupManager,
55
-								IDBConnection $dbConn) {
56
-		$this->userManager = $userManager;
57
-		$this->groupManager = $groupManager;
58
-		$this->dbConn = $dbConn;
59
-
60
-		$this->userManager->listen('\OC\User', 'postDelete', function($user) {
61
-			$this->post_deleteUser($user);
62
-		});
63
-		$this->groupManager->listen('\OC\Group', 'postDelete', function($group) {
64
-			$this->post_deleteGroup($group);	
65
-		});
66
-	}
67
-
68
-	/**
69
-	 * add a SubAdmin
70
-	 * @param IUser $user user to be SubAdmin
71
-	 * @param IGroup $group group $user becomes subadmin of
72
-	 * @return bool
73
-	 */
74
-	public function createSubAdmin(IUser $user, IGroup $group) {
75
-		$qb = $this->dbConn->getQueryBuilder();
76
-
77
-		$qb->insert('group_admin')
78
-			->values([
79
-				'gid' => $qb->createNamedParameter($group->getGID()),
80
-				'uid' => $qb->createNamedParameter($user->getUID())
81
-			])
82
-			->execute();
83
-
84
-		$this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]);
85
-		\OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]);
86
-		return true;
87
-	}
88
-
89
-	/**
90
-	 * delete a SubAdmin
91
-	 * @param IUser $user the user that is the SubAdmin
92
-	 * @param IGroup $group the group
93
-	 * @return bool
94
-	 */
95
-	public function deleteSubAdmin(IUser $user, IGroup $group) {
96
-		$qb = $this->dbConn->getQueryBuilder();
97
-
98
-		$qb->delete('group_admin')
99
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
100
-			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
101
-			->execute();
102
-
103
-		$this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
104
-		\OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]);
105
-		return true;
106
-	}
107
-
108
-	/**
109
-	 * get groups of a SubAdmin
110
-	 * @param IUser $user the SubAdmin
111
-	 * @return IGroup[]
112
-	 */
113
-	public function getSubAdminsGroups(IUser $user) {
114
-		$qb = $this->dbConn->getQueryBuilder();
115
-
116
-		$result = $qb->select('gid')
117
-			->from('group_admin')
118
-			->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
119
-			->execute();
120
-
121
-		$groups = [];
122
-		while($row = $result->fetch()) {
123
-			$group = $this->groupManager->get($row['gid']);
124
-			if(!is_null($group)) {
125
-				$groups[] = $group;
126
-			}
127
-		}
128
-		$result->closeCursor();
129
-
130
-		return $groups;
131
-	}
132
-
133
-	/**
134
-	 * get SubAdmins of a group
135
-	 * @param IGroup $group the group
136
-	 * @return IUser[]
137
-	 */
138
-	public function getGroupsSubAdmins(IGroup $group) {
139
-		$qb = $this->dbConn->getQueryBuilder();
140
-
141
-		$result = $qb->select('uid')
142
-			->from('group_admin')
143
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
144
-			->execute();
145
-
146
-		$users = [];
147
-		while($row = $result->fetch()) {
148
-			$user = $this->userManager->get($row['uid']);
149
-			if(!is_null($user)) {
150
-				$users[] = $user;
151
-			}
152
-		}
153
-		$result->closeCursor();
154
-
155
-		return $users;
156
-	}
157
-
158
-	/**
159
-	 * get all SubAdmins
160
-	 * @return array
161
-	 */
162
-	public function getAllSubAdmins() {
163
-		$qb = $this->dbConn->getQueryBuilder();
164
-
165
-		$result = $qb->select('*')
166
-			->from('group_admin')
167
-			->execute();
168
-
169
-		$subadmins = [];
170
-		while($row = $result->fetch()) {
171
-			$user = $this->userManager->get($row['uid']);
172
-			$group = $this->groupManager->get($row['gid']);
173
-			if(!is_null($user) && !is_null($group)) {
174
-				$subadmins[] = [
175
-					'user'  => $user,
176
-					'group' => $group
177
-				];
178
-			}
179
-		}
180
-		$result->closeCursor();
181
-
182
-		return $subadmins;
183
-	}
184
-
185
-	/**
186
-	 * checks if a user is a SubAdmin of a group
187
-	 * @param IUser $user 
188
-	 * @param IGroup $group
189
-	 * @return bool
190
-	 */
191
-	public function isSubAdminofGroup(IUser $user, IGroup $group) {
192
-		$qb = $this->dbConn->getQueryBuilder();
193
-
194
-		/*
39
+    /** @var IUserManager */
40
+    private $userManager;
41
+
42
+    /** @var IGroupManager */
43
+    private $groupManager;
44
+
45
+    /** @var IDBConnection */
46
+    private $dbConn;
47
+
48
+    /**
49
+     * @param IUserManager $userManager
50
+     * @param IGroupManager $groupManager
51
+     * @param IDBConnection $dbConn
52
+     */
53
+    public function __construct(IUserManager $userManager,
54
+                                IGroupManager $groupManager,
55
+                                IDBConnection $dbConn) {
56
+        $this->userManager = $userManager;
57
+        $this->groupManager = $groupManager;
58
+        $this->dbConn = $dbConn;
59
+
60
+        $this->userManager->listen('\OC\User', 'postDelete', function($user) {
61
+            $this->post_deleteUser($user);
62
+        });
63
+        $this->groupManager->listen('\OC\Group', 'postDelete', function($group) {
64
+            $this->post_deleteGroup($group);	
65
+        });
66
+    }
67
+
68
+    /**
69
+     * add a SubAdmin
70
+     * @param IUser $user user to be SubAdmin
71
+     * @param IGroup $group group $user becomes subadmin of
72
+     * @return bool
73
+     */
74
+    public function createSubAdmin(IUser $user, IGroup $group) {
75
+        $qb = $this->dbConn->getQueryBuilder();
76
+
77
+        $qb->insert('group_admin')
78
+            ->values([
79
+                'gid' => $qb->createNamedParameter($group->getGID()),
80
+                'uid' => $qb->createNamedParameter($user->getUID())
81
+            ])
82
+            ->execute();
83
+
84
+        $this->emit('\OC\SubAdmin', 'postCreateSubAdmin', [$user, $group]);
85
+        \OC_Hook::emit("OC_SubAdmin", "post_createSubAdmin", ["gid" => $group->getGID()]);
86
+        return true;
87
+    }
88
+
89
+    /**
90
+     * delete a SubAdmin
91
+     * @param IUser $user the user that is the SubAdmin
92
+     * @param IGroup $group the group
93
+     * @return bool
94
+     */
95
+    public function deleteSubAdmin(IUser $user, IGroup $group) {
96
+        $qb = $this->dbConn->getQueryBuilder();
97
+
98
+        $qb->delete('group_admin')
99
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
100
+            ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
101
+            ->execute();
102
+
103
+        $this->emit('\OC\SubAdmin', 'postDeleteSubAdmin', [$user, $group]);
104
+        \OC_Hook::emit("OC_SubAdmin", "post_deleteSubAdmin", ["gid" => $group->getGID()]);
105
+        return true;
106
+    }
107
+
108
+    /**
109
+     * get groups of a SubAdmin
110
+     * @param IUser $user the SubAdmin
111
+     * @return IGroup[]
112
+     */
113
+    public function getSubAdminsGroups(IUser $user) {
114
+        $qb = $this->dbConn->getQueryBuilder();
115
+
116
+        $result = $qb->select('gid')
117
+            ->from('group_admin')
118
+            ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
119
+            ->execute();
120
+
121
+        $groups = [];
122
+        while($row = $result->fetch()) {
123
+            $group = $this->groupManager->get($row['gid']);
124
+            if(!is_null($group)) {
125
+                $groups[] = $group;
126
+            }
127
+        }
128
+        $result->closeCursor();
129
+
130
+        return $groups;
131
+    }
132
+
133
+    /**
134
+     * get SubAdmins of a group
135
+     * @param IGroup $group the group
136
+     * @return IUser[]
137
+     */
138
+    public function getGroupsSubAdmins(IGroup $group) {
139
+        $qb = $this->dbConn->getQueryBuilder();
140
+
141
+        $result = $qb->select('uid')
142
+            ->from('group_admin')
143
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
144
+            ->execute();
145
+
146
+        $users = [];
147
+        while($row = $result->fetch()) {
148
+            $user = $this->userManager->get($row['uid']);
149
+            if(!is_null($user)) {
150
+                $users[] = $user;
151
+            }
152
+        }
153
+        $result->closeCursor();
154
+
155
+        return $users;
156
+    }
157
+
158
+    /**
159
+     * get all SubAdmins
160
+     * @return array
161
+     */
162
+    public function getAllSubAdmins() {
163
+        $qb = $this->dbConn->getQueryBuilder();
164
+
165
+        $result = $qb->select('*')
166
+            ->from('group_admin')
167
+            ->execute();
168
+
169
+        $subadmins = [];
170
+        while($row = $result->fetch()) {
171
+            $user = $this->userManager->get($row['uid']);
172
+            $group = $this->groupManager->get($row['gid']);
173
+            if(!is_null($user) && !is_null($group)) {
174
+                $subadmins[] = [
175
+                    'user'  => $user,
176
+                    'group' => $group
177
+                ];
178
+            }
179
+        }
180
+        $result->closeCursor();
181
+
182
+        return $subadmins;
183
+    }
184
+
185
+    /**
186
+     * checks if a user is a SubAdmin of a group
187
+     * @param IUser $user 
188
+     * @param IGroup $group
189
+     * @return bool
190
+     */
191
+    public function isSubAdminofGroup(IUser $user, IGroup $group) {
192
+        $qb = $this->dbConn->getQueryBuilder();
193
+
194
+        /*
195 195
 		 * Primary key is ('gid', 'uid') so max 1 result possible here
196 196
 		 */
197
-		$result = $qb->select('*')
198
-			->from('group_admin')
199
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
200
-			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
201
-			->execute();
202
-
203
-		$fetch =  $result->fetch();
204
-		$result->closeCursor();
205
-		$result = !empty($fetch) ? true : false;
206
-
207
-		return $result;
208
-	}
209
-
210
-	/**
211
-	 * checks if a user is a SubAdmin
212
-	 * @param IUser $user 
213
-	 * @return bool
214
-	 */
215
-	public function isSubAdmin(IUser $user) {
216
-		// Check if the user is already an admin
217
-		if ($this->groupManager->isAdmin($user->getUID())) {
218
-			return true;
219
-		}
220
-
221
-		$qb = $this->dbConn->getQueryBuilder();
222
-
223
-		$result = $qb->select('gid')
224
-			->from('group_admin')
225
-			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
226
-			->setMaxResults(1)
227
-			->execute();
228
-
229
-		$isSubAdmin = $result->fetch();
230
-		$result->closeCursor();
231
-
232
-		$result = $isSubAdmin === false ? false : true;
233
-
234
-		return $result;
235
-	}
236
-
237
-	/**
238
-	 * checks if a user is a accessible by a subadmin
239
-	 * @param IUser $subadmin
240
-	 * @param IUser $user
241
-	 * @return bool
242
-	 */
243
-	public function isUserAccessible($subadmin, $user) {
244
-		if(!$this->isSubAdmin($subadmin)) {
245
-			return false;
246
-		}
247
-		if($this->groupManager->isAdmin($user->getUID())) {
248
-			return false;
249
-		}
250
-		$accessibleGroups = $this->getSubAdminsGroups($subadmin);
251
-		foreach($accessibleGroups as $accessibleGroup) {
252
-			if($accessibleGroup->inGroup($user)) {
253
-				return true;
254
-			}
255
-		}
256
-		return false;
257
-	}
258
-
259
-	/**
260
-	 * delete all SubAdmins by $user
261
-	 * @param IUser $user
262
-	 * @return boolean
263
-	 */
264
-	private function post_deleteUser($user) {
265
-		$qb = $this->dbConn->getQueryBuilder();
266
-
267
-		$qb->delete('group_admin')
268
-			->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
269
-			->execute();
270
-
271
-		return true;
272
-	}
273
-
274
-	/**
275
-	 * delete all SubAdmins by $group
276
-	 * @param IGroup $group
277
-	 * @return boolean
278
-	 */
279
-	private function post_deleteGroup($group) {
280
-		$qb = $this->dbConn->getQueryBuilder();
281
-
282
-		$qb->delete('group_admin')
283
-			->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
284
-			->execute();
285
-
286
-		return true;
287
-	}
197
+        $result = $qb->select('*')
198
+            ->from('group_admin')
199
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
200
+            ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
201
+            ->execute();
202
+
203
+        $fetch =  $result->fetch();
204
+        $result->closeCursor();
205
+        $result = !empty($fetch) ? true : false;
206
+
207
+        return $result;
208
+    }
209
+
210
+    /**
211
+     * checks if a user is a SubAdmin
212
+     * @param IUser $user 
213
+     * @return bool
214
+     */
215
+    public function isSubAdmin(IUser $user) {
216
+        // Check if the user is already an admin
217
+        if ($this->groupManager->isAdmin($user->getUID())) {
218
+            return true;
219
+        }
220
+
221
+        $qb = $this->dbConn->getQueryBuilder();
222
+
223
+        $result = $qb->select('gid')
224
+            ->from('group_admin')
225
+            ->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
226
+            ->setMaxResults(1)
227
+            ->execute();
228
+
229
+        $isSubAdmin = $result->fetch();
230
+        $result->closeCursor();
231
+
232
+        $result = $isSubAdmin === false ? false : true;
233
+
234
+        return $result;
235
+    }
236
+
237
+    /**
238
+     * checks if a user is a accessible by a subadmin
239
+     * @param IUser $subadmin
240
+     * @param IUser $user
241
+     * @return bool
242
+     */
243
+    public function isUserAccessible($subadmin, $user) {
244
+        if(!$this->isSubAdmin($subadmin)) {
245
+            return false;
246
+        }
247
+        if($this->groupManager->isAdmin($user->getUID())) {
248
+            return false;
249
+        }
250
+        $accessibleGroups = $this->getSubAdminsGroups($subadmin);
251
+        foreach($accessibleGroups as $accessibleGroup) {
252
+            if($accessibleGroup->inGroup($user)) {
253
+                return true;
254
+            }
255
+        }
256
+        return false;
257
+    }
258
+
259
+    /**
260
+     * delete all SubAdmins by $user
261
+     * @param IUser $user
262
+     * @return boolean
263
+     */
264
+    private function post_deleteUser($user) {
265
+        $qb = $this->dbConn->getQueryBuilder();
266
+
267
+        $qb->delete('group_admin')
268
+            ->where($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
269
+            ->execute();
270
+
271
+        return true;
272
+    }
273
+
274
+    /**
275
+     * delete all SubAdmins by $group
276
+     * @param IGroup $group
277
+     * @return boolean
278
+     */
279
+    private function post_deleteGroup($group) {
280
+        $qb = $this->dbConn->getQueryBuilder();
281
+
282
+        $qb->delete('group_admin')
283
+            ->where($qb->expr()->eq('gid', $qb->createNamedParameter($group->getGID())))
284
+            ->execute();
285
+
286
+        return true;
287
+    }
288 288
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
 			->execute();
120 120
 
121 121
 		$groups = [];
122
-		while($row = $result->fetch()) {
122
+		while ($row = $result->fetch()) {
123 123
 			$group = $this->groupManager->get($row['gid']);
124
-			if(!is_null($group)) {
124
+			if (!is_null($group)) {
125 125
 				$groups[] = $group;
126 126
 			}
127 127
 		}
@@ -144,9 +144,9 @@  discard block
 block discarded – undo
144 144
 			->execute();
145 145
 
146 146
 		$users = [];
147
-		while($row = $result->fetch()) {
147
+		while ($row = $result->fetch()) {
148 148
 			$user = $this->userManager->get($row['uid']);
149
-			if(!is_null($user)) {
149
+			if (!is_null($user)) {
150 150
 				$users[] = $user;
151 151
 			}
152 152
 		}
@@ -167,10 +167,10 @@  discard block
 block discarded – undo
167 167
 			->execute();
168 168
 
169 169
 		$subadmins = [];
170
-		while($row = $result->fetch()) {
170
+		while ($row = $result->fetch()) {
171 171
 			$user = $this->userManager->get($row['uid']);
172 172
 			$group = $this->groupManager->get($row['gid']);
173
-			if(!is_null($user) && !is_null($group)) {
173
+			if (!is_null($user) && !is_null($group)) {
174 174
 				$subadmins[] = [
175 175
 					'user'  => $user,
176 176
 					'group' => $group
@@ -200,7 +200,7 @@  discard block
 block discarded – undo
200 200
 			->andWhere($qb->expr()->eq('uid', $qb->createNamedParameter($user->getUID())))
201 201
 			->execute();
202 202
 
203
-		$fetch =  $result->fetch();
203
+		$fetch = $result->fetch();
204 204
 		$result->closeCursor();
205 205
 		$result = !empty($fetch) ? true : false;
206 206
 
@@ -241,15 +241,15 @@  discard block
 block discarded – undo
241 241
 	 * @return bool
242 242
 	 */
243 243
 	public function isUserAccessible($subadmin, $user) {
244
-		if(!$this->isSubAdmin($subadmin)) {
244
+		if (!$this->isSubAdmin($subadmin)) {
245 245
 			return false;
246 246
 		}
247
-		if($this->groupManager->isAdmin($user->getUID())) {
247
+		if ($this->groupManager->isAdmin($user->getUID())) {
248 248
 			return false;
249 249
 		}
250 250
 		$accessibleGroups = $this->getSubAdminsGroups($subadmin);
251
-		foreach($accessibleGroups as $accessibleGroup) {
252
-			if($accessibleGroup->inGroup($user)) {
251
+		foreach ($accessibleGroups as $accessibleGroup) {
252
+			if ($accessibleGroup->inGroup($user)) {
253 253
 				return true;
254 254
 			}
255 255
 		}
Please login to merge, or discard this patch.
lib/private/apphelper.php 1 patch
Indentation   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -29,20 +29,20 @@
 block discarded – undo
29 29
  * @deprecated 8.1.0
30 30
  */
31 31
 class AppHelper implements \OCP\IHelper {
32
-	/**
33
-	 * Gets the content of an URL by using CURL or a fallback if it is not
34
-	 * installed
35
-	 * @param string $url the url that should be fetched
36
-	 * @return string the content of the webpage
37
-	 * @deprecated 8.1.0 Use \OCP\IServerContainer::getHTTPClientService
38
-	 */
39
-	public function getUrlContent($url) {
40
-		try {
41
-			$client = \OC::$server->getHTTPClientService()->newClient();
42
-			$response = $client->get($url);
43
-			return $response->getBody();
44
-		} catch (\Exception $e) {
45
-			return false;
46
-		}
47
-	}
32
+    /**
33
+     * Gets the content of an URL by using CURL or a fallback if it is not
34
+     * installed
35
+     * @param string $url the url that should be fetched
36
+     * @return string the content of the webpage
37
+     * @deprecated 8.1.0 Use \OCP\IServerContainer::getHTTPClientService
38
+     */
39
+    public function getUrlContent($url) {
40
+        try {
41
+            $client = \OC::$server->getHTTPClientService()->newClient();
42
+            $response = $client->get($url);
43
+            return $response->getBody();
44
+        } catch (\Exception $e) {
45
+            return false;
46
+        }
47
+    }
48 48
 }
Please login to merge, or discard this patch.
lib/private/json.php 2 patches
Indentation   +134 added lines, -134 removed lines patch added patch discarded remove patch
@@ -34,152 +34,152 @@
 block discarded – undo
34 34
  * @deprecated Use a AppFramework JSONResponse instead
35 35
  */
36 36
 class OC_JSON{
37
-	static protected $send_content_type_header = false;
38
-	/**
39
-	 * set Content-Type header to jsonrequest
40
-	 * @deprecated Use a AppFramework JSONResponse instead
41
-	 */
42
-	public static function setContentTypeHeader($type='application/json') {
43
-		if (!self::$send_content_type_header) {
44
-			// We send json data
45
-			header( 'Content-Type: '.$type . '; charset=utf-8');
46
-			self::$send_content_type_header = true;
47
-		}
48
-	}
37
+    static protected $send_content_type_header = false;
38
+    /**
39
+     * set Content-Type header to jsonrequest
40
+     * @deprecated Use a AppFramework JSONResponse instead
41
+     */
42
+    public static function setContentTypeHeader($type='application/json') {
43
+        if (!self::$send_content_type_header) {
44
+            // We send json data
45
+            header( 'Content-Type: '.$type . '; charset=utf-8');
46
+            self::$send_content_type_header = true;
47
+        }
48
+    }
49 49
 
50
-	/**
51
-	 * Check if the app is enabled, send json error msg if not
52
-	 * @param string $app
53
-	 * @deprecated Use the AppFramework instead. It will automatically check if the app is enabled.
54
-	 */
55
-	public static function checkAppEnabled($app) {
56
-		if( !OC_App::isEnabled($app)) {
57
-			$l = \OC::$server->getL10N('lib');
58
-			self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled' )));
59
-			exit();
60
-		}
61
-	}
50
+    /**
51
+     * Check if the app is enabled, send json error msg if not
52
+     * @param string $app
53
+     * @deprecated Use the AppFramework instead. It will automatically check if the app is enabled.
54
+     */
55
+    public static function checkAppEnabled($app) {
56
+        if( !OC_App::isEnabled($app)) {
57
+            $l = \OC::$server->getL10N('lib');
58
+            self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled' )));
59
+            exit();
60
+        }
61
+    }
62 62
 
63
-	/**
64
-	 * Check if the user is logged in, send json error msg if not
65
-	 * @deprecated Use annotation based ACLs from the AppFramework instead
66
-	 */
67
-	public static function checkLoggedIn() {
68
-		if( !OC_User::isLoggedIn()) {
69
-			$l = \OC::$server->getL10N('lib');
70
-			http_response_code(\OCP\AppFramework\Http::STATUS_UNAUTHORIZED);
71
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
72
-			exit();
73
-		}
74
-	}
63
+    /**
64
+     * Check if the user is logged in, send json error msg if not
65
+     * @deprecated Use annotation based ACLs from the AppFramework instead
66
+     */
67
+    public static function checkLoggedIn() {
68
+        if( !OC_User::isLoggedIn()) {
69
+            $l = \OC::$server->getL10N('lib');
70
+            http_response_code(\OCP\AppFramework\Http::STATUS_UNAUTHORIZED);
71
+            self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
72
+            exit();
73
+        }
74
+    }
75 75
 
76
-	/**
77
-	 * Check an ajax get/post call if the request token is valid, send json error msg if not.
78
-	 * @deprecated Use annotation based CSRF checks from the AppFramework instead
79
-	 */
80
-	public static function callCheck() {
81
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
82
-			header('Location: '.\OC::$WEBROOT);
83
-			exit();
84
-		}
76
+    /**
77
+     * Check an ajax get/post call if the request token is valid, send json error msg if not.
78
+     * @deprecated Use annotation based CSRF checks from the AppFramework instead
79
+     */
80
+    public static function callCheck() {
81
+        if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
82
+            header('Location: '.\OC::$WEBROOT);
83
+            exit();
84
+        }
85 85
 
86
-		if( !(\OC::$server->getRequest()->passesCSRFCheck())) {
87
-			$l = \OC::$server->getL10N('lib');
88
-			self::error(array( 'data' => array( 'message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired' )));
89
-			exit();
90
-		}
91
-	}
86
+        if( !(\OC::$server->getRequest()->passesCSRFCheck())) {
87
+            $l = \OC::$server->getL10N('lib');
88
+            self::error(array( 'data' => array( 'message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired' )));
89
+            exit();
90
+        }
91
+    }
92 92
 
93
-	/**
94
-	 * Check if the user is a admin, send json error msg if not.
95
-	 * @deprecated Use annotation based ACLs from the AppFramework instead
96
-	 */
97
-	public static function checkAdminUser() {
98
-		if( !OC_User::isAdminUser(OC_User::getUser())) {
99
-			$l = \OC::$server->getL10N('lib');
100
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
101
-			exit();
102
-		}
103
-	}
93
+    /**
94
+     * Check if the user is a admin, send json error msg if not.
95
+     * @deprecated Use annotation based ACLs from the AppFramework instead
96
+     */
97
+    public static function checkAdminUser() {
98
+        if( !OC_User::isAdminUser(OC_User::getUser())) {
99
+            $l = \OC::$server->getL10N('lib');
100
+            self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
101
+            exit();
102
+        }
103
+    }
104 104
 
105
-	/**
106
-	 * Check is a given user exists - send json error msg if not
107
-	 * @param string $user
108
-	 * @deprecated Use a AppFramework JSONResponse instead
109
-	 */
110
-	public static function checkUserExists($user) {
111
-		if (!OCP\User::userExists($user)) {
112
-			$l = \OC::$server->getL10N('lib');
113
-			OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user' )));
114
-			exit;
115
-		}
116
-	}
105
+    /**
106
+     * Check is a given user exists - send json error msg if not
107
+     * @param string $user
108
+     * @deprecated Use a AppFramework JSONResponse instead
109
+     */
110
+    public static function checkUserExists($user) {
111
+        if (!OCP\User::userExists($user)) {
112
+            $l = \OC::$server->getL10N('lib');
113
+            OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user' )));
114
+            exit;
115
+        }
116
+    }
117 117
 
118 118
 
119
-	/**
120
-	 * Check if the user is a subadmin, send json error msg if not
121
-	 * @deprecated Use annotation based ACLs from the AppFramework instead
122
-	 */
123
-	public static function checkSubAdminUser() {
124
-		$userObject = \OC::$server->getUserSession()->getUser();
125
-		$isSubAdmin = false;
126
-		if($userObject !== null) {
127
-			$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
128
-		}
119
+    /**
120
+     * Check if the user is a subadmin, send json error msg if not
121
+     * @deprecated Use annotation based ACLs from the AppFramework instead
122
+     */
123
+    public static function checkSubAdminUser() {
124
+        $userObject = \OC::$server->getUserSession()->getUser();
125
+        $isSubAdmin = false;
126
+        if($userObject !== null) {
127
+            $isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
128
+        }
129 129
 
130
-		if(!$isSubAdmin) {
131
-			$l = \OC::$server->getL10N('lib');
132
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
133
-			exit();
134
-		}
135
-	}
130
+        if(!$isSubAdmin) {
131
+            $l = \OC::$server->getL10N('lib');
132
+            self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
133
+            exit();
134
+        }
135
+    }
136 136
 
137
-	/**
138
-	 * Send json error msg
139
-	 * @deprecated Use a AppFramework JSONResponse instead
140
-	 */
141
-	public static function error($data = array()) {
142
-		$data['status'] = 'error';
143
-		self::encodedPrint($data);
144
-	}
137
+    /**
138
+     * Send json error msg
139
+     * @deprecated Use a AppFramework JSONResponse instead
140
+     */
141
+    public static function error($data = array()) {
142
+        $data['status'] = 'error';
143
+        self::encodedPrint($data);
144
+    }
145 145
 
146
-	/**
147
-	 * Send json success msg
148
-	 * @deprecated Use a AppFramework JSONResponse instead
149
-	 */
150
-	public static function success($data = array()) {
151
-		$data['status'] = 'success';
152
-		self::encodedPrint($data);
153
-	}
146
+    /**
147
+     * Send json success msg
148
+     * @deprecated Use a AppFramework JSONResponse instead
149
+     */
150
+    public static function success($data = array()) {
151
+        $data['status'] = 'success';
152
+        self::encodedPrint($data);
153
+    }
154 154
 
155
-	/**
156
-	 * Convert OC_L10N_String to string, for use in json encodings
157
-	 */
158
-	protected static function to_string(&$value) {
159
-		if ($value instanceof OC_L10N_String) {
160
-			$value = (string)$value;
161
-		}
162
-	}
155
+    /**
156
+     * Convert OC_L10N_String to string, for use in json encodings
157
+     */
158
+    protected static function to_string(&$value) {
159
+        if ($value instanceof OC_L10N_String) {
160
+            $value = (string)$value;
161
+        }
162
+    }
163 163
 
164
-	/**
165
-	 * Encode and print $data in json format
166
-	 * @deprecated Use a AppFramework JSONResponse instead
167
-	 */
168
-	public static function encodedPrint($data, $setContentType=true) {
169
-		if($setContentType) {
170
-			self::setContentTypeHeader();
171
-		}
172
-		echo self::encode($data);
173
-	}
164
+    /**
165
+     * Encode and print $data in json format
166
+     * @deprecated Use a AppFramework JSONResponse instead
167
+     */
168
+    public static function encodedPrint($data, $setContentType=true) {
169
+        if($setContentType) {
170
+            self::setContentTypeHeader();
171
+        }
172
+        echo self::encode($data);
173
+    }
174 174
 
175
-	/**
176
-	 * Encode JSON
177
-	 * @deprecated Use a AppFramework JSONResponse instead
178
-	 */
179
-	public static function encode($data) {
180
-		if (is_array($data)) {
181
-			array_walk_recursive($data, array('OC_JSON', 'to_string'));
182
-		}
183
-		return json_encode($data, JSON_HEX_TAG);
184
-	}
175
+    /**
176
+     * Encode JSON
177
+     * @deprecated Use a AppFramework JSONResponse instead
178
+     */
179
+    public static function encode($data) {
180
+        if (is_array($data)) {
181
+            array_walk_recursive($data, array('OC_JSON', 'to_string'));
182
+        }
183
+        return json_encode($data, JSON_HEX_TAG);
184
+    }
185 185
 }
Please login to merge, or discard this patch.
Spacing   +19 added lines, -19 removed lines patch added patch discarded remove patch
@@ -33,16 +33,16 @@  discard block
 block discarded – undo
33 33
  * Class OC_JSON
34 34
  * @deprecated Use a AppFramework JSONResponse instead
35 35
  */
36
-class OC_JSON{
36
+class OC_JSON {
37 37
 	static protected $send_content_type_header = false;
38 38
 	/**
39 39
 	 * set Content-Type header to jsonrequest
40 40
 	 * @deprecated Use a AppFramework JSONResponse instead
41 41
 	 */
42
-	public static function setContentTypeHeader($type='application/json') {
42
+	public static function setContentTypeHeader($type = 'application/json') {
43 43
 		if (!self::$send_content_type_header) {
44 44
 			// We send json data
45
-			header( 'Content-Type: '.$type . '; charset=utf-8');
45
+			header('Content-Type: '.$type.'; charset=utf-8');
46 46
 			self::$send_content_type_header = true;
47 47
 		}
48 48
 	}
@@ -53,9 +53,9 @@  discard block
 block discarded – undo
53 53
 	 * @deprecated Use the AppFramework instead. It will automatically check if the app is enabled.
54 54
 	 */
55 55
 	public static function checkAppEnabled($app) {
56
-		if( !OC_App::isEnabled($app)) {
56
+		if (!OC_App::isEnabled($app)) {
57 57
 			$l = \OC::$server->getL10N('lib');
58
-			self::error(array( 'data' => array( 'message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled' )));
58
+			self::error(array('data' => array('message' => $l->t('Application is not enabled'), 'error' => 'application_not_enabled')));
59 59
 			exit();
60 60
 		}
61 61
 	}
@@ -65,10 +65,10 @@  discard block
 block discarded – undo
65 65
 	 * @deprecated Use annotation based ACLs from the AppFramework instead
66 66
 	 */
67 67
 	public static function checkLoggedIn() {
68
-		if( !OC_User::isLoggedIn()) {
68
+		if (!OC_User::isLoggedIn()) {
69 69
 			$l = \OC::$server->getL10N('lib');
70 70
 			http_response_code(\OCP\AppFramework\Http::STATUS_UNAUTHORIZED);
71
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
71
+			self::error(array('data' => array('message' => $l->t('Authentication error'), 'error' => 'authentication_error')));
72 72
 			exit();
73 73
 		}
74 74
 	}
@@ -78,14 +78,14 @@  discard block
 block discarded – undo
78 78
 	 * @deprecated Use annotation based CSRF checks from the AppFramework instead
79 79
 	 */
80 80
 	public static function callCheck() {
81
-		if(!\OC::$server->getRequest()->passesStrictCookieCheck()) {
81
+		if (!\OC::$server->getRequest()->passesStrictCookieCheck()) {
82 82
 			header('Location: '.\OC::$WEBROOT);
83 83
 			exit();
84 84
 		}
85 85
 
86
-		if( !(\OC::$server->getRequest()->passesCSRFCheck())) {
86
+		if (!(\OC::$server->getRequest()->passesCSRFCheck())) {
87 87
 			$l = \OC::$server->getL10N('lib');
88
-			self::error(array( 'data' => array( 'message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired' )));
88
+			self::error(array('data' => array('message' => $l->t('Token expired. Please reload page.'), 'error' => 'token_expired')));
89 89
 			exit();
90 90
 		}
91 91
 	}
@@ -95,9 +95,9 @@  discard block
 block discarded – undo
95 95
 	 * @deprecated Use annotation based ACLs from the AppFramework instead
96 96
 	 */
97 97
 	public static function checkAdminUser() {
98
-		if( !OC_User::isAdminUser(OC_User::getUser())) {
98
+		if (!OC_User::isAdminUser(OC_User::getUser())) {
99 99
 			$l = \OC::$server->getL10N('lib');
100
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
100
+			self::error(array('data' => array('message' => $l->t('Authentication error'), 'error' => 'authentication_error')));
101 101
 			exit();
102 102
 		}
103 103
 	}
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	public static function checkUserExists($user) {
111 111
 		if (!OCP\User::userExists($user)) {
112 112
 			$l = \OC::$server->getL10N('lib');
113
-			OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user' )));
113
+			OCP\JSON::error(array('data' => array('message' => $l->t('Unknown user'), 'error' => 'unknown_user')));
114 114
 			exit;
115 115
 		}
116 116
 	}
@@ -123,13 +123,13 @@  discard block
 block discarded – undo
123 123
 	public static function checkSubAdminUser() {
124 124
 		$userObject = \OC::$server->getUserSession()->getUser();
125 125
 		$isSubAdmin = false;
126
-		if($userObject !== null) {
126
+		if ($userObject !== null) {
127 127
 			$isSubAdmin = \OC::$server->getGroupManager()->getSubAdmin()->isSubAdmin($userObject);
128 128
 		}
129 129
 
130
-		if(!$isSubAdmin) {
130
+		if (!$isSubAdmin) {
131 131
 			$l = \OC::$server->getL10N('lib');
132
-			self::error(array( 'data' => array( 'message' => $l->t('Authentication error'), 'error' => 'authentication_error' )));
132
+			self::error(array('data' => array('message' => $l->t('Authentication error'), 'error' => 'authentication_error')));
133 133
 			exit();
134 134
 		}
135 135
 	}
@@ -157,7 +157,7 @@  discard block
 block discarded – undo
157 157
 	 */
158 158
 	protected static function to_string(&$value) {
159 159
 		if ($value instanceof OC_L10N_String) {
160
-			$value = (string)$value;
160
+			$value = (string) $value;
161 161
 		}
162 162
 	}
163 163
 
@@ -165,8 +165,8 @@  discard block
 block discarded – undo
165 165
 	 * Encode and print $data in json format
166 166
 	 * @deprecated Use a AppFramework JSONResponse instead
167 167
 	 */
168
-	public static function encodedPrint($data, $setContentType=true) {
169
-		if($setContentType) {
168
+	public static function encodedPrint($data, $setContentType = true) {
169
+		if ($setContentType) {
170 170
 			self::setContentTypeHeader();
171 171
 		}
172 172
 		echo self::encode($data);
Please login to merge, or discard this patch.
lib/private/console/timestampformatter.php 2 patches
Indentation   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -28,81 +28,81 @@
 block discarded – undo
28 28
 use Symfony\Component\Console\Formatter\OutputFormatterStyleInterface;
29 29
 
30 30
 class TimestampFormatter implements OutputFormatterInterface {
31
-	/** @var IConfig */
32
-	protected $config;
31
+    /** @var IConfig */
32
+    protected $config;
33 33
 
34
-	/**
35
-	 * @param IConfig $config
36
-	 * @param OutputFormatterInterface $formatter
37
-	 */
38
-	public function __construct(IConfig $config, OutputFormatterInterface $formatter) {
39
-		$this->config = $config;
40
-		$this->formatter = $formatter;
41
-	}
34
+    /**
35
+     * @param IConfig $config
36
+     * @param OutputFormatterInterface $formatter
37
+     */
38
+    public function __construct(IConfig $config, OutputFormatterInterface $formatter) {
39
+        $this->config = $config;
40
+        $this->formatter = $formatter;
41
+    }
42 42
 
43
-	/**
44
-	 * Sets the decorated flag.
45
-	 *
46
-	 * @param bool $decorated Whether to decorate the messages or not
47
-	 */
48
-	public function setDecorated($decorated) {
49
-		$this->formatter->setDecorated($decorated);
50
-	}
43
+    /**
44
+     * Sets the decorated flag.
45
+     *
46
+     * @param bool $decorated Whether to decorate the messages or not
47
+     */
48
+    public function setDecorated($decorated) {
49
+        $this->formatter->setDecorated($decorated);
50
+    }
51 51
 
52
-	/**
53
-	 * Gets the decorated flag.
54
-	 *
55
-	 * @return bool true if the output will decorate messages, false otherwise
56
-	 */
57
-	public function isDecorated() {
58
-		return $this->formatter->isDecorated();
59
-	}
52
+    /**
53
+     * Gets the decorated flag.
54
+     *
55
+     * @return bool true if the output will decorate messages, false otherwise
56
+     */
57
+    public function isDecorated() {
58
+        return $this->formatter->isDecorated();
59
+    }
60 60
 
61
-	/**
62
-	 * Sets a new style.
63
-	 *
64
-	 * @param string $name The style name
65
-	 * @param OutputFormatterStyleInterface $style The style instance
66
-	 */
67
-	public function setStyle($name, OutputFormatterStyleInterface $style) {
68
-		$this->formatter->setStyle($name, $style);
69
-	}
61
+    /**
62
+     * Sets a new style.
63
+     *
64
+     * @param string $name The style name
65
+     * @param OutputFormatterStyleInterface $style The style instance
66
+     */
67
+    public function setStyle($name, OutputFormatterStyleInterface $style) {
68
+        $this->formatter->setStyle($name, $style);
69
+    }
70 70
 
71
-	/**
72
-	 * Checks if output formatter has style with specified name.
73
-	 *
74
-	 * @param string $name
75
-	 * @return bool
76
-	 */
77
-	public function hasStyle($name) {
78
-		$this->formatter->hasStyle($name);
79
-	}
71
+    /**
72
+     * Checks if output formatter has style with specified name.
73
+     *
74
+     * @param string $name
75
+     * @return bool
76
+     */
77
+    public function hasStyle($name) {
78
+        $this->formatter->hasStyle($name);
79
+    }
80 80
 
81
-	/**
82
-	 * Gets style options from style with specified name.
83
-	 *
84
-	 * @param string $name
85
-	 * @return OutputFormatterStyleInterface
86
-	 */
87
-	public function getStyle($name) {
88
-		return $this->formatter->getStyle($name);
89
-	}
81
+    /**
82
+     * Gets style options from style with specified name.
83
+     *
84
+     * @param string $name
85
+     * @return OutputFormatterStyleInterface
86
+     */
87
+    public function getStyle($name) {
88
+        return $this->formatter->getStyle($name);
89
+    }
90 90
 
91
-	/**
92
-	 * Formats a message according to the given styles.
93
-	 *
94
-	 * @param string $message The message to style
95
-	 * @return string The styled message, prepended with a timestamp using the
96
-	 * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00"
97
-	 */
98
-	public function format($message) {
91
+    /**
92
+     * Formats a message according to the given styles.
93
+     *
94
+     * @param string $message The message to style
95
+     * @return string The styled message, prepended with a timestamp using the
96
+     * log timezone and dateformat, e.g. "2015-06-23T17:24:37+02:00"
97
+     */
98
+    public function format($message) {
99 99
 
100
-		$timeZone = $this->config->getSystemValue('logtimezone', null);
101
-		$timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;
100
+        $timeZone = $this->config->getSystemValue('logtimezone', null);
101
+        $timeZone = $timeZone !== null ? new \DateTimeZone($timeZone) : null;
102 102
 
103
-		$time = new \DateTime('now', $timeZone);
104
-		$timestampInfo = $time->format($this->config->getSystemValue('logdateformat', 'c'));
103
+        $time = new \DateTime('now', $timeZone);
104
+        $timestampInfo = $time->format($this->config->getSystemValue('logdateformat', 'c'));
105 105
 
106
-		return $timestampInfo . ' ' . $this->formatter->format($message);
107
-	}
106
+        return $timestampInfo . ' ' . $this->formatter->format($message);
107
+    }
108 108
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -103,6 +103,6 @@
 block discarded – undo
103 103
 		$time = new \DateTime('now', $timeZone);
104 104
 		$timestampInfo = $time->format($this->config->getSystemValue('logdateformat', 'c'));
105 105
 
106
-		return $timestampInfo . ' ' . $this->formatter->format($message);
106
+		return $timestampInfo.' '.$this->formatter->format($message);
107 107
 	}
108 108
 }
Please login to merge, or discard this patch.
lib/private/share20/share.php 2 patches
Indentation   +357 added lines, -357 removed lines patch added patch discarded remove patch
@@ -30,361 +30,361 @@
 block discarded – undo
30 30
 
31 31
 class Share implements \OCP\Share\IShare {
32 32
 
33
-	/** @var string */
34
-	private $id;
35
-	/** @var string */
36
-	private $providerId;
37
-	/** @var Node */
38
-	private $node;
39
-	/** @var int */
40
-	private $fileId;
41
-	/** @var string */
42
-	private $nodeType;
43
-	/** @var int */
44
-	private $shareType;
45
-	/** @var string */
46
-	private $sharedWith;
47
-	/** @var string */
48
-	private $sharedBy;
49
-	/** @var string */
50
-	private $shareOwner;
51
-	/** @var int */
52
-	private $permissions;
53
-	/** @var \DateTime */
54
-	private $expireDate;
55
-	/** @var string */
56
-	private $password;
57
-	/** @var string */
58
-	private $token;
59
-	/** @var int */
60
-	private $parent;
61
-	/** @var string */
62
-	private $target;
63
-	/** @var \DateTime */
64
-	private $shareTime;
65
-	/** @var bool */
66
-	private $mailSend;
67
-
68
-	/** @var IRootFolder */
69
-	private $rootFolder;
70
-
71
-	public function __construct(IRootFolder $rootFolder) {
72
-		$this->rootFolder = $rootFolder;
73
-	}
74
-
75
-	/**
76
-	 * @inheritdoc
77
-	 */
78
-	public function setId($id) {
79
-		$this->id = $id;
80
-		return $this;
81
-	}
82
-
83
-	/**
84
-	 * @inheritdoc
85
-	 */
86
-	public function getId() {
87
-		return $this->id;
88
-	}
89
-
90
-	/**
91
-	 * @inheritdoc
92
-	 */
93
-	public function getFullId() {
94
-		if ($this->providerId === null || $this->id === null) {
95
-			throw new \UnexpectedValueException;
96
-		}
97
-		return $this->providerId . ':' . $this->id;
98
-	}
99
-
100
-	/**
101
-	 * @inheritdoc
102
-	 */
103
-	public function setProviderId($id) {
104
-		$this->providerId = $id;
105
-		return $this;
106
-	}
107
-
108
-	/**
109
-	 * @inheritdoc
110
-	 */
111
-	public function setNode(Node $node) {
112
-		$this->fileId = null;
113
-		$this->nodeType = null;
114
-		$this->node = $node;
115
-		return $this;
116
-	}
117
-
118
-	/**
119
-	 * @inheritdoc
120
-	 */
121
-	public function getNode() {
122
-		if ($this->node === null) {
123
-
124
-			if ($this->shareOwner === null || $this->fileId === null) {
125
-				throw new NotFoundException();
126
-			}
127
-
128
-			$userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
129
-
130
-			$nodes = $userFolder->getById($this->fileId);
131
-			if (empty($nodes)) {
132
-				throw new NotFoundException();
133
-			}
134
-
135
-			$this->node = $nodes[0];
136
-		}
137
-
138
-		return $this->node;
139
-	}
140
-
141
-	/**
142
-	 * @inheritdoc
143
-	 */
144
-	public function setNodeId($fileId) {
145
-		$this->node = null;
146
-		$this->fileId = $fileId;
147
-		return $this;
148
-	}
149
-
150
-	/**
151
-	 * @inheritdoc
152
-	 */
153
-	public function getNodeId() {
154
-		if ($this->fileId === null) {
155
-			$this->fileId = $this->getNode()->getId();
156
-		}
157
-
158
-		return $this->fileId;
159
-	}
160
-
161
-	/**
162
-	 * @inheritdoc
163
-	 */
164
-	public function setNodeType($type) {
165
-		if ($type !== 'file' && $type !== 'folder') {
166
-			throw new \InvalidArgumentException();
167
-		}
168
-
169
-		$this->nodeType = $type;
170
-		return $this;
171
-	}
172
-
173
-	/**
174
-	 * @inheritdoc
175
-	 */
176
-	public function getNodeType() {
177
-		if ($this->nodeType === null) {
178
-			$node = $this->getNode();
179
-			$this->nodeType = $node instanceof File ? 'file' : 'folder';
180
-		}
181
-
182
-		return $this->nodeType;
183
-	}
184
-
185
-	/**
186
-	 * @inheritdoc
187
-	 */
188
-	public function setShareType($shareType) {
189
-		$this->shareType = $shareType;
190
-		return $this;
191
-	}
192
-
193
-	/**
194
-	 * @inheritdoc
195
-	 */
196
-	public function getShareType() {
197
-		return $this->shareType;
198
-	}
199
-
200
-	/**
201
-	 * @inheritdoc
202
-	 */
203
-	public function setSharedWith($sharedWith) {
204
-		if (!is_string($sharedWith)) {
205
-			throw new \InvalidArgumentException();
206
-		}
207
-		$this->sharedWith = $sharedWith;
208
-		return $this;
209
-	}
210
-
211
-	/**
212
-	 * @inheritdoc
213
-	 */
214
-	public function getSharedWith() {
215
-		return $this->sharedWith;
216
-	}
217
-
218
-	/**
219
-	 * @inheritdoc
220
-	 */
221
-	public function setPermissions($permissions) {
222
-		//TODO checkes
223
-
224
-		$this->permissions = $permissions;
225
-		return $this;
226
-	}
227
-
228
-	/**
229
-	 * @inheritdoc
230
-	 */
231
-	public function getPermissions() {
232
-		return $this->permissions;
233
-	}
234
-
235
-	/**
236
-	 * @inheritdoc
237
-	 */
238
-	public function setExpirationDate($expireDate) {
239
-		//TODO checks
240
-
241
-		$this->expireDate = $expireDate;
242
-		return $this;
243
-	}
244
-
245
-	/**
246
-	 * @inheritdoc
247
-	 */
248
-	public function getExpirationDate() {
249
-		return $this->expireDate;
250
-	}
251
-
252
-	/**
253
-	 * @inheritdoc
254
-	 */
255
-	public function setSharedBy($sharedBy) {
256
-		if (!is_string($sharedBy)) {
257
-			throw new \InvalidArgumentException();
258
-		}
259
-		//TODO checks
260
-		$this->sharedBy = $sharedBy;
261
-
262
-		return $this;
263
-	}
264
-
265
-	/**
266
-	 * @inheritdoc
267
-	 */
268
-	public function getSharedBy() {
269
-		//TODO check if set
270
-		return $this->sharedBy;
271
-	}
272
-
273
-	/**
274
-	 * @inheritdoc
275
-	 */
276
-	public function setShareOwner($shareOwner) {
277
-		if (!is_string($shareOwner)) {
278
-			throw new \InvalidArgumentException();
279
-		}
280
-		//TODO checks
281
-
282
-		$this->shareOwner = $shareOwner;
283
-		return $this;
284
-	}
285
-
286
-	/**
287
-	 * @inheritdoc
288
-	 */
289
-	public function getShareOwner() {
290
-		//TODO check if set
291
-		return $this->shareOwner;
292
-	}
293
-
294
-	/**
295
-	 * @inheritdoc
296
-	 */
297
-	public function setPassword($password) {
298
-		$this->password = $password;
299
-		return $this;
300
-	}
301
-
302
-	/**
303
-	 * @inheritdoc
304
-	 */
305
-	public function getPassword() {
306
-		return $this->password;
307
-	}
308
-
309
-	/**
310
-	 * @inheritdoc
311
-	 */
312
-	public function setToken($token) {
313
-		$this->token = $token;
314
-		return $this;
315
-	}
316
-
317
-	/**
318
-	 * @inheritdoc
319
-	 */
320
-	public function getToken() {
321
-		return $this->token;
322
-	}
323
-
324
-	/**
325
-	 * Set the parent of this share
326
-	 *
327
-	 * @param int parent
328
-	 * @return \OCP\Share\IShare
329
-	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
330
-	 */
331
-	public function setParent($parent) {
332
-		$this->parent = $parent;
333
-		return $this;
334
-	}
335
-
336
-	/**
337
-	 * Get the parent of this share.
338
-	 *
339
-	 * @return int
340
-	 * @deprecated The new shares do not have parents. This is just here for legacy reasons.
341
-	 */
342
-	public function getParent() {
343
-		return $this->parent;
344
-	}
345
-
346
-	/**
347
-	 * @inheritdoc
348
-	 */
349
-	public function setTarget($target) {
350
-		$this->target = $target;
351
-		return $this;
352
-	}
353
-
354
-	/**
355
-	 * @inheritdoc
356
-	 */
357
-	public function getTarget() {
358
-		return $this->target;
359
-	}
360
-
361
-	/**
362
-	 * @inheritdoc
363
-	 */
364
-	public function setShareTime(\DateTime $shareTime) {
365
-		$this->shareTime = $shareTime;
366
-		return $this;
367
-	}
368
-
369
-	/**
370
-	 * @inheritdoc
371
-	 */
372
-	public function getShareTime() {
373
-		return $this->shareTime;
374
-	}
375
-
376
-	/**
377
-	 * @inheritdoc
378
-	 */
379
-	public function setMailSend($mailSend) {
380
-		$this->mailSend = $mailSend;
381
-		return $this;
382
-	}
383
-
384
-	/**
385
-	 * @inheritdoc
386
-	 */
387
-	public function getMailSend() {
388
-		return $this->mailSend;
389
-	}
33
+    /** @var string */
34
+    private $id;
35
+    /** @var string */
36
+    private $providerId;
37
+    /** @var Node */
38
+    private $node;
39
+    /** @var int */
40
+    private $fileId;
41
+    /** @var string */
42
+    private $nodeType;
43
+    /** @var int */
44
+    private $shareType;
45
+    /** @var string */
46
+    private $sharedWith;
47
+    /** @var string */
48
+    private $sharedBy;
49
+    /** @var string */
50
+    private $shareOwner;
51
+    /** @var int */
52
+    private $permissions;
53
+    /** @var \DateTime */
54
+    private $expireDate;
55
+    /** @var string */
56
+    private $password;
57
+    /** @var string */
58
+    private $token;
59
+    /** @var int */
60
+    private $parent;
61
+    /** @var string */
62
+    private $target;
63
+    /** @var \DateTime */
64
+    private $shareTime;
65
+    /** @var bool */
66
+    private $mailSend;
67
+
68
+    /** @var IRootFolder */
69
+    private $rootFolder;
70
+
71
+    public function __construct(IRootFolder $rootFolder) {
72
+        $this->rootFolder = $rootFolder;
73
+    }
74
+
75
+    /**
76
+     * @inheritdoc
77
+     */
78
+    public function setId($id) {
79
+        $this->id = $id;
80
+        return $this;
81
+    }
82
+
83
+    /**
84
+     * @inheritdoc
85
+     */
86
+    public function getId() {
87
+        return $this->id;
88
+    }
89
+
90
+    /**
91
+     * @inheritdoc
92
+     */
93
+    public function getFullId() {
94
+        if ($this->providerId === null || $this->id === null) {
95
+            throw new \UnexpectedValueException;
96
+        }
97
+        return $this->providerId . ':' . $this->id;
98
+    }
99
+
100
+    /**
101
+     * @inheritdoc
102
+     */
103
+    public function setProviderId($id) {
104
+        $this->providerId = $id;
105
+        return $this;
106
+    }
107
+
108
+    /**
109
+     * @inheritdoc
110
+     */
111
+    public function setNode(Node $node) {
112
+        $this->fileId = null;
113
+        $this->nodeType = null;
114
+        $this->node = $node;
115
+        return $this;
116
+    }
117
+
118
+    /**
119
+     * @inheritdoc
120
+     */
121
+    public function getNode() {
122
+        if ($this->node === null) {
123
+
124
+            if ($this->shareOwner === null || $this->fileId === null) {
125
+                throw new NotFoundException();
126
+            }
127
+
128
+            $userFolder = $this->rootFolder->getUserFolder($this->shareOwner);
129
+
130
+            $nodes = $userFolder->getById($this->fileId);
131
+            if (empty($nodes)) {
132
+                throw new NotFoundException();
133
+            }
134
+
135
+            $this->node = $nodes[0];
136
+        }
137
+
138
+        return $this->node;
139
+    }
140
+
141
+    /**
142
+     * @inheritdoc
143
+     */
144
+    public function setNodeId($fileId) {
145
+        $this->node = null;
146
+        $this->fileId = $fileId;
147
+        return $this;
148
+    }
149
+
150
+    /**
151
+     * @inheritdoc
152
+     */
153
+    public function getNodeId() {
154
+        if ($this->fileId === null) {
155
+            $this->fileId = $this->getNode()->getId();
156
+        }
157
+
158
+        return $this->fileId;
159
+    }
160
+
161
+    /**
162
+     * @inheritdoc
163
+     */
164
+    public function setNodeType($type) {
165
+        if ($type !== 'file' && $type !== 'folder') {
166
+            throw new \InvalidArgumentException();
167
+        }
168
+
169
+        $this->nodeType = $type;
170
+        return $this;
171
+    }
172
+
173
+    /**
174
+     * @inheritdoc
175
+     */
176
+    public function getNodeType() {
177
+        if ($this->nodeType === null) {
178
+            $node = $this->getNode();
179
+            $this->nodeType = $node instanceof File ? 'file' : 'folder';
180
+        }
181
+
182
+        return $this->nodeType;
183
+    }
184
+
185
+    /**
186
+     * @inheritdoc
187
+     */
188
+    public function setShareType($shareType) {
189
+        $this->shareType = $shareType;
190
+        return $this;
191
+    }
192
+
193
+    /**
194
+     * @inheritdoc
195
+     */
196
+    public function getShareType() {
197
+        return $this->shareType;
198
+    }
199
+
200
+    /**
201
+     * @inheritdoc
202
+     */
203
+    public function setSharedWith($sharedWith) {
204
+        if (!is_string($sharedWith)) {
205
+            throw new \InvalidArgumentException();
206
+        }
207
+        $this->sharedWith = $sharedWith;
208
+        return $this;
209
+    }
210
+
211
+    /**
212
+     * @inheritdoc
213
+     */
214
+    public function getSharedWith() {
215
+        return $this->sharedWith;
216
+    }
217
+
218
+    /**
219
+     * @inheritdoc
220
+     */
221
+    public function setPermissions($permissions) {
222
+        //TODO checkes
223
+
224
+        $this->permissions = $permissions;
225
+        return $this;
226
+    }
227
+
228
+    /**
229
+     * @inheritdoc
230
+     */
231
+    public function getPermissions() {
232
+        return $this->permissions;
233
+    }
234
+
235
+    /**
236
+     * @inheritdoc
237
+     */
238
+    public function setExpirationDate($expireDate) {
239
+        //TODO checks
240
+
241
+        $this->expireDate = $expireDate;
242
+        return $this;
243
+    }
244
+
245
+    /**
246
+     * @inheritdoc
247
+     */
248
+    public function getExpirationDate() {
249
+        return $this->expireDate;
250
+    }
251
+
252
+    /**
253
+     * @inheritdoc
254
+     */
255
+    public function setSharedBy($sharedBy) {
256
+        if (!is_string($sharedBy)) {
257
+            throw new \InvalidArgumentException();
258
+        }
259
+        //TODO checks
260
+        $this->sharedBy = $sharedBy;
261
+
262
+        return $this;
263
+    }
264
+
265
+    /**
266
+     * @inheritdoc
267
+     */
268
+    public function getSharedBy() {
269
+        //TODO check if set
270
+        return $this->sharedBy;
271
+    }
272
+
273
+    /**
274
+     * @inheritdoc
275
+     */
276
+    public function setShareOwner($shareOwner) {
277
+        if (!is_string($shareOwner)) {
278
+            throw new \InvalidArgumentException();
279
+        }
280
+        //TODO checks
281
+
282
+        $this->shareOwner = $shareOwner;
283
+        return $this;
284
+    }
285
+
286
+    /**
287
+     * @inheritdoc
288
+     */
289
+    public function getShareOwner() {
290
+        //TODO check if set
291
+        return $this->shareOwner;
292
+    }
293
+
294
+    /**
295
+     * @inheritdoc
296
+     */
297
+    public function setPassword($password) {
298
+        $this->password = $password;
299
+        return $this;
300
+    }
301
+
302
+    /**
303
+     * @inheritdoc
304
+     */
305
+    public function getPassword() {
306
+        return $this->password;
307
+    }
308
+
309
+    /**
310
+     * @inheritdoc
311
+     */
312
+    public function setToken($token) {
313
+        $this->token = $token;
314
+        return $this;
315
+    }
316
+
317
+    /**
318
+     * @inheritdoc
319
+     */
320
+    public function getToken() {
321
+        return $this->token;
322
+    }
323
+
324
+    /**
325
+     * Set the parent of this share
326
+     *
327
+     * @param int parent
328
+     * @return \OCP\Share\IShare
329
+     * @deprecated The new shares do not have parents. This is just here for legacy reasons.
330
+     */
331
+    public function setParent($parent) {
332
+        $this->parent = $parent;
333
+        return $this;
334
+    }
335
+
336
+    /**
337
+     * Get the parent of this share.
338
+     *
339
+     * @return int
340
+     * @deprecated The new shares do not have parents. This is just here for legacy reasons.
341
+     */
342
+    public function getParent() {
343
+        return $this->parent;
344
+    }
345
+
346
+    /**
347
+     * @inheritdoc
348
+     */
349
+    public function setTarget($target) {
350
+        $this->target = $target;
351
+        return $this;
352
+    }
353
+
354
+    /**
355
+     * @inheritdoc
356
+     */
357
+    public function getTarget() {
358
+        return $this->target;
359
+    }
360
+
361
+    /**
362
+     * @inheritdoc
363
+     */
364
+    public function setShareTime(\DateTime $shareTime) {
365
+        $this->shareTime = $shareTime;
366
+        return $this;
367
+    }
368
+
369
+    /**
370
+     * @inheritdoc
371
+     */
372
+    public function getShareTime() {
373
+        return $this->shareTime;
374
+    }
375
+
376
+    /**
377
+     * @inheritdoc
378
+     */
379
+    public function setMailSend($mailSend) {
380
+        $this->mailSend = $mailSend;
381
+        return $this;
382
+    }
383
+
384
+    /**
385
+     * @inheritdoc
386
+     */
387
+    public function getMailSend() {
388
+        return $this->mailSend;
389
+    }
390 390
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -94,7 +94,7 @@
 block discarded – undo
94 94
 		if ($this->providerId === null || $this->id === null) {
95 95
 			throw new \UnexpectedValueException;
96 96
 		}
97
-		return $this->providerId . ':' . $this->id;
97
+		return $this->providerId.':'.$this->id;
98 98
 	}
99 99
 
100 100
 	/**
Please login to merge, or discard this patch.
lib/private/share20/providerfactory.php 2 patches
Indentation   +118 added lines, -118 removed lines patch added patch discarded remove patch
@@ -38,127 +38,127 @@
 block discarded – undo
38 38
  */
39 39
 class ProviderFactory implements IProviderFactory {
40 40
 
41
-	/** @var IServerContainer */
42
-	private $serverContainer;
43
-	/** @var DefaultShareProvider */
44
-	private $defaultProvider = null;
45
-	/** @var FederatedShareProvider */
46
-	private $federatedProvider = null;
47
-
48
-	/**
49
-	 * IProviderFactory constructor.
50
-	 * @param IServerContainer $serverContainer
51
-	 */
52
-	public function __construct(IServerContainer $serverContainer) {
53
-		$this->serverContainer = $serverContainer;
54
-	}
55
-
56
-	/**
57
-	 * Create the default share provider.
58
-	 *
59
-	 * @return DefaultShareProvider
60
-	 */
61
-	protected function defaultShareProvider() {
62
-		if ($this->defaultProvider === null) {
63
-			$this->defaultProvider = new DefaultShareProvider(
64
-				$this->serverContainer->getDatabaseConnection(),
65
-				$this->serverContainer->getUserManager(),
66
-				$this->serverContainer->getGroupManager(),
67
-				$this->serverContainer->getRootFolder()
68
-			);
69
-		}
70
-
71
-		return $this->defaultProvider;
72
-	}
73
-
74
-	/**
75
-	 * Create the federated share provider
76
-	 *
77
-	 * @return FederatedShareProvider
78
-	 */
79
-	protected function federatedShareProvider() {
80
-		if ($this->federatedProvider === null) {
81
-			/*
41
+    /** @var IServerContainer */
42
+    private $serverContainer;
43
+    /** @var DefaultShareProvider */
44
+    private $defaultProvider = null;
45
+    /** @var FederatedShareProvider */
46
+    private $federatedProvider = null;
47
+
48
+    /**
49
+     * IProviderFactory constructor.
50
+     * @param IServerContainer $serverContainer
51
+     */
52
+    public function __construct(IServerContainer $serverContainer) {
53
+        $this->serverContainer = $serverContainer;
54
+    }
55
+
56
+    /**
57
+     * Create the default share provider.
58
+     *
59
+     * @return DefaultShareProvider
60
+     */
61
+    protected function defaultShareProvider() {
62
+        if ($this->defaultProvider === null) {
63
+            $this->defaultProvider = new DefaultShareProvider(
64
+                $this->serverContainer->getDatabaseConnection(),
65
+                $this->serverContainer->getUserManager(),
66
+                $this->serverContainer->getGroupManager(),
67
+                $this->serverContainer->getRootFolder()
68
+            );
69
+        }
70
+
71
+        return $this->defaultProvider;
72
+    }
73
+
74
+    /**
75
+     * Create the federated share provider
76
+     *
77
+     * @return FederatedShareProvider
78
+     */
79
+    protected function federatedShareProvider() {
80
+        if ($this->federatedProvider === null) {
81
+            /*
82 82
 			 * Check if the app is enabled
83 83
 			 */
84
-			$appManager = $this->serverContainer->getAppManager();
85
-			if (!$appManager->isEnabledForUser('federatedfilesharing')) {
86
-				return null;
87
-			}
84
+            $appManager = $this->serverContainer->getAppManager();
85
+            if (!$appManager->isEnabledForUser('federatedfilesharing')) {
86
+                return null;
87
+            }
88 88
 
89
-			/*
89
+            /*
90 90
 			 * TODO: add factory to federated sharing app
91 91
 			 */
92
-			$l = $this->serverContainer->getL10N('federatedfilessharing');
93
-			$addressHandler = new AddressHandler(
94
-				$this->serverContainer->getURLGenerator(),
95
-				$l
96
-			);
97
-			$discoveryManager = new DiscoveryManager(
98
-				$this->serverContainer->getMemCacheFactory(),
99
-				$this->serverContainer->getHTTPClientService()
100
-			);
101
-			$notifications = new Notifications(
102
-				$addressHandler,
103
-				$this->serverContainer->getHTTPClientService(),
104
-				$discoveryManager
105
-			);
106
-			$tokenHandler = new TokenHandler(
107
-				$this->serverContainer->getSecureRandom()
108
-			);
109
-
110
-			$this->federatedProvider = new FederatedShareProvider(
111
-				$this->serverContainer->getDatabaseConnection(),
112
-				$addressHandler,
113
-				$notifications,
114
-				$tokenHandler,
115
-				$l,
116
-				$this->serverContainer->getLogger(),
117
-				$this->serverContainer->getRootFolder()
118
-			);
119
-		}
120
-
121
-		return $this->federatedProvider;
122
-	}
123
-
124
-	/**
125
-	 * @inheritdoc
126
-	 */
127
-	public function getProvider($id) {
128
-		$provider = null;
129
-		if ($id === 'ocinternal') {
130
-			$provider = $this->defaultShareProvider();
131
-		} else if ($id === 'ocFederatedSharing') {
132
-			$provider = $this->federatedShareProvider();
133
-		}
134
-
135
-		if ($provider === null) {
136
-			throw new ProviderException('No provider with id .' . $id . ' found.');
137
-		}
138
-
139
-		return $provider;
140
-	}
141
-
142
-	/**
143
-	 * @inheritdoc
144
-	 */
145
-	public function getProviderForType($shareType) {
146
-		$provider = null;
147
-
148
-		//FIXME we should not report type 2
149
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER  ||
150
-			$shareType === 2 ||
151
-			$shareType === \OCP\Share::SHARE_TYPE_GROUP ||
152
-			$shareType === \OCP\Share::SHARE_TYPE_LINK) {
153
-			$provider = $this->defaultShareProvider();
154
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
155
-			$provider = $this->federatedShareProvider();
156
-		}
157
-
158
-		if ($provider === null) {
159
-			throw new ProviderException('No share provider for share type ' . $shareType);
160
-		}
161
-
162
-		return $provider;
163
-	}
92
+            $l = $this->serverContainer->getL10N('federatedfilessharing');
93
+            $addressHandler = new AddressHandler(
94
+                $this->serverContainer->getURLGenerator(),
95
+                $l
96
+            );
97
+            $discoveryManager = new DiscoveryManager(
98
+                $this->serverContainer->getMemCacheFactory(),
99
+                $this->serverContainer->getHTTPClientService()
100
+            );
101
+            $notifications = new Notifications(
102
+                $addressHandler,
103
+                $this->serverContainer->getHTTPClientService(),
104
+                $discoveryManager
105
+            );
106
+            $tokenHandler = new TokenHandler(
107
+                $this->serverContainer->getSecureRandom()
108
+            );
109
+
110
+            $this->federatedProvider = new FederatedShareProvider(
111
+                $this->serverContainer->getDatabaseConnection(),
112
+                $addressHandler,
113
+                $notifications,
114
+                $tokenHandler,
115
+                $l,
116
+                $this->serverContainer->getLogger(),
117
+                $this->serverContainer->getRootFolder()
118
+            );
119
+        }
120
+
121
+        return $this->federatedProvider;
122
+    }
123
+
124
+    /**
125
+     * @inheritdoc
126
+     */
127
+    public function getProvider($id) {
128
+        $provider = null;
129
+        if ($id === 'ocinternal') {
130
+            $provider = $this->defaultShareProvider();
131
+        } else if ($id === 'ocFederatedSharing') {
132
+            $provider = $this->federatedShareProvider();
133
+        }
134
+
135
+        if ($provider === null) {
136
+            throw new ProviderException('No provider with id .' . $id . ' found.');
137
+        }
138
+
139
+        return $provider;
140
+    }
141
+
142
+    /**
143
+     * @inheritdoc
144
+     */
145
+    public function getProviderForType($shareType) {
146
+        $provider = null;
147
+
148
+        //FIXME we should not report type 2
149
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER  ||
150
+            $shareType === 2 ||
151
+            $shareType === \OCP\Share::SHARE_TYPE_GROUP ||
152
+            $shareType === \OCP\Share::SHARE_TYPE_LINK) {
153
+            $provider = $this->defaultShareProvider();
154
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_REMOTE) {
155
+            $provider = $this->federatedShareProvider();
156
+        }
157
+
158
+        if ($provider === null) {
159
+            throw new ProviderException('No share provider for share type ' . $shareType);
160
+        }
161
+
162
+        return $provider;
163
+    }
164 164
 }
Please login to merge, or discard this patch.
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 		}
134 134
 
135 135
 		if ($provider === null) {
136
-			throw new ProviderException('No provider with id .' . $id . ' found.');
136
+			throw new ProviderException('No provider with id .'.$id.' found.');
137 137
 		}
138 138
 
139 139
 		return $provider;
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 		$provider = null;
147 147
 
148 148
 		//FIXME we should not report type 2
149
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER  ||
149
+		if ($shareType === \OCP\Share::SHARE_TYPE_USER ||
150 150
 			$shareType === 2 ||
151 151
 			$shareType === \OCP\Share::SHARE_TYPE_GROUP ||
152 152
 			$shareType === \OCP\Share::SHARE_TYPE_LINK) {
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
 		}
157 157
 
158 158
 		if ($provider === null) {
159
-			throw new ProviderException('No share provider for share type ' . $shareType);
159
+			throw new ProviderException('No share provider for share type '.$shareType);
160 160
 		}
161 161
 
162 162
 		return $provider;
Please login to merge, or discard this patch.
lib/private/share20/defaultshareprovider.php 2 patches
Indentation   +796 added lines, -796 removed lines patch added patch discarded remove patch
@@ -44,818 +44,818 @@
 block discarded – undo
44 44
  */
45 45
 class DefaultShareProvider implements IShareProvider {
46 46
 
47
-	// Special share type for user modified group shares
48
-	const SHARE_TYPE_USERGROUP = 2;
49
-
50
-	/** @var IDBConnection */
51
-	private $dbConn;
52
-
53
-	/** @var IUserManager */
54
-	private $userManager;
55
-
56
-	/** @var IGroupManager */
57
-	private $groupManager;
58
-
59
-	/** @var IRootFolder */
60
-	private $rootFolder;
61
-
62
-	/**
63
-	 * DefaultShareProvider constructor.
64
-	 *
65
-	 * @param IDBConnection $connection
66
-	 * @param IUserManager $userManager
67
-	 * @param IGroupManager $groupManager
68
-	 * @param IRootFolder $rootFolder
69
-	 */
70
-	public function __construct(
71
-			IDBConnection $connection,
72
-			IUserManager $userManager,
73
-			IGroupManager $groupManager,
74
-			IRootFolder $rootFolder) {
75
-		$this->dbConn = $connection;
76
-		$this->userManager = $userManager;
77
-		$this->groupManager = $groupManager;
78
-		$this->rootFolder = $rootFolder;
79
-	}
80
-
81
-	/**
82
-	 * Return the identifier of this provider.
83
-	 *
84
-	 * @return string Containing only [a-zA-Z0-9]
85
-	 */
86
-	public function identifier() {
87
-		return 'ocinternal';
88
-	}
89
-
90
-	/**
91
-	 * Share a path
92
-	 *
93
-	 * @param \OCP\Share\IShare $share
94
-	 * @return \OCP\Share\IShare The share object
95
-	 * @throws ShareNotFound
96
-	 * @throws \Exception
97
-	 */
98
-	public function create(\OCP\Share\IShare $share) {
99
-		$qb = $this->dbConn->getQueryBuilder();
100
-
101
-		$qb->insert('share');
102
-		$qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()));
103
-
104
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
105
-			//Set the UID of the user we share with
106
-			$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
107
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
108
-			//Set the GID of the group we share with
109
-			$qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
110
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
111
-			//Set the token of the share
112
-			$qb->setValue('token', $qb->createNamedParameter($share->getToken()));
113
-
114
-			//If a password is set store it
115
-			if ($share->getPassword() !== null) {
116
-				$qb->setValue('share_with', $qb->createNamedParameter($share->getPassword()));
117
-			}
118
-
119
-			//If an expiration date is set store it
120
-			if ($share->getExpirationDate() !== null) {
121
-				$qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
122
-			}
123
-
124
-			if (method_exists($share, 'getParent')) {
125
-				$qb->setValue('parent', $qb->createNamedParameter($share->getParent()));
126
-			}
127
-		} else {
128
-			throw new \Exception('invalid share type!');
129
-		}
130
-
131
-		// Set what is shares
132
-		$qb->setValue('item_type', $qb->createParameter('itemType'));
133
-		if ($share->getNode() instanceof \OCP\Files\File) {
134
-			$qb->setParameter('itemType', 'file');
135
-		} else {
136
-			$qb->setParameter('itemType', 'folder');
137
-		}
138
-
139
-		// Set the file id
140
-		$qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
141
-		$qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
142
-
143
-		// set the permissions
144
-		$qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
145
-
146
-		// Set who created this share
147
-		$qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
148
-
149
-		// Set who is the owner of this file/folder (and this the owner of the share)
150
-		$qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
151
-
152
-		// Set the file target
153
-		$qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
154
-
155
-		// Set the time this share was created
156
-		$qb->setValue('stime', $qb->createNamedParameter(time()));
157
-
158
-		// insert the data and fetch the id of the share
159
-		$this->dbConn->beginTransaction();
160
-		$qb->execute();
161
-		$id = $this->dbConn->lastInsertId('*PREFIX*share');
162
-		$this->dbConn->commit();
163
-
164
-		// Now fetch the inserted share and create a complete share object
165
-		$qb = $this->dbConn->getQueryBuilder();
166
-		$qb->select('*')
167
-			->from('share')
168
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
169
-
170
-		$cursor = $qb->execute();
171
-		$data = $cursor->fetch();
172
-		$cursor->closeCursor();
173
-
174
-		if ($data === false) {
175
-			throw new ShareNotFound();
176
-		}
177
-
178
-		$share = $this->createShare($data);
179
-		return $share;
180
-	}
181
-
182
-	/**
183
-	 * Update a share
184
-	 *
185
-	 * @param \OCP\Share\IShare $share
186
-	 * @return \OCP\Share\IShare The share object
187
-	 */
188
-	public function update(\OCP\Share\IShare $share) {
189
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
190
-			/*
47
+    // Special share type for user modified group shares
48
+    const SHARE_TYPE_USERGROUP = 2;
49
+
50
+    /** @var IDBConnection */
51
+    private $dbConn;
52
+
53
+    /** @var IUserManager */
54
+    private $userManager;
55
+
56
+    /** @var IGroupManager */
57
+    private $groupManager;
58
+
59
+    /** @var IRootFolder */
60
+    private $rootFolder;
61
+
62
+    /**
63
+     * DefaultShareProvider constructor.
64
+     *
65
+     * @param IDBConnection $connection
66
+     * @param IUserManager $userManager
67
+     * @param IGroupManager $groupManager
68
+     * @param IRootFolder $rootFolder
69
+     */
70
+    public function __construct(
71
+            IDBConnection $connection,
72
+            IUserManager $userManager,
73
+            IGroupManager $groupManager,
74
+            IRootFolder $rootFolder) {
75
+        $this->dbConn = $connection;
76
+        $this->userManager = $userManager;
77
+        $this->groupManager = $groupManager;
78
+        $this->rootFolder = $rootFolder;
79
+    }
80
+
81
+    /**
82
+     * Return the identifier of this provider.
83
+     *
84
+     * @return string Containing only [a-zA-Z0-9]
85
+     */
86
+    public function identifier() {
87
+        return 'ocinternal';
88
+    }
89
+
90
+    /**
91
+     * Share a path
92
+     *
93
+     * @param \OCP\Share\IShare $share
94
+     * @return \OCP\Share\IShare The share object
95
+     * @throws ShareNotFound
96
+     * @throws \Exception
97
+     */
98
+    public function create(\OCP\Share\IShare $share) {
99
+        $qb = $this->dbConn->getQueryBuilder();
100
+
101
+        $qb->insert('share');
102
+        $qb->setValue('share_type', $qb->createNamedParameter($share->getShareType()));
103
+
104
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
105
+            //Set the UID of the user we share with
106
+            $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
107
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
108
+            //Set the GID of the group we share with
109
+            $qb->setValue('share_with', $qb->createNamedParameter($share->getSharedWith()));
110
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
111
+            //Set the token of the share
112
+            $qb->setValue('token', $qb->createNamedParameter($share->getToken()));
113
+
114
+            //If a password is set store it
115
+            if ($share->getPassword() !== null) {
116
+                $qb->setValue('share_with', $qb->createNamedParameter($share->getPassword()));
117
+            }
118
+
119
+            //If an expiration date is set store it
120
+            if ($share->getExpirationDate() !== null) {
121
+                $qb->setValue('expiration', $qb->createNamedParameter($share->getExpirationDate(), 'datetime'));
122
+            }
123
+
124
+            if (method_exists($share, 'getParent')) {
125
+                $qb->setValue('parent', $qb->createNamedParameter($share->getParent()));
126
+            }
127
+        } else {
128
+            throw new \Exception('invalid share type!');
129
+        }
130
+
131
+        // Set what is shares
132
+        $qb->setValue('item_type', $qb->createParameter('itemType'));
133
+        if ($share->getNode() instanceof \OCP\Files\File) {
134
+            $qb->setParameter('itemType', 'file');
135
+        } else {
136
+            $qb->setParameter('itemType', 'folder');
137
+        }
138
+
139
+        // Set the file id
140
+        $qb->setValue('item_source', $qb->createNamedParameter($share->getNode()->getId()));
141
+        $qb->setValue('file_source', $qb->createNamedParameter($share->getNode()->getId()));
142
+
143
+        // set the permissions
144
+        $qb->setValue('permissions', $qb->createNamedParameter($share->getPermissions()));
145
+
146
+        // Set who created this share
147
+        $qb->setValue('uid_initiator', $qb->createNamedParameter($share->getSharedBy()));
148
+
149
+        // Set who is the owner of this file/folder (and this the owner of the share)
150
+        $qb->setValue('uid_owner', $qb->createNamedParameter($share->getShareOwner()));
151
+
152
+        // Set the file target
153
+        $qb->setValue('file_target', $qb->createNamedParameter($share->getTarget()));
154
+
155
+        // Set the time this share was created
156
+        $qb->setValue('stime', $qb->createNamedParameter(time()));
157
+
158
+        // insert the data and fetch the id of the share
159
+        $this->dbConn->beginTransaction();
160
+        $qb->execute();
161
+        $id = $this->dbConn->lastInsertId('*PREFIX*share');
162
+        $this->dbConn->commit();
163
+
164
+        // Now fetch the inserted share and create a complete share object
165
+        $qb = $this->dbConn->getQueryBuilder();
166
+        $qb->select('*')
167
+            ->from('share')
168
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)));
169
+
170
+        $cursor = $qb->execute();
171
+        $data = $cursor->fetch();
172
+        $cursor->closeCursor();
173
+
174
+        if ($data === false) {
175
+            throw new ShareNotFound();
176
+        }
177
+
178
+        $share = $this->createShare($data);
179
+        return $share;
180
+    }
181
+
182
+    /**
183
+     * Update a share
184
+     *
185
+     * @param \OCP\Share\IShare $share
186
+     * @return \OCP\Share\IShare The share object
187
+     */
188
+    public function update(\OCP\Share\IShare $share) {
189
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
190
+            /*
191 191
 			 * We allow updating the recipient on user shares.
192 192
 			 */
193
-			$qb = $this->dbConn->getQueryBuilder();
194
-			$qb->update('share')
195
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
196
-				->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
197
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
198
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
199
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
200
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
201
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
202
-				->execute();
203
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
204
-			$qb = $this->dbConn->getQueryBuilder();
205
-			$qb->update('share')
206
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
207
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
208
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
209
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
210
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
211
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
212
-				->execute();
213
-
214
-			/*
193
+            $qb = $this->dbConn->getQueryBuilder();
194
+            $qb->update('share')
195
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
196
+                ->set('share_with', $qb->createNamedParameter($share->getSharedWith()))
197
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
198
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
199
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
200
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
201
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
202
+                ->execute();
203
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
204
+            $qb = $this->dbConn->getQueryBuilder();
205
+            $qb->update('share')
206
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
207
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
208
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
209
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
210
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
211
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
212
+                ->execute();
213
+
214
+            /*
215 215
 			 * Update all user defined group shares
216 216
 			 */
217
-			$qb = $this->dbConn->getQueryBuilder();
218
-			$qb->update('share')
219
-				->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
220
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
221
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
222
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
223
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
224
-				->execute();
225
-
226
-			/*
217
+            $qb = $this->dbConn->getQueryBuilder();
218
+            $qb->update('share')
219
+                ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
220
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
221
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
222
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
223
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
224
+                ->execute();
225
+
226
+            /*
227 227
 			 * Now update the permissions for all children that have not set it to 0
228 228
 			 */
229
-			$qb = $this->dbConn->getQueryBuilder();
230
-			$qb->update('share')
231
-				->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
232
-				->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
233
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
234
-				->execute();
235
-
236
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
237
-			$qb = $this->dbConn->getQueryBuilder();
238
-			$qb->update('share')
239
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
240
-				->set('share_with', $qb->createNamedParameter($share->getPassword()))
241
-				->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
242
-				->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
243
-				->set('permissions', $qb->createNamedParameter($share->getPermissions()))
244
-				->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
245
-				->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
246
-				->set('token', $qb->createNamedParameter($share->getToken()))
247
-				->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
248
-				->execute();
249
-		}
250
-
251
-		return $share;
252
-	}
253
-
254
-	/**
255
-	 * Get all children of this share
256
-	 * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
257
-	 *
258
-	 * @param \OCP\Share\IShare $parent
259
-	 * @return \OCP\Share\IShare[]
260
-	 */
261
-	public function getChildren(\OCP\Share\IShare $parent) {
262
-		$children = [];
263
-
264
-		$qb = $this->dbConn->getQueryBuilder();
265
-		$qb->select('*')
266
-			->from('share')
267
-			->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
268
-			->andWhere(
269
-				$qb->expr()->in(
270
-					'share_type',
271
-					$qb->createNamedParameter([
272
-						\OCP\Share::SHARE_TYPE_USER,
273
-						\OCP\Share::SHARE_TYPE_GROUP,
274
-						\OCP\Share::SHARE_TYPE_LINK,
275
-					], IQueryBuilder::PARAM_INT_ARRAY)
276
-				)
277
-			)
278
-			->andWhere($qb->expr()->orX(
279
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
280
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
281
-			))
282
-			->orderBy('id');
283
-
284
-		$cursor = $qb->execute();
285
-		while($data = $cursor->fetch()) {
286
-			$children[] = $this->createShare($data);
287
-		}
288
-		$cursor->closeCursor();
289
-
290
-		return $children;
291
-	}
292
-
293
-	/**
294
-	 * Delete a share
295
-	 *
296
-	 * @param \OCP\Share\IShare $share
297
-	 */
298
-	public function delete(\OCP\Share\IShare $share) {
299
-		$qb = $this->dbConn->getQueryBuilder();
300
-		$qb->delete('share')
301
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
302
-
303
-		/*
229
+            $qb = $this->dbConn->getQueryBuilder();
230
+            $qb->update('share')
231
+                ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
232
+                ->andWhere($qb->expr()->neq('permissions', $qb->createNamedParameter(0)))
233
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
234
+                ->execute();
235
+
236
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
237
+            $qb = $this->dbConn->getQueryBuilder();
238
+            $qb->update('share')
239
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
240
+                ->set('share_with', $qb->createNamedParameter($share->getPassword()))
241
+                ->set('uid_owner', $qb->createNamedParameter($share->getShareOwner()))
242
+                ->set('uid_initiator', $qb->createNamedParameter($share->getSharedBy()))
243
+                ->set('permissions', $qb->createNamedParameter($share->getPermissions()))
244
+                ->set('item_source', $qb->createNamedParameter($share->getNode()->getId()))
245
+                ->set('file_source', $qb->createNamedParameter($share->getNode()->getId()))
246
+                ->set('token', $qb->createNamedParameter($share->getToken()))
247
+                ->set('expiration', $qb->createNamedParameter($share->getExpirationDate(), IQueryBuilder::PARAM_DATE))
248
+                ->execute();
249
+        }
250
+
251
+        return $share;
252
+    }
253
+
254
+    /**
255
+     * Get all children of this share
256
+     * FIXME: remove once https://github.com/owncloud/core/pull/21660 is in
257
+     *
258
+     * @param \OCP\Share\IShare $parent
259
+     * @return \OCP\Share\IShare[]
260
+     */
261
+    public function getChildren(\OCP\Share\IShare $parent) {
262
+        $children = [];
263
+
264
+        $qb = $this->dbConn->getQueryBuilder();
265
+        $qb->select('*')
266
+            ->from('share')
267
+            ->where($qb->expr()->eq('parent', $qb->createNamedParameter($parent->getId())))
268
+            ->andWhere(
269
+                $qb->expr()->in(
270
+                    'share_type',
271
+                    $qb->createNamedParameter([
272
+                        \OCP\Share::SHARE_TYPE_USER,
273
+                        \OCP\Share::SHARE_TYPE_GROUP,
274
+                        \OCP\Share::SHARE_TYPE_LINK,
275
+                    ], IQueryBuilder::PARAM_INT_ARRAY)
276
+                )
277
+            )
278
+            ->andWhere($qb->expr()->orX(
279
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
280
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
281
+            ))
282
+            ->orderBy('id');
283
+
284
+        $cursor = $qb->execute();
285
+        while($data = $cursor->fetch()) {
286
+            $children[] = $this->createShare($data);
287
+        }
288
+        $cursor->closeCursor();
289
+
290
+        return $children;
291
+    }
292
+
293
+    /**
294
+     * Delete a share
295
+     *
296
+     * @param \OCP\Share\IShare $share
297
+     */
298
+    public function delete(\OCP\Share\IShare $share) {
299
+        $qb = $this->dbConn->getQueryBuilder();
300
+        $qb->delete('share')
301
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())));
302
+
303
+        /*
304 304
 		 * If the share is a group share delete all possible
305 305
 		 * user defined groups shares.
306 306
 		 */
307
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
308
-			$qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
309
-		}
310
-
311
-		$qb->execute();
312
-	}
313
-
314
-	/**
315
-	 * Unshare a share from the recipient. If this is a group share
316
-	 * this means we need a special entry in the share db.
317
-	 *
318
-	 * @param \OCP\Share\IShare $share
319
-	 * @param string $recipient UserId of recipient
320
-	 * @throws BackendError
321
-	 * @throws ProviderException
322
-	 */
323
-	public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) {
324
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
325
-
326
-			$group = $this->groupManager->get($share->getSharedWith());
327
-			$user = $this->userManager->get($recipient);
328
-
329
-			if (!$group->inGroup($user)) {
330
-				throw new ProviderException('Recipient not in receiving group');
331
-			}
332
-
333
-			// Try to fetch user specific share
334
-			$qb = $this->dbConn->getQueryBuilder();
335
-			$stmt = $qb->select('*')
336
-				->from('share')
337
-				->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
338
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
339
-				->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
340
-				->andWhere($qb->expr()->orX(
341
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
342
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
343
-				))
344
-				->execute();
345
-
346
-			$data = $stmt->fetch();
347
-
348
-			/*
307
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
308
+            $qb->orWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())));
309
+        }
310
+
311
+        $qb->execute();
312
+    }
313
+
314
+    /**
315
+     * Unshare a share from the recipient. If this is a group share
316
+     * this means we need a special entry in the share db.
317
+     *
318
+     * @param \OCP\Share\IShare $share
319
+     * @param string $recipient UserId of recipient
320
+     * @throws BackendError
321
+     * @throws ProviderException
322
+     */
323
+    public function deleteFromSelf(\OCP\Share\IShare $share, $recipient) {
324
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
325
+
326
+            $group = $this->groupManager->get($share->getSharedWith());
327
+            $user = $this->userManager->get($recipient);
328
+
329
+            if (!$group->inGroup($user)) {
330
+                throw new ProviderException('Recipient not in receiving group');
331
+            }
332
+
333
+            // Try to fetch user specific share
334
+            $qb = $this->dbConn->getQueryBuilder();
335
+            $stmt = $qb->select('*')
336
+                ->from('share')
337
+                ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
338
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
339
+                ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
340
+                ->andWhere($qb->expr()->orX(
341
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
342
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
343
+                ))
344
+                ->execute();
345
+
346
+            $data = $stmt->fetch();
347
+
348
+            /*
349 349
 			 * Check if there already is a user specific group share.
350 350
 			 * If there is update it (if required).
351 351
 			 */
352
-			if ($data === false) {
353
-				$qb = $this->dbConn->getQueryBuilder();
354
-
355
-				$type = $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder';
356
-
357
-				//Insert new share
358
-				$qb->insert('share')
359
-					->values([
360
-						'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
361
-						'share_with' => $qb->createNamedParameter($recipient),
362
-						'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
363
-						'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
364
-						'parent' => $qb->createNamedParameter($share->getId()),
365
-						'item_type' => $qb->createNamedParameter($type),
366
-						'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
367
-						'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
368
-						'file_target' => $qb->createNamedParameter($share->getTarget()),
369
-						'permissions' => $qb->createNamedParameter(0),
370
-						'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
371
-					])->execute();
372
-
373
-			} else if ($data['permissions'] !== 0) {
374
-
375
-				// Update existing usergroup share
376
-				$qb = $this->dbConn->getQueryBuilder();
377
-				$qb->update('share')
378
-					->set('permissions', $qb->createNamedParameter(0))
379
-					->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
380
-					->execute();
381
-			}
382
-
383
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
384
-
385
-			if ($share->getSharedWith() !== $recipient) {
386
-				throw new ProviderException('Recipient does not match');
387
-			}
388
-
389
-			// We can just delete user and link shares
390
-			$this->delete($share);
391
-		} else {
392
-			throw new ProviderException('Invalid shareType');
393
-		}
394
-	}
395
-
396
-	/**
397
-	 * @inheritdoc
398
-	 */
399
-	public function move(\OCP\Share\IShare $share, $recipient) {
400
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
401
-			// Just update the target
402
-			$qb = $this->dbConn->getQueryBuilder();
403
-			$qb->update('share')
404
-				->set('file_target', $qb->createNamedParameter($share->getTarget()))
405
-				->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
406
-				->execute();
407
-
408
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
409
-
410
-			// Check if there is a usergroup share
411
-			$qb = $this->dbConn->getQueryBuilder();
412
-			$stmt = $qb->select('id')
413
-				->from('share')
414
-				->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
415
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
416
-				->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
417
-				->andWhere($qb->expr()->orX(
418
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
419
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
420
-				))
421
-				->setMaxResults(1)
422
-				->execute();
423
-
424
-			$data = $stmt->fetch();
425
-			$stmt->closeCursor();
426
-
427
-			if ($data === false) {
428
-				// No usergroup share yet. Create one.
429
-				$qb = $this->dbConn->getQueryBuilder();
430
-				$qb->insert('share')
431
-					->values([
432
-						'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
433
-						'share_with' => $qb->createNamedParameter($recipient),
434
-						'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
435
-						'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
436
-						'parent' => $qb->createNamedParameter($share->getId()),
437
-						'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'),
438
-						'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
439
-						'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
440
-						'file_target' => $qb->createNamedParameter($share->getTarget()),
441
-						'permissions' => $qb->createNamedParameter($share->getPermissions()),
442
-						'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
443
-					])->execute();
444
-			} else {
445
-				// Already a usergroup share. Update it.
446
-				$qb = $this->dbConn->getQueryBuilder();
447
-				$qb->update('share')
448
-					->set('file_target', $qb->createNamedParameter($share->getTarget()))
449
-					->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
450
-					->execute();
451
-			}
452
-		}
453
-
454
-		return $share;
455
-	}
456
-
457
-	/**
458
-	 * Get all shares by the given user. Sharetype and path can be used to filter.
459
-	 *
460
-	 * @param string $userId
461
-	 * @param int $shareType
462
-	 * @param \OCP\Files\File|\OCP\Files\Folder $node
463
-	 * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
464
-	 * @param int $limit The maximum number of shares to be returned, -1 for all shares
465
-	 * @param int $offset
466
-	 * @return Share[]
467
-	 */
468
-	public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
469
-		$qb = $this->dbConn->getQueryBuilder();
470
-		$qb->select('*')
471
-			->from('share')
472
-			->andWhere($qb->expr()->orX(
473
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
474
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
475
-			));
476
-
477
-		$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
478
-
479
-		/**
480
-		 * Reshares for this user are shares where they are the owner.
481
-		 */
482
-		if ($reshares === false) {
483
-			//Special case for old shares created via the web UI
484
-			$or1 = $qb->expr()->andX(
485
-				$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
486
-				$qb->expr()->isNull('uid_initiator')
487
-			);
488
-
489
-			$qb->andWhere(
490
-				$qb->expr()->orX(
491
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
492
-					$or1
493
-				)
494
-			);
495
-		} else {
496
-			$qb->andWhere(
497
-				$qb->expr()->orX(
498
-					$qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
499
-					$qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
500
-				)
501
-			);
502
-		}
503
-
504
-		if ($node !== null) {
505
-			$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
506
-		}
507
-
508
-		if ($limit !== -1) {
509
-			$qb->setMaxResults($limit);
510
-		}
511
-
512
-		$qb->setFirstResult($offset);
513
-		$qb->orderBy('id');
514
-
515
-		$cursor = $qb->execute();
516
-		$shares = [];
517
-		while($data = $cursor->fetch()) {
518
-			$shares[] = $this->createShare($data);
519
-		}
520
-		$cursor->closeCursor();
521
-
522
-		return $shares;
523
-	}
524
-
525
-	/**
526
-	 * @inheritdoc
527
-	 */
528
-	public function getShareById($id, $recipientId = null) {
529
-		$qb = $this->dbConn->getQueryBuilder();
530
-
531
-		$qb->select('*')
532
-			->from('share')
533
-			->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
534
-			->andWhere(
535
-				$qb->expr()->in(
536
-					'share_type',
537
-					$qb->createNamedParameter([
538
-						\OCP\Share::SHARE_TYPE_USER,
539
-						\OCP\Share::SHARE_TYPE_GROUP,
540
-						\OCP\Share::SHARE_TYPE_LINK,
541
-					], IQueryBuilder::PARAM_INT_ARRAY)
542
-				)
543
-			)
544
-			->andWhere($qb->expr()->orX(
545
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
546
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
547
-			));
352
+            if ($data === false) {
353
+                $qb = $this->dbConn->getQueryBuilder();
354
+
355
+                $type = $share->getNode() instanceof \OCP\Files\File ? 'file' : 'folder';
356
+
357
+                //Insert new share
358
+                $qb->insert('share')
359
+                    ->values([
360
+                        'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
361
+                        'share_with' => $qb->createNamedParameter($recipient),
362
+                        'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
363
+                        'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
364
+                        'parent' => $qb->createNamedParameter($share->getId()),
365
+                        'item_type' => $qb->createNamedParameter($type),
366
+                        'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
367
+                        'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
368
+                        'file_target' => $qb->createNamedParameter($share->getTarget()),
369
+                        'permissions' => $qb->createNamedParameter(0),
370
+                        'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
371
+                    ])->execute();
372
+
373
+            } else if ($data['permissions'] !== 0) {
374
+
375
+                // Update existing usergroup share
376
+                $qb = $this->dbConn->getQueryBuilder();
377
+                $qb->update('share')
378
+                    ->set('permissions', $qb->createNamedParameter(0))
379
+                    ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
380
+                    ->execute();
381
+            }
382
+
383
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
384
+
385
+            if ($share->getSharedWith() !== $recipient) {
386
+                throw new ProviderException('Recipient does not match');
387
+            }
388
+
389
+            // We can just delete user and link shares
390
+            $this->delete($share);
391
+        } else {
392
+            throw new ProviderException('Invalid shareType');
393
+        }
394
+    }
395
+
396
+    /**
397
+     * @inheritdoc
398
+     */
399
+    public function move(\OCP\Share\IShare $share, $recipient) {
400
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
401
+            // Just update the target
402
+            $qb = $this->dbConn->getQueryBuilder();
403
+            $qb->update('share')
404
+                ->set('file_target', $qb->createNamedParameter($share->getTarget()))
405
+                ->where($qb->expr()->eq('id', $qb->createNamedParameter($share->getId())))
406
+                ->execute();
407
+
408
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
409
+
410
+            // Check if there is a usergroup share
411
+            $qb = $this->dbConn->getQueryBuilder();
412
+            $stmt = $qb->select('id')
413
+                ->from('share')
414
+                ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
415
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($recipient)))
416
+                ->andWhere($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
417
+                ->andWhere($qb->expr()->orX(
418
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
419
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
420
+                ))
421
+                ->setMaxResults(1)
422
+                ->execute();
423
+
424
+            $data = $stmt->fetch();
425
+            $stmt->closeCursor();
426
+
427
+            if ($data === false) {
428
+                // No usergroup share yet. Create one.
429
+                $qb = $this->dbConn->getQueryBuilder();
430
+                $qb->insert('share')
431
+                    ->values([
432
+                        'share_type' => $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP),
433
+                        'share_with' => $qb->createNamedParameter($recipient),
434
+                        'uid_owner' => $qb->createNamedParameter($share->getShareOwner()),
435
+                        'uid_initiator' => $qb->createNamedParameter($share->getSharedBy()),
436
+                        'parent' => $qb->createNamedParameter($share->getId()),
437
+                        'item_type' => $qb->createNamedParameter($share->getNode() instanceof File ? 'file' : 'folder'),
438
+                        'item_source' => $qb->createNamedParameter($share->getNode()->getId()),
439
+                        'file_source' => $qb->createNamedParameter($share->getNode()->getId()),
440
+                        'file_target' => $qb->createNamedParameter($share->getTarget()),
441
+                        'permissions' => $qb->createNamedParameter($share->getPermissions()),
442
+                        'stime' => $qb->createNamedParameter($share->getShareTime()->getTimestamp()),
443
+                    ])->execute();
444
+            } else {
445
+                // Already a usergroup share. Update it.
446
+                $qb = $this->dbConn->getQueryBuilder();
447
+                $qb->update('share')
448
+                    ->set('file_target', $qb->createNamedParameter($share->getTarget()))
449
+                    ->where($qb->expr()->eq('id', $qb->createNamedParameter($data['id'])))
450
+                    ->execute();
451
+            }
452
+        }
453
+
454
+        return $share;
455
+    }
456
+
457
+    /**
458
+     * Get all shares by the given user. Sharetype and path can be used to filter.
459
+     *
460
+     * @param string $userId
461
+     * @param int $shareType
462
+     * @param \OCP\Files\File|\OCP\Files\Folder $node
463
+     * @param bool $reshares Also get the shares where $user is the owner instead of just the shares where $user is the initiator
464
+     * @param int $limit The maximum number of shares to be returned, -1 for all shares
465
+     * @param int $offset
466
+     * @return Share[]
467
+     */
468
+    public function getSharesBy($userId, $shareType, $node, $reshares, $limit, $offset) {
469
+        $qb = $this->dbConn->getQueryBuilder();
470
+        $qb->select('*')
471
+            ->from('share')
472
+            ->andWhere($qb->expr()->orX(
473
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
474
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
475
+            ));
476
+
477
+        $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter($shareType)));
478
+
479
+        /**
480
+         * Reshares for this user are shares where they are the owner.
481
+         */
482
+        if ($reshares === false) {
483
+            //Special case for old shares created via the web UI
484
+            $or1 = $qb->expr()->andX(
485
+                $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
486
+                $qb->expr()->isNull('uid_initiator')
487
+            );
488
+
489
+            $qb->andWhere(
490
+                $qb->expr()->orX(
491
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId)),
492
+                    $or1
493
+                )
494
+            );
495
+        } else {
496
+            $qb->andWhere(
497
+                $qb->expr()->orX(
498
+                    $qb->expr()->eq('uid_owner', $qb->createNamedParameter($userId)),
499
+                    $qb->expr()->eq('uid_initiator', $qb->createNamedParameter($userId))
500
+                )
501
+            );
502
+        }
503
+
504
+        if ($node !== null) {
505
+            $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
506
+        }
507
+
508
+        if ($limit !== -1) {
509
+            $qb->setMaxResults($limit);
510
+        }
511
+
512
+        $qb->setFirstResult($offset);
513
+        $qb->orderBy('id');
514
+
515
+        $cursor = $qb->execute();
516
+        $shares = [];
517
+        while($data = $cursor->fetch()) {
518
+            $shares[] = $this->createShare($data);
519
+        }
520
+        $cursor->closeCursor();
521
+
522
+        return $shares;
523
+    }
524
+
525
+    /**
526
+     * @inheritdoc
527
+     */
528
+    public function getShareById($id, $recipientId = null) {
529
+        $qb = $this->dbConn->getQueryBuilder();
530
+
531
+        $qb->select('*')
532
+            ->from('share')
533
+            ->where($qb->expr()->eq('id', $qb->createNamedParameter($id)))
534
+            ->andWhere(
535
+                $qb->expr()->in(
536
+                    'share_type',
537
+                    $qb->createNamedParameter([
538
+                        \OCP\Share::SHARE_TYPE_USER,
539
+                        \OCP\Share::SHARE_TYPE_GROUP,
540
+                        \OCP\Share::SHARE_TYPE_LINK,
541
+                    ], IQueryBuilder::PARAM_INT_ARRAY)
542
+                )
543
+            )
544
+            ->andWhere($qb->expr()->orX(
545
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
546
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
547
+            ));
548 548
 		
549
-		$cursor = $qb->execute();
550
-		$data = $cursor->fetch();
551
-		$cursor->closeCursor();
552
-
553
-		if ($data === false) {
554
-			throw new ShareNotFound();
555
-		}
556
-
557
-		try {
558
-			$share = $this->createShare($data);
559
-		} catch (InvalidShare $e) {
560
-			throw new ShareNotFound();
561
-		}
562
-
563
-		// If the recipient is set for a group share resolve to that user
564
-		if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
565
-			$share = $this->resolveGroupShare($share, $recipientId);
566
-		}
567
-
568
-		return $share;
569
-	}
570
-
571
-	/**
572
-	 * Get shares for a given path
573
-	 *
574
-	 * @param \OCP\Files\Node $path
575
-	 * @return \OCP\Share\IShare[]
576
-	 */
577
-	public function getSharesByPath(Node $path) {
578
-		$qb = $this->dbConn->getQueryBuilder();
579
-
580
-		$cursor = $qb->select('*')
581
-			->from('share')
582
-			->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
583
-			->andWhere(
584
-				$qb->expr()->orX(
585
-					$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
586
-					$qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))
587
-				)
588
-			)
589
-			->andWhere($qb->expr()->orX(
590
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
591
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
592
-			))
593
-			->execute();
594
-
595
-		$shares = [];
596
-		while($data = $cursor->fetch()) {
597
-			$shares[] = $this->createShare($data);
598
-		}
599
-		$cursor->closeCursor();
600
-
601
-		return $shares;
602
-	}
603
-
604
-	/**
605
-	 * @inheritdoc
606
-	 */
607
-	public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
608
-		/** @var Share[] $shares */
609
-		$shares = [];
610
-
611
-		if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
612
-			//Get shares directly with this user
613
-			$qb = $this->dbConn->getQueryBuilder();
614
-			$qb->select('*')
615
-				->from('share');
616
-
617
-			// Order by id
618
-			$qb->orderBy('id');
619
-
620
-			// Set limit and offset
621
-			if ($limit !== -1) {
622
-				$qb->setMaxResults($limit);
623
-			}
624
-			$qb->setFirstResult($offset);
625
-
626
-			$qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)))
627
-				->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
628
-				->andWhere($qb->expr()->orX(
629
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
630
-					$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
631
-				));
632
-
633
-			// Filter by node if provided
634
-			if ($node !== null) {
635
-				$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
636
-			}
637
-
638
-			$cursor = $qb->execute();
639
-
640
-			while($data = $cursor->fetch()) {
641
-				$shares[] = $this->createShare($data);
642
-			}
643
-			$cursor->closeCursor();
644
-
645
-		} else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
646
-			$user = $this->userManager->get($userId);
647
-			$allGroups = $this->groupManager->getUserGroups($user);
648
-
649
-			/** @var Share[] $shares2 */
650
-			$shares2 = [];
651
-
652
-			$start = 0;
653
-			while(true) {
654
-				$groups = array_slice($allGroups, $start, 100);
655
-				$start += 100;
656
-
657
-				if ($groups === []) {
658
-					break;
659
-				}
660
-
661
-				$qb = $this->dbConn->getQueryBuilder();
662
-				$qb->select('*')
663
-					->from('share')
664
-					->orderBy('id')
665
-					->setFirstResult(0);
666
-
667
-				if ($limit !== -1) {
668
-					$qb->setMaxResults($limit - count($shares));
669
-				}
670
-
671
-				// Filter by node if provided
672
-				if ($node !== null) {
673
-					$qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
674
-				}
675
-
676
-				$groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups);
677
-
678
-				$qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
679
-					->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
680
-						$groups,
681
-						IQueryBuilder::PARAM_STR_ARRAY
682
-					)))
683
-					->andWhere($qb->expr()->orX(
684
-						$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
685
-						$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
686
-					));
687
-
688
-				$cursor = $qb->execute();
689
-				while($data = $cursor->fetch()) {
690
-					if ($offset > 0) {
691
-						$offset--;
692
-						continue;
693
-					}
694
-					$shares2[] = $this->createShare($data);
695
-				}
696
-				$cursor->closeCursor();
697
-			}
698
-
699
-			/*
549
+        $cursor = $qb->execute();
550
+        $data = $cursor->fetch();
551
+        $cursor->closeCursor();
552
+
553
+        if ($data === false) {
554
+            throw new ShareNotFound();
555
+        }
556
+
557
+        try {
558
+            $share = $this->createShare($data);
559
+        } catch (InvalidShare $e) {
560
+            throw new ShareNotFound();
561
+        }
562
+
563
+        // If the recipient is set for a group share resolve to that user
564
+        if ($recipientId !== null && $share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
565
+            $share = $this->resolveGroupShare($share, $recipientId);
566
+        }
567
+
568
+        return $share;
569
+    }
570
+
571
+    /**
572
+     * Get shares for a given path
573
+     *
574
+     * @param \OCP\Files\Node $path
575
+     * @return \OCP\Share\IShare[]
576
+     */
577
+    public function getSharesByPath(Node $path) {
578
+        $qb = $this->dbConn->getQueryBuilder();
579
+
580
+        $cursor = $qb->select('*')
581
+            ->from('share')
582
+            ->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($path->getId())))
583
+            ->andWhere(
584
+                $qb->expr()->orX(
585
+                    $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)),
586
+                    $qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP))
587
+                )
588
+            )
589
+            ->andWhere($qb->expr()->orX(
590
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
591
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
592
+            ))
593
+            ->execute();
594
+
595
+        $shares = [];
596
+        while($data = $cursor->fetch()) {
597
+            $shares[] = $this->createShare($data);
598
+        }
599
+        $cursor->closeCursor();
600
+
601
+        return $shares;
602
+    }
603
+
604
+    /**
605
+     * @inheritdoc
606
+     */
607
+    public function getSharedWith($userId, $shareType, $node, $limit, $offset) {
608
+        /** @var Share[] $shares */
609
+        $shares = [];
610
+
611
+        if ($shareType === \OCP\Share::SHARE_TYPE_USER) {
612
+            //Get shares directly with this user
613
+            $qb = $this->dbConn->getQueryBuilder();
614
+            $qb->select('*')
615
+                ->from('share');
616
+
617
+            // Order by id
618
+            $qb->orderBy('id');
619
+
620
+            // Set limit and offset
621
+            if ($limit !== -1) {
622
+                $qb->setMaxResults($limit);
623
+            }
624
+            $qb->setFirstResult($offset);
625
+
626
+            $qb->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_USER)))
627
+                ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
628
+                ->andWhere($qb->expr()->orX(
629
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
630
+                    $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
631
+                ));
632
+
633
+            // Filter by node if provided
634
+            if ($node !== null) {
635
+                $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
636
+            }
637
+
638
+            $cursor = $qb->execute();
639
+
640
+            while($data = $cursor->fetch()) {
641
+                $shares[] = $this->createShare($data);
642
+            }
643
+            $cursor->closeCursor();
644
+
645
+        } else if ($shareType === \OCP\Share::SHARE_TYPE_GROUP) {
646
+            $user = $this->userManager->get($userId);
647
+            $allGroups = $this->groupManager->getUserGroups($user);
648
+
649
+            /** @var Share[] $shares2 */
650
+            $shares2 = [];
651
+
652
+            $start = 0;
653
+            while(true) {
654
+                $groups = array_slice($allGroups, $start, 100);
655
+                $start += 100;
656
+
657
+                if ($groups === []) {
658
+                    break;
659
+                }
660
+
661
+                $qb = $this->dbConn->getQueryBuilder();
662
+                $qb->select('*')
663
+                    ->from('share')
664
+                    ->orderBy('id')
665
+                    ->setFirstResult(0);
666
+
667
+                if ($limit !== -1) {
668
+                    $qb->setMaxResults($limit - count($shares));
669
+                }
670
+
671
+                // Filter by node if provided
672
+                if ($node !== null) {
673
+                    $qb->andWhere($qb->expr()->eq('file_source', $qb->createNamedParameter($node->getId())));
674
+                }
675
+
676
+                $groups = array_map(function(IGroup $group) { return $group->getGID(); }, $groups);
677
+
678
+                $qb->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_GROUP)))
679
+                    ->andWhere($qb->expr()->in('share_with', $qb->createNamedParameter(
680
+                        $groups,
681
+                        IQueryBuilder::PARAM_STR_ARRAY
682
+                    )))
683
+                    ->andWhere($qb->expr()->orX(
684
+                        $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
685
+                        $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
686
+                    ));
687
+
688
+                $cursor = $qb->execute();
689
+                while($data = $cursor->fetch()) {
690
+                    if ($offset > 0) {
691
+                        $offset--;
692
+                        continue;
693
+                    }
694
+                    $shares2[] = $this->createShare($data);
695
+                }
696
+                $cursor->closeCursor();
697
+            }
698
+
699
+            /*
700 700
  			 * Resolve all group shares to user specific shares
701 701
  			 * TODO: Optmize this!
702 702
  			 */
703
-			foreach($shares2 as $share) {
704
-				$shares[] = $this->resolveGroupShare($share, $userId);
705
-			}
706
-		} else {
707
-			throw new BackendError('Invalid backend');
708
-		}
709
-
710
-
711
-		return $shares;
712
-	}
713
-
714
-	/**
715
-	 * Get a share by token
716
-	 *
717
-	 * @param string $token
718
-	 * @return \OCP\Share\IShare
719
-	 * @throws ShareNotFound
720
-	 */
721
-	public function getShareByToken($token) {
722
-		$qb = $this->dbConn->getQueryBuilder();
723
-
724
-		$cursor = $qb->select('*')
725
-			->from('share')
726
-			->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
727
-			->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
728
-			->andWhere($qb->expr()->orX(
729
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
730
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
731
-			))
732
-			->execute();
733
-
734
-		$data = $cursor->fetch();
735
-
736
-		if ($data === false) {
737
-			throw new ShareNotFound();
738
-		}
739
-
740
-		try {
741
-			$share = $this->createShare($data);
742
-		} catch (InvalidShare $e) {
743
-			throw new ShareNotFound();
744
-		}
745
-
746
-		return $share;
747
-	}
703
+            foreach($shares2 as $share) {
704
+                $shares[] = $this->resolveGroupShare($share, $userId);
705
+            }
706
+        } else {
707
+            throw new BackendError('Invalid backend');
708
+        }
709
+
710
+
711
+        return $shares;
712
+    }
713
+
714
+    /**
715
+     * Get a share by token
716
+     *
717
+     * @param string $token
718
+     * @return \OCP\Share\IShare
719
+     * @throws ShareNotFound
720
+     */
721
+    public function getShareByToken($token) {
722
+        $qb = $this->dbConn->getQueryBuilder();
723
+
724
+        $cursor = $qb->select('*')
725
+            ->from('share')
726
+            ->where($qb->expr()->eq('share_type', $qb->createNamedParameter(\OCP\Share::SHARE_TYPE_LINK)))
727
+            ->andWhere($qb->expr()->eq('token', $qb->createNamedParameter($token)))
728
+            ->andWhere($qb->expr()->orX(
729
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
730
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
731
+            ))
732
+            ->execute();
733
+
734
+        $data = $cursor->fetch();
735
+
736
+        if ($data === false) {
737
+            throw new ShareNotFound();
738
+        }
739
+
740
+        try {
741
+            $share = $this->createShare($data);
742
+        } catch (InvalidShare $e) {
743
+            throw new ShareNotFound();
744
+        }
745
+
746
+        return $share;
747
+    }
748 748
 	
749
-	/**
750
-	 * Create a share object from an database row
751
-	 *
752
-	 * @param mixed[] $data
753
-	 * @return \OCP\Share\IShare
754
-	 * @throws InvalidShare
755
-	 */
756
-	private function createShare($data) {
757
-		$share = new Share($this->rootFolder);
758
-		$share->setId((int)$data['id'])
759
-			->setShareType((int)$data['share_type'])
760
-			->setPermissions((int)$data['permissions'])
761
-			->setTarget($data['file_target'])
762
-			->setMailSend((bool)$data['mail_send']);
763
-
764
-		$shareTime = new \DateTime();
765
-		$shareTime->setTimestamp((int)$data['stime']);
766
-		$share->setShareTime($shareTime);
767
-
768
-		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
769
-			$share->setSharedWith($data['share_with']);
770
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
771
-			$share->setSharedWith($data['share_with']);
772
-		} else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
773
-			$share->setPassword($data['share_with']);
774
-			$share->setToken($data['token']);
775
-		}
776
-
777
-		if ($data['uid_initiator'] === null) {
778
-			//OLD SHARE
779
-			$share->setSharedBy($data['uid_owner']);
780
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
781
-
782
-			$owner = $path->getOwner();
783
-			$share->setShareOwner($owner->getUID());
784
-		} else {
785
-			//New share!
786
-			$share->setSharedBy($data['uid_initiator']);
787
-			$share->setShareOwner($data['uid_owner']);
788
-		}
789
-
790
-		$share->setNodeId((int)$data['file_source']);
791
-		$share->setNodeType($data['item_type']);
792
-
793
-		if ($data['expiration'] !== null) {
794
-			$expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
795
-			$share->setExpirationDate($expiration);
796
-		}
797
-
798
-		$share->setProviderId($this->identifier());
799
-
800
-		return $share;
801
-	}
802
-
803
-	/**
804
-	 * Get the node with file $id for $user
805
-	 *
806
-	 * @param string $user The userId
807
-	 * @param int $id
808
-	 * @return \OCP\Files\File|\OCP\Files\Folder
809
-	 * @throws InvalidShare
810
-	 */
811
-	private function getNode($user, $id) {
812
-		try {
813
-			$userFolder = $this->rootFolder->getUserFolder($user);
814
-		} catch (NotFoundException $e) {
815
-			throw new InvalidShare();
816
-		}
817
-
818
-		$nodes = $userFolder->getById($id);
819
-
820
-		if (empty($nodes)) {
821
-			throw new InvalidShare();
822
-		}
823
-
824
-		return $nodes[0];
825
-	}
826
-
827
-	/**
828
-	 * Resolve a group share to a user specific share
829
-	 * Thus if the user moved their group share make sure this is properly reflected here.
830
-	 *
831
-	 * @param \OCP\Share\IShare $share
832
-	 * @param string $userId
833
-	 * @return Share Returns the updated share if one was found else return the original share.
834
-	 */
835
-	private function resolveGroupShare(\OCP\Share\IShare $share, $userId) {
836
-		$qb = $this->dbConn->getQueryBuilder();
837
-
838
-		$stmt = $qb->select('*')
839
-			->from('share')
840
-			->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
841
-			->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
842
-			->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
843
-			->andWhere($qb->expr()->orX(
844
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
845
-				$qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
846
-			))
847
-			->setMaxResults(1)
848
-			->execute();
849
-
850
-		$data = $stmt->fetch();
851
-		$stmt->closeCursor();
852
-
853
-		if ($data !== false) {
854
-			$share->setPermissions((int)$data['permissions']);
855
-			$share->setTarget($data['file_target']);
856
-		}
857
-
858
-		return $share;
859
-	}
749
+    /**
750
+     * Create a share object from an database row
751
+     *
752
+     * @param mixed[] $data
753
+     * @return \OCP\Share\IShare
754
+     * @throws InvalidShare
755
+     */
756
+    private function createShare($data) {
757
+        $share = new Share($this->rootFolder);
758
+        $share->setId((int)$data['id'])
759
+            ->setShareType((int)$data['share_type'])
760
+            ->setPermissions((int)$data['permissions'])
761
+            ->setTarget($data['file_target'])
762
+            ->setMailSend((bool)$data['mail_send']);
763
+
764
+        $shareTime = new \DateTime();
765
+        $shareTime->setTimestamp((int)$data['stime']);
766
+        $share->setShareTime($shareTime);
767
+
768
+        if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
769
+            $share->setSharedWith($data['share_with']);
770
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_GROUP) {
771
+            $share->setSharedWith($data['share_with']);
772
+        } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK) {
773
+            $share->setPassword($data['share_with']);
774
+            $share->setToken($data['token']);
775
+        }
776
+
777
+        if ($data['uid_initiator'] === null) {
778
+            //OLD SHARE
779
+            $share->setSharedBy($data['uid_owner']);
780
+            $path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
781
+
782
+            $owner = $path->getOwner();
783
+            $share->setShareOwner($owner->getUID());
784
+        } else {
785
+            //New share!
786
+            $share->setSharedBy($data['uid_initiator']);
787
+            $share->setShareOwner($data['uid_owner']);
788
+        }
789
+
790
+        $share->setNodeId((int)$data['file_source']);
791
+        $share->setNodeType($data['item_type']);
792
+
793
+        if ($data['expiration'] !== null) {
794
+            $expiration = \DateTime::createFromFormat('Y-m-d H:i:s', $data['expiration']);
795
+            $share->setExpirationDate($expiration);
796
+        }
797
+
798
+        $share->setProviderId($this->identifier());
799
+
800
+        return $share;
801
+    }
802
+
803
+    /**
804
+     * Get the node with file $id for $user
805
+     *
806
+     * @param string $user The userId
807
+     * @param int $id
808
+     * @return \OCP\Files\File|\OCP\Files\Folder
809
+     * @throws InvalidShare
810
+     */
811
+    private function getNode($user, $id) {
812
+        try {
813
+            $userFolder = $this->rootFolder->getUserFolder($user);
814
+        } catch (NotFoundException $e) {
815
+            throw new InvalidShare();
816
+        }
817
+
818
+        $nodes = $userFolder->getById($id);
819
+
820
+        if (empty($nodes)) {
821
+            throw new InvalidShare();
822
+        }
823
+
824
+        return $nodes[0];
825
+    }
826
+
827
+    /**
828
+     * Resolve a group share to a user specific share
829
+     * Thus if the user moved their group share make sure this is properly reflected here.
830
+     *
831
+     * @param \OCP\Share\IShare $share
832
+     * @param string $userId
833
+     * @return Share Returns the updated share if one was found else return the original share.
834
+     */
835
+    private function resolveGroupShare(\OCP\Share\IShare $share, $userId) {
836
+        $qb = $this->dbConn->getQueryBuilder();
837
+
838
+        $stmt = $qb->select('*')
839
+            ->from('share')
840
+            ->where($qb->expr()->eq('parent', $qb->createNamedParameter($share->getId())))
841
+            ->andWhere($qb->expr()->eq('share_type', $qb->createNamedParameter(self::SHARE_TYPE_USERGROUP)))
842
+            ->andWhere($qb->expr()->eq('share_with', $qb->createNamedParameter($userId)))
843
+            ->andWhere($qb->expr()->orX(
844
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('file')),
845
+                $qb->expr()->eq('item_type', $qb->createNamedParameter('folder'))
846
+            ))
847
+            ->setMaxResults(1)
848
+            ->execute();
849
+
850
+        $data = $stmt->fetch();
851
+        $stmt->closeCursor();
852
+
853
+        if ($data !== false) {
854
+            $share->setPermissions((int)$data['permissions']);
855
+            $share->setTarget($data['file_target']);
856
+        }
857
+
858
+        return $share;
859
+    }
860 860
 
861 861
 }
Please login to merge, or discard this patch.
Spacing   +15 added lines, -15 removed lines patch added patch discarded remove patch
@@ -282,7 +282,7 @@  discard block
 block discarded – undo
282 282
 			->orderBy('id');
283 283
 
284 284
 		$cursor = $qb->execute();
285
-		while($data = $cursor->fetch()) {
285
+		while ($data = $cursor->fetch()) {
286 286
 			$children[] = $this->createShare($data);
287 287
 		}
288 288
 		$cursor->closeCursor();
@@ -514,7 +514,7 @@  discard block
 block discarded – undo
514 514
 
515 515
 		$cursor = $qb->execute();
516 516
 		$shares = [];
517
-		while($data = $cursor->fetch()) {
517
+		while ($data = $cursor->fetch()) {
518 518
 			$shares[] = $this->createShare($data);
519 519
 		}
520 520
 		$cursor->closeCursor();
@@ -593,7 +593,7 @@  discard block
 block discarded – undo
593 593
 			->execute();
594 594
 
595 595
 		$shares = [];
596
-		while($data = $cursor->fetch()) {
596
+		while ($data = $cursor->fetch()) {
597 597
 			$shares[] = $this->createShare($data);
598 598
 		}
599 599
 		$cursor->closeCursor();
@@ -637,7 +637,7 @@  discard block
 block discarded – undo
637 637
 
638 638
 			$cursor = $qb->execute();
639 639
 
640
-			while($data = $cursor->fetch()) {
640
+			while ($data = $cursor->fetch()) {
641 641
 				$shares[] = $this->createShare($data);
642 642
 			}
643 643
 			$cursor->closeCursor();
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 			$shares2 = [];
651 651
 
652 652
 			$start = 0;
653
-			while(true) {
653
+			while (true) {
654 654
 				$groups = array_slice($allGroups, $start, 100);
655 655
 				$start += 100;
656 656
 
@@ -686,7 +686,7 @@  discard block
 block discarded – undo
686 686
 					));
687 687
 
688 688
 				$cursor = $qb->execute();
689
-				while($data = $cursor->fetch()) {
689
+				while ($data = $cursor->fetch()) {
690 690
 					if ($offset > 0) {
691 691
 						$offset--;
692 692
 						continue;
@@ -700,7 +700,7 @@  discard block
 block discarded – undo
700 700
  			 * Resolve all group shares to user specific shares
701 701
  			 * TODO: Optmize this!
702 702
  			 */
703
-			foreach($shares2 as $share) {
703
+			foreach ($shares2 as $share) {
704 704
 				$shares[] = $this->resolveGroupShare($share, $userId);
705 705
 			}
706 706
 		} else {
@@ -755,14 +755,14 @@  discard block
 block discarded – undo
755 755
 	 */
756 756
 	private function createShare($data) {
757 757
 		$share = new Share($this->rootFolder);
758
-		$share->setId((int)$data['id'])
759
-			->setShareType((int)$data['share_type'])
760
-			->setPermissions((int)$data['permissions'])
758
+		$share->setId((int) $data['id'])
759
+			->setShareType((int) $data['share_type'])
760
+			->setPermissions((int) $data['permissions'])
761 761
 			->setTarget($data['file_target'])
762
-			->setMailSend((bool)$data['mail_send']);
762
+			->setMailSend((bool) $data['mail_send']);
763 763
 
764 764
 		$shareTime = new \DateTime();
765
-		$shareTime->setTimestamp((int)$data['stime']);
765
+		$shareTime->setTimestamp((int) $data['stime']);
766 766
 		$share->setShareTime($shareTime);
767 767
 
768 768
 		if ($share->getShareType() === \OCP\Share::SHARE_TYPE_USER) {
@@ -777,7 +777,7 @@  discard block
 block discarded – undo
777 777
 		if ($data['uid_initiator'] === null) {
778 778
 			//OLD SHARE
779 779
 			$share->setSharedBy($data['uid_owner']);
780
-			$path = $this->getNode($share->getSharedBy(), (int)$data['file_source']);
780
+			$path = $this->getNode($share->getSharedBy(), (int) $data['file_source']);
781 781
 
782 782
 			$owner = $path->getOwner();
783 783
 			$share->setShareOwner($owner->getUID());
@@ -787,7 +787,7 @@  discard block
 block discarded – undo
787 787
 			$share->setShareOwner($data['uid_owner']);
788 788
 		}
789 789
 
790
-		$share->setNodeId((int)$data['file_source']);
790
+		$share->setNodeId((int) $data['file_source']);
791 791
 		$share->setNodeType($data['item_type']);
792 792
 
793 793
 		if ($data['expiration'] !== null) {
@@ -851,7 +851,7 @@  discard block
 block discarded – undo
851 851
 		$stmt->closeCursor();
852 852
 
853 853
 		if ($data !== false) {
854
-			$share->setPermissions((int)$data['permissions']);
854
+			$share->setPermissions((int) $data['permissions']);
855 855
 			$share->setTarget($data['file_target']);
856 856
 		}
857 857
 
Please login to merge, or discard this patch.
lib/private/urlgenerator.php 2 patches
Indentation   +183 added lines, -183 removed lines patch added patch discarded remove patch
@@ -40,187 +40,187 @@
 block discarded – undo
40 40
  * Class to generate URLs
41 41
  */
42 42
 class URLGenerator implements IURLGenerator {
43
-	/** @var IConfig */
44
-	private $config;
45
-	/** @var ICacheFactory */
46
-	private $cacheFactory;
47
-
48
-	/**
49
-	 * @param IConfig $config
50
-	 * @param ICacheFactory $cacheFactory
51
-	 */
52
-	public function __construct(IConfig $config,
53
-								ICacheFactory $cacheFactory) {
54
-		$this->config = $config;
55
-		$this->cacheFactory = $cacheFactory;
56
-	}
57
-
58
-	/**
59
-	 * Creates an url using a defined route
60
-	 * @param string $route
61
-	 * @param array $parameters args with param=>value, will be appended to the returned url
62
-	 * @return string the url
63
-	 *
64
-	 * Returns a url to the given route.
65
-	 */
66
-	public function linkToRoute($route, $parameters = array()) {
67
-		// TODO: mock router
68
-		$urlLinkTo = \OC::$server->getRouter()->generate($route, $parameters);
69
-		return $urlLinkTo;
70
-	}
71
-
72
-	/**
73
-	 * Creates an absolute url using a defined route
74
-	 * @param string $routeName
75
-	 * @param array $arguments args with param=>value, will be appended to the returned url
76
-	 * @return string the url
77
-	 *
78
-	 * Returns an absolute url to the given route.
79
-	 */
80
-	public function linkToRouteAbsolute($routeName, $arguments = array()) {
81
-		return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments));
82
-	}
83
-
84
-	/**
85
-	 * Creates an url
86
-	 * @param string $app app
87
-	 * @param string $file file
88
-	 * @param array $args array with param=>value, will be appended to the returned url
89
-	 *    The value of $args will be urlencoded
90
-	 * @return string the url
91
-	 *
92
-	 * Returns a url to the given app and file.
93
-	 */
94
-	public function linkTo( $app, $file, $args = array() ) {
95
-		$frontControllerActive = (getenv('front_controller_active') === 'true');
96
-
97
-		if( $app != '' ) {
98
-			$app_path = \OC_App::getAppPath($app);
99
-			// Check if the app is in the app folder
100
-			if ($app_path && file_exists($app_path . '/' . $file)) {
101
-				if (substr($file, -3) == 'php') {
102
-
103
-					$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
104
-					if ($frontControllerActive) {
105
-						$urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
106
-					}
107
-					$urlLinkTo .= ($file != 'index.php') ? '/' . $file : '';
108
-				} else {
109
-					$urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
110
-				}
111
-			} else {
112
-				$urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
113
-			}
114
-		} else {
115
-			if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
116
-				$urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
117
-			} else {
118
-				if ($frontControllerActive && $file === 'index.php') {
119
-					$urlLinkTo = \OC::$WEBROOT . '/';
120
-				} else {
121
-					$urlLinkTo = \OC::$WEBROOT . '/' . $file;
122
-				}
123
-			}
124
-		}
125
-
126
-		if ($args && $query = http_build_query($args, '', '&')) {
127
-			$urlLinkTo .= '?' . $query;
128
-		}
129
-
130
-		return $urlLinkTo;
131
-	}
132
-
133
-	/**
134
-	 * Creates path to an image
135
-	 * @param string $app app
136
-	 * @param string $image image name
137
-	 * @throws \RuntimeException If the image does not exist
138
-	 * @return string the url
139
-	 *
140
-	 * Returns the path to the image.
141
-	 */
142
-	public function imagePath($app, $image) {
143
-		$cache = $this->cacheFactory->create('imagePath');
144
-		$cacheKey = $app.'-'.$image;
145
-		if($key = $cache->get($cacheKey)) {
146
-			return $key;
147
-		}
148
-
149
-		// Read the selected theme from the config file
150
-		$theme = \OC_Util::getTheme();
151
-
152
-		//if a theme has a png but not an svg always use the png
153
-		$basename = substr(basename($image),0,-4);
154
-
155
-		$appPath = \OC_App::getAppPath($app);
156
-
157
-		// Check if the app is in the app folder
158
-		$path = '';
159
-		if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) {
160
-			$path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image";
161
-		} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg")
162
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) {
163
-			$path =  \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png";
164
-		} elseif ($appPath && file_exists($appPath . "/img/$image")) {
165
-			$path =  \OC_App::getAppWebPath($app) . "/img/$image";
166
-		} elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")
167
-			&& file_exists($appPath . "/img/$basename.png")) {
168
-			$path =  \OC_App::getAppWebPath($app) . "/img/$basename.png";
169
-		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) {
170
-			$path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$image";
171
-		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg")
172
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) {
173
-			$path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png";
174
-		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) {
175
-			$path =  \OC::$WEBROOT . "/$app/img/$image";
176
-		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg")
177
-			&& file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) {
178
-			$path =  \OC::$WEBROOT . "/$app/img/$basename.png";
179
-		} elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) {
180
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$image";
181
-		} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg")
182
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) {
183
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
184
-		} elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) {
185
-			$path =  \OC::$WEBROOT . "/core/img/$image";
186
-		}
187
-
188
-		if($path !== '') {
189
-			$cache->set($cacheKey, $path);
190
-			return $path;
191
-		} else {
192
-			throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT);
193
-		}
194
-	}
195
-
196
-
197
-	/**
198
-	 * Makes an URL absolute
199
-	 * @param string $url the url in the ownCloud host
200
-	 * @return string the absolute version of the url
201
-	 */
202
-	public function getAbsoluteURL($url) {
203
-		$separator = $url[0] === '/' ? '' : '/';
204
-
205
-		if (\OC::$CLI && !defined('PHPUNIT_RUN')) {
206
-			return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/');
207
-		}
208
-
209
-		// The ownCloud web root can already be prepended.
210
-		$webRoot = substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT
211
-			? ''
212
-			: \OC::$WEBROOT;
213
-
214
-		$request = \OC::$server->getRequest();
215
-		return $request->getServerProtocol() . '://' . $request->getServerHost() . $webRoot . $separator . $url;
216
-	}
217
-
218
-	/**
219
-	 * @param string $key
220
-	 * @return string url to the online documentation
221
-	 */
222
-	public function linkToDocs($key) {
223
-		$theme = \OC::$server->getThemingDefaults();
224
-		return $theme->buildDocLinkToKey($key);
225
-	}
43
+    /** @var IConfig */
44
+    private $config;
45
+    /** @var ICacheFactory */
46
+    private $cacheFactory;
47
+
48
+    /**
49
+     * @param IConfig $config
50
+     * @param ICacheFactory $cacheFactory
51
+     */
52
+    public function __construct(IConfig $config,
53
+                                ICacheFactory $cacheFactory) {
54
+        $this->config = $config;
55
+        $this->cacheFactory = $cacheFactory;
56
+    }
57
+
58
+    /**
59
+     * Creates an url using a defined route
60
+     * @param string $route
61
+     * @param array $parameters args with param=>value, will be appended to the returned url
62
+     * @return string the url
63
+     *
64
+     * Returns a url to the given route.
65
+     */
66
+    public function linkToRoute($route, $parameters = array()) {
67
+        // TODO: mock router
68
+        $urlLinkTo = \OC::$server->getRouter()->generate($route, $parameters);
69
+        return $urlLinkTo;
70
+    }
71
+
72
+    /**
73
+     * Creates an absolute url using a defined route
74
+     * @param string $routeName
75
+     * @param array $arguments args with param=>value, will be appended to the returned url
76
+     * @return string the url
77
+     *
78
+     * Returns an absolute url to the given route.
79
+     */
80
+    public function linkToRouteAbsolute($routeName, $arguments = array()) {
81
+        return $this->getAbsoluteURL($this->linkToRoute($routeName, $arguments));
82
+    }
83
+
84
+    /**
85
+     * Creates an url
86
+     * @param string $app app
87
+     * @param string $file file
88
+     * @param array $args array with param=>value, will be appended to the returned url
89
+     *    The value of $args will be urlencoded
90
+     * @return string the url
91
+     *
92
+     * Returns a url to the given app and file.
93
+     */
94
+    public function linkTo( $app, $file, $args = array() ) {
95
+        $frontControllerActive = (getenv('front_controller_active') === 'true');
96
+
97
+        if( $app != '' ) {
98
+            $app_path = \OC_App::getAppPath($app);
99
+            // Check if the app is in the app folder
100
+            if ($app_path && file_exists($app_path . '/' . $file)) {
101
+                if (substr($file, -3) == 'php') {
102
+
103
+                    $urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
104
+                    if ($frontControllerActive) {
105
+                        $urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
106
+                    }
107
+                    $urlLinkTo .= ($file != 'index.php') ? '/' . $file : '';
108
+                } else {
109
+                    $urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
110
+                }
111
+            } else {
112
+                $urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
113
+            }
114
+        } else {
115
+            if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
116
+                $urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
117
+            } else {
118
+                if ($frontControllerActive && $file === 'index.php') {
119
+                    $urlLinkTo = \OC::$WEBROOT . '/';
120
+                } else {
121
+                    $urlLinkTo = \OC::$WEBROOT . '/' . $file;
122
+                }
123
+            }
124
+        }
125
+
126
+        if ($args && $query = http_build_query($args, '', '&')) {
127
+            $urlLinkTo .= '?' . $query;
128
+        }
129
+
130
+        return $urlLinkTo;
131
+    }
132
+
133
+    /**
134
+     * Creates path to an image
135
+     * @param string $app app
136
+     * @param string $image image name
137
+     * @throws \RuntimeException If the image does not exist
138
+     * @return string the url
139
+     *
140
+     * Returns the path to the image.
141
+     */
142
+    public function imagePath($app, $image) {
143
+        $cache = $this->cacheFactory->create('imagePath');
144
+        $cacheKey = $app.'-'.$image;
145
+        if($key = $cache->get($cacheKey)) {
146
+            return $key;
147
+        }
148
+
149
+        // Read the selected theme from the config file
150
+        $theme = \OC_Util::getTheme();
151
+
152
+        //if a theme has a png but not an svg always use the png
153
+        $basename = substr(basename($image),0,-4);
154
+
155
+        $appPath = \OC_App::getAppPath($app);
156
+
157
+        // Check if the app is in the app folder
158
+        $path = '';
159
+        if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) {
160
+            $path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image";
161
+        } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg")
162
+            && file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) {
163
+            $path =  \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png";
164
+        } elseif ($appPath && file_exists($appPath . "/img/$image")) {
165
+            $path =  \OC_App::getAppWebPath($app) . "/img/$image";
166
+        } elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")
167
+            && file_exists($appPath . "/img/$basename.png")) {
168
+            $path =  \OC_App::getAppWebPath($app) . "/img/$basename.png";
169
+        } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) {
170
+            $path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$image";
171
+        } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg")
172
+            && file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) {
173
+            $path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png";
174
+        } elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) {
175
+            $path =  \OC::$WEBROOT . "/$app/img/$image";
176
+        } elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg")
177
+            && file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) {
178
+            $path =  \OC::$WEBROOT . "/$app/img/$basename.png";
179
+        } elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) {
180
+            $path =  \OC::$WEBROOT . "/themes/$theme/core/img/$image";
181
+        } elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg")
182
+            && file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) {
183
+            $path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
184
+        } elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) {
185
+            $path =  \OC::$WEBROOT . "/core/img/$image";
186
+        }
187
+
188
+        if($path !== '') {
189
+            $cache->set($cacheKey, $path);
190
+            return $path;
191
+        } else {
192
+            throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT);
193
+        }
194
+    }
195
+
196
+
197
+    /**
198
+     * Makes an URL absolute
199
+     * @param string $url the url in the ownCloud host
200
+     * @return string the absolute version of the url
201
+     */
202
+    public function getAbsoluteURL($url) {
203
+        $separator = $url[0] === '/' ? '' : '/';
204
+
205
+        if (\OC::$CLI && !defined('PHPUNIT_RUN')) {
206
+            return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/');
207
+        }
208
+
209
+        // The ownCloud web root can already be prepended.
210
+        $webRoot = substr($url, 0, strlen(\OC::$WEBROOT)) === \OC::$WEBROOT
211
+            ? ''
212
+            : \OC::$WEBROOT;
213
+
214
+        $request = \OC::$server->getRequest();
215
+        return $request->getServerProtocol() . '://' . $request->getServerHost() . $webRoot . $separator . $url;
216
+    }
217
+
218
+    /**
219
+     * @param string $key
220
+     * @return string url to the online documentation
221
+     */
222
+    public function linkToDocs($key) {
223
+        $theme = \OC::$server->getThemingDefaults();
224
+        return $theme->buildDocLinkToKey($key);
225
+    }
226 226
 }
Please login to merge, or discard this patch.
Spacing   +46 added lines, -46 removed lines patch added patch discarded remove patch
@@ -91,40 +91,40 @@  discard block
 block discarded – undo
91 91
 	 *
92 92
 	 * Returns a url to the given app and file.
93 93
 	 */
94
-	public function linkTo( $app, $file, $args = array() ) {
94
+	public function linkTo($app, $file, $args = array()) {
95 95
 		$frontControllerActive = (getenv('front_controller_active') === 'true');
96 96
 
97
-		if( $app != '' ) {
97
+		if ($app != '') {
98 98
 			$app_path = \OC_App::getAppPath($app);
99 99
 			// Check if the app is in the app folder
100
-			if ($app_path && file_exists($app_path . '/' . $file)) {
100
+			if ($app_path && file_exists($app_path.'/'.$file)) {
101 101
 				if (substr($file, -3) == 'php') {
102 102
 
103
-					$urlLinkTo = \OC::$WEBROOT . '/index.php/apps/' . $app;
103
+					$urlLinkTo = \OC::$WEBROOT.'/index.php/apps/'.$app;
104 104
 					if ($frontControllerActive) {
105
-						$urlLinkTo = \OC::$WEBROOT . '/apps/' . $app;
105
+						$urlLinkTo = \OC::$WEBROOT.'/apps/'.$app;
106 106
 					}
107
-					$urlLinkTo .= ($file != 'index.php') ? '/' . $file : '';
107
+					$urlLinkTo .= ($file != 'index.php') ? '/'.$file : '';
108 108
 				} else {
109
-					$urlLinkTo = \OC_App::getAppWebPath($app) . '/' . $file;
109
+					$urlLinkTo = \OC_App::getAppWebPath($app).'/'.$file;
110 110
 				}
111 111
 			} else {
112
-				$urlLinkTo = \OC::$WEBROOT . '/' . $app . '/' . $file;
112
+				$urlLinkTo = \OC::$WEBROOT.'/'.$app.'/'.$file;
113 113
 			}
114 114
 		} else {
115
-			if (file_exists(\OC::$SERVERROOT . '/core/' . $file)) {
116
-				$urlLinkTo = \OC::$WEBROOT . '/core/' . $file;
115
+			if (file_exists(\OC::$SERVERROOT.'/core/'.$file)) {
116
+				$urlLinkTo = \OC::$WEBROOT.'/core/'.$file;
117 117
 			} else {
118 118
 				if ($frontControllerActive && $file === 'index.php') {
119
-					$urlLinkTo = \OC::$WEBROOT . '/';
119
+					$urlLinkTo = \OC::$WEBROOT.'/';
120 120
 				} else {
121
-					$urlLinkTo = \OC::$WEBROOT . '/' . $file;
121
+					$urlLinkTo = \OC::$WEBROOT.'/'.$file;
122 122
 				}
123 123
 			}
124 124
 		}
125 125
 
126 126
 		if ($args && $query = http_build_query($args, '', '&')) {
127
-			$urlLinkTo .= '?' . $query;
127
+			$urlLinkTo .= '?'.$query;
128 128
 		}
129 129
 
130 130
 		return $urlLinkTo;
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	public function imagePath($app, $image) {
143 143
 		$cache = $this->cacheFactory->create('imagePath');
144 144
 		$cacheKey = $app.'-'.$image;
145
-		if($key = $cache->get($cacheKey)) {
145
+		if ($key = $cache->get($cacheKey)) {
146 146
 			return $key;
147 147
 		}
148 148
 
@@ -150,46 +150,46 @@  discard block
 block discarded – undo
150 150
 		$theme = \OC_Util::getTheme();
151 151
 
152 152
 		//if a theme has a png but not an svg always use the png
153
-		$basename = substr(basename($image),0,-4);
153
+		$basename = substr(basename($image), 0, -4);
154 154
 
155 155
 		$appPath = \OC_App::getAppPath($app);
156 156
 
157 157
 		// Check if the app is in the app folder
158 158
 		$path = '';
159
-		if (file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$image")) {
160
-			$path = \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$image";
161
-		} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.svg")
162
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/apps/$app/img/$basename.png")) {
163
-			$path =  \OC::$WEBROOT . "/themes/$theme/apps/$app/img/$basename.png";
164
-		} elseif ($appPath && file_exists($appPath . "/img/$image")) {
165
-			$path =  \OC_App::getAppWebPath($app) . "/img/$image";
166
-		} elseif ($appPath && !file_exists($appPath . "/img/$basename.svg")
167
-			&& file_exists($appPath . "/img/$basename.png")) {
168
-			$path =  \OC_App::getAppWebPath($app) . "/img/$basename.png";
169
-		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$image")) {
170
-			$path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$image";
171
-		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.svg")
172
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/$app/img/$basename.png"))) {
173
-			$path =  \OC::$WEBROOT . "/themes/$theme/$app/img/$basename.png";
174
-		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT . "/$app/img/$image")) {
175
-			$path =  \OC::$WEBROOT . "/$app/img/$image";
176
-		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT . "/$app/img/$basename.svg")
177
-			&& file_exists(\OC::$SERVERROOT . "/$app/img/$basename.png"))) {
178
-			$path =  \OC::$WEBROOT . "/$app/img/$basename.png";
179
-		} elseif (file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$image")) {
180
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$image";
181
-		} elseif (!file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.svg")
182
-			&& file_exists(\OC::$SERVERROOT . "/themes/$theme/core/img/$basename.png")) {
183
-			$path =  \OC::$WEBROOT . "/themes/$theme/core/img/$basename.png";
184
-		} elseif (file_exists(\OC::$SERVERROOT . "/core/img/$image")) {
185
-			$path =  \OC::$WEBROOT . "/core/img/$image";
159
+		if (file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$image")) {
160
+			$path = \OC::$WEBROOT."/themes/$theme/apps/$app/img/$image";
161
+		} elseif (!file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$basename.svg")
162
+			&& file_exists(\OC::$SERVERROOT."/themes/$theme/apps/$app/img/$basename.png")) {
163
+			$path = \OC::$WEBROOT."/themes/$theme/apps/$app/img/$basename.png";
164
+		} elseif ($appPath && file_exists($appPath."/img/$image")) {
165
+			$path = \OC_App::getAppWebPath($app)."/img/$image";
166
+		} elseif ($appPath && !file_exists($appPath."/img/$basename.svg")
167
+			&& file_exists($appPath."/img/$basename.png")) {
168
+			$path = \OC_App::getAppWebPath($app)."/img/$basename.png";
169
+		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$image")) {
170
+			$path = \OC::$WEBROOT."/themes/$theme/$app/img/$image";
171
+		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$basename.svg")
172
+			&& file_exists(\OC::$SERVERROOT."/themes/$theme/$app/img/$basename.png"))) {
173
+			$path = \OC::$WEBROOT."/themes/$theme/$app/img/$basename.png";
174
+		} elseif (!empty($app) and file_exists(\OC::$SERVERROOT."/$app/img/$image")) {
175
+			$path = \OC::$WEBROOT."/$app/img/$image";
176
+		} elseif (!empty($app) and (!file_exists(\OC::$SERVERROOT."/$app/img/$basename.svg")
177
+			&& file_exists(\OC::$SERVERROOT."/$app/img/$basename.png"))) {
178
+			$path = \OC::$WEBROOT."/$app/img/$basename.png";
179
+		} elseif (file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$image")) {
180
+			$path = \OC::$WEBROOT."/themes/$theme/core/img/$image";
181
+		} elseif (!file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$basename.svg")
182
+			&& file_exists(\OC::$SERVERROOT."/themes/$theme/core/img/$basename.png")) {
183
+			$path = \OC::$WEBROOT."/themes/$theme/core/img/$basename.png";
184
+		} elseif (file_exists(\OC::$SERVERROOT."/core/img/$image")) {
185
+			$path = \OC::$WEBROOT."/core/img/$image";
186 186
 		}
187 187
 
188
-		if($path !== '') {
188
+		if ($path !== '') {
189 189
 			$cache->set($cacheKey, $path);
190 190
 			return $path;
191 191
 		} else {
192
-			throw new RuntimeException('image not found: image:' . $image . ' webroot:' . \OC::$WEBROOT . ' serverroot:' . \OC::$SERVERROOT);
192
+			throw new RuntimeException('image not found: image:'.$image.' webroot:'.\OC::$WEBROOT.' serverroot:'.\OC::$SERVERROOT);
193 193
 		}
194 194
 	}
195 195
 
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
 		$separator = $url[0] === '/' ? '' : '/';
204 204
 
205 205
 		if (\OC::$CLI && !defined('PHPUNIT_RUN')) {
206
-			return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/') . '/' . ltrim($url, '/');
206
+			return rtrim($this->config->getSystemValue('overwrite.cli.url'), '/').'/'.ltrim($url, '/');
207 207
 		}
208 208
 
209 209
 		// The ownCloud web root can already be prepended.
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
 			: \OC::$WEBROOT;
213 213
 
214 214
 		$request = \OC::$server->getRequest();
215
-		return $request->getServerProtocol() . '://' . $request->getServerHost() . $webRoot . $separator . $url;
215
+		return $request->getServerProtocol().'://'.$request->getServerHost().$webRoot.$separator.$url;
216 216
 	}
217 217
 
218 218
 	/**
Please login to merge, or discard this patch.
lib/private/largefilehelper.php 1 patch
Indentation   +169 added lines, -169 removed lines patch added patch discarded remove patch
@@ -30,182 +30,182 @@
 block discarded – undo
30 30
  * Helper class for large files on 32-bit platforms.
31 31
  */
32 32
 class LargeFileHelper {
33
-	/**
34
-	* pow(2, 53) as a base-10 string.
35
-	* @var string
36
-	*/
37
-	const POW_2_53 = '9007199254740992';
33
+    /**
34
+     * pow(2, 53) as a base-10 string.
35
+     * @var string
36
+     */
37
+    const POW_2_53 = '9007199254740992';
38 38
 
39
-	/**
40
-	* pow(2, 53) - 1 as a base-10 string.
41
-	* @var string
42
-	*/
43
-	const POW_2_53_MINUS_1 = '9007199254740991';
39
+    /**
40
+     * pow(2, 53) - 1 as a base-10 string.
41
+     * @var string
42
+     */
43
+    const POW_2_53_MINUS_1 = '9007199254740991';
44 44
 
45
-	/**
46
-	* @brief Checks whether our assumptions hold on the PHP platform we are on.
47
-	*
48
-	* @throws \RunTimeException if our assumptions do not hold on the current
49
-	*                           PHP platform.
50
-	*/
51
-	public function __construct() {
52
-		$pow_2_53 = floatval(self::POW_2_53_MINUS_1) + 1.0;
53
-		if ($this->formatUnsignedInteger($pow_2_53) !== self::POW_2_53) {
54
-			throw new \RunTimeException(
55
-				'This class assumes floats to be double precision or "better".'
56
-			);
57
-		}
58
-	}
45
+    /**
46
+     * @brief Checks whether our assumptions hold on the PHP platform we are on.
47
+     *
48
+     * @throws \RunTimeException if our assumptions do not hold on the current
49
+     *                           PHP platform.
50
+     */
51
+    public function __construct() {
52
+        $pow_2_53 = floatval(self::POW_2_53_MINUS_1) + 1.0;
53
+        if ($this->formatUnsignedInteger($pow_2_53) !== self::POW_2_53) {
54
+            throw new \RunTimeException(
55
+                'This class assumes floats to be double precision or "better".'
56
+            );
57
+        }
58
+    }
59 59
 
60
-	/**
61
-	* @brief Formats a signed integer or float as an unsigned integer base-10
62
-	*        string. Passed strings will be checked for being base-10.
63
-	*
64
-	* @param int|float|string $number Number containing unsigned integer data
65
-	*
66
-	* @throws \UnexpectedValueException if $number is not a float, not an int
67
-	*                                   and not a base-10 string.
68
-	*
69
-	* @return string Unsigned integer base-10 string
70
-	*/
71
-	public function formatUnsignedInteger($number) {
72
-		if (is_float($number)) {
73
-			// Undo the effect of the php.ini setting 'precision'.
74
-			return number_format($number, 0, '', '');
75
-		} else if (is_string($number) && ctype_digit($number)) {
76
-			return $number;
77
-		} else if (is_int($number)) {
78
-			// Interpret signed integer as unsigned integer.
79
-			return sprintf('%u', $number);
80
-		} else {
81
-			throw new \UnexpectedValueException(
82
-				'Expected int, float or base-10 string'
83
-			);
84
-		}
85
-	}
60
+    /**
61
+     * @brief Formats a signed integer or float as an unsigned integer base-10
62
+     *        string. Passed strings will be checked for being base-10.
63
+     *
64
+     * @param int|float|string $number Number containing unsigned integer data
65
+     *
66
+     * @throws \UnexpectedValueException if $number is not a float, not an int
67
+     *                                   and not a base-10 string.
68
+     *
69
+     * @return string Unsigned integer base-10 string
70
+     */
71
+    public function formatUnsignedInteger($number) {
72
+        if (is_float($number)) {
73
+            // Undo the effect of the php.ini setting 'precision'.
74
+            return number_format($number, 0, '', '');
75
+        } else if (is_string($number) && ctype_digit($number)) {
76
+            return $number;
77
+        } else if (is_int($number)) {
78
+            // Interpret signed integer as unsigned integer.
79
+            return sprintf('%u', $number);
80
+        } else {
81
+            throw new \UnexpectedValueException(
82
+                'Expected int, float or base-10 string'
83
+            );
84
+        }
85
+    }
86 86
 
87
-	/**
88
-	* @brief Tries to get the size of a file via various workarounds that
89
-	*        even work for large files on 32-bit platforms.
90
-	*
91
-	* @param string $filename Path to the file.
92
-	*
93
-	* @return null|int|float Number of bytes as number (float or int) or
94
-	*                        null on failure.
95
-	*/
96
-	public function getFileSize($filename) {
97
-		$fileSize = $this->getFileSizeViaCurl($filename);
98
-		if (!is_null($fileSize)) {
99
-			return $fileSize;
100
-		}
101
-		$fileSize = $this->getFileSizeViaCOM($filename);
102
-		if (!is_null($fileSize)) {
103
-			return $fileSize;
104
-		}
105
-		$fileSize = $this->getFileSizeViaExec($filename);
106
-		if (!is_null($fileSize)) {
107
-			return $fileSize;
108
-		}
109
-		return $this->getFileSizeNative($filename);
110
-	}
87
+    /**
88
+     * @brief Tries to get the size of a file via various workarounds that
89
+     *        even work for large files on 32-bit platforms.
90
+     *
91
+     * @param string $filename Path to the file.
92
+     *
93
+     * @return null|int|float Number of bytes as number (float or int) or
94
+     *                        null on failure.
95
+     */
96
+    public function getFileSize($filename) {
97
+        $fileSize = $this->getFileSizeViaCurl($filename);
98
+        if (!is_null($fileSize)) {
99
+            return $fileSize;
100
+        }
101
+        $fileSize = $this->getFileSizeViaCOM($filename);
102
+        if (!is_null($fileSize)) {
103
+            return $fileSize;
104
+        }
105
+        $fileSize = $this->getFileSizeViaExec($filename);
106
+        if (!is_null($fileSize)) {
107
+            return $fileSize;
108
+        }
109
+        return $this->getFileSizeNative($filename);
110
+    }
111 111
 
112
-	/**
113
-	* @brief Tries to get the size of a file via a CURL HEAD request.
114
-	*
115
-	* @param string $fileName Path to the file.
116
-	*
117
-	* @return null|int|float Number of bytes as number (float or int) or
118
-	*                        null on failure.
119
-	*/
120
-	public function getFileSizeViaCurl($fileName) {
121
-		if (\OC::$server->getIniWrapper()->getString('open_basedir') === '') {
122
-			$encodedFileName = rawurlencode($fileName);
123
-			$ch = curl_init("file://$encodedFileName");
124
-			curl_setopt($ch, CURLOPT_NOBODY, true);
125
-			curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
126
-			curl_setopt($ch, CURLOPT_HEADER, true);
127
-			$data = curl_exec($ch);
128
-			curl_close($ch);
129
-			if ($data !== false) {
130
-				$matches = array();
131
-				preg_match('/Content-Length: (\d+)/', $data, $matches);
132
-				if (isset($matches[1])) {
133
-					return 0 + $matches[1];
134
-				}
135
-			}
136
-		}
137
-		return null;
138
-	}
112
+    /**
113
+     * @brief Tries to get the size of a file via a CURL HEAD request.
114
+     *
115
+     * @param string $fileName Path to the file.
116
+     *
117
+     * @return null|int|float Number of bytes as number (float or int) or
118
+     *                        null on failure.
119
+     */
120
+    public function getFileSizeViaCurl($fileName) {
121
+        if (\OC::$server->getIniWrapper()->getString('open_basedir') === '') {
122
+            $encodedFileName = rawurlencode($fileName);
123
+            $ch = curl_init("file://$encodedFileName");
124
+            curl_setopt($ch, CURLOPT_NOBODY, true);
125
+            curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
126
+            curl_setopt($ch, CURLOPT_HEADER, true);
127
+            $data = curl_exec($ch);
128
+            curl_close($ch);
129
+            if ($data !== false) {
130
+                $matches = array();
131
+                preg_match('/Content-Length: (\d+)/', $data, $matches);
132
+                if (isset($matches[1])) {
133
+                    return 0 + $matches[1];
134
+                }
135
+            }
136
+        }
137
+        return null;
138
+    }
139 139
 
140
-	/**
141
-	* @brief Tries to get the size of a file via the Windows DOM extension.
142
-	*
143
-	* @param string $filename Path to the file.
144
-	*
145
-	* @return null|int|float Number of bytes as number (float or int) or
146
-	*                        null on failure.
147
-	*/
148
-	public function getFileSizeViaCOM($filename) {
149
-		if (class_exists('COM')) {
150
-			$fsObj = new \COM("Scripting.FileSystemObject");
151
-			$file = $fsObj->GetFile($filename);
152
-			return 0 + $file->Size;
153
-		}
154
-		return null;
155
-	}
140
+    /**
141
+     * @brief Tries to get the size of a file via the Windows DOM extension.
142
+     *
143
+     * @param string $filename Path to the file.
144
+     *
145
+     * @return null|int|float Number of bytes as number (float or int) or
146
+     *                        null on failure.
147
+     */
148
+    public function getFileSizeViaCOM($filename) {
149
+        if (class_exists('COM')) {
150
+            $fsObj = new \COM("Scripting.FileSystemObject");
151
+            $file = $fsObj->GetFile($filename);
152
+            return 0 + $file->Size;
153
+        }
154
+        return null;
155
+    }
156 156
 
157
-	/**
158
-	* @brief Tries to get the size of a file via an exec() call.
159
-	*
160
-	* @param string $filename Path to the file.
161
-	*
162
-	* @return null|int|float Number of bytes as number (float or int) or
163
-	*                        null on failure.
164
-	*/
165
-	public function getFileSizeViaExec($filename) {
166
-		if (\OC_Helper::is_function_enabled('exec')) {
167
-			$os = strtolower(php_uname('s'));
168
-			$arg = escapeshellarg($filename);
169
-			$result = null;
170
-			if (strpos($os, 'linux') !== false) {
171
-				$result = $this->exec("stat -c %s $arg");
172
-			} else if (strpos($os, 'bsd') !== false || strpos($os, 'darwin') !== false) {
173
-				$result = $this->exec("stat -f %z $arg");
174
-			} else if (strpos($os, 'win') !== false) {
175
-				$result = $this->exec("for %F in ($arg) do @echo %~zF");
176
-				if (is_null($result)) {
177
-					// PowerShell
178
-					$result = $this->exec("(Get-Item $arg).length");
179
-				}
180
-			}
181
-			return $result;
182
-		}
183
-		return null;
184
-	}
157
+    /**
158
+     * @brief Tries to get the size of a file via an exec() call.
159
+     *
160
+     * @param string $filename Path to the file.
161
+     *
162
+     * @return null|int|float Number of bytes as number (float or int) or
163
+     *                        null on failure.
164
+     */
165
+    public function getFileSizeViaExec($filename) {
166
+        if (\OC_Helper::is_function_enabled('exec')) {
167
+            $os = strtolower(php_uname('s'));
168
+            $arg = escapeshellarg($filename);
169
+            $result = null;
170
+            if (strpos($os, 'linux') !== false) {
171
+                $result = $this->exec("stat -c %s $arg");
172
+            } else if (strpos($os, 'bsd') !== false || strpos($os, 'darwin') !== false) {
173
+                $result = $this->exec("stat -f %z $arg");
174
+            } else if (strpos($os, 'win') !== false) {
175
+                $result = $this->exec("for %F in ($arg) do @echo %~zF");
176
+                if (is_null($result)) {
177
+                    // PowerShell
178
+                    $result = $this->exec("(Get-Item $arg).length");
179
+                }
180
+            }
181
+            return $result;
182
+        }
183
+        return null;
184
+    }
185 185
 
186
-	/**
187
-	* @brief Gets the size of a file via a filesize() call and converts
188
-	*        negative signed int to positive float. As the result of filesize()
189
-	*        will wrap around after a file size of 2^32 bytes = 4 GiB, this
190
-	*        should only be used as a last resort.
191
-	*
192
-	* @param string $filename Path to the file.
193
-	*
194
-	* @return int|float Number of bytes as number (float or int).
195
-	*/
196
-	public function getFileSizeNative($filename) {
197
-		$result = filesize($filename);
198
-		if ($result < 0) {
199
-			// For file sizes between 2 GiB and 4 GiB, filesize() will return a
200
-			// negative int, as the PHP data type int is signed. Interpret the
201
-			// returned int as an unsigned integer and put it into a float.
202
-			return (float) sprintf('%u', $result);
203
-		}
204
-		return $result;
205
-	}
186
+    /**
187
+     * @brief Gets the size of a file via a filesize() call and converts
188
+     *        negative signed int to positive float. As the result of filesize()
189
+     *        will wrap around after a file size of 2^32 bytes = 4 GiB, this
190
+     *        should only be used as a last resort.
191
+     *
192
+     * @param string $filename Path to the file.
193
+     *
194
+     * @return int|float Number of bytes as number (float or int).
195
+     */
196
+    public function getFileSizeNative($filename) {
197
+        $result = filesize($filename);
198
+        if ($result < 0) {
199
+            // For file sizes between 2 GiB and 4 GiB, filesize() will return a
200
+            // negative int, as the PHP data type int is signed. Interpret the
201
+            // returned int as an unsigned integer and put it into a float.
202
+            return (float) sprintf('%u', $result);
203
+        }
204
+        return $result;
205
+    }
206 206
 
207
-	protected function exec($cmd) {
208
-		$result = trim(exec($cmd));
209
-		return ctype_digit($result) ? 0 + $result : null;
210
-	}
207
+    protected function exec($cmd) {
208
+        $result = trim(exec($cmd));
209
+        return ctype_digit($result) ? 0 + $result : null;
210
+    }
211 211
 }
Please login to merge, or discard this patch.