Add propfind properties to trashbin
* get original filename (without the weird timestamp) * get original location Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
parent
cb617c4949
commit
d5937e0fd6
|
@ -40,5 +40,8 @@ To prevent a user from running out of disk space, the Deleted files app will not
|
|||
<collections>
|
||||
<collection>OCA\Files_Trashbin\Sabre\RootCollection</collection>
|
||||
</collections>
|
||||
<plugins>
|
||||
<plugin>OCA\Files_Trashbin\Sabre\PropfindPlugin</plugin>
|
||||
</plugins>
|
||||
</sabre>
|
||||
</info>
|
||||
|
|
|
@ -19,6 +19,7 @@ return array(
|
|||
'OCA\\Files_Trashbin\\Helper' => $baseDir . '/../lib/Helper.php',
|
||||
'OCA\\Files_Trashbin\\Hooks' => $baseDir . '/../lib/Hooks.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\ITrash' => $baseDir . '/../lib/Sabre/ITrash.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\PropfindPlugin' => $baseDir . '/../lib/Sabre/PropfindPlugin.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\RestoreFolder' => $baseDir . '/../lib/Sabre/RestoreFolder.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\RootCollection' => $baseDir . '/../lib/Sabre/RootCollection.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\TrashFile' => $baseDir . '/../lib/Sabre/TrashFile.php',
|
||||
|
|
|
@ -34,6 +34,7 @@ class ComposerStaticInitFiles_Trashbin
|
|||
'OCA\\Files_Trashbin\\Helper' => __DIR__ . '/..' . '/../lib/Helper.php',
|
||||
'OCA\\Files_Trashbin\\Hooks' => __DIR__ . '/..' . '/../lib/Hooks.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\ITrash' => __DIR__ . '/..' . '/../lib/Sabre/ITrash.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\PropfindPlugin' => __DIR__ . '/..' . '/../lib/Sabre/PropfindPlugin.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\RestoreFolder' => __DIR__ . '/..' . '/../lib/Sabre/RestoreFolder.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\RootCollection' => __DIR__ . '/..' . '/../lib/Sabre/RootCollection.php',
|
||||
'OCA\\Files_Trashbin\\Sabre\\TrashFile' => __DIR__ . '/..' . '/../lib/Sabre/TrashFile.php',
|
||||
|
|
|
@ -24,4 +24,8 @@ namespace OCA\Files_Trashbin\Sabre;
|
|||
|
||||
interface ITrash {
|
||||
public function restore(): bool;
|
||||
|
||||
public function getFilename(): string;
|
||||
|
||||
public function getOriginalLocation(): string;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
<?php
|
||||
/**
|
||||
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @author Roeland Jago Douma <roeland@famdouma.nl>
|
||||
*
|
||||
* @license GNU AGPL version 3 or any later version
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
namespace OCA\Files_Trashbin\Sabre;
|
||||
|
||||
use Sabre\DAV\INode;
|
||||
use Sabre\DAV\PropFind;
|
||||
use Sabre\DAV\Server;
|
||||
use Sabre\DAV\ServerPlugin;
|
||||
|
||||
class PropfindPlugin extends ServerPlugin {
|
||||
|
||||
const TRASHBIN_FILENAME = '{http://nextcloud.org/ns}trashbin-filename';
|
||||
const TRASHBIN_ORIGINAL_LOCATION = '{http://nextcloud.org/ns}trashbin-original-location';
|
||||
|
||||
/** @var Server */
|
||||
private $server;
|
||||
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
public function initialize(Server $server) {
|
||||
$this->server = $server;
|
||||
|
||||
$this->server->on('propFind', [$this, 'propFind']);
|
||||
}
|
||||
|
||||
|
||||
public function propFind(PropFind $propFind, INode $node) {
|
||||
if (!($node instanceof ITrash)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$propFind->handle(self::TRASHBIN_FILENAME, function() use ($node) {
|
||||
return $node->getFilename();
|
||||
});
|
||||
|
||||
$propFind->handle(self::TRASHBIN_ORIGINAL_LOCATION, function() use ($node) {
|
||||
return $node->getOriginalLocation();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
|
@ -78,4 +78,13 @@ class TrashFile implements IFile, ITrash {
|
|||
return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
|
||||
}
|
||||
|
||||
public function getFilename(): string {
|
||||
return $this->data->getName();
|
||||
}
|
||||
|
||||
public function getOriginalLocation(): string {
|
||||
return $this->data['extraData'];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -52,9 +52,9 @@ class TrashFolder implements ICollection, ITrash {
|
|||
foreach ($entries as $entry) {
|
||||
if ($entry->getName() === $name) {
|
||||
if ($entry->getMimetype() === 'httpd/unix-directory') {
|
||||
return new TrashFolderFolder($this->getName(), $this->userId, $entry);
|
||||
return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
|
||||
}
|
||||
return new TrashFolderFile($this->getName(), $this->userId, $entry);
|
||||
return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -64,9 +64,9 @@ class TrashFolder implements ICollection, ITrash {
|
|||
|
||||
$children = array_map(function (FileInfo $entry) {
|
||||
if ($entry->getMimetype() === 'httpd/unix-directory') {
|
||||
return new TrashFolderFolder($this->getName(), $this->userId, $entry);
|
||||
return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
|
||||
}
|
||||
return new TrashFolderFile($this->getName(), $this->userId, $entry);
|
||||
return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
|
||||
}, $entries);
|
||||
|
||||
return $children;
|
||||
|
@ -104,5 +104,13 @@ class TrashFolder implements ICollection, ITrash {
|
|||
return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
|
||||
}
|
||||
|
||||
public function getFilename(): string {
|
||||
return $this->data->getName();
|
||||
}
|
||||
|
||||
public function getOriginalLocation(): string {
|
||||
return $this->data['extraData'];
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -36,10 +36,17 @@ class TrashFolderFile implements IFile, ITrash {
|
|||
/** @var FileInfo */
|
||||
private $data;
|
||||
|
||||
public function __construct(string $root, string $userId, FileInfo $data) {
|
||||
/** @var string */
|
||||
private $location;
|
||||
|
||||
public function __construct(string $root,
|
||||
string $userId,
|
||||
FileInfo $data,
|
||||
string $location) {
|
||||
$this->root = $root;
|
||||
$this->userId = $userId;
|
||||
$this->data = $data;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
public function put($data) {
|
||||
|
@ -82,4 +89,13 @@ class TrashFolderFile implements IFile, ITrash {
|
|||
return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
|
||||
}
|
||||
|
||||
public function getFilename(): string {
|
||||
return $this->data->getName();
|
||||
}
|
||||
|
||||
public function getOriginalLocation(): string {
|
||||
return $this->location . '/' . $this->getFilename();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -38,10 +38,17 @@ class TrashFolderFolder implements ICollection, ITrash {
|
|||
/** @var FileInfo */
|
||||
private $data;
|
||||
|
||||
public function __construct(string $root, string $userId, FileInfo $data) {
|
||||
/** @var string */
|
||||
private $location;
|
||||
|
||||
public function __construct(string $root,
|
||||
string $userId,
|
||||
FileInfo $data,
|
||||
string $location) {
|
||||
$this->root = $root;
|
||||
$this->userId = $userId;
|
||||
$this->data = $data;
|
||||
$this->location = $location;
|
||||
}
|
||||
|
||||
public function createFile($name, $data = null) {
|
||||
|
@ -58,9 +65,9 @@ class TrashFolderFolder implements ICollection, ITrash {
|
|||
foreach ($entries as $entry) {
|
||||
if ($entry->getName() === $name) {
|
||||
if ($entry->getMimetype() === 'httpd/unix-directory') {
|
||||
return new TrashFolderFolder($this->root . '/' . $this->getName(), $this->userId, $entry);
|
||||
return new TrashFolderFolder($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation());
|
||||
}
|
||||
return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry);
|
||||
return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -70,9 +77,9 @@ class TrashFolderFolder implements ICollection, ITrash {
|
|||
|
||||
$children = array_map(function (FileInfo $entry) {
|
||||
if ($entry->getMimetype() === 'httpd/unix-directory') {
|
||||
return new TrashFolderFolder($this->root.'/'.$this->getName(), $this->userId, $entry);
|
||||
return new TrashFolderFolder($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation());
|
||||
}
|
||||
return new TrashFolderFile($this->root.'/'.$this->getName(), $this->userId, $entry);
|
||||
return new TrashFolderFile($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation());
|
||||
}, $entries);
|
||||
|
||||
return $children;
|
||||
|
@ -111,4 +118,13 @@ class TrashFolderFolder implements ICollection, ITrash {
|
|||
return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
|
||||
}
|
||||
|
||||
public function getFilename(): string {
|
||||
return $this->data->getName();
|
||||
}
|
||||
|
||||
public function getOriginalLocation(): string {
|
||||
return $this->location . '/' . $this->getFilename();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue