Skip to content

Commit 1c397d0

Browse files
chore: drop \OCP\DB (#41458)
1 parent 385b912 commit 1c397d0

File tree

12 files changed

+149
-601
lines changed

12 files changed

+149
-601
lines changed

apps/files_sharing/lib/Helper.php

Lines changed: 0 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -163,93 +163,6 @@ public static function authenticate($linkItem, $password = null) {
163163
return true;
164164
}
165165

166-
public static function getSharesFromItem($target) {
167-
$result = [];
168-
$owner = Filesystem::getOwner($target);
169-
Filesystem::initMountPoints($owner);
170-
$info = Filesystem::getFileInfo($target);
171-
$ownerView = new View('/'.$owner.'/files');
172-
if ($owner != User::getUser()) {
173-
$path = $ownerView->getPath($info['fileid']);
174-
} else {
175-
$path = $target;
176-
}
177-
178-
$ids = [];
179-
while ($path !== \dirname($path)) {
180-
$info = $ownerView->getFileInfo($path);
181-
if ($info instanceof \OC\Files\FileInfo) {
182-
$ids[] = $info['fileid'];
183-
} else {
184-
\OCP\Util::writeLog('files_sharing', 'No fileinfo available for: ' . $path, \OCP\Util::WARN);
185-
}
186-
$path = \dirname($path);
187-
}
188-
189-
if (!empty($ids)) {
190-
$idList = \array_chunk($ids, 99, true);
191-
192-
foreach ($idList as $subList) {
193-
$statement = "SELECT `share_with`, `share_type`, `file_target` FROM `*PREFIX*share` WHERE `file_source` IN (" . \implode(',', $subList) . ") AND `share_type` IN (0, 1, 2)";
194-
$query = \OCP\DB::prepare($statement);
195-
$r = $query->execute();
196-
$result = \array_merge($result, $r->fetchAll());
197-
}
198-
}
199-
200-
return $result;
201-
}
202-
203-
/**
204-
* get the UID of the owner of the file and the path to the file relative to
205-
* owners files folder
206-
*
207-
* @param $filename
208-
* @return array
209-
* @throws \OC\User\NoUserException
210-
*/
211-
public static function getUidAndFilename($filename) {
212-
$uid = Filesystem::getOwner($filename);
213-
$userManager = \OC::$server->getUserManager();
214-
// if the user with the UID doesn't exists, e.g. because the UID points
215-
// to a remote user with a federated cloud ID we use the current logged-in
216-
// user. We need a valid local user to create the share
217-
if (!$userManager->userExists($uid)) {
218-
$uid = User::getUser();
219-
}
220-
Filesystem::initMountPoints($uid);
221-
if ($uid != User::getUser()) {
222-
$info = Filesystem::getFileInfo($filename);
223-
$ownerView = new View('/'.$uid.'/files');
224-
try {
225-
$filename = $ownerView->getPath($info['fileid']);
226-
} catch (NotFoundException $e) {
227-
$filename = null;
228-
}
229-
}
230-
return [$uid, $filename];
231-
}
232-
233-
/**
234-
* Format a path to be relative to the /user/files/ directory
235-
* @param string $path the absolute path
236-
* @return string e.g. turns '/admin/files/test.txt' into 'test.txt'
237-
*/
238-
public static function stripUserFilesPath($path) {
239-
$trimmed = \ltrim($path, '/');
240-
$split = \explode('/', $trimmed);
241-
242-
// it is not a file relative to data/user/files
243-
if (\count($split) < 3 || $split[1] !== 'files') {
244-
return false;
245-
}
246-
247-
$sliced = \array_slice($split, 2);
248-
$relPath = \implode('/', $sliced);
249-
250-
return $relPath;
251-
}
252-
253166
/**
254167
* check if file name already exists and generate unique target
255168
*

apps/files_sharing/lib/ShareBackend/File.php

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -194,48 +194,4 @@ public function isShareTypeAllowed($shareType) {
194194

195195
return true;
196196
}
197-
198-
/**
199-
* resolve reshares to return the correct source item
200-
* @param array $source
201-
* @return array source item
202-
*/
203-
protected static function resolveReshares($source) {
204-
if (isset($source['parent'])) {
205-
$parent = $source['parent'];
206-
while (isset($parent)) {
207-
$query = \OCP\DB::prepare('SELECT `parent`, `uid_owner` FROM `*PREFIX*share` WHERE `id` = ?', 1);
208-
$item = $query->execute([$parent])->fetchRow();
209-
if (isset($item['parent'])) {
210-
$parent = $item['parent'];
211-
} else {
212-
$fileOwner = $item['uid_owner'];
213-
break;
214-
}
215-
}
216-
} else {
217-
$fileOwner = $source['uid_owner'];
218-
}
219-
if (isset($fileOwner)) {
220-
$source['fileOwner'] = $fileOwner;
221-
} else {
222-
\OCP\Util::writeLog('files_sharing', "No owner found for reshare", \OCP\Util::ERROR);
223-
}
224-
225-
return $source;
226-
}
227-
228-
/**
229-
* @param string $target
230-
* @param array $share
231-
* @return array|false source item
232-
*/
233-
public static function getSource($target, $share) {
234-
if ($share['item_type'] === 'folder' && $target !== '') {
235-
// note: in case of ext storage mount points the path might be empty
236-
// which would cause a leading slash to appear
237-
$share['path'] = \ltrim($share['path'] . '/' . $target, '/');
238-
}
239-
return self::resolveReshares($share);
240-
}
241197
}

