Passed
Push — master ( 328fbd...bbba7b )
by Joas
11:54 queued 11s
created
lib/private/Repair/OldGroupMembershipShares.php 1 patch
Indentation   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -31,89 +31,89 @@
 block discarded – undo
31 31
 
32 32
 class OldGroupMembershipShares implements IRepairStep {
33 33
 
34
-	/** @var \OCP\IDBConnection */
35
-	protected $connection;
36
-
37
-	/** @var \OCP\IGroupManager */
38
-	protected $groupManager;
39
-
40
-	/**
41
-	 * @var array [gid => [uid => (bool)]]
42
-	 */
43
-	protected $memberships;
44
-
45
-	/**
46
-	 * @param IDBConnection $connection
47
-	 * @param IGroupManager $groupManager
48
-	 */
49
-	public function __construct(IDBConnection $connection, IGroupManager $groupManager) {
50
-		$this->connection = $connection;
51
-		$this->groupManager = $groupManager;
52
-	}
53
-
54
-	/**
55
-	 * Returns the step's name
56
-	 *
57
-	 * @return string
58
-	 */
59
-	public function getName() {
60
-		return 'Remove shares of old group memberships';
61
-	}
62
-
63
-	/**
64
-	 * Run repair step.
65
-	 * Must throw exception on error.
66
-	 *
67
-	 * @throws \Exception in case of failure
68
-	 * @suppress SqlInjectionChecker
69
-	 */
70
-	public function run(IOutput $output) {
71
-		$deletedEntries = 0;
72
-
73
-		$query = $this->connection->getQueryBuilder();
74
-		$query->select('s1.id')->selectAlias('s1.share_with', 'user')->selectAlias('s2.share_with', 'group')
75
-			->from('share', 's1')
76
-			->where($query->expr()->isNotNull('s1.parent'))
77
-				// \OC\Share\Constant::$shareTypeGroupUserUnique === 2
78
-				->andWhere($query->expr()->eq('s1.share_type', $query->expr()->literal(2)))
79
-				->andWhere($query->expr()->isNotNull('s2.id'))
80
-				->andWhere($query->expr()->eq('s2.share_type', $query->expr()->literal(Share::SHARE_TYPE_GROUP)))
81
-			->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'));
82
-
83
-		$deleteQuery = $this->connection->getQueryBuilder();
84
-		$deleteQuery->delete('share')
85
-			->where($query->expr()->eq('id', $deleteQuery->createParameter('share')));
86
-
87
-		$result = $query->execute();
88
-		while ($row = $result->fetch()) {
89
-			if (!$this->isMember($row['group'], $row['user'])) {
90
-				$deletedEntries += $deleteQuery->setParameter('share', (int) $row['id'])
91
-					->execute();
92
-			}
93
-		}
94
-		$result->closeCursor();
95
-
96
-		if ($deletedEntries) {
97
-			$output->info('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore');
98
-		}
99
-	}
100
-
101
-	/**
102
-	 * @param string $gid
103
-	 * @param string $uid
104
-	 * @return bool
105
-	 */
106
-	protected function isMember($gid, $uid) {
107
-		if (isset($this->memberships[$gid][$uid])) {
108
-			return $this->memberships[$gid][$uid];
109
-		}
110
-
111
-		$isMember = $this->groupManager->isInGroup($uid, $gid);
112
-		if (!isset($this->memberships[$gid])) {
113
-			$this->memberships[$gid] = [];
114
-		}
115
-		$this->memberships[$gid][$uid] = $isMember;
116
-
117
-		return $isMember;
118
-	}
34
+    /** @var \OCP\IDBConnection */
35
+    protected $connection;
36
+
37
+    /** @var \OCP\IGroupManager */
38
+    protected $groupManager;
39
+
40
+    /**
41
+     * @var array [gid => [uid => (bool)]]
42
+     */
43
+    protected $memberships;
44
+
45
+    /**
46
+     * @param IDBConnection $connection
47
+     * @param IGroupManager $groupManager
48
+     */
49
+    public function __construct(IDBConnection $connection, IGroupManager $groupManager) {
50
+        $this->connection = $connection;
51
+        $this->groupManager = $groupManager;
52
+    }
53
+
54
+    /**
55
+     * Returns the step's name
56
+     *
57
+     * @return string
58
+     */
59
+    public function getName() {
60
+        return 'Remove shares of old group memberships';
61
+    }
62
+
63
+    /**
64
+     * Run repair step.
65
+     * Must throw exception on error.
66
+     *
67
+     * @throws \Exception in case of failure
68
+     * @suppress SqlInjectionChecker
69
+     */
70
+    public function run(IOutput $output) {
71
+        $deletedEntries = 0;
72
+
73
+        $query = $this->connection->getQueryBuilder();
74
+        $query->select('s1.id')->selectAlias('s1.share_with', 'user')->selectAlias('s2.share_with', 'group')
75
+            ->from('share', 's1')
76
+            ->where($query->expr()->isNotNull('s1.parent'))
77
+                // \OC\Share\Constant::$shareTypeGroupUserUnique === 2
78
+                ->andWhere($query->expr()->eq('s1.share_type', $query->expr()->literal(2)))
79
+                ->andWhere($query->expr()->isNotNull('s2.id'))
80
+                ->andWhere($query->expr()->eq('s2.share_type', $query->expr()->literal(Share::SHARE_TYPE_GROUP)))
81
+            ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'));
82
+
83
+        $deleteQuery = $this->connection->getQueryBuilder();
84
+        $deleteQuery->delete('share')
85
+            ->where($query->expr()->eq('id', $deleteQuery->createParameter('share')));
86
+
87
+        $result = $query->execute();
88
+        while ($row = $result->fetch()) {
89
+            if (!$this->isMember($row['group'], $row['user'])) {
90
+                $deletedEntries += $deleteQuery->setParameter('share', (int) $row['id'])
91
+                    ->execute();
92
+            }
93
+        }
94
+        $result->closeCursor();
95
+
96
+        if ($deletedEntries) {
97
+            $output->info('Removed ' . $deletedEntries . ' shares where user is not a member of the group anymore');
98
+        }
99
+    }
100
+
101
+    /**
102
+     * @param string $gid
103
+     * @param string $uid
104
+     * @return bool
105
+     */
106
+    protected function isMember($gid, $uid) {
107
+        if (isset($this->memberships[$gid][$uid])) {
108
+            return $this->memberships[$gid][$uid];
109
+        }
110
+
111
+        $isMember = $this->groupManager->isInGroup($uid, $gid);
112
+        if (!isset($this->memberships[$gid])) {
113
+            $this->memberships[$gid] = [];
114
+        }
115
+        $this->memberships[$gid][$uid] = $isMember;
116
+
117
+        return $isMember;
118
+    }
119 119
 }
Please login to merge, or discard this patch.
lib/private/Repair/RepairInvalidShares.php 1 patch
Indentation   +86 added lines, -86 removed lines patch added patch discarded remove patch
@@ -33,90 +33,90 @@
 block discarded – undo
33 33
  */
