summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2013-01-29 13:36:33 +0100
committerBjörn Schießle <schiessle@owncloud.com>2013-01-29 13:36:33 +0100
commit0c8bcacdc8cbeec479c5b7f42ebb8a89ae1cd7bd (patch)
treecc668ae2ce002f0523ded90102be21df407f9265 /apps/files_trashbin
parenteafd34684ca1ceceeef01156745b00bad9e903c9 (diff)
downloadnextcloud-server-0c8bcacdc8cbeec479c5b7f42ebb8a89ae1cd7bd.tar.gz
nextcloud-server-0c8bcacdc8cbeec479c5b7f42ebb8a89ae1cd7bd.zip
added some additional error handling
Diffstat (limited to 'apps/files_trashbin')
-rw-r--r--apps/files_trashbin/lib/trash.php33
1 files changed, 22 insertions, 11 deletions
diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index fad96e5222a..68473c46b15 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -52,18 +52,27 @@ class Trashbin {
}
self::copy_recursive($file_path, 'files_trashbin/'.$deleted.'.d'.$timestamp, $view);
-
- $query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user) VALUES (?,?,?,?,?,?)");
- $query->execute(array($deleted, $timestamp, $location, $type, $mime, $user));
-
- if ( \OCP\App::isEnabled('files_versions') ) {
- if ( $view->is_dir('files_versions'.$file_path) ) {
- $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp);
- } else if ( $versions = \OCA_Versions\Storage::getVersions($file_path) ) {
- foreach ($versions as $v) {
- $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp);
- }
+
+ if ( $view->file_exists('files_trashbin/'.$deleted.'.d'.$timestamp) ) {
+ $query = \OC_DB::prepare("INSERT INTO *PREFIX*files_trash (id,timestamp,location,type,mime,user) VALUES (?,?,?,?,?,?)");
+ $result = $query->execute(array($deleted, $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/'.$deleted.'.d'.$timestamp);
+ \OC_Log::write('files_trashbin', 'trash bin database couldn\'t be updated', \OC_log::ERROR);
+ return;
}
+
+ if ( \OCP\App::isEnabled('files_versions') ) {
+ if ( $view->is_dir('files_versions'.$file_path) ) {
+ $view->rename('files_versions'.$file_path, 'versions_trashbin/'. $deleted.'.d'.$timestamp);
+ } else if ( $versions = \OCA_Versions\Storage::getVersions($file_path) ) {
+ foreach ($versions as $v) {
+ $view->rename('files_versions'.$v['path'].'.v'.$v['version'], 'versions_trashbin/'. $deleted.'.v'.$v['version'].'.d'.$timestamp);
+ }
+ }
+ }
+ } else {
+ \OC_Log::write('files_trashbin', 'Couldn\'t move '.$file_path.' to the trash bin' , \OC_log::ERROR);
}
self::expire();
@@ -133,6 +142,8 @@ class Trashbin {
}
return true;
+ } else {
+ \OC_Log::write('files_trashbin', 'Couldn\'t restore file from trash bin, '.$filename , \OC_log::ERROR);
}
return false;