aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorJohn Molakvoæ <skjnldsv@users.noreply.github.com>2020-11-07 10:19:23 +0100
committerGitHub <noreply@github.com>2020-11-07 10:19:23 +0100
commite90e499c8b3cccca838b6561ea646f63dacce14f (patch)
tree318cd0ea5d4294027684591b6a88185fd24d6474 /apps/files_trashbin
parent8210e94e8a7ee86b698959031ae67af4d3c974a2 (diff)
parente52925c5fb357323eb081b9833554366aa2540ae (diff)
downloadnextcloud-server-e90e499c8b3cccca838b6561ea646f63dacce14f.tar.gz
nextcloud-server-e90e499c8b3cccca838b6561ea646f63dacce14f.zip
Merge pull request #23936 from nextcloud/bugfix/noid/trashbin-ocdb
Use query builder instead of OC_DB in trashbin
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/lib/Trashbin.php77
1 files changed, 56 insertions, 21 deletions
diff --git a/apps/files_trashbin/lib/Trashbin.php b/apps/files_trashbin/lib/Trashbin.php
index a18cac25bb9..2ad67e5559a 100644
--- a/apps/files_trashbin/lib/Trashbin.php
+++ b/apps/files_trashbin/lib/Trashbin.php
@@ -128,17 +128,20 @@ class Trashbin {
* @return array (filename => array (timestamp => original location))
*/
public static function getLocations($user) {
- $query = \OC_DB::prepare('SELECT `id`, `timestamp`, `location`'
- . ' FROM `*PREFIX*files_trash` WHERE `user`=?');
- $result = $query->execute([$user]);
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->select('id', 'timestamp', 'location')
+ ->from('files_trash')
+ ->where($query->expr()->eq('user', $query->createNamedParameter($user)));
+ $result = $query->execute();
$array = [];
- while ($row = $result->fetchRow()) {
+ while ($row = $result->fetch()) {
if (isset($array[$row['id']])) {
$array[$row['id']][$row['timestamp']] = $row['location'];
} else {
$array[$row['id']] = [$row['timestamp'] => $row['location']];
}
}
+ $result->closeCursor();
return $array;
}
@@ -151,11 +154,19 @@ class Trashbin {
* @return string original location
*/
public static function getLocation($user, $filename, $timestamp) {
- $query = \OC_DB::prepare('SELECT `location` FROM `*PREFIX*files_trash`'
- . ' WHERE `user`=? AND `id`=? AND `timestamp`=?');
- $result = $query->execute([$user, $filename, $timestamp])->fetchAll();
- if (isset($result[0]['location'])) {
- return $result[0]['location'];
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->select('location')
+ ->from('files_trash')
+ ->where($query->expr()->eq('user', $query->createNamedParameter($user)))
+ ->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename)))
+ ->andWhere($query->expr()->eq('timestamp', $query->createNamedParameter($timestamp)));
+
+ $result = $query->execute();
+ $row = $result->fetch();
+ $result->closeCursor();
+
+ if (isset($row['location'])) {
+ return $row['location'];
} else {
return false;
}
@@ -208,8 +219,13 @@ class Trashbin {
if ($view->file_exists($target)) {
- $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
- $result = $query->execute([$targetFilename, $timestamp, $targetLocation, $user]);
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->insert('files_trash')
+ ->setValue('id', $query->createNamedParameter($targetFilename))
+ ->setValue('timestamp', $query->createNamedParameter($timestamp))
+ ->setValue('location', $query->createNamedParameter($targetLocation))
+ ->setValue('user', $query->createNamedParameter($user));
+ $result = $query->execute();
if (!$result) {
\OC::$server->getLogger()->error('trash bin database couldn\'t be updated for the files owner', ['app' => 'files_trashbin']);
}
@@ -330,8 +346,13 @@ class Trashbin {
}
if ($moveSuccessful) {
- $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
- $result = $query->execute([$filename, $timestamp, $location, $owner]);
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->insert('files_trash')
+ ->setValue('id', $query->createNamedParameter($filename))
+ ->setValue('timestamp', $query->createNamedParameter($timestamp))
+ ->setValue('location', $query->createNamedParameter($location))
+ ->setValue('user', $query->createNamedParameter($owner));
+ $result = $query->execute();
if (!$result) {
\OC::$server->getLogger()->error('trash bin database couldn\'t be updated', ['app' => 'files_trashbin']);
}
@@ -489,8 +510,12 @@ class Trashbin {
self::restoreVersions($view, $file, $filename, $uniqueFilename, $location, $timestamp);
if ($timestamp) {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=? AND `id`=? AND `timestamp`=?');
- $query->execute([$user, $filename, $timestamp]);
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('files_trash')
+ ->where($query->expr()->eq('user', $query->createNamedParameter($user)))
+ ->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename)))
+ ->andWhere($query->expr()->eq('timestamp', $query->createNamedParameter($timestamp)));
+ $query->execute();
}
return true;
@@ -576,8 +601,11 @@ class Trashbin {
// actual file deletion
$trash->delete();
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?');
- $query->execute([$user]);
+
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('files_trash')
+ ->where($query->expr()->eq('user', $query->createNamedParameter($user)));
+ $query->execute();
// Bulk PostDelete-Hook
\OC_Hook::emit('\OCP\Trashbin', 'deleteAll', ['paths' => $filePaths]);
@@ -626,8 +654,13 @@ class Trashbin {
$size = 0;
if ($timestamp) {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=? AND `id`=? AND `timestamp`=?');
- $query->execute([$user, $filename, $timestamp]);
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('files_trash')
+ ->where($query->expr()->eq('user', $query->createNamedParameter($user)))
+ ->andWhere($query->expr()->eq('id', $query->createNamedParameter($filename)))
+ ->andWhere($query->expr()->eq('timestamp', $query->createNamedParameter($timestamp)));
+ $query->execute();
+
$file = $filename . '.d' . $timestamp;
} else {
$file = $filename;
@@ -709,8 +742,10 @@ class Trashbin {
* @return bool result of db delete operation
*/
public static function deleteUser($uid) {
- $query = \OC_DB::prepare('DELETE FROM `*PREFIX*files_trash` WHERE `user`=?');
- return $query->execute([$uid]);
+ $query = \OC::$server->getDatabaseConnection()->getQueryBuilder();
+ $query->delete('files_trash')
+ ->where($query->expr()->eq('user', $query->createNamedParameter($uid)));
+ return (bool) $query->execute();
}
/**