Add special restore folder

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
This commit is contained in:
Roeland Jago Douma 2018-04-16 17:02:50 +02:00
parent f7ca6149d6
commit cb617c4949
No known key found for this signature in database
GPG Key ID: F941078878347C0C
9 changed files with 145 additions and 4 deletions

View File

@ -18,6 +18,8 @@ return array(
'OCA\\Files_Trashbin\\Expiration' => $baseDir . '/../lib/Expiration.php',
'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\\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',
'OCA\\Files_Trashbin\\Sabre\\TrashFolder' => $baseDir . '/../lib/Sabre/TrashFolder.php',

View File

@ -33,6 +33,8 @@ class ComposerStaticInitFiles_Trashbin
'OCA\\Files_Trashbin\\Expiration' => __DIR__ . '/..' . '/../lib/Expiration.php',
'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\\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',
'OCA\\Files_Trashbin\\Sabre\\TrashFolder' => __DIR__ . '/..' . '/../lib/Sabre/TrashFolder.php',

View File

@ -0,0 +1,27 @@
<?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;
interface ITrash {
public function restore(): bool;
}

View File

@ -0,0 +1,86 @@
<?php
declare(strict_types=1);
/**
* @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\Exception\Forbidden;
use Sabre\DAV\ICollection;
use Sabre\DAV\IMoveTarget;
use Sabre\DAV\INode;
class RestoreFolder implements ICollection, IMoveTarget {
/** @var string */
protected $userId;
public function __construct(string $userId) {
$this->userId = $userId;
}
public function createFile($name, $data = null) {
throw new Forbidden();
}
public function createDirectory($name) {
throw new Forbidden();
}
public function getChild($name) {
return null;
}
public function delete() {
throw new Forbidden();
}
public function getName() {
return 'restore';
}
public function setName($name) {
throw new Forbidden();
}
public function getLastModified() {
return 0;
}
public function getChildren() {
return [];
}
public function childExists($name) {
return false;
}
function moveInto($targetName, $sourcePath, INode $sourceNode) {
if (!($sourceNode instanceof ITrash)) {
return false;
}
return $sourceNode->restore();
}
}

View File

@ -26,7 +26,7 @@ use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\IFile;
class TrashFile implements IFile {
class TrashFile implements IFile, ITrash {
/** @var string */
private $userId;
@ -74,4 +74,8 @@ class TrashFile implements IFile {
return $this->data->getMtime();
}
public function restore(): bool {
return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
}
}

View File

@ -26,7 +26,7 @@ use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\ICollection;
class TrashFolder implements ICollection {
class TrashFolder implements ICollection, ITrash {
/** @var string */
private $userId;
@ -99,4 +99,10 @@ class TrashFolder implements ICollection {
public function getLastModified() {
return $this->data->getMtime();
}
public function restore(): bool {
return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
}
}

View File

@ -26,7 +26,7 @@ use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\IFile;
class TrashFolderFile implements IFile {
class TrashFolderFile implements IFile, ITrash {
/** @var string */
private $root;
@ -78,4 +78,8 @@ class TrashFolderFile implements IFile {
return $this->data->getMtime();
}
public function restore(): bool {
return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
}
}

View File

@ -26,7 +26,7 @@ use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\ICollection;
class TrashFolderFolder implements ICollection {
class TrashFolderFolder implements ICollection, ITrash {
/** @var string */
private $root;
@ -107,4 +107,8 @@ class TrashFolderFolder implements ICollection {
return $this->data->getMtime();
}
public function restore(): bool {
return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
}
}

View File

@ -67,6 +67,10 @@ class TrashHome implements ICollection {
public function getChild($name) {
list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']);
if ($name === 'restore') {
return new RestoreFolder($userId);
}
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $userId);
foreach ($entries as $entry) {
@ -93,6 +97,8 @@ class TrashHome implements ICollection {
return new TrashFile($userId, $entry);
}, $entries);
$children[] = new RestoreFolder($userId);
return $children;
}