aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Sabre
diff options
context:
space:
mode:
authorRobin Appelman <robin@icewind.nl>2018-09-10 14:40:35 +0200
committerRobin Appelman <robin@icewind.nl>2018-10-17 14:56:45 +0200
commit4adac445dc57d1ccc7f26e21018e1e731e5b1654 (patch)
treeb3da061a9332a1ebca2809a61ea3cf186d9fb259 /apps/files_trashbin/lib/Sabre
parent2634ceb35b72eac94e6bf4c61640036392c5f97f (diff)
downloadnextcloud-server-4adac445dc57d1ccc7f26e21018e1e731e5b1654.tar.gz
nextcloud-server-4adac445dc57d1ccc7f26e21018e1e731e5b1654.zip
fix select statement
fix select statement Make trashbin api modules Apps can register trashbin backends for specific storages, allowing them to modify trashbin behavior for storages The old trashbin implementation has been wrapped in a "legacy" backend, for future work this can be replaced with a new backend that better handles shares while still keeping the legacy backend around to keep existing trash from being accessible Signed-off-by: Robin Appelman <robin@icewind.nl>
Diffstat (limited to 'apps/files_trashbin/lib/Sabre')
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrash.php31
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrashFile.php36
-rw-r--r--apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php77
-rw-r--r--apps/files_trashbin/lib/Sabre/RootCollection.php15
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFile.php37
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolder.php78
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolderFile.php44
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashFolderFolder.php91
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashHome.php30
-rw-r--r--apps/files_trashbin/lib/Sabre/TrashRoot.php57
10 files changed, 209 insertions, 287 deletions
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrash.php b/apps/files_trashbin/lib/Sabre/AbstractTrash.php
index 43f9cc02749..5d4b19513a4 100644
--- a/apps/files_trashbin/lib/Sabre/AbstractTrash.php
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrash.php
@@ -1,4 +1,5 @@
<?php
+declare(strict_types=1);
/**
* @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
*
@@ -21,13 +22,24 @@
namespace OCA\Files_Trashbin\Sabre;
+use OCA\Files_Trashbin\Trash\ITrashItem;
+use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Files\FileInfo;
+use OCP\IUser;
abstract class AbstractTrash implements ITrash {
- /** @var FileInfo */
+ /** @var ITrashItem */
protected $data;
- public function __construct(FileInfo $data) {
+ /** @var ITrashManager */
+ protected $trashManager;
+
+ /** @var IUser */
+ protected $user;
+
+ public function __construct(ITrashManager $trashManager, IUser $user, ITrashItem $data) {
+ $this->trashManager = $trashManager;
+ $this->user = $user;
$this->data = $data;
}
@@ -36,7 +48,7 @@ abstract class AbstractTrash implements ITrash {
}
public function getDeletionTime(): int {
- return $this->data->getMtime();
+ return $this->data->getDeletedTime();
}
public function getFileId(): int {
@@ -66,4 +78,17 @@ abstract class AbstractTrash implements ITrash {
public function getName(): string {
return $this->data->getName();
}
+
+ public function getOriginalLocation(): string {
+ return $this->data->getOriginalLocation($this->user);
+ }
+
+ public function delete() {
+ $this->trashManager->removeItem($this->user, $this->data);
+ }
+
+ public function restore(): bool {
+ $this->trashManager->restoreItem($this->data);
+ return true;
+ }
}
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php b/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php
new file mode 100644
index 00000000000..da7c94eb35d
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrashFile.php
@@ -0,0 +1,36 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.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\IFile;
+
+abstract class AbstractTrashFile extends AbstractTrash implements IFile , ITrash{
+ public function put($data) {
+ throw new Forbidden();
+ }
+
+ public function setName($name) {
+ throw new Forbidden();
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php b/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php
new file mode 100644
index 00000000000..19a6ba2d3fb
--- /dev/null
+++ b/apps/files_trashbin/lib/Sabre/AbstractTrashFolder.php
@@ -0,0 +1,77 @@
+<?php
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.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 OCA\Files_Trashbin\Trash\ITrashItem;
+use OCP\Files\FileInfo;
+use Sabre\DAV\Exception\Forbidden;
+use Sabre\DAV\Exception\NotFound;
+use Sabre\DAV\ICollection;
+
+abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
+ public function getChildren(): array {
+ $entries = $this->trashManager->listTrashFolder($this->user, $this->data);
+
+ $children = array_map(function (ITrashItem $entry) {
+ if ($entry->getType() === FileInfo::TYPE_FOLDER) {
+ return new TrashFolderFolder($this->trashManager, $this->user, $entry);
+ }
+ return new TrashFolderFile($this->trashManager, $this->user, $entry);
+ }, $entries);
+
+ return $children;
+ }
+
+ public function getChild($name): ITrash {
+ $entries = $this->getChildren();
+
+ foreach ($entries as $entry) {
+ if ($entry->getName() === $name) {
+ return $entry;
+ }
+ }
+
+ throw new NotFound();
+ }
+
+ public function childExists($name): bool {
+ try {
+ $this->getChild($name);
+ return true;
+ } catch (NotFound $e) {
+ return false;
+ }
+ }
+
+ public function setName($name) {
+ throw new Forbidden();
+ }
+
+ public function createFile($name, $data = null) {
+ throw new Forbidden();
+ }
+
+ public function createDirectory($name) {
+ throw new Forbidden();
+ }
+}
diff --git a/apps/files_trashbin/lib/Sabre/RootCollection.php b/apps/files_trashbin/lib/Sabre/RootCollection.php
index be31d200f71..0b55953aa3f 100644
--- a/apps/files_trashbin/lib/Sabre/RootCollection.php
+++ b/apps/files_trashbin/lib/Sabre/RootCollection.php
@@ -21,18 +21,27 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace OCA\Files_Trashbin\Sabre;
+use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\IConfig;
use Sabre\DAV\INode;
use Sabre\DAVACL\AbstractPrincipalCollection;
use Sabre\DAVACL\PrincipalBackend;
class RootCollection extends AbstractPrincipalCollection {
+ /** @var ITrashManager */
+ private $trashManager;
- public function __construct(PrincipalBackend\BackendInterface $principalBackend, IConfig $config) {
+ public function __construct(
+ ITrashManager $trashManager,
+ PrincipalBackend\BackendInterface $principalBackend,
+ IConfig $config
+ ) {
parent::__construct($principalBackend, 'principals/users');
+ $this->trashManager = $trashManager;
$this->disableListing = !$config->getSystemValue('debug', false);
}
@@ -47,12 +56,12 @@ class RootCollection extends AbstractPrincipalCollection {
* @return INode
*/
public function getChildForPrincipal(array $principalInfo): TrashHome {
- list(,$name) = \Sabre\Uri\split($principalInfo['uri']);
+ list(, $name) = \Sabre\Uri\split($principalInfo['uri']);
$user = \OC::$server->getUserSession()->getUser();
if (is_null($user) || $name !== $user->getUID()) {
throw new \Sabre\DAV\Exception\Forbidden();
}
- return new TrashHome($principalInfo);
+ return new TrashHome($principalInfo, $this->trashManager, $user);
}
public function getName(): string {
diff --git a/apps/files_trashbin/lib/Sabre/TrashFile.php b/apps/files_trashbin/lib/Sabre/TrashFile.php
index 840ca6a1938..dd6500e5b81 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFile.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFile.php
@@ -21,46 +21,15 @@ declare(strict_types=1);
* 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\IFile;
-
-class TrashFile extends AbstractTrash implements IFile, ITrash {
- /** @var string */
- private $userId;
-
- public function __construct(string $userId, FileInfo $data) {
- $this->userId = $userId;
- parent::__construct($data);
- }
- public function put($data) {
- throw new Forbidden();
- }
+namespace OCA\Files_Trashbin\Sabre;
+class TrashFile extends AbstractTrashFile {
public function get() {
- return $this->data->getStorage()->fopen($this->data->getInternalPath().'.d'.$this->getLastModified(), 'rb');
- }
-
- public function delete() {
- \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified());
+ return $this->data->getStorage()->fopen($this->data->getInternalPath() . '.d' . $this->getLastModified(), 'rb');
}
public function getName(): string {
return $this->data->getName() . '.d' . $this->getLastModified();
}
-
- public function setName($name) {
- throw new Forbidden();
- }
-
- public function restore(): bool {
- return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
- }
-
- public function getOriginalLocation(): string {
- return $this->data['extraData'];
- }
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolder.php
index d884eefcc9f..108aaf4f312 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolder.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolder.php
@@ -23,85 +23,9 @@ declare(strict_types=1);
*/
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 extends AbstractTrash implements ICollection, ITrash {
- /** @var string */
- private $userId;
-
- public function __construct(string $root, string $userId, FileInfo $data) {
- $this->userId = $userId;
- parent::__construct($data);
- }
-
- public function createFile($name, $data = null) {
- throw new Forbidden();
- }
-
- public function createDirectory($name) {
- throw new Forbidden();
- }
-
- public function getChild($name): ITrash {
- $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
-
- foreach ($entries as $entry) {
- if ($entry->getName() === $name) {
- if ($entry->getType() === FileInfo::TYPE_FOLDER) {
- return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
- }
- return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
- }
- }
-
- throw new NotFound();
- }
-
- public function getChildren(): array {
- $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
-
- $children = array_map(function (FileInfo $entry) {
- if ($entry->getType() === FileInfo::TYPE_FOLDER) {
- return new TrashFolderFolder($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
- }
- return new TrashFolderFile($this->getName(), $this->userId, $entry, $this->getOriginalLocation());
- }, $entries);
-
- return $children;
- }
-
- public function childExists($name): bool {
- $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->getName(), $this->userId);
-
- foreach ($entries as $entry) {
- if ($entry->getName() === $name) {
- return true;
- }
- }
-
- return false;
- }
-
- public function delete() {
- \OCA\Files_Trashbin\Trashbin::delete($this->data->getName(), $this->userId, $this->getLastModified());
- }
+class TrashFolder extends AbstractTrashFolder {
public function getName(): string {
return $this->data->getName() . '.d' . $this->getLastModified();
}
-
- public function setName($name) {
- throw new Forbidden();
- }
-
- public function restore(): bool {
- return \OCA\Files_Trashbin\Trashbin::restore($this->getName(), $this->data->getName(), $this->getLastModified());
- }
-
- public function getOriginalLocation(): string {
- return $this->data['extraData'];
- }
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
index 3e28d048b42..31ee9535b72 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolderFile.php
@@ -23,51 +23,9 @@ declare(strict_types=1);
*/
namespace OCA\Files_Trashbin\Sabre;
-use OCP\Files\FileInfo;
-use Sabre\DAV\Exception\Forbidden;
-use Sabre\DAV\IFile;
-
-class TrashFolderFile extends AbstractTrash implements IFile, ITrash {
- /** @var string */
- private $root;
-
- /** @var string */
- private $userId;
-
- /** @var string */
- private $location;
-
- public function __construct(string $root,
- string $userId,
- FileInfo $data,
- string $location) {
- $this->root = $root;
- $this->userId = $userId;
- $this->location = $location;
- parent::__construct($data);
- }
-
- public function put($data) {
- throw new Forbidden();
- }
+class TrashFolderFile extends AbstractTrashFile {
public function get() {
return $this->data->getStorage()->fopen($this->data->getInternalPath(), 'rb');
}
-
- public function delete() {
- \OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null);
- }
-
- public function setName($name) {
- throw new Forbidden();
- }
-
- public function restore(): bool {
- return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
- }
-
- public function getOriginalLocation(): string {
- return $this->location . '/' . $this->getFilename();
- }
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
index 4ee9a0e2db0..5332b7dd4c0 100644
--- a/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
+++ b/apps/files_trashbin/lib/Sabre/TrashFolderFolder.php
@@ -21,95 +21,8 @@ declare(strict_types=1);
* 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 TrashFolderFolder extends AbstractTrash implements ICollection, ITrash {
-
- /** @var string */
- private $root;
-
- /** @var string */
- private $userId;
-
- /** @var string */
- private $location;
-
- public function __construct(string $root,
- string $userId,
- FileInfo $data,
- string $location) {
- $this->root = $root;
- $this->userId = $userId;
- $this->location = $location;
- parent::__construct($data);
- }
-
- public function createFile($name, $data = null) {
- throw new Forbidden();
- }
-
- public function createDirectory($name) {
- throw new Forbidden();
- }
-
- public function getChild($name): ITrash {
- $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId);
-
- foreach ($entries as $entry) {
- if ($entry->getName() === $name) {
- if ($entry->getType() === FileInfo::TYPE_FOLDER) {
- return new TrashFolderFolder($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation());
- }
- return new TrashFolderFile($this->root . '/' . $this->getName(), $this->userId, $entry, $this->getOriginalLocation());
- }
- }
- throw new NotFound();
- }
-
- public function getChildren(): array {
- $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId);
-
- $children = array_map(function (FileInfo $entry) {
- if ($entry->getType() === FileInfo::TYPE_FOLDER) {
- return new TrashFolderFolder($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation());
- }
- return new TrashFolderFile($this->root.'/'.$this->getName(), $this->userId, $entry, $this->getOriginalLocation());
- }, $entries);
-
- return $children;
- }
-
- public function childExists($name): bool {
- $entries = \OCA\Files_Trashbin\Helper::getTrashFiles($this->root . '/' . $this->getName(), $this->userId);
-
- foreach ($entries as $entry) {
- if ($entry->getName() === $name) {
- return true;
- }
- }
-
- return false;
- }
-
- public function delete() {
- \OCA\Files_Trashbin\Trashbin::delete($this->root . '/' . $this->getName(), $this->userId, null);
- }
-
- public function setName($name) {
- throw new Forbidden();
- }
-
- public function restore(): bool {
- return \OCA\Files_Trashbin\Trashbin::restore($this->root . '/' . $this->getName(), $this->data->getName(), null);
- }
+namespace OCA\Files_Trashbin\Sabre;
- public function getOriginalLocation(): string {
- return $this->location . '/' . $this->getFilename();
- }
+class TrashFolderFolder extends AbstractTrashFolder {
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashHome.php b/apps/files_trashbin/lib/Sabre/TrashHome.php
index d1c50c9c6a3..416b88635a4 100644
--- a/apps/files_trashbin/lib/Sabre/TrashHome.php
+++ b/apps/files_trashbin/lib/Sabre/TrashHome.php
@@ -21,19 +21,33 @@ declare(strict_types=1);
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/
+
namespace OCA\Files_Trashbin\Sabre;
+use OCA\Files_Trashbin\Trash\ITrashManager;
+use OCP\IUser;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
class TrashHome implements ICollection {
+ /** @var ITrashManager */
+ private $trashManager;
/** @var array */
private $principalInfo;
- public function __construct(array $principalInfo) {
+ /** @var IUser */
+ private $user;
+
+ public function __construct(
+ array $principalInfo,
+ ITrashManager $trashManager,
+ IUser $user
+ ) {
$this->principalInfo = $principalInfo;
+ $this->trashManager = $trashManager;
+ $this->user = $user;
}
public function delete() {
@@ -41,7 +55,7 @@ class TrashHome implements ICollection {
}
public function getName(): string {
- list(,$name) = \Sabre\Uri\split($this->principalInfo['uri']);
+ list(, $name) = \Sabre\Uri\split($this->principalInfo['uri']);
return $name;
}
@@ -58,24 +72,20 @@ class TrashHome implements ICollection {
}
public function getChild($name) {
- list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']);
-
if ($name === 'restore') {
- return new RestoreFolder($userId);
+ return new RestoreFolder($this->user->getUID());
}
if ($name === 'trash') {
- return new TrashRoot($userId);
+ return new TrashRoot($this->user, $this->trashManager);
}
throw new NotFound();
}
public function getChildren(): array {
- list(,$userId) = \Sabre\Uri\split($this->principalInfo['uri']);
-
return [
- new RestoreFolder($userId),
- new TrashRoot($userId),
+ new RestoreFolder($this->user->getUID()),
+ new TrashRoot($this->user, $this->trashManager)
];
}
diff --git a/apps/files_trashbin/lib/Sabre/TrashRoot.php b/apps/files_trashbin/lib/Sabre/TrashRoot.php
index 73b9d44d7e1..57cfe2b2dff 100644
--- a/apps/files_trashbin/lib/Sabre/TrashRoot.php
+++ b/apps/files_trashbin/lib/Sabre/TrashRoot.php
@@ -23,18 +23,25 @@ declare(strict_types=1);
*/
namespace OCA\Files_Trashbin\Sabre;
+use OCA\Files_Trashbin\Trash\ITrashItem;
+use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Files\FileInfo;
+use OCP\IUser;
use Sabre\DAV\Exception\Forbidden;
use Sabre\DAV\Exception\NotFound;
use Sabre\DAV\ICollection;
class TrashRoot implements ICollection {
- /** @var string */
- private $userId;
+ /** @var IUser */
+ private $user;
- public function __construct(string $userId) {
- $this->userId = $userId;
+ /** @var ITrashManager */
+ private $trashManager;
+
+ public function __construct(IUser $user, ITrashManager $trashManager) {
+ $this->user = $user;
+ $this->trashManager = $trashManager;
}
public function delete() {
@@ -57,44 +64,38 @@ class TrashRoot implements ICollection {
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);
+ $entries = $this->trashManager->listTrashRoot($this->user);
- $children = array_map(function (FileInfo $entry) {
+ $children = array_map(function (ITrashItem $entry) {
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
- return new TrashFolder('/', $this->userId, $entry);
+ return new TrashFolder($this->trashManager, $this->user, $entry);
}
- return new TrashFile($this->userId, $entry);
+ return new TrashFile($this->trashManager, $this->user, $entry);
}, $entries);
return $children;
}
- public function childExists($name): bool {
- $entries = \OCA\Files_Trashbin\Helper::getTrashFiles('/', $this->userId);
+ public function getChild($name): ITrash {
+ $entries = $this->getChildren();
foreach ($entries as $entry) {
- if ($entry->getName() . '.d'.$entry->getMtime() === $name) {
- return true;
+ if ($entry->getName() === $name) {
+ return $entry;
}
}
- return false;
+ throw new NotFound();
+ }
+
+ public function childExists($name): bool {
+ try {
+ $this->getChild($name);
+ return true;
+ } catch (NotFound $e) {
+ return false;
+ }
}
public function getLastModified(): int {