34 34
 class RepairInvalidShares implements IRepairStep {
35 35
 
36
-	const CHUNK_SIZE = 200;
37
-
38
-	/** @var \OCP\IConfig */
39
-	protected $config;
40
-
41
-	/** @var \OCP\IDBConnection */
42
-	protected $connection;
43
-
44
-	/**
45
-	 * @param \OCP\IConfig $config
46
-	 * @param \OCP\IDBConnection $connection
47
-	 */
48
-	public function __construct($config, $connection) {
49
-		$this->connection = $connection;
50
-		$this->config = $config;
51
-	}
52
-
53
-	public function getName() {
54
-		return 'Repair invalid shares';
55
-	}
56
-
57
-	/**
58
-	 * Adjust file share permissions
59
-	 * @suppress SqlInjectionChecker
60
-	 */
61
-	private function adjustFileSharePermissions(IOutput $out) {
62
-		$mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE;
63
-		$builder = $this->connection->getQueryBuilder();
64
-
65
-		$permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask);
66
-		$builder
67
-			->update('share')
68
-			->set('permissions', $permsFunc)
69
-			->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
70
-			->andWhere($builder->expr()->neq('permissions', $permsFunc));
71
-
72
-		$updatedEntries = $builder->execute();
73
-		if ($updatedEntries > 0) {
74
-			$out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
75
-		}
76
-	}
77
-
78
-	/**
79
-	 * Remove shares where the parent share does not exist anymore
80
-	 */
81
-	private function removeSharesNonExistingParent(IOutput $out) {
82
-		$deletedEntries = 0;
83
-
84
-		$query = $this->connection->getQueryBuilder();
85
-		$query->select('s1.parent')
86
-			->from('share', 's1')
87
-			->where($query->expr()->isNotNull('s1.parent'))
88
-				->andWhere($query->expr()->isNull('s2.id'))
89
-			->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))
90
-			->groupBy('s1.parent')
91
-			->setMaxResults(self::CHUNK_SIZE);
92
-
93
-		$deleteQuery = $this->connection->getQueryBuilder();
94
-		$deleteQuery->delete('share')
95
-			->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
96
-
97
-		$deletedInLastChunk = self::CHUNK_SIZE;
98
-		while ($deletedInLastChunk === self::CHUNK_SIZE) {
99
-			$deletedInLastChunk = 0;
100
-			$result = $query->execute();
101
-			while ($row = $result->fetch()) {
102
-				$deletedInLastChunk++;
103
-				$deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])
104
-					->execute();
105
-			}
106
-			$result->closeCursor();
107
-		}
108
-
109
-		if ($deletedEntries) {
110
-			$out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
111
-		}
112
-	}
113
-
114
-	public function run(IOutput $out) {
115
-		$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
116
-		if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
117
-			$this->adjustFileSharePermissions($out);
118
-		}
119
-
120
-		$this->removeSharesNonExistingParent($out);
121
-	}
36
+    const CHUNK_SIZE = 200;
37
+
38
+    /** @var \OCP\IConfig */
39
+    protected $config;
40
+
41
+    /** @var \OCP\IDBConnection */
42
+    protected $connection;
43
+
44
+    /**
45
+     * @param \OCP\IConfig $config
46
+     * @param \OCP\IDBConnection $connection
47
+     */
48
+    public function __construct($config, $connection) {
49
+        $this->connection = $connection;
50
+        $this->config = $config;
51
+    }
52
+
53
+    public function getName() {
54
+        return 'Repair invalid shares';
55
+    }
56
+
57
+    /**
58
+     * Adjust file share permissions
59
+     * @suppress SqlInjectionChecker
60
+     */
61
+    private function adjustFileSharePermissions(IOutput $out) {
62
+        $mask = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_SHARE;
63
+        $builder = $this->connection->getQueryBuilder();
64
+
65
+        $permsFunc = $builder->expr()->bitwiseAnd('permissions', $mask);
66
+        $builder
67
+            ->update('share')
68
+            ->set('permissions', $permsFunc)
69
+            ->where($builder->expr()->eq('item_type', $builder->expr()->literal('file')))
70
+            ->andWhere($builder->expr()->neq('permissions', $permsFunc));
71
+
72
+        $updatedEntries = $builder->execute();
73
+        if ($updatedEntries > 0) {
74
+            $out->info('Fixed file share permissions for ' . $updatedEntries . ' shares');
75
+        }
76
+    }
77
+
78
+    /**
79
+     * Remove shares where the parent share does not exist anymore
80
+     */
81
+    private function removeSharesNonExistingParent(IOutput $out) {
82
+        $deletedEntries = 0;
83
+
84
+        $query = $this->connection->getQueryBuilder();
85
+        $query->select('s1.parent')
86
+            ->from('share', 's1')
87
+            ->where($query->expr()->isNotNull('s1.parent'))
88
+                ->andWhere($query->expr()->isNull('s2.id'))
89
+            ->leftJoin('s1', 'share', 's2', $query->expr()->eq('s1.parent', 's2.id'))
90
+            ->groupBy('s1.parent')
91
+            ->setMaxResults(self::CHUNK_SIZE);
92
+
93
+        $deleteQuery = $this->connection->getQueryBuilder();
94
+        $deleteQuery->delete('share')
95
+            ->where($deleteQuery->expr()->eq('parent', $deleteQuery->createParameter('parent')));
96
+
97
+        $deletedInLastChunk = self::CHUNK_SIZE;
98
+        while ($deletedInLastChunk === self::CHUNK_SIZE) {
99
+            $deletedInLastChunk = 0;
100
+            $result = $query->execute();
101
+            while ($row = $result->fetch()) {
102
+                $deletedInLastChunk++;
103
+                $deletedEntries += $deleteQuery->setParameter('parent', (int) $row['parent'])
104
+                    ->execute();
105
+            }
106
+            $result->closeCursor();
107
+        }
108
+
109
+        if ($deletedEntries) {
110
+            $out->info('Removed ' . $deletedEntries . ' shares where the parent did not exist');
111
+        }
112
+    }
113
+
114
+    public function run(IOutput $out) {
115
+        $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
116
+        if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
117
+            $this->adjustFileSharePermissions($out);
118
+        }
119
+
120
+        $this->removeSharesNonExistingParent($out);
121
+    }
122 122
 }
Please login to merge, or discard this patch.
apps/testing/lib/Controller/ConfigController.php 1 patch
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -29,39 +29,39 @@
 block discarded – undo
29 29
 
30 30
 class ConfigController extends OCSController {
31 31
 
32
-	/** @var IConfig */
33
-	private $config;
32
+    /** @var IConfig */
33
+    private $config;
34 34
 
35
-	/**
36
-	 * @param string $appName
37
-	 * @param IRequest $request
38
-	 * @param IConfig $config
39
-	 */
40
-	public function __construct($appName,
41
-								IRequest $request,
42
-								IConfig $config) {
43
-		parent::__construct($appName, $request);
44
-		$this->config = $config;
45
-	}
35
+    /**
36
+     * @param string $appName
37
+     * @param IRequest $request
38
+     * @param IConfig $config
39
+     */
40
+    public function __construct($appName,
41
+                                IRequest $request,
42
+                                IConfig $config) {
43
+        parent::__construct($appName, $request);
44
+        $this->config = $config;
45
+    }
46 46
 
47
-	/**
48
-	 * @param string $appid
49
-	 * @param string $configkey
50
-	 * @param string $value
51
-	 * @return DataResponse
52
-	 */
53
-	public function setAppValue($appid, $configkey, $value) {
54
-		$this->config->setAppValue($appid, $configkey, $value);
55
-		return new DataResponse();
56
-	}
47
+    /**
48
+     * @param string $appid
49
+     * @param string $configkey
50
+     * @param string $value
51
+     * @return DataResponse
52
+     */
53
+    public function setAppValue($appid, $configkey, $value) {
54
+        $this->config->setAppValue($appid, $configkey, $value);
55
+        return new DataResponse();
56
+    }
57 57
 
58
-	/**
59
-	 * @param string $appid
60
-	 * @param string $configkey
61
-	 * @return DataResponse
62
-	 */
63
-	public function deleteAppValue($appid, $configkey) {
64
-		$this->config->deleteAppValue($appid, $configkey);
65
-		return new DataResponse();
66
-	}
58
+    /**
59
+     * @param string $appid
60
+     * @param string $configkey
61
+     * @return DataResponse
62
+     */
63
+    public function deleteAppValue($appid, $configkey) {
64
+        $this->config->deleteAppValue($appid, $configkey);
65
+        return new DataResponse();
66
+    }
67 67
 }
Please login to merge, or discard this patch.
apps/testing/lib/Controller/LockingController.php 1 patch
Indentation   +204 added lines, -204 removed lines patch added patch discarded remove patch
@@ -39,208 +39,208 @@
 block discarded – undo
39 39
 
