Skip to content

Commit

Permalink
Keep properties when file goes to trashbin
Browse files Browse the repository at this point in the history
  • Loading branch information
VicDeo committed Jul 30, 2019
1 parent abd3ca2 commit a12f45d
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 6 deletions.
10 changes: 9 additions & 1 deletion apps/dav/lib/DAV/AbstractCustomPropertiesBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

namespace OCA\DAV\DAV;

use OCP\Files\IRootFolder;
use OCP\IDBConnection;
use OCP\IUser;
use Sabre\DAV\Exception\Forbidden;
Expand Down Expand Up @@ -66,6 +67,11 @@ abstract class AbstractCustomPropertiesBackend implements BackendInterface {
*/
protected $user;

/**
* @var IRootFolder
*/
protected $rootFolder;

/**
* Property cache for the filesystem items
* @var array
Expand All @@ -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;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions apps/dav/lib/DAV/FileCustomPropertiesBackend.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions apps/dav/lib/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
6 changes: 4 additions & 2 deletions apps/dav/tests/unit/DAV/FileCustomPropertiesBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(
Expand Down
3 changes: 2 additions & 1 deletion apps/dav/tests/unit/DAV/MiscCustomPropertiesBackendTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit a12f45d

Please sign in to comment.