Add folder for trashbin

The trashbin home now contains 2 entries restore and trash.

Made all files strict. Added more types.

Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
pull/9202/head
Roeland Jago Douma 7 years ago
parent dadc740db5
commit c625fc5931
No known key found for this signature in database
GPG Key ID: F941078878347C0C
  1. 1
      apps/files_trashbin/composer/composer/autoload_classmap.php
  2. 1
      apps/files_trashbin/composer/composer/autoload_static.php
  3. 1
      apps/files_trashbin/lib/Sabre/ITrash.php
  4. 1
      apps/files_trashbin/lib/Sabre/PropfindPlugin.php
  5. 8
      apps/files_trashbin/lib/Sabre/RestoreFolder.php
  6. 5
      apps/files_trashbin/lib/Sabre/RootCollection.php
  7. 11
      apps/files_trashbin/lib/Sabre/TrashFile.php
  8. 14
      apps/files_trashbin/lib/Sabre/TrashFolder.php
  9. 11
      apps/files_trashbin/lib/Sabre/TrashFolderFile.php
  10. 15
      apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
  11. 61
      apps/files_trashbin/lib/Sabre/TrashHome.php
  12. 103
      apps/files_trashbin/lib/Sabre/TrashRoot.php

@ -27,6 +27,7 @@ return array(
'OCA\\Files_Trashbin\\Sabre\\TrashFolderFile' => $baseDir . '/../lib/Sabre/TrashFolderFile.php',
'OCA\\Files_Trashbin\\Sabre\\TrashFolderFolder' => $baseDir . '/../lib/Sabre/TrashFolderFolder.php',
'OCA\\Files_Trashbin\\Sabre\\TrashHome' => $baseDir . '/../lib/Sabre/TrashHome.php',
'OCA\\Files_Trashbin\\Sabre\\TrashRoot' => $baseDir . '/../lib/Sabre/TrashRoot.php',
'OCA\\Files_Trashbin\\Storage' => $baseDir . '/../lib/Storage.php',
'OCA\\Files_Trashbin\\Trashbin' => $baseDir . '/../lib/Trashbin.php',
);

@ -42,6 +42,7 @@ class ComposerStaticInitFiles_Trashbin
'OCA\\Files_Trashbin\\Sabre\\TrashFolderFile' => __DIR__ . '/..' . '/../lib/Sabre/TrashFolderFile.php',
'OCA\\Files_Trashbin\\Sabre\\TrashFolderFolder' => __DIR__ . '/..' . '/../lib/Sabre/TrashFolderFolder.php',
'OCA\\Files_Trashbin\\Sabre\\TrashHome' => __DIR__ . '/..' . '/../lib/Sabre/TrashHome.php',
'OCA\\Files_Trashbin\\Sabre\\TrashRoot' => __DIR__ . '/..' . '/../lib/Sabre/TrashRoot.php',
'OCA\\Files_Trashbin\\Storage' => __DIR__ . '/..' . '/../lib/Storage.php',
'OCA\\Files_Trashbin\\Trashbin' => __DIR__ . '/..' . '/../lib/Trashbin.php',
);

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*