40 40
 class LockingController extends OCSController {
41 41
 
42
-	/** @var ILockingProvider */
43
-	protected $lockingProvider;
44
-
45
-	/** @var FakeDBLockingProvider */
46
-	protected $fakeDBLockingProvider;
47
-
48
-	/** @var IDBConnection */
49
-	protected $connection;
50
-
51
-	/** @var IConfig */
52
-	protected $config;
53
-
54
-	/** @var IRootFolder */
55
-	protected $rootFolder;
56
-
57
-	/**
58
-	 * @param string $appName
59
-	 * @param IRequest $request
60
-	 * @param ILockingProvider $lockingProvider
61
-	 * @param FakeDBLockingProvider $fakeDBLockingProvider
62
-	 * @param IDBConnection $connection
63
-	 * @param IConfig $config
64
-	 * @param IRootFolder $rootFolder
65
-	 */
66
-	public function __construct($appName,
67
-								IRequest $request,
68
-								ILockingProvider $lockingProvider,
69
-								FakeDBLockingProvider $fakeDBLockingProvider,
70
-								IDBConnection $connection,
71
-								IConfig $config,
72
-								IRootFolder $rootFolder) {
73
-		parent::__construct($appName, $request);
74
-
75
-		$this->lockingProvider = $lockingProvider;
76
-		$this->fakeDBLockingProvider = $fakeDBLockingProvider;
77
-		$this->connection = $connection;
78
-		$this->config = $config;
79
-		$this->rootFolder = $rootFolder;
80
-	}
81
-
82
-	/**
83
-	 * @return ILockingProvider
84
-	 * @throws \RuntimeException
85
-	 */
86
-	protected function getLockingProvider() {
87
-		if ($this->lockingProvider instanceof DBLockingProvider) {
88
-			return $this->fakeDBLockingProvider;
89
-		}
90
-		throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
91
-	}
92
-
93
-	/**
94
-	 * @param string $user
95
-	 * @param string $path
96
-	 * @return string
97
-	 * @throws NotFoundException
98
-	 */
99
-	protected function getPath($user, $path) {
100
-		$node = $this->rootFolder->getUserFolder($user)->get($path);
101
-		return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
102
-	}
103
-
104
-	/**
105
-	 * @return DataResponse
106
-	 * @throws OCSException
107
-	 */
108
-	public function isLockingEnabled() {
109
-		try {
110
-			$this->getLockingProvider();
111
-			return new DataResponse();
112
-		} catch (\RuntimeException $e) {
113
-			throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e);
114
-		}
115
-	}
116
-
117
-	/**
118
-	 * @param int $type
119
-	 * @param string $user
120
-	 * @param string $path
121
-	 * @return DataResponse
122
-	 * @throws OCSException
123
-	 */
124
-	public function acquireLock($type, $user, $path) {
125
-		try {
126
-			$path = $this->getPath($user, $path);
127
-		} catch (NoUserException $e) {
128
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
129
-		} catch (NotFoundException $e) {
130
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
131
-		}
132
-
133
-		$lockingProvider = $this->getLockingProvider();
134
-
135
-		try {
136
-			$lockingProvider->acquireLock($path, $type);
137
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
138
-			return new DataResponse();
139
-		} catch (LockedException $e) {
140
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
141
-		}
142
-	}
143
-
144
-	/**
145
-	 * @param int $type
146
-	 * @param string $user
147
-	 * @param string $path
148
-	 * @return DataResponse
149
-	 * @throws OCSException
150
-	 */
151
-	public function changeLock($type, $user, $path) {
152
-		try {
153
-			$path = $this->getPath($user, $path);
154
-		} catch (NoUserException $e) {
155
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
156
-		} catch (NotFoundException $e) {
157
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
158
-		}
159
-
160
-		$lockingProvider = $this->getLockingProvider();
161
-
162
-		try {
163
-			$lockingProvider->changeLock($path, $type);
164
-			$this->config->setAppValue('testing', 'locking_' . $path, $type);
165
-			return new DataResponse();
166
-		} catch (LockedException $e) {
167
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
168
-		}
169
-	}
170
-
171
-	/**
172
-	 * @param int $type
173
-	 * @param string $user
174
-	 * @param string $path
175
-	 * @return DataResponse
176
-	 * @throws OCSException
177
-	 */
178
-	public function releaseLock($type, $user, $path) {
179
-		try {
180
-			$path = $this->getPath($user, $path);
181
-		} catch (NoUserException $e) {
182
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
183
-		} catch (NotFoundException $e) {
184
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
185
-		}
186
-
187
-		$lockingProvider = $this->getLockingProvider();
188
-
189
-		try {
190
-			$lockingProvider->releaseLock($path, $type);
191
-			$this->config->deleteAppValue('testing', 'locking_' . $path);
192
-			return new DataResponse();
193
-		} catch (LockedException $e) {
194
-			throw new OCSException('', Http::STATUS_LOCKED, $e);
195
-		}
196
-	}
197
-
198
-	/**
199
-	 * @param int $type
200
-	 * @param string $user
201
-	 * @param string $path
202
-	 * @return DataResponse
203
-	 * @throws OCSException
204
-	 */
205
-	public function isLocked($type, $user, $path) {
206
-		try {
207
-			$path = $this->getPath($user, $path);
208
-		} catch (NoUserException $e) {
209
-			throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
210
-		} catch (NotFoundException $e) {
211
-			throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
212
-		}
213
-
214
-		$lockingProvider = $this->getLockingProvider();
215
-
216
-		if ($lockingProvider->isLocked($path, $type)) {
217
-			return new DataResponse();
218
-		}
219
-
220
-		throw new OCSException('', Http::STATUS_LOCKED);
221
-	}
222
-
223
-	/**
224
-	 * @param int $type
225
-	 * @return DataResponse
226
-	 */
227
-	public function releaseAll($type = null) {
228
-		$lockingProvider = $this->getLockingProvider();
229
-
230
-		foreach ($this->config->getAppKeys('testing') as $lock) {
231
-			if (strpos($lock, 'locking_') === 0) {
232
-				$path = substr($lock, strlen('locking_'));
233
-
234
-				if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
-				} else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238
-				} else {
239
-					$lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
240
-				}
241
-			}
242
-		}
243
-
244
-		return new DataResponse();
245
-	}
42
+    /** @var ILockingProvider */
43
+    protected $lockingProvider;
44
+
45
+    /** @var FakeDBLockingProvider */
46
+    protected $fakeDBLockingProvider;
47
+
48
+    /** @var IDBConnection */
49
+    protected $connection;
50
+
51
+    /** @var IConfig */
52
+    protected $config;
53
+
54
+    /** @var IRootFolder */
55
+    protected $rootFolder;
56
+
57
+    /**
58
+     * @param string $appName
59
+     * @param IRequest $request
60
+     * @param ILockingProvider $lockingProvider
61
+     * @param FakeDBLockingProvider $fakeDBLockingProvider
62
+     * @param IDBConnection $connection
63
+     * @param IConfig $config
64
+     * @param IRootFolder $rootFolder
65
+     */
66
+    public function __construct($appName,
67
+                                IRequest $request,
68
+                                ILockingProvider $lockingProvider,
69
+                                FakeDBLockingProvider $fakeDBLockingProvider,
70
+                                IDBConnection $connection,
71
+                                IConfig $config,
72
+                                IRootFolder $rootFolder) {
73
+        parent::__construct($appName, $request);
74
+
75
+        $this->lockingProvider = $lockingProvider;
76
+        $this->fakeDBLockingProvider = $fakeDBLockingProvider;
77
+        $this->connection = $connection;
78
+        $this->config = $config;
79
+        $this->rootFolder = $rootFolder;
80
+    }
81
+
82
+    /**
83
+     * @return ILockingProvider
84
+     * @throws \RuntimeException
85
+     */
86
+    protected function getLockingProvider() {
87
+        if ($this->lockingProvider instanceof DBLockingProvider) {
88
+            return $this->fakeDBLockingProvider;
89
+        }
90
+        throw new \RuntimeException('Lock provisioning is only possible using the DBLockingProvider');
91
+    }
92
+
93
+    /**
94
+     * @param string $user
95
+     * @param string $path
96
+     * @return string
97
+     * @throws NotFoundException
98
+     */
99
+    protected function getPath($user, $path) {
100
+        $node = $this->rootFolder->getUserFolder($user)->get($path);
101
+        return 'files/' . md5($node->getStorage()->getId() . '::' . trim($node->getInternalPath(), '/'));
102
+    }
103
+
104
+    /**
105
+     * @return DataResponse
106
+     * @throws OCSException
107
+     */
108
+    public function isLockingEnabled() {
109
+        try {
110
+            $this->getLockingProvider();
111
+            return new DataResponse();
112
+        } catch (\RuntimeException $e) {
113
+            throw new OCSException($e->getMessage(), Http::STATUS_NOT_IMPLEMENTED, $e);
114
+        }
115
+    }
116
+
117
+    /**
118
+     * @param int $type
119
+     * @param string $user
120
+     * @param string $path
121
+     * @return DataResponse
122
+     * @throws OCSException
123
+     */
124
+    public function acquireLock($type, $user, $path) {
125
+        try {
126
+            $path = $this->getPath($user, $path);
127
+        } catch (NoUserException $e) {
128
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
129
+        } catch (NotFoundException $e) {
130
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
131
+        }
132
+
133
+        $lockingProvider = $this->getLockingProvider();
134
+
135
+        try {
136
+            $lockingProvider->acquireLock($path, $type);
137
+            $this->config->setAppValue('testing', 'locking_' . $path, $type);
138
+            return new DataResponse();
139
+        } catch (LockedException $e) {
140
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
141
+        }
142
+    }
143
+
144
+    /**
145
+     * @param int $type
146
+     * @param string $user
147
+     * @param string $path
148
+     * @return DataResponse
149
+     * @throws OCSException
150
+     */
151
+    public function changeLock($type, $user, $path) {
152
+        try {
153
+            $path = $this->getPath($user, $path);
154
+        } catch (NoUserException $e) {
155
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
156
+        } catch (NotFoundException $e) {
157
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
158
+        }
159
+
160
+        $lockingProvider = $this->getLockingProvider();
161
+
162
+        try {
163
+            $lockingProvider->changeLock($path, $type);
164
+            $this->config->setAppValue('testing', 'locking_' . $path, $type);
165
+            return new DataResponse();
166
+        } catch (LockedException $e) {
167
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
168
+        }
169
+    }
170
+
171
+    /**
172
+     * @param int $type
173
+     * @param string $user
174
+     * @param string $path
175
+     * @return DataResponse
176
+     * @throws OCSException
177
+     */
178
+    public function releaseLock($type, $user, $path) {
179
+        try {
180
+            $path = $this->getPath($user, $path);
181
+        } catch (NoUserException $e) {
182
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
183
+        } catch (NotFoundException $e) {
184
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
185
+        }
186
+
187
+        $lockingProvider = $this->getLockingProvider();
188
+
189
+        try {
190
+            $lockingProvider->releaseLock($path, $type);
191
+            $this->config->deleteAppValue('testing', 'locking_' . $path);
192
+            return new DataResponse();
193
+        } catch (LockedException $e) {
194
+            throw new OCSException('', Http::STATUS_LOCKED, $e);
195
+        }
196
+    }
197
+
198
+    /**
199
+     * @param int $type
200
+     * @param string $user
201
+     * @param string $path
202
+     * @return DataResponse
203
+     * @throws OCSException
204
+     */
205
+    public function isLocked($type, $user, $path) {
206
+        try {
207
+            $path = $this->getPath($user, $path);
208
+        } catch (NoUserException $e) {
209
+            throw new OCSException('User not found', Http::STATUS_NOT_FOUND, $e);
210
+        } catch (NotFoundException $e) {
211
+            throw new OCSException('Path not found', Http::STATUS_NOT_FOUND, $e);
212
+        }
213
+
214
+        $lockingProvider = $this->getLockingProvider();
215
+
216
+        if ($lockingProvider->isLocked($path, $type)) {
217
+            return new DataResponse();
218
+        }
219
+
220
+        throw new OCSException('', Http::STATUS_LOCKED);
221
+    }
222
+
223
+    /**
224
+     * @param int $type
225
+     * @return DataResponse
226
+     */
227
+    public function releaseAll($type = null) {
228
+        $lockingProvider = $this->getLockingProvider();
229
+
230
+        foreach ($this->config->getAppKeys('testing') as $lock) {
231
+            if (strpos($lock, 'locking_') === 0) {
232
+                $path = substr($lock, strlen('locking_'));
233
+
234
+                if ($type === ILockingProvider::LOCK_EXCLUSIVE && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_EXCLUSIVE) {
235
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
236
+                } else if ($type === ILockingProvider::LOCK_SHARED && (int)$this->config->getAppValue('testing', $lock) === ILockingProvider::LOCK_SHARED) {
237
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
238
+                } else {
239
+                    $lockingProvider->releaseLock($path, $this->config->getAppValue('testing', $lock));
240
+                }
241
+            }
242
+        }
243
+
244
+        return new DataResponse();
245
+    }
246 246
 }
