store user for trashitem in the trashitem

Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
Robin Appelman 2018-10-17 15:21:09 +02:00
parent 136113a22b
commit 9e0ebf1830
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
10 changed files with 49 additions and 67 deletions

View File

@ -34,12 +34,8 @@ abstract class AbstractTrash implements ITrash {
/** @var ITrashManager */
protected $trashManager;
/** @var IUser */
protected $user;
public function __construct(ITrashManager $trashManager, IUser $user, ITrashItem $data) {
public function __construct(ITrashManager $trashManager, ITrashItem $data) {
$this->trashManager = $trashManager;
$this->user = $user;
$this->data = $data;
}
@ -80,11 +76,11 @@ abstract class AbstractTrash implements ITrash {
}
public function getOriginalLocation(): string {
return $this->data->getOriginalLocation($this->user);
return $this->data->getOriginalLocation();
}
public function delete() {
$this->trashManager->removeItem($this->user, $this->data);
$this->trashManager->removeItem($this->data);
}
public function restore(): bool {

View File

@ -30,13 +30,13 @@ use Sabre\DAV\ICollection;
abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
public function getChildren(): array {
$entries = $this->trashManager->listTrashFolder($this->user, $this->data);
$entries = $this->trashManager->listTrashFolder($this->data);
$children = array_map(function (ITrashItem $entry) {
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
return new TrashFolderFolder($this->trashManager, $this->user, $entry);
return new TrashFolderFolder($this->trashManager, $entry);
}
return new TrashFolderFile($this->trashManager, $this->user, $entry);
return new TrashFolderFile($this->trashManager, $entry);
}, $entries);
return $children;

View File

@ -31,14 +31,6 @@ 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();
}

View File

@ -73,7 +73,7 @@ class TrashHome implements ICollection {
public function getChild($name) {
if ($name === 'restore') {
return new RestoreFolder($this->user->getUID());
return new RestoreFolder();
}
if ($name === 'trash') {
return new TrashRoot($this->user, $this->trashManager);
@ -84,7 +84,7 @@ class TrashHome implements ICollection {
public function getChildren(): array {
return [
new RestoreFolder($this->user->getUID()),
new RestoreFolder(),
new TrashRoot($this->user, $this->trashManager)
];
}

View File

@ -69,9 +69,9 @@ class TrashRoot implements ICollection {
$children = array_map(function (ITrashItem $entry) {
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
return new TrashFolder($this->trashManager, $this->user, $entry);
return new TrashFolder($this->trashManager, $entry);
}
return new TrashFile($this->trashManager, $this->user, $entry);
return new TrashFile($this->trashManager, $entry);
}, $entries);
return $children;

View File

@ -43,12 +43,11 @@ interface ITrashBackend {
/**
* List all trash items in a subfolder in the trashbin
*
* @param IUser $user
* @param ITrashItem $folder
* @return ITrashItem[]
* @since 15.0.0
*/
public function listTrashFolder(IUser $user, ITrashItem $folder): array;
public function listTrashFolder(ITrashItem $folder): array;
/**
* Restore a trashbin item
@ -61,11 +60,10 @@ interface ITrashBackend {
/**
* Permanently remove an item from trash
*
* @param IUser $user
* @param ITrashItem $item
* @since 15.0.0
*/
public function removeItem(IUser $user, ITrashItem $item);
public function removeItem(ITrashItem $item);
/**
* Move a file or folder to trash

View File

@ -67,4 +67,12 @@ interface ITrashItem extends FileInfo {
* @since 15.0.0
*/
public function isRootItem(): bool;
/**
* Get the user for which this trash item applies
*
* @return IUser
* @since 15.0.0
*/
public function getUser(): IUser;
}

View File

@ -49,35 +49,38 @@ class LegacyTrashBackend implements ITrashBackend {
* @param ITrashItem $parent
* @return ITrashItem[]
*/
private function mapTrashItems(array $items, ITrashItem $parent = null): array {
private function mapTrashItems(array $items, IUser $user, ITrashItem $parent = null): array {
$parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
$isRoot = $parent === null;
return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot) {
return array_map(function (FileInfo $file) use ($parent, $parentTrashPath, $isRoot, $user) {
return new TrashItem(
$this,
$isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName(),
$file->getMTime(),
$parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
$file
$file,
$user
);
}, $items);
}
public function listTrashRoot(IUser $user): array {
$entries = Helper::getTrashFiles('/', $user->getUID());
return $this->mapTrashItems($entries);
return $this->mapTrashItems($entries, $user);
}
public function listTrashFolder(IUser $user, ITrashItem $folder): array {
public function listTrashFolder(ITrashItem $folder): array {
$user = $folder->getUser();
$entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
return $this->mapTrashItems($entries, $folder);
return $this->mapTrashItems($entries, $user ,$folder);
}
public function restoreItem(ITrashItem $item) {
Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null);
}
public function removeItem(IUser $user, ITrashItem $item) {
public function removeItem(ITrashItem $item) {
$user = $item->getUser();
if ($item->isRootItem()) {
$path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());

View File

@ -35,22 +35,23 @@ class TrashItem implements ITrashItem {
private $trashPath;
/** @var FileInfo */
private $fileInfo;
/** @var IUser */
private $user;
/**
* TrashItem constructor.
*
* @param ITrashBackend $backend
* @param string $originalLocation
* @param int $deletedTime
* @param string $trashPath
* @param FileInfo $fileInfo
*/
public function __construct(ITrashBackend $backend, string $originalLocation, int $deletedTime, string $trashPath, FileInfo $fileInfo) {
public function __construct(
ITrashBackend $backend,
string $originalLocation,
int $deletedTime,
string $trashPath,
FileInfo $fileInfo,
IUser $user
) {
$this->backend = $backend;
$this->orignalLocation = $originalLocation;
$this->deletedTime = $deletedTime;
$this->trashPath = $trashPath;
$this->fileInfo = $fileInfo;
$this->user = $user;
}
public function getTrashBackend(): ITrashBackend {
@ -73,6 +74,10 @@ class TrashItem implements ITrashItem {
return substr_count($this->getTrashPath(), '/') === 1;
}
public function getUser(): IUser {
return $this->user;
}
public function getEtag() {
return $this->fileInfo->getEtag();
}
@ -93,95 +98,75 @@ class TrashItem implements ITrashItem {
return $this->fileInfo->getInternalPath();
}
public function getPath() {
return $this->fileInfo->getPath();
}
public function getMimetype() {
return $this->fileInfo->getMimetype();
}
public function getMimePart() {
return $this->fileInfo->getMimePart();
}
public function getStorage() {
return $this->fileInfo->getStorage();
}
public function getId() {
return $this->fileInfo->getId();
}
public function isEncrypted() {
return $this->fileInfo->isEncrypted();
}
public function getPermissions() {
return $this->fileInfo->getPermissions();
}
public function getType() {
return $this->fileInfo->getType();
}
public function isReadable() {
return $this->fileInfo->isReadable();
}
public function isUpdateable() {
return $this->fileInfo->isUpdateable();
}
public function isCreatable() {
return $this->fileInfo->isCreatable();
}
public function isDeletable() {
return $this->fileInfo->isDeletable();
}
public function isShareable() {
return $this->fileInfo->isShareable();
}
public function isShared() {
return $this->fileInfo->isShared();
}
public function isMounted() {
return $this->fileInfo->isMounted();
}
public function getMountPoint() {
return $this->fileInfo->getMountPoint();
}
public function getOwner() {
return $this->fileInfo->getOwner();
}
public function getChecksum() {
return $this->fileInfo->getChecksum();
}
}

View File

@ -57,16 +57,16 @@ class TrashManager implements ITrashManager {
return $item->getTrashBackend();
}
public function listTrashFolder(IUser $user, ITrashItem $folder): array {
return $this->getBackendForItem($folder)->listTrashFolder($user, $folder);
public function listTrashFolder(ITrashItem $folder): array {
return $this->getBackendForItem($folder)->listTrashFolder($folder);
}
public function restoreItem(ITrashItem $item) {
return $this->getBackendForItem($item)->restoreItem($item);
}
public function removeItem(IUser $user, ITrashItem $item) {
$this->getBackendForItem($item)->removeItem($user, $item);
public function removeItem(ITrashItem $item) {
$this->getBackendForItem($item)->removeItem($item);
}
/**