From a12f45d6d2f8727f33c2e2daec89890c7a99564d Mon Sep 17 00:00:00 2001 From: Victor Dubiniuk Date: Tue, 30 Jul 2019 22:32:08 +0300 Subject: [PATCH] Keep properties when file goes to trashbin --- apps/dav/lib/DAV/AbstractCustomPropertiesBackend.php | 10 +++++++++- apps/dav/lib/DAV/FileCustomPropertiesBackend.php | 8 ++++++++ apps/dav/lib/Server.php | 6 ++++-- .../tests/unit/DAV/FileCustomPropertiesBackendTest.php | 6 ++++-- .../tests/unit/DAV/MiscCustomPropertiesBackendTest.php | 3 ++- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/apps/dav/lib/DAV/AbstractCustomPropertiesBackend.php b/apps/dav/lib/DAV/AbstractCustomPropertiesBackend.php index 0c80c1fb3347..eeceaedcd6fc 100644 --- a/apps/dav/lib/DAV/AbstractCustomPropertiesBackend.php +++ b/apps/dav/lib/DAV/AbstractCustomPropertiesBackend.php @@ -21,6 +21,7 @@ namespace OCA\DAV\DAV; +use OCP\Files\IRootFolder; use OCP\IDBConnection; use OCP\IUser; use Sabre\DAV\Exception\Forbidden; @@ -66,6 +67,11 @@ abstract class AbstractCustomPropertiesBackend implements BackendInterface { */ protected $user; + /** + * @var IRootFolder + */ + protected $rootFolder; + /** * Property cache for the filesystem items * @var array @@ -80,10 +86,12 @@ abstract class AbstractCustomPropertiesBackend implements BackendInterface { public function __construct( Tree $tree, IDBConnection $connection, - IUser $user) { + IUser $user, + IRootFolder $rootFolder) { $this->tree = $tree; $this->connection = $connection; $this->user = $user->getUID(); + $this->rootFolder = $rootFolder; } /** diff --git a/apps/dav/lib/DAV/FileCustomPropertiesBackend.php b/apps/dav/lib/DAV/FileCustomPropertiesBackend.php index 00752de87825..ddcfec8bba60 100644 --- a/apps/dav/lib/DAV/FileCustomPropertiesBackend.php +++ b/apps/dav/lib/DAV/FileCustomPropertiesBackend.php @@ -105,6 +105,14 @@ public function delete($path) { $fileId = $this->deletedItemsCache->get($path); if ($fileId !== null) { + $items = $this->rootFolder->getById($fileId); + /** @var \OCP\Files\Node $item */ + foreach ($items as $item) { + if ($item->getStorage()->instanceOfStorage(\OCA\Files_Trashbin\Storage::class)) { + return; + } + } + $statement = $this->connection->prepare(self::DELETE_BY_ID_STMT); $statement->execute([$fileId]); $this->offsetUnset($fileId); diff --git a/apps/dav/lib/Server.php b/apps/dav/lib/Server.php index 4f6b10fba8b2..475f616be277 100644 --- a/apps/dav/lib/Server.php +++ b/apps/dav/lib/Server.php @@ -228,7 +228,8 @@ public function __construct(IRequest $request, $baseUri) { new FileCustomPropertiesBackend( $this->server->tree, \OC::$server->getDatabaseConnection(), - \OC::$server->getUserSession()->getUser() + \OC::$server->getUserSession()->getUser(), + \OC::$server->getRootFolder() ) ); $this->server->addPlugin($filePropertiesPlugin); @@ -237,7 +238,8 @@ public function __construct(IRequest $request, $baseUri) { new MiscCustomPropertiesBackend( $this->server->tree, \OC::$server->getDatabaseConnection(), - \OC::$server->getUserSession()->getUser() + \OC::$server->getUserSession()->getUser(), + OC::$server->getRootFolder() ) ); $this->server->addPlugin($miscPropertiesPlugin); diff --git a/apps/dav/tests/unit/DAV/FileCustomPropertiesBackendTest.php b/apps/dav/tests/unit/DAV/FileCustomPropertiesBackendTest.php index 456658120c6f..9f34d514910f 100644 --- a/apps/dav/tests/unit/DAV/FileCustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/DAV/FileCustomPropertiesBackendTest.php @@ -87,7 +87,8 @@ public function setUp() { $this->backend = new FileCustomPropertiesBackend( $this->tree, \OC::$server->getDatabaseConnection(), - $this->user + $this->user, + \OC::$server->getRootFolder() ); $this->plugin = new FileCustomPropertiesPlugin($this->backend); @@ -436,7 +437,8 @@ public function testGetChunks($toSlice, $otherPlaceholdersCount, AbstractPlatfor $this->backend = new FileCustomPropertiesBackend( $this->tree, $dbConnectionMock, - $this->user + $this->user, + \OC::$server->getRootFolder() ); $actual = $this->invokePrivate( diff --git a/apps/dav/tests/unit/DAV/MiscCustomPropertiesBackendTest.php b/apps/dav/tests/unit/DAV/MiscCustomPropertiesBackendTest.php index 42e25c92f1fc..250ef0e60236 100644 --- a/apps/dav/tests/unit/DAV/MiscCustomPropertiesBackendTest.php +++ b/apps/dav/tests/unit/DAV/MiscCustomPropertiesBackendTest.php @@ -76,7 +76,8 @@ public function setUp() { $this->plugin = new MiscCustomPropertiesBackend( $this->tree, \OC::$server->getDatabaseConnection(), - $this->user + $this->user, + \OC::$server->getRootFolder() ); $connection = \OC::$server->getDatabaseConnection();