Please login to merge, or discard this patch.
lib/public/AppFramework/Http/ICallbackResponse.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -33,12 +33,12 @@
 block discarded – undo
33 33
  */
34 34
 interface ICallbackResponse {
35 35
 
36
-	/**
37
-	 * Outputs the content that should be printed
38
-	 *
39
-	 * @param IOutput $output a small wrapper that handles output
40
-	 * @since 8.1.0
41
-	 */
42
-	public function callback(IOutput $output);
36
+    /**
37
+     * Outputs the content that should be printed
38
+     *
39
+     * @param IOutput $output a small wrapper that handles output
40
+     * @since 8.1.0
41
+     */
42
+    public function callback(IOutput $output);
43 43
 
44 44
 }
Please login to merge, or discard this patch.
lib/private/TempManager.php 1 patch
Indentation   +221 added lines, -221 removed lines patch added patch discarded remove patch
@@ -34,246 +34,246 @@
 block discarded – undo
34 34
 use OCP\ITempManager;
35 35
 
36 36
 class TempManager implements ITempManager {
37
-	/** @var string[] Current temporary files and folders, used for cleanup */
38
-	protected $current = [];
39
-	/** @var string i.e. /tmp on linux systems */
40
-	protected $tmpBaseDir;
41
-	/** @var ILogger */
42
-	protected $log;
43
-	/** @var IConfig */
44
-	protected $config;
37
+    /** @var string[] Current temporary files and folders, used for cleanup */
38
+    protected $current = [];
39
+    /** @var string i.e. /tmp on linux systems */
40
+    protected $tmpBaseDir;
41
+    /** @var ILogger */
42
+    protected $log;
43
+    /** @var IConfig */
44
+    protected $config;
45 45
 
46
-	/** Prefix */
47
-	const TMP_PREFIX = 'oc_tmp_';
46
+    /** Prefix */
47
+    const TMP_PREFIX = 'oc_tmp_';
48 48
 
49
-	/**
50
-	 * @param \OCP\ILogger $logger
51
-	 * @param \OCP\IConfig $config
52
-	 */
53
-	public function __construct(ILogger $logger, IConfig $config) {
54
-		$this->log = $logger;
55
-		$this->config = $config;
56
-		$this->tmpBaseDir = $this->getTempBaseDir();
57
-	}
49
+    /**
50
+     * @param \OCP\ILogger $logger
51
+     * @param \OCP\IConfig $config
52
+     */
53
+    public function __construct(ILogger $logger, IConfig $config) {
54
+        $this->log = $logger;
55
+        $this->config = $config;
56
+        $this->tmpBaseDir = $this->getTempBaseDir();
57
+    }
58 58
 
59
-	/**
60
-	 * Builds the filename with suffix and removes potential dangerous characters
61
-	 * such as directory separators.
62
-	 *
63
-	 * @param string $absolutePath Absolute path to the file / folder
64
-	 * @param string $postFix Postfix appended to the temporary file name, may be user controlled
65
-	 * @return string
66
-	 */
67
-	private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
68
-		if($postFix !== '') {
69
-			$postFix = '.' . ltrim($postFix, '.');
70
-			$postFix = str_replace(['\\', '/'], '', $postFix);
71
-			$absolutePath .= '-';
72
-		}
59
+    /**
60
+     * Builds the filename with suffix and removes potential dangerous characters
61
+     * such as directory separators.
62
+     *
63
+     * @param string $absolutePath Absolute path to the file / folder
64
+     * @param string $postFix Postfix appended to the temporary file name, may be user controlled
65
+     * @return string
66
+     */
67
+    private function buildFileNameWithSuffix($absolutePath, $postFix = '') {
68
+        if($postFix !== '') {
69
+            $postFix = '.' . ltrim($postFix, '.');
70
+            $postFix = str_replace(['\\', '/'], '', $postFix);
71
+            $absolutePath .= '-';
72
+        }
73 73
 
74
-		return $absolutePath . $postFix;
75
-	}
74
+        return $absolutePath . $postFix;
75
+    }
76 76
 
