summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/trashbin.php
diff options
context:
space:
mode:
authorBjoern Schiessle <schiessle@owncloud.com>2014-02-25 20:46:41 +0100
committerBjoern Schiessle <schiessle@owncloud.com>2014-03-10 15:13:28 +0100
commiteab844e2267a2955711f9d426c47eedeeea2d479 (patch)
tree31efab64fb3a949ba4c57ba7c04e75349f7c9d2f /apps/files_trashbin/lib/trashbin.php
parent9b4af31bac977cb788a6f4a013d32ba0a21437f0 (diff)
downloadnextcloud-server-eab844e2267a2955711f9d426c47eedeeea2d479.tar.gz
nextcloud-server-eab844e2267a2955711f9d426c47eedeeea2d479.zip
if file is not in db, fall back to restore file to the users root
Diffstat (limited to 'apps/files_trashbin/lib/trashbin.php')
-rw-r--r--apps/files_trashbin/lib/trashbin.php60
1 files changed, 22 insertions, 38 deletions
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index bc77e9c1543..3933395c298 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -62,11 +62,13 @@ class Trashbin {
/**
+ * @brief copy file to owners trash
+ * @param string $sourcePath
* @param string $owner
+ * @param string $ownerPath
* @param integer $timestamp
- * @param string $type
*/
- private static function copyFilesToOwner($sourcePath, $owner, $ownerPath, $timestamp, $type, $mime) {
+ private static function copyFilesToOwner($sourcePath, $owner, $ownerPath, $timestamp) {
self::setUpTrash($owner);
$ownerFilename = basename($ownerPath);
@@ -82,12 +84,10 @@ class Trashbin {
if ($view->file_exists($target)) {
- $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
- $result = $query->execute(array($ownerFilename, $timestamp, $ownerLocation, $type, $mime, $owner));
- if (!$result) { // if file couldn't be added to the database than also don't store it in the trash bin.
- $view->deleteAll($owner.'/files_trashbin/files/' . $ownerFilename . '.d' . $timestamp);
+ $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
+ $result = $query->execute(array($ownerFilename, $timestamp, $ownerLocation, $owner));
+ if (!$result) {
\OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated for the files owner', \OC_log::ERROR);
- return;
}
}
}
@@ -110,13 +110,6 @@ class Trashbin {
$filename = $path_parts['basename'];
$location = $path_parts['dirname'];
$timestamp = time();
- $mime = $view->getMimeType('files' . $file_path);
-
- if ($view->is_dir('files' . $file_path)) {
- $type = 'dir';
- } else {
- $type = 'file';
- }
$userTrashSize = self::getTrashbinSize($user);
if ($userTrashSize === false || $userTrashSize < 0) {
@@ -132,12 +125,10 @@ class Trashbin {
if ($view->file_exists('files_trashbin/files/' . $filename . '.d' . $timestamp)) {
$size = $sizeOfAddedFiles;
- $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`type`,`mime`,`user`) VALUES (?,?,?,?,?,?)");
- $result = $query->execute(array($filename, $timestamp, $location, $type, $mime, $user));
- if (!$result) { // if file couldn't be added to the database than also don't store it in the trash bin.
- $view->deleteAll('files_trashbin/files/' . $filename . '.d' . $timestamp);
+ $query = \OC_DB::prepare("INSERT INTO `*PREFIX*files_trash` (`id`,`timestamp`,`location`,`user`) VALUES (?,?,?,?)");
+ $result = $query->execute(array($filename, $timestamp, $location, $user));
+ if (!$result) {
\OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
- return;
}
\OCP\Util::emitHook('\OCA\Files_Trashbin\Trashbin', 'post_moveToTrash', array('filePath' => \OC\Files\Filesystem::normalizePath($file_path),
'trashPath' => \OC\Files\Filesystem::normalizePath($filename . '.d' . $timestamp)));
@@ -147,7 +138,7 @@ class Trashbin {
// if owner !== user we need to also add a copy to the owners trash
if ($user !== $owner) {
- self::copyFilesToOwner($file_path, $owner, $ownerPath, $timestamp, $type, $mime);
+ self::copyFilesToOwner($file_path, $owner, $ownerPath, $timestamp);
}
} else {
\OC_Log::write('files_trashbin', 'Couldn\'t move ' . $file_path . ' to the trash bin', \OC_log::ERROR);
@@ -330,29 +321,22 @@ class Trashbin {
if ($trashbinSize === false || $trashbinSize < 0) {
$trashbinSize = self::calculateSize(new \OC\Files\View('/' . $user . '/files_trashbin'));
}
+ $location = '';
if ($timestamp) {
- $query = \OC_DB::prepare('SELECT `location`,`type` FROM `*PREFIX*files_trash`'
- . ' WHERE `user`=? AND `id`=? AND `timestamp`=?');
+ $query = \OC_DB::prepare('SELECT `location` FROM `*PREFIX*files_trash`'
+ . ' WHERE `user`=? AND `id`=? AND `timestamp`=?');
$result = $query->execute(array($user, $filename, $timestamp))->fetchAll();
if (count($result) !== 1) {
\OC_Log::write('files_trashbin', 'trash bin database inconsistent!', \OC_Log::ERROR);
- return false;
- }
-
- // if location no longer exists, restore file in the root directory
- $location = $result[0]['location'];
- if ($result[0]['location'] !== '/' &&
- (!$view->is_dir('files' . $result[0]['location']) ||
- !$view->isUpdatable('files' . $result[0]['location']))) {
- $location = '';
+ } else {
+ $location = $result[0]['location'];
+ // if location no longer exists, restore file in the root directory
+ if ($location !== '/' &&
+ (!$view->is_dir('files' . $location) ||
+ !$view->isUpdatable('files' . $location))) {
+ $location = '';
+ }
}
- } else {
- $path_parts = pathinfo($file);
- $result[] = array(
- 'location' => $path_parts['dirname'],
- 'type' => $view->is_dir('/files_trashbin/files/' . $file) ? 'dir' : 'files',
- );
- $location = '';
}
// we need a extension in case a file/dir with the same name already exists