From e2516a2b65185bd3081361d0b8f25e6eaf7d698f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Schie=C3=9Fle?= <schiessle@owncloud.com>
Date: Wed, 6 Feb 2013 16:23:22 +0100
Subject: [PATCH] allow to delete single files from the trash bin permanently

---
 apps/files/js/fileactions.js                  |   2 +
 apps/files_trashbin/ajax/delete.php           |  24 +++++++++++
 .../js/disableDefaultActions.js               | Bin 108 -> 131 bytes
 apps/files_trashbin/js/trash.js               | Bin 5418 -> 6418 bytes
 apps/files_trashbin/lib/trash.php             |  39 ++++++++++++++++++
 5 files changed, 65 insertions(+)
 create mode 100644 apps/files_trashbin/ajax/delete.php

diff --git a/apps/files/js/fileactions.js b/apps/files/js/fileactions.js
index c30f1bcddd8..af3fc483910 100644
--- a/apps/files/js/fileactions.js
+++ b/apps/files/js/fileactions.js
@@ -115,6 +115,8 @@ var FileActions = {
 			// NOTE: Temporary fix to allow unsharing of files in root of Shared folder
 			if ($('#dir').val() == '/Shared') {
 				var html = '<a href="#" original-title="' + t('files', 'Unshare') + '" class="action delete" />';
+			} else if (typeof trashBinApp !== 'undefined' && trashBinApp) {
+				var html = '<a href="#" original-title="' + t('files', 'Delete permanently') + '" class="action delete" />';
 			} else {
 				var html = '<a href="#" original-title="' + t('files', 'Delete') + '" class="action delete" />';
 			}
diff --git a/apps/files_trashbin/ajax/delete.php b/apps/files_trashbin/ajax/delete.php
new file mode 100644
index 00000000000..fe41f53d49e
--- /dev/null
+++ b/apps/files_trashbin/ajax/delete.php
@@ -0,0 +1,24 @@
+<?php
+
+OCP\JSON::checkLoggedIn();
+OCP\JSON::callCheck();
+
+$file = $_REQUEST['file'];
+
+$path_parts = pathinfo($file);
+if ($path_parts['dirname'] == '.') {
+	$delimiter = strrpos($file, '.d');
+	$filename = substr($file, 0, $delimiter);
+	$timestamp =  substr($file, $delimiter+2);
+} else {
+	$filename = $file;
+	$timestamp = null;
+}
+sleep(5);
+if (OCA_Trash\Trashbin::delete($filename, $timestamp)) {
+	error_log("feinifeini");
+	OCP\JSON::success(array("data" => array("filename" => $file)));
+} else {
+	OCP\JSON::error(array("data" => array("message" => "Couldn't delete ".$file. " permanently")));
+}
+
diff --git a/apps/files_trashbin/js/disableDefaultActions.js b/apps/files_trashbin/js/disableDefaultActions.js
index 56b95407dd34cb105f90f8f00776dfffd5b185f5..27c3e13db4d12d05a8c8e9796b031d72c1232247 100644
GIT binary patch
delta 29
jcmd04W}J{CUY1y-P*RjwoZ*z2=U7mnU<>4xrdk64oK6Zs

delta 5
McmZo>%$bk_00n3P?EnA(

diff --git a/apps/files_trashbin/js/trash.js b/apps/files_trashbin/js/trash.js
index f1241fce51e2b9e6fcdedb106bae72667e95e006..6c810e4c2bd017ac92e8ad1b2e62f1c3ebd2c31b 100644
GIT binary patch
delta 491
zcmaKp&q~8U5XPykU}8l*NIj^mp|G1;7ttQXl0(6R;GdJ?p?C<%)CRVjxVx#8;zPuJ
zfgZ(^;Kh?q;KTR`W|M*^J<iTI-}jr@*Vgml+iESl+Fm>b1}b~lYz$H!s3_)$xM*ry
zmL))?g6pKx$Yx8u(C7fW-MsbGM!)Jo#DM!Fm`^ncrYcJ01iMtgC>{eTW~}VX(=V0t
zTN(@_77F0Rp?;A_OK+#tjeUV)7M@*SULX&ZtzMz)AKcM6RUk~ya9Bpm;nCE3t+Le%
zedX_$rk+!51`bk@V&FM=PZ4ZjC2k{J`XW=K1jNYaz!jV5u}!KGzt=N+qxolc&NWZ%
z>hI-Fs}#~?m|(YUxU8u$K2d`DN(q7sF7u>67j~P`01+fWrc6<(e3eS%c?ioi2tZ1V
m%q8_ly`yic$43a5gz`gj-~W*2N9)?UzmjuR8}Ien&iW77U7P*@

delta 12
TcmbPav`T9OKg;It?9ze&9^eEy

diff --git a/apps/files_trashbin/lib/trash.php b/apps/files_trashbin/lib/trash.php
index a7eff3d44e0..bf98b6dfe80 100644
--- a/apps/files_trashbin/lib/trash.php
+++ b/apps/files_trashbin/lib/trash.php
@@ -150,6 +150,45 @@ class Trashbin {
 		return false;
 	}
 	
+	/**
+	 * delete file from trash bin permanently
+	 * @param $filename path to the file
+	 * @param $timestamp of deletion time
+	 * @return true/false
+	 */
+	public static function delete($filename, $timestamp=null) {
+	
+		$user = \OCP\User::getUser();
+		$view = new \OC_FilesystemView('/'.$user);
+	
+		if ( $timestamp ) {
+			$query = \OC_DB::prepare('DELETE FROM *PREFIX*files_trash WHERE user=? AND id=? AND timestamp=?');
+			$query->execute(array($user,$filename,$timestamp))->fetchAll();
+			$file = $filename.'.d'.$timestamp;
+		} else {
+			$file = $filename;
+		}
+		
+		if ( \OCP\App::isEnabled('files_versions') ) {
+			if ($view->is_dir('versions_trashbin/'.$file)) {
+				$view->unlink('versions_trashbin/'.$file);
+			} else if ( $versions = self::getVersionsFromTrash($file, $timestamp) ) {
+				foreach ($versions as $v) {
+					if ($timestamp ) {
+						$view->unlink('versions_trashbin/'.$filename.'.v'.$v.'.d'.$timestamp);
+					} else {
+						$view->unlink('versions_trashbin/'.$file.'.v'.$v);
+					}
+				}
+			}
+		}
+	
+		$view->unlink('/files_trashbin/'.$file);
+		
+		return true;
+	}
+	
+	
 	/**
 	 * clean up the trash bin
 	 */
-- 
GitLab