77
-	/**
78
-	 * Create a temporary file and return the path
79
-	 *
80
-	 * @param string $postFix Postfix appended to the temporary file name
81
-	 * @return string
82
-	 */
83
-	public function getTemporaryFile($postFix = '') {
84
-		if (is_writable($this->tmpBaseDir)) {
85
-			// To create an unique file and prevent the risk of race conditions
86
-			// or duplicated temporary files by other means such as collisions
87
-			// we need to create the file using `tempnam` and append a possible
88
-			// postfix to it later
89
-			$file = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
90
-			$this->current[] = $file;
77
+    /**
78
+     * Create a temporary file and return the path
79
+     *
80
+     * @param string $postFix Postfix appended to the temporary file name
81
+     * @return string
82
+     */
83
+    public function getTemporaryFile($postFix = '') {
84
+        if (is_writable($this->tmpBaseDir)) {
85
+            // To create an unique file and prevent the risk of race conditions
86
+            // or duplicated temporary files by other means such as collisions
87
+            // we need to create the file using `tempnam` and append a possible
88
+            // postfix to it later
89
+            $file = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
90
+            $this->current[] = $file;
91 91
 
92
-			// If a postfix got specified sanitize it and create a postfixed
93
-			// temporary file
94
-			if($postFix !== '') {
95
-				$fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
96
-				touch($fileNameWithPostfix);
97
-				chmod($fileNameWithPostfix, 0600);
98
-				$this->current[] = $fileNameWithPostfix;
99
-				return $fileNameWithPostfix;
100
-			}
92
+            // If a postfix got specified sanitize it and create a postfixed
93
+            // temporary file
94
+            if($postFix !== '') {
95
+                $fileNameWithPostfix = $this->buildFileNameWithSuffix($file, $postFix);
96
+                touch($fileNameWithPostfix);
97
+                chmod($fileNameWithPostfix, 0600);
98
+                $this->current[] = $fileNameWithPostfix;
99
+                return $fileNameWithPostfix;
100
+            }
101 101
 
102
-			return $file;
103
-		} else {
104
-			$this->log->warning(
105
-				'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
106
-				[
107
-					'dir' => $this->tmpBaseDir,
108
-				]
109
-			);
110
-			return false;
111
-		}
112
-	}
102
+            return $file;
103
+        } else {
104
+            $this->log->warning(
105
+                'Can not create a temporary file in directory {dir}. Check it exists and has correct permissions',
106
+                [
107
+                    'dir' => $this->tmpBaseDir,
108
+                ]
109
+            );
110
+            return false;
111
+        }
112
+    }
113 113
 
114
-	/**
115
-	 * Create a temporary folder and return the path
116
-	 *
117
-	 * @param string $postFix Postfix appended to the temporary folder name
118
-	 * @return string
119
-	 */
120
-	public function getTemporaryFolder($postFix = '') {
121
-		if (is_writable($this->tmpBaseDir)) {
122
-			// To create an unique directory and prevent the risk of race conditions
123
-			// or duplicated temporary files by other means such as collisions
124
-			// we need to create the file using `tempnam` and append a possible
125
-			// postfix to it later
126
-			$uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
127
-			$this->current[] = $uniqueFileName;
114
+    /**
115
+     * Create a temporary folder and return the path
116
+     *
117
+     * @param string $postFix Postfix appended to the temporary folder name
118
+     * @return string
119
+     */
120
+    public function getTemporaryFolder($postFix = '') {
121
+        if (is_writable($this->tmpBaseDir)) {
122
+            // To create an unique directory and prevent the risk of race conditions
123
+            // or duplicated temporary files by other means such as collisions
124
+            // we need to create the file using `tempnam` and append a possible
125
+            // postfix to it later
126
+            $uniqueFileName = tempnam($this->tmpBaseDir, self::TMP_PREFIX);
127
+            $this->current[] = $uniqueFileName;
128 128
 
129
-			// Build a name without postfix
130
-			$path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
131
-			mkdir($path, 0700);
132
-			$this->current[] = $path;
129
+            // Build a name without postfix
130
+            $path = $this->buildFileNameWithSuffix($uniqueFileName . '-folder', $postFix);
131
+            mkdir($path, 0700);
132
+            $this->current[] = $path;
133 133
 
134
-			return $path . '/';
135
-		} else {
136
-			$this->log->warning(
137
-				'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
138
-				[
139
-					'dir' => $this->tmpBaseDir,
140
-				]
141
-			);
142
-			return false;
143
-		}
144
-	}
134
+            return $path . '/';
135
+        } else {
136
+            $this->log->warning(
137
+                'Can not create a temporary folder in directory {dir}. Check it exists and has correct permissions',
138
+                [
139
+                    'dir' => $this->tmpBaseDir,
140
+                ]
141
+            );
142
+            return false;
143
+        }
144
+    }
145 145
 
146
-	/**
147
-	 * Remove the temporary files and folders generated during this request
148
-	 */
149
-	public function clean() {
150
-		$this->cleanFiles($this->current);
151
-	}
146
+    /**
147
+     * Remove the temporary files and folders generated during this request
148
+     */
149
+    public function clean() {
150
+        $this->cleanFiles($this->current);
151
+    }
152 152
 
153
-	/**
154
-	 * @param string[] $files
155
-	 */
156
-	protected function cleanFiles($files) {
157
-		foreach ($files as $file) {
158
-			if (file_exists($file)) {
159
-				try {
160
-					\OC_Helper::rmdirr($file);
161
-				} catch (\UnexpectedValueException $ex) {
162
-					$this->log->warning(
163
-						"Error deleting temporary file/folder: {file} - Reason: {error}",
164
-						[
165
-							'file' => $file,
166
-							'error' => $ex->getMessage(),
167
-						]
168
-					);
169
-				}
170
-			}
171
-		}
172
-	}
153
+    /**
154
+     * @param string[] $files
155
+     */
156
+    protected function cleanFiles($files) {
157
+        foreach ($files as $file) {
158
+            if (file_exists($file)) {
159
+                try {
160
+                    \OC_Helper::rmdirr($file);
161
+                } catch (\UnexpectedValueException $ex) {
162
+                    $this->log->warning(
163
+                        "Error deleting temporary file/folder: {file} - Reason: {error}",
164
+                        [
165
+                            'file' => $file,
166
+                            'error' => $ex->getMessage(),
167
+                        ]
168
+                    );
169
+                }
170
+            }
171
+        }
172
+    }
173 173
 
174
-	/**
175
-	 * Remove old temporary files and folders that were failed to be cleaned
176
-	 */
177
-	public function cleanOld() {
178
-		$this->cleanFiles($this->getOldFiles());
179
-	}
174
+    /**
175
+     * Remove old temporary files and folders that were failed to be cleaned
176
+     */
177
+    public function cleanOld() {
178
+        $this->cleanFiles($this->getOldFiles());
179
+    }
180 180
 
181
-	/**
182
-	 * Get all temporary files and folders generated by oc older than an hour
183
-	 *
184
-	 * @return string[]
185
-	 */
186
-	protected function getOldFiles() {
187
-		$cutOfTime = time() - 3600;
188
-		$files = [];
189
-		$dh = opendir($this->tmpBaseDir);
190
-		if ($dh) {
191
-			while (($file = readdir($dh)) !== false) {
192
-				if (substr($file, 0, 7) === self::TMP_PREFIX) {
193
-					$path = $this->tmpBaseDir . '/' . $file;
194
-					$mtime = filemtime($path);
195
-					if ($mtime < $cutOfTime) {
196
-						$files[] = $path;
197
-					}
198
-				}
199
-			}
200
-		}
201
-		return $files;
202
-	}
181
+    /**
182
+     * Get all temporary files and folders generated by oc older than an hour
183
+     *
184
+     * @return string[]
185
+     */
186
+    protected function getOldFiles() {
187
+        $cutOfTime = time() - 3600;
188
+        $files = [];
189
+        $dh = opendir($this->tmpBaseDir);
190
+        if ($dh) {
191
+            while (($file = readdir($dh)) !== false) {
192
+                if (substr($file, 0, 7) === self::TMP_PREFIX) {
193
+                    $path = $this->tmpBaseDir . '/' . $file;
194
+                    $mtime = filemtime($path);
195
+                    if ($mtime < $cutOfTime) {
196
+                        $files[] = $path;
197
+                    }
198
+                }
199
+            }
200
+        }
201
+        return $files;
202
+    }
203 203
 
