aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/trashbin.php
diff options
context:
space:
mode:
authorRobin McCorkell <rmccorkell@karoshi.org.uk>2014-08-27 10:28:31 +0100
committerRobin McCorkell <rmccorkell@karoshi.org.uk>2014-09-11 15:45:42 +0100
commit99d41bec5d04fbdf5d457584cd4d22fef65ece25 (patch)
tree079ee19291f919a90ad7b1ca2595555050d25b7a /apps/files_trashbin/lib/trashbin.php
parent712addac683110c44527cbb9dfe9133821712241 (diff)
downloadnextcloud-server-99d41bec5d04fbdf5d457584cd4d22fef65ece25.tar.gz
nextcloud-server-99d41bec5d04fbdf5d457584cd4d22fef65ece25.zip
Show original path information in trashbin and sharing views
Path will only be shown if in subdirectory, not in root.
Diffstat (limited to 'apps/files_trashbin/lib/trashbin.php')
-rw-r--r--apps/files_trashbin/lib/trashbin.php47
1 files changed, 42 insertions, 5 deletions
diff --git a/apps/files_trashbin/lib/trashbin.php b/apps/files_trashbin/lib/trashbin.php
index 69eef09d1e9..12bf6a78114 100644
--- a/apps/files_trashbin/lib/trashbin.php
+++ b/apps/files_trashbin/lib/trashbin.php
@@ -41,6 +41,46 @@ class Trashbin {
return array($uid, $filename);
}
+ /**
+ * get original location of files for user
+ *
+ * @param string $user
+ * @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(array($user));
+ $array = array();
+ while ($row = $result->fetchRow()) {
+ if (isset($array[$row['id']])) {
+ $array[$row['id']][$row['timestamp']] = $row['location'];
+ } else {
+ $array[$row['id']] = array($row['timestamp'] => $row['location']);
+ }
+ }
+ return $array;
+ }
+
+ /**
+ * get original location of file
+ *
+ * @param string $user
+ * @param string $filename
+ * @param string $timestamp
+ * @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(array($user, $filename, $timestamp))->fetchAll();
+ if (isset($result[0]['location'])) {
+ return $result[0]['location'];
+ } else {
+ return false;
+ }
+ }
+
private static function setUpTrash($user) {
$view = new \OC\Files\View('/' . $user);
if (!$view->is_dir('files_trashbin')) {
@@ -318,13 +358,10 @@ class Trashbin {
$location = '';
if ($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) {
+ $location = self::getLocation($user, $filename, $timestamp);
+ if ($location === false) {
\OC_Log::write('files_trashbin', 'trash bin database inconsistent!', \OC_Log::ERROR);
} else {
- $location = $result[0]['location'];
// if location no longer exists, restore file in the root directory
if ($location !== '/' &&
(!$view->is_dir('files' . $location) ||