@ -63,19 +63,19 @@ class RestoreFolder implements ICollection, IMoveTarget {
throw new Forbidden();
}
public function getLastModified() {
public function getLastModified(): int {
return 0;
}
public function getChildren() {
public function getChildren(): array {
return [];
}
public function childExists($name) {
public function childExists($name): bool {
return false;
}
function moveInto($targetName, $sourcePath, INode $sourceNode) {
public function moveInto($targetName, $sourcePath, INode $sourceNode): bool {
if (!($sourceNode instanceof ITrash)) {
return false;
}

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*
@ -42,7 +43,7 @@ class RootCollection extends AbstractPrincipalCollection {
* @param array $principalInfo
* @return INode
*/
public function getChildForPrincipal(array $principalInfo) {
public function getChildForPrincipal(array $principalInfo): TrashHome {
list(,$name) = \Sabre\Uri\split($principalInfo['uri']);
$user = \OC::$server->getUserSession()->getUser();
if (is_null($user) || $name !== $user->getUID()) {
@ -51,7 +52,7 @@ class RootCollection extends AbstractPrincipalCollection {
return new TrashHome($principalInfo);
}
public function getName() {
public function getName(): string {
return 'trashbin';
}

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*
@ -46,15 +47,15 @@ class TrashFile implements IFile, ITrash {
return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb');
}
public function getContentType() {
public function getContentType(): string {
return $this->data->getMimetype();
}
public function getETag() {
public function getETag(): string {
return $this->data->getEtag();
}
public function getSize() {
public function getSize(): int {
return $this->data->getSize();
}
@ -62,7 +63,7 @@ class TrashFile implements IFile, ITrash {
\OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified());
}
public function getName() {
public function getName(): string {
return $this->data->getName() . '.d' . $this->getLastModified();
}
@ -70,7 +71,7 @@ class TrashFile implements IFile, ITrash {
throw new Forbidden();
}
public function getLastModified() {
public function getLastModified(): int {
return $this->data->getMtime();
}

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*
@ -24,6 +25,7 @@ namespace OCA\Files_Trashbin\Sabre;
use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
class TrashFolder implements ICollection, ITrash {
@ -46,7 +48,7 @@ class TrashFolder implements ICollection, ITrash {
throw new Forbidden();
}
public function getChild($name) {
public function getChild($name): ITrash {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
foreach ($entries as $entry) {
@ -57,9 +59,11 @@ class TrashFolder implements ICollection, ITrash {
return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
}
}
throw new NotFound();
}
public function getChildren() {
public function getChildren(): array {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
$children = array_map(function (FileInfo $entry) {
@ -72,7 +76,7 @@ class TrashFolder implements ICollection, ITrash {
return $children;
}
public function childExists($name) {
public function childExists($name): bool {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
foreach ($entries as $entry) {
@ -88,7 +92,7 @@ class TrashFolder implements ICollection, ITrash {
\OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified());
}
public function getName() {
public function getName(): string {
return $this->data->getName() . '.d' . $this->getLastModified();
}
@ -96,7 +100,7 @@ class TrashFolder implements ICollection, ITrash {
throw new Forbidden();
}
public function getLastModified() {
public function getLastModified(): int {
return $this->data->getMtime();
}

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*
@ -57,15 +58,15 @@ class TrashFolderFile implements IFile, ITrash {
return $this->data->getStorage()->fopen($this->data->getInternalPath(), 'rb');
}
public function getContentType() {
public function getContentType(): string {
return $this->data->getMimetype();
}
public function getETag() {
public function getETag(): string {
return $this->data->getEtag();
}
public function getSize() {
public function getSize(): int {
return $this->data->getSize();
}
@ -73,7 +74,7 @@ class TrashFolderFile implements IFile, ITrash {
\OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null);
}
public function getName() {
public function getName(): string {
return $this->data->getName();
}
@ -81,7 +82,7 @@ class TrashFolderFile implements IFile, ITrash {
throw new Forbidden();
}
public function getLastModified() {
public function getLastModified(): int {
return $this->data->getMtime();
}

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*
@ -24,6 +25,7 @@ namespace OCA\Files_Trashbin\Sabre;
use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
class TrashFolderFolder implements ICollection, ITrash {
@ -31,7 +33,6 @@ class TrashFolderFolder implements ICollection, ITrash {
/** @var string */
private $root;
/** @var string */
private $userId;
@ -59,7 +60,7 @@ class TrashFolderFolder implements ICollection, ITrash {
throw new Forbidden();
}
public function getChild($name) {
public function getChild($name): ITrash {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId);
foreach ($entries as $entry) {
@ -70,9 +71,11 @@ class TrashFolderFolder implements ICollection, ITrash {
return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation());
}
}
throw new NotFound();
}
public function getChildren() {
public function getChildren(): array {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId);
$children = array_map(function (FileInfo $entry) {
@ -85,7 +88,7 @@ class TrashFolderFolder implements ICollection, ITrash {
return $children;
}
public function childExists($name) {
public function childExists($name): bool {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId);
foreach ($entries as $entry) {
@ -101,7 +104,7 @@ class TrashFolderFolder implements ICollection, ITrash {
\OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null);
}
public function getName() {
public function getName(): string {
return $this->data->getName();
}
@ -110,7 +113,7 @@ class TrashFolderFolder implements ICollection, ITrash {
throw new Forbidden();
}
function getLastModified() {
public function getLastModified(): int {
return $this->data->getMtime();
}

@ -1,4 +1,5 @@
<?php
declare(strict_types=1);
/**
* @copyright 2018, Roeland Jago Douma <roeland@famdouma.nl>
*
@ -22,29 +23,21 @@
*/
namespace OCA\Files_Trashbin\Sabre;
use OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
class TrashHome implements ICollection {
/**
* @var array
*/
/** @var array */
private $principalInfo;
/**
* FilesHome constructor.
*
* @param array $principalInfo
*/
public function __construct($principalInfo) {
public function __construct(array $principalInfo) {
$this->principalInfo = $principalInfo;
}
public function delete() {
\OCA\Files_Trashbin\Trashbin::deleteAll();
throw new Forbidden();
}
public function getName(): string {
@ -70,53 +63,27 @@ class TrashHome implements ICollection {
if ($name === 'restore') {
return new RestoreFolder($userId);
}
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $userId);
foreach ($entries as $entry) {
if ($entry->getName() . '.d'.$entry->getMtime() === $name) {
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
return new TrashFolder('/', $userId, $entry);
}
return new TrashFile($userId, $entry);
}
if ($name === 'trash') {
return new TrashRoot($userId);
}
throw new NotFound();
}
public function getChildren() {
public function getChildren(): array {
list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']);
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $userId);
$children = array_map(function (FileInfo $entry) use ($userId) {
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
return new TrashFolder('/', $userId, $entry);
}
return new TrashFile($userId, $entry);
}, $entries);
$children[] = new RestoreFolder($userId);
return $children;
return [
new RestoreFolder($userId),
new TrashRoot($userId),
];
}
public function childExists($name) {
list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']);
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $userId);
foreach ($entries as $entry) {
if ($entry->getName() . '.d'.$entry->getMtime() === $name) {
return true;
}
}
return false;
public function childExists($name): bool {
return $name === 'restore' || $name === 'trash';
}
public function getLastModified() {
public function getLastModified(): int {
return 0;
}
}

@ -0,0 +1,103 @@
<?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 OCP\Files\FileInfo;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
class TrashRoot implements ICollection {
/** @var string */
private $userId;
public function __construct(string $userId) {
$this->userId = $userId;
}
public function delete() {
\OCA\Files_Trashbin\Trashbin::deleteAll();
}
public function getName(): string {
return 'trash';
}
public function setName($name) {
throw new Forbidden('Permission denied to rename this trashbin');
}
public function createFile($name, $data = null) {
throw new Forbidden('Not allowed to create files in the trashbin');
}
public function createDirectory($name) {
throw new Forbidden('Not allowed to create folders in the trashbin');
}
public function getChild($name): ITrash {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->userId);
foreach ($entries as $entry) {
if ($entry->getName() . '.d'.$entry->getMtime() === $name) {
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
return new TrashFolder('/', $this->userId, $entry);
}
return new TrashFile($this->userId, $entry);
}
}
throw new NotFound();
}
public function getChildren(): array {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->userId);
$children = array_map(function (FileInfo $entry) {
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
return new TrashFolder('/', $this->userId, $entry);
}
return new TrashFile($this->userId, $entry);
}, $entries);
return $children;
}
public function childExists($name): bool {
$entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->userId);
foreach ($entries as $entry) {
if ($entry->getName() . '.d'.$entry->getMtime() === $name) {
return true;
}
}
return false;
}
public function getLastModified(): int {
return 0;
}
}
Loading…
Cancel
Save