204
-	/**
205
-	 * Get the temporary base directory configured on the server
206
-	 *
207
-	 * @return string Path to the temporary directory or null
208
-	 * @throws \UnexpectedValueException
209
-	 */
210
-	public function getTempBaseDir() {
211
-		if ($this->tmpBaseDir) {
212
-			return $this->tmpBaseDir;
213
-		}
204
+    /**
205
+     * Get the temporary base directory configured on the server
206
+     *
207
+     * @return string Path to the temporary directory or null
208
+     * @throws \UnexpectedValueException
209
+     */
210
+    public function getTempBaseDir() {
211
+        if ($this->tmpBaseDir) {
212
+            return $this->tmpBaseDir;
213
+        }
214 214
 
215
-		$directories = [];
216
-		if ($temp = $this->config->getSystemValue('tempdirectory', null)) {
217
-			$directories[] = $temp;
218
-		}
219
-		if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) {
220
-			$directories[] = $temp;
221
-		}
222
-		if ($temp = getenv('TMP')) {
223
-			$directories[] = $temp;
224
-		}
225
-		if ($temp = getenv('TEMP')) {
226
-			$directories[] = $temp;
227
-		}
228
-		if ($temp = getenv('TMPDIR')) {
229
-			$directories[] = $temp;
230
-		}
231
-		if ($temp = sys_get_temp_dir()) {
232
-			$directories[] = $temp;
233
-		}
215
+        $directories = [];
216
+        if ($temp = $this->config->getSystemValue('tempdirectory', null)) {
217
+            $directories[] = $temp;
218
+        }
219
+        if ($temp = \OC::$server->getIniWrapper()->get('upload_tmp_dir')) {
220
+            $directories[] = $temp;
221
+        }
222
+        if ($temp = getenv('TMP')) {
223
+            $directories[] = $temp;
224
+        }
225
+        if ($temp = getenv('TEMP')) {
226
+            $directories[] = $temp;
227
+        }
228
+        if ($temp = getenv('TMPDIR')) {
229
+            $directories[] = $temp;
230
+        }
231
+        if ($temp = sys_get_temp_dir()) {
232
+            $directories[] = $temp;
233
+        }
234 234
 
235
-		foreach ($directories as $dir) {
236
-			if ($this->checkTemporaryDirectory($dir)) {
237
-				return $dir;
238
-			}
239
-		}
235
+        foreach ($directories as $dir) {
236
+            if ($this->checkTemporaryDirectory($dir)) {
237
+                return $dir;
238
+            }
239
+        }
240 240
 
241
-		$temp = tempnam(dirname(__FILE__), '');
242
-		if (file_exists($temp)) {
243
-			unlink($temp);
244
-			return dirname($temp);
245
-		}
246
-		throw new \UnexpectedValueException('Unable to detect system temporary directory');
247
-	}
241
+        $temp = tempnam(dirname(__FILE__), '');
242
+        if (file_exists($temp)) {
243
+            unlink($temp);
244
+            return dirname($temp);
245
+        }
246
+        throw new \UnexpectedValueException('Unable to detect system temporary directory');
247
+    }
248 248
 
249
-	/**
250
-	 * Check if a temporary directory is ready for use
251
-	 *
252
-	 * @param mixed $directory
253
-	 * @return bool
254
-	 */
255
-	private function checkTemporaryDirectory($directory) {
256
-		// suppress any possible errors caused by is_writable
257
-		// checks missing or invalid path or characters, wrong permissions etc
258
-		try {
259
-			if (is_writable($directory)) {
260
-				return true;
261
-			}
262
-		} catch (\Exception $e) {
263
-		}
264
-		$this->log->warning('Temporary directory {dir} is not present or writable',
265
-			['dir' => $directory]
266
-		);
267
-		return false;
268
-	}
249
+    /**
250
+     * Check if a temporary directory is ready for use
251
+     *
252
+     * @param mixed $directory
253
+     * @return bool
254
+     */
255
+    private function checkTemporaryDirectory($directory) {
256
+        // suppress any possible errors caused by is_writable
257
+        // checks missing or invalid path or characters, wrong permissions etc
258
+        try {
259
+            if (is_writable($directory)) {
260
+                return true;
261
+            }
262
+        } catch (\Exception $e) {
263
+        }
264
+        $this->log->warning('Temporary directory {dir} is not present or writable',
265
+            ['dir' => $directory]
266
+        );
267
+        return false;
268
+    }
269 269
 
270
-	/**
271
-	 * Override the temporary base directory
272
-	 *
273
-	 * @param string $directory
274
-	 */
275
-	public function overrideTempBaseDir($directory) {
276
-		$this->tmpBaseDir = $directory;
277
-	}
270
+    /**
271
+     * Override the temporary base directory
272
+     *
273
+     * @param string $directory
274
+     */
275
+    public function overrideTempBaseDir($directory) {
276
+        $this->tmpBaseDir = $directory;
277
+    }
278 278
 
279 279
 }
Please login to merge, or discard this patch.
lib/private/App/CodeChecker/MigrationSchemaChecker.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -29,179 +29,179 @@
 block discarded – undo
29 29
 