apps/files_sharing/lib/ShareBackend/Folder.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,37 +69,41 @@ public function getParents($itemSource, $shareWith = null, $owner = null) {
6969
* @return mixed parent ID or null
7070
*/
7171
private function getParentId($child) {
72-
$query = \OCP\DB::prepare('SELECT `parent` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
73-
$result = $query->execute([$child]);
74-
$row = $result->fetchRow();
72+
$query = \OC::$server->getDatabaseConnection()->prepare('SELECT `parent` FROM `*PREFIX*filecache` WHERE `fileid` = ?');
73+
$result = $query->executeQuery([$child]);
74+
$row = $result->fetchAssociative();
7575
$parent = ($row) ? $row['parent'] : null;
76+
$result->free();
7677

7778
return $parent;
7879
}
7980

8081
public function getChildren($itemSource) {
8182
$children = [];
8283
$parents = [$itemSource];
83-
$query = \OCP\DB::prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
84-
$result = $query->execute(['httpd/unix-directory']);
85-
if ($row = $result->fetchRow()) {
84+
$query = \OC::$server->getDatabaseConnection()->prepare('SELECT `id` FROM `*PREFIX*mimetypes` WHERE `mimetype` = ?');
85+
$result = $query->executeQuery(['httpd/unix-directory']);
86+
if ($row = $result->fetchAssociative()) {
8687
$mimetype = $row['id'];
8788
} else {
8889
$mimetype = -1;
8990
}
91+
$result->free();
92+
9093
while (!empty($parents)) {
9194
$parents = "'".\implode("','", $parents)."'";
92-
$query = \OCP\DB::prepare('SELECT `fileid`, `name`, `mimetype` FROM `*PREFIX*filecache`'
95+
$query = \OC::$server->getDatabaseConnection()->prepare('SELECT `fileid`, `name`, `mimetype` FROM `*PREFIX*filecache`'
9396
.' WHERE `parent` IN ('.$parents.')');
94-
$result = $query->execute();
97+
$result = $query->executeQuery();
9598
$parents = [];
96-
while ($file = $result->fetchRow()) {
99+
while ($file = $result->fetchAssociative()) {
97100
$children[] = ['source' => $file['fileid'], 'file_path' => $file['name']];
98101
// If a child folder is found look inside it
99102
if ($file['mimetype'] == $mimetype) {
100103
$parents[] = $file['fileid'];
101104
}
102105
}
106+
$result->free();
103107
}
104108
return $children;
105109
}

apps/files_sharing/tests/ApiTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1443,11 +1443,11 @@ public function testDefaultExpireDate() {
14431443

14441444
//manipulate stime so that both shares are older then the default expire date
14451445
$statement = "UPDATE `*PREFIX*share` SET `stime` = ? WHERE `share_type` = ?";
1446-
$query = \OCP\DB::prepare($statement);
1447-
$result = $query->execute([$shareCreated, Share::SHARE_TYPE_LINK]);
1446+
$query = \OC::$server->getDatabaseConnection()->prepare($statement);
1447+
$result = $query->executeStatement([$shareCreated, Share::SHARE_TYPE_LINK]);
14481448
$this->assertSame(1, $result);
1449-
$query = \OCP\DB::prepare($statement);
1450-
$result = $query->execute([$shareCreated, Share::SHARE_TYPE_USER]);
1449+
$query = \OC::$server->getDatabaseConnection()->prepare($statement);
1450+
$result = $query->executeStatement([$shareCreated, Share::SHARE_TYPE_USER]);
14511451
$this->assertSame(1, $result);
14521452

14531453
// now the link share should expire because of enforced default expire date

apps/files_sharing/tests/ShareTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ protected function tearDown(): void {
5959
$this->view->deleteAll($this->folder);
6060

6161
// clear database table
62-
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`');
63-
$query->execute();
62+
\OC::$server->getDatabaseConnection()->executeStatement('DELETE FROM `*PREFIX*share`');
6463

6564
parent::tearDown();
6665
}

apps/files_sharing/tests/TestCase.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,8 +125,7 @@ protected function setUp(): void {
125125
}
126126

127127
protected function tearDown(): void {
128-
$query = \OCP\DB::prepare('DELETE FROM `*PREFIX*share`');
129-
$query->execute();
128+
\OC::$server->getDatabaseConnection()->executeStatement('DELETE FROM `*PREFIX*share`');
130129

131130
parent::tearDown();
132131
}

0 commit comments

Comments
 (0)