30 30
 class MigrationSchemaChecker extends NodeVisitorAbstract {
31 31
 
32
-	/** @var string */
33
-	protected $schemaVariableName = null;
34
-	/** @var array */
35
-	protected $tableVariableNames = [];
36
-	/** @var array */
37
-	public $errors = [];
32
+    /** @var string */
33
+    protected $schemaVariableName = null;
34
+    /** @var array */
35
+    protected $tableVariableNames = [];
36
+    /** @var array */
37
+    public $errors = [];
38 38
 
39
-	/**
40
-	 * @param Node $node
41
-	 * @return void
42
-	 *
43
-	 * @suppress PhanUndeclaredProperty
44
-	 */
45
-	public function enterNode(Node $node) {
46
-		/**
47
-		 * Check tables
48
-		 */
49
-		if ($this->schemaVariableName !== null &&
50
-			 $node instanceof Node\Expr\Assign &&
51
-			 $node->var instanceof Node\Expr\Variable &&
52
-			 $node->expr instanceof Node\Expr\MethodCall &&
53
-			 $node->expr->var instanceof Node\Expr\Variable &&
54
-			 $node->expr->var->name === $this->schemaVariableName) {
39
+    /**
40
+     * @param Node $node
41
+     * @return void
42
+     *
43
+     * @suppress PhanUndeclaredProperty
44
+     */
45
+    public function enterNode(Node $node) {
46
+        /**
47
+         * Check tables
48
+         */
49
+        if ($this->schemaVariableName !== null &&
50
+             $node instanceof Node\Expr\Assign &&
51
+             $node->var instanceof Node\Expr\Variable &&
52
+             $node->expr instanceof Node\Expr\MethodCall &&
53
+             $node->expr->var instanceof Node\Expr\Variable &&
54
+             $node->expr->var->name === $this->schemaVariableName) {
55 55
 
56
-			if ($node->expr->name === 'createTable') {
57
-				if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) {
58
-					if (!$this->checkNameLength($node->expr->args[0]->value->value)) {
59
-						$this->errors[] = [
60
-							'line' => $node->getLine(),
61
-							'disallowedToken' => $node->expr->args[0]->value->value,
62
-							'reason' => 'Table name is too long (max. 27)',
63
-						];
64
-					} else {
65
-						$this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value;
66
-					}
67
-				}
68
-			} else if ($node->expr->name === 'getTable') {
69
-				if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) {
70
-					$this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value;
71
-				}
72
-			}
73
-		} else if ($this->schemaVariableName !== null &&
74
-			 $node instanceof Node\Expr\MethodCall &&
75
-			 $node->var instanceof Node\Expr\Variable &&
76
-			 $node->var->name === $this->schemaVariableName) {
56
+            if ($node->expr->name === 'createTable') {
57
+                if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) {
58
+                    if (!$this->checkNameLength($node->expr->args[0]->value->value)) {
59
+                        $this->errors[] = [
60
+                            'line' => $node->getLine(),
61
+                            'disallowedToken' => $node->expr->args[0]->value->value,
62
+                            'reason' => 'Table name is too long (max. 27)',
63
+                        ];
64
+                    } else {
65
+                        $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value;
66
+                    }
67
+                }
68
+            } else if ($node->expr->name === 'getTable') {
69
+                if (isset($node->expr->args[0]) && $node->expr->args[0]->value instanceof Node\Scalar\String_) {
70
+                    $this->tableVariableNames[$node->var->name] = $node->expr->args[0]->value->value;
71
+                }
72
+            }
73
+        } else if ($this->schemaVariableName !== null &&
74
+             $node instanceof Node\Expr\MethodCall &&
75
+             $node->var instanceof Node\Expr\Variable &&
76
+             $node->var->name === $this->schemaVariableName) {
77 77
 
78
-			if ($node->name === 'renameTable') {
79
-				$this->errors[] = [
80
-					'line' => $node->getLine(),
81
-					'disallowedToken' => 'Deprecated method',
82
-					'reason' => sprintf(
83
-						'`$%s->renameTable()` must not be used',
84
-						$node->var->name
85
-					),
86
-				];
87
-			}
78
+            if ($node->name === 'renameTable') {
79
+                $this->errors[] = [
80
+                    'line' => $node->getLine(),
81
+                    'disallowedToken' => 'Deprecated method',
82
+                    'reason' => sprintf(
83
+                        '`$%s->renameTable()` must not be used',
84
+                        $node->var->name
85
+                    ),
86
+                ];
87
+            }
88 88
 
89
-		/**
90
-		 * Check columns and Indexes
91
-		 */
92
-		} else if (!empty($this->tableVariableNames) &&
93
-			 $node instanceof Node\Expr\MethodCall &&
94
-			 $node->var instanceof Node\Expr\Variable &&
95
-			 isset($this->tableVariableNames[$node->var->name])) {
89
+        /**
90
+         * Check columns and Indexes
91
+         */
92
+        } else if (!empty($this->tableVariableNames) &&
93
+             $node instanceof Node\Expr\MethodCall &&
94
+             $node->var instanceof Node\Expr\Variable &&
95
+             isset($this->tableVariableNames[$node->var->name])) {
96 96
 
97
-			if ($node->name === 'addColumn' || $node->name === 'changeColumn') {
98
-				if (isset($node->args[0]) && $node->args[0]->value instanceof Node\Scalar\String_) {
99
-					if (!$this->checkNameLength($node->args[0]->value->value)) {
100
-						$this->errors[] = [
101
-							'line' => $node->getLine(),
102
-							'disallowedToken' => $node->args[0]->value->value,
103
-							'reason' => sprintf(
104
-								'Column name is too long on table `%s` (max. 27)',
105
-								$this->tableVariableNames[$node->var->name]
106
-							),
107
-						];
108
-					}
97
+            if ($node->name === 'addColumn' || $node->name === 'changeColumn') {
98
+                if (isset($node->args[0]) && $node->args[0]->value instanceof Node\Scalar\String_) {
99
+                    if (!$this->checkNameLength($node->args[0]->value->value)) {
100
+                        $this->errors[] = [
101
+                            'line' => $node->getLine(),
102
+                            'disallowedToken' => $node->args[0]->value->value,
103
+                            'reason' => sprintf(
104
+                                'Column name is too long on table `%s` (max. 27)',
105
+                                $this->tableVariableNames[$node->var->name]
106
+                            ),
107
+                        ];
108
+                    }
109 109
 
110
-					// On autoincrement the max length of the table name is 21 instead of 27
111
-					if (isset($node->args[2]) && $node->args[2]->value instanceof Node\Expr\Array_) {
112
-						/** @var Node\Expr\Array_ $options */
113
-						$options = $node->args[2]->value;
114
-						if ($this->checkColumnForAutoincrement($options)) {
115
-							if (!$this->checkNameLength($this->tableVariableNames[$node->var->name], true)) {
116
-								$this->errors[] = [
117
-									'line' => $node->getLine(),
118
-									'disallowedToken' => $this->tableVariableNames[$node->var->name],
119
-									'reason' => 'Table name is too long because of autoincrement (max. 21)',
120
-								];
121
-							}
122
-						}
123
-					}
124
-				}
125
-			} else if ($node->name === 'addIndex' ||
126
-				 $node->name === 'addUniqueIndex' ||
127
-				 $node->name === 'renameIndex' ||
128
-				 $node->name === 'setPrimaryKey') {
129
-				if (isset($node->args[1]) && $node->args[1]->value instanceof Node\Scalar\String_) {
130
-					if (!$this->checkNameLength($node->args[1]->value->value)) {
131
-						$this->errors[] = [
132
-							'line' => $node->getLine(),
133
-							'disallowedToken' => $node->args[1]->value->value,
134
-							'reason' => sprintf(
135
-								'Index name is too long on table `%s` (max. 27)',
136
-								$this->tableVariableNames[$node->var->name]
137
-							),
138
-						];
139
-					}
140
-				}
141
-			} else if ($node->name === 'addForeignKeyConstraint') {
142
-				if (isset($node->args[4]) && $node->args[4]->value instanceof Node\Scalar\String_) {
143
-					if (!$this->checkNameLength($node->args[4]->value->value)) {
144
-						$this->errors[] = [
145
-							'line' => $node->getLine(),
146
-							'disallowedToken' => $node->args[4]->value->value,
147
-							'reason' => sprintf(
148
-								'Constraint name is too long on table `%s` (max. 27)',
149
-								$this->tableVariableNames[$node->var->name]
150
-							),
151
-						];
152
-					}
153
-				}
154
-			} else if ($node->name === 'renameColumn') {
155
-				$this->errors[] = [
156
-					'line' => $node->getLine(),
157
-					'disallowedToken' => 'Deprecated method',
158
-					'reason' => sprintf(
159
-						'`$%s->renameColumn()` must not be used',
160
-						$node->var->name
161
-					),
162
-				];
163
-			}
110
+                    // On autoincrement the max length of the table name is 21 instead of 27
111
+                    if (isset($node->args[2]) && $node->args[2]->value instanceof Node\Expr\Array_) {
112
+                        /** @var Node\Expr\Array_ $options */
113
+                        $options = $node->args[2]->value;
114
+                        if ($this->checkColumnForAutoincrement($options)) {
115
+                            if (!$this->checkNameLength($this->tableVariableNames[$node->var->name], true)) {
116
+                                $this->errors[] = [
117
+                                    'line' => $node->getLine(),
118
+                                    'disallowedToken' => $this->tableVariableNames[$node->var->name],
119
+                                    'reason' => 'Table name is too long because of autoincrement (max. 21)',
120
+                                ];
121
+                            }
122
+                        }
123
+                    }
124
+                }
125
+            } else if ($node->name === 'addIndex' ||
126
+                 $node->name === 'addUniqueIndex' ||
127
+                 $node->name === 'renameIndex' ||
128
+                 $node->name === 'setPrimaryKey') {
129
+                if (isset($node->args[1]) && $node->args[1]->value instanceof Node\Scalar\String_) {
130
+                    if (!$this->checkNameLength($node->args[1]->value->value)) {
131
+                        $this->errors[] = [
132
+                            'line' => $node->getLine(),
133
+                            'disallowedToken' => $node->args[1]->value->value,
134
+                            'reason' => sprintf(
135
+                                'Index name is too long on table `%s` (max. 27)',
136
+                                $this->tableVariableNames[$node->var->name]
137
+                            ),
138
+                        ];
139
+                    }
140
+                }
141
+            } else if ($node->name === 'addForeignKeyConstraint') {
142
+                if (isset($node->args[4]) && $node->args[4]->value instanceof Node\Scalar\String_) {
143
+                    if (!$this->checkNameLength($node->args[4]->value->value)) {
144
+                        $this->errors[] = [
145
+                            'line' => $node->getLine(),
146
+                            'disallowedToken' => $node->args[4]->value->value,
147
+                            'reason' => sprintf(
148
+                                'Constraint name is too long on table `%s` (max. 27)',
149
+                                $this->tableVariableNames[$node->var->name]
150
+                            ),
151
+                        ];
152
+                    }
153
+                }
154
+            } else if ($node->name === 'renameColumn') {
155
+                $this->errors[] = [
156
+                    'line' => $node->getLine(),
157
+                    'disallowedToken' => 'Deprecated method',
158
+                    'reason' => sprintf(
159
+                        '`$%s->renameColumn()` must not be used',
160
+                        $node->var->name
161
+                    ),
162
+                ];
163
+            }
164 164
 
165
-		/**
166
-		 * Find the schema
167
-		 */
168
-		} else if ($node instanceof Node\Expr\Assign &&
169
-			 $node->expr instanceof Node\Expr\FuncCall &&
170
-			 $node->var instanceof Node\Expr\Variable &&
171
-			 $node->expr->name instanceof Node\Expr\Variable &&
172
-			 $node->expr->name->name === 'schemaClosure') {
173
-			// E.g. $schema = $schemaClosure();
174
-			$this->schemaVariableName = $node->var->name;
175
-		}
176
-	}
165
+        /**
166
+         * Find the schema
167
+         */
168
+        } else if ($node instanceof Node\Expr\Assign &&
169
+             $node->expr instanceof Node\Expr\FuncCall &&
170
+             $node->var instanceof Node\Expr\Variable &&
171
+             $node->expr->name instanceof Node\Expr\Variable &&
172
+             $node->expr->name->name === 'schemaClosure') {
173
+            // E.g. $schema = $schemaClosure();
174
+            $this->schemaVariableName = $node->var->name;
175
+        }
176
+    }
177 177
 
178
-	protected function checkNameLength($tableName, $hasAutoincrement = false) {
179
-		if ($hasAutoincrement) {
180
-			return strlen($tableName) <= 21;
181
-		}
182
-		return strlen($tableName) <= 27;
183
-	}
178
+    protected function checkNameLength($tableName, $hasAutoincrement = false) {
179
+        if ($hasAutoincrement) {
180
+            return strlen($tableName) <= 21;
181
+        }
182
+        return strlen($tableName) <= 27;
183
+    }
184 184
 
185
-	/**
186
-	 * @param Node\Expr\Array_ $optionsArray
187
-	 * @return bool Whether the column is an autoincrement column
188
-	 */
189
-	protected function checkColumnForAutoincrement(Node\Expr\Array_ $optionsArray) {
190
-		foreach ($optionsArray->items as $option) {
191
-			if ($option->key instanceof Node\Scalar\String_) {
192
-				if ($option->key->value === 'autoincrement' &&
193
-					 $option->value instanceof Node\Expr\ConstFetch) {
194
-					/** @var Node\Expr\ConstFetch $const */
195
-					$const = $option->value;
185
+    /**
186
+     * @param Node\Expr\Array_ $optionsArray
187
+     * @return bool Whether the column is an autoincrement column
188
+     */
189
+    protected function checkColumnForAutoincrement(Node\Expr\Array_ $optionsArray) {
190
+        foreach ($optionsArray->items as $option) {
191
+            if ($option->key instanceof Node\Scalar\String_) {
192
+                if ($option->key->value === 'autoincrement' &&
193
+                     $option->value instanceof Node\Expr\ConstFetch) {
194
+                    /** @var Node\Expr\ConstFetch $const */
195
+                    $const = $option->value;
196 196
 
197
-					if ($const->name instanceof Name &&
198
-						 $const->name->parts === ['true']) {
199
-						return true;
200
-					}
201
-				}
202
-			}
203
-		}
197
+                    if ($const->name instanceof Name &&
198
+                         $const->name->parts === ['true']) {
199
+                        return true;
200
+                    }
201
+                }
202
+            }
203
+        }
204 204
 
205
-		return false;
206
-	}
205
+        return false;
206
+    }
207 207
 }
Please login to merge, or discard this patch.
lib/private/OCS/Exception.php 1 patch
Indentation   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@
 block discarded – undo
25 25
 
26 26
 class Exception extends \Exception {
27 27
 
28
-	/** @var Result */
29
-	private $result;
28
+    /** @var Result */
29
+    private $result;
30 30
 
31
-	public function __construct(Result $result) {
32
-		parent::__construct();
33
-		$this->result = $result;
34
-	}
31
+    public function __construct(Result $result) {
32
+        parent::__construct();
33
+        $this->result = $result;
34
+    }
35 35
 
36
-	public function getResult() {
37
-		return $this->result;
38
-	}
36
+    public function getResult() {
37
+        return $this->result;
38
+    }
39 39
 
40 40
 }
Please login to merge, or discard this patch.
lib/private/Search/Result/File.php 1 patch
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -32,85 +32,85 @@
 block discarded – undo
32 32
  */
33 33
 class File extends \OCP\Search\Result {
34 34
 
35
-	/**
36
-	 * Type name; translated in templates
37
-	 * @var string 
38
-	 */
39
-	public $type = 'file';
35
+    /**
36
+     * Type name; translated in templates
37
+     * @var string 
38
+     */
39
+    public $type = 'file';
40 40
 
41
-	/**
42
-	 * Path to file
43
-	 * @var string
44
-	 */
45
-	public $path;
41
+    /**
42
+     * Path to file
43
+     * @var string
44
+     */
45
+    public $path;
46 46
 
47
-	/**
48
-	 * Size, in bytes
49
-	 * @var int 
50
-	 */
51
-	public $size;
47
+    /**
48
+     * Size, in bytes
49
+     * @var int 
50
+     */
51
+    public $size;
52 52
 
53
-	/**
54
-	 * Date modified, in human readable form
55
-	 * @var string
56
-	 */
57
-	public $modified;
53
+    /**
54
+     * Date modified, in human readable form
55
+     * @var string
56
+     */
57
+    public $modified;
58 58
 
59
-	/**
60
-	 * File mime type
61
-	 * @var string
62
-	 */
63
-	public $mime_type;
59
+    /**
60
+     * File mime type
61
+     * @var string
62
+     */
63
+    public $mime_type;
64 64
 
65
-	/**
66
-	 * File permissions:
67
-	 * 
68
-	 * @var string
69
-	 */
70
-	public $permissions;
65
+    /**
66
+     * File permissions:
67
+     * 
68
+     * @var string
69
+     */
70
+    public $permissions;
71 71
 
72
-	/**
73
-	 * Create a new file search result
74
-	 * @param FileInfo $data file data given by provider
75
-	 */
76
-	public function __construct(FileInfo $data) {
72
+    /**
73
+     * Create a new file search result
74
+     * @param FileInfo $data file data given by provider
75
+     */
76
+    public function __construct(FileInfo $data) {
77 77
 
78
-		$path = $this->getRelativePath($data->getPath());
78
+        $path = $this->getRelativePath($data->getPath());
79 79
 
80
-		$info = pathinfo($path);
81
-		$this->id = $data->getId();
82
-		$this->name = $info['basename'];
83
-		$this->link = \OC::$server->getURLGenerator()->linkToRoute(
84
-			'files.view.index',
85
-			[
86
-				'dir' => $info['dirname'],
87
-				'scrollto' => $info['basename'],
88
-			]
89
-		);
90
-		$this->permissions = $data->getPermissions();
91
-		$this->path = $path;
92
-		$this->size = $data->getSize();
93
-		$this->modified = $data->getMtime();
94
-		$this->mime_type = $data->getMimetype();
95
-	}
80
+        $info = pathinfo($path);
81
+        $this->id = $data->getId();
82
+        $this->name = $info['basename'];
83
+        $this->link = \OC::$server->getURLGenerator()->linkToRoute(
84
+            'files.view.index',
85
+            [
86
+                'dir' => $info['dirname'],
87
+                'scrollto' => $info['basename'],
88
+            ]
89
+        );
90
+        $this->permissions = $data->getPermissions();
91
+        $this->path = $path;
92
+        $this->size = $data->getSize();
93
+        $this->modified = $data->getMtime();
94
+        $this->mime_type = $data->getMimetype();
95
+    }
96 96
 
97
-	/**
98
-	 * @var Folder $userFolderCache
99
-	 */
100
-	static protected $userFolderCache = null;
97
+    /**
98
+     * @var Folder $userFolderCache
99
+     */
100
+    static protected $userFolderCache = null;
101 101
 
102
-	/**
103
-	 * converts a path relative to the users files folder
104
-	 * eg /user/files/foo.txt -> /foo.txt
105
-	 * @param string $path
106
-	 * @return string relative path
107
-	 */
108
-	protected function getRelativePath ($path) {
109
-		if (!isset(self::$userFolderCache)) {
110
-			$user = \OC::$server->getUserSession()->getUser()->getUID();
111
-			self::$userFolderCache = \OC::$server->getUserFolder($user);
112
-		}
113
-		return self::$userFolderCache->getRelativePath($path);
114
-	}
102
+    /**
103
+     * converts a path relative to the users files folder
104
+     * eg /user/files/foo.txt -> /foo.txt
105
+     * @param string $path
106
+     * @return string relative path
107
+     */
108
+    protected function getRelativePath ($path) {
109
+        if (!isset(self::$userFolderCache)) {
110
+            $user = \OC::$server->getUserSession()->getUser()->getUID();
111
+            self::$userFolderCache = \OC::$server->getUserFolder($user);
112
+        }
113
+        return self::$userFolderCache->getRelativePath($path);
114
+    }
115 115
 
116 116
 }
Please login to merge, or discard this patch.