store user for trashitem in the trashitem
Signed-off-by: Robin Appelman <robin@icewind.nl>
This commit is contained in:
parent
136113a22b
commit
9e0ebf1830
|
@ -34,12 +34,8 @@ abstract class AbstractTrash implements ITrash {
|
||||||
/** @var ITrashManager */
|
/** @var ITrashManager */
|
||||||
protected $trashManager;
|
protected $trashManager;
|
||||||
|
|
||||||
/** @var IUser */
|
public function __construct(ITrashManager $trashManager, ITrashItem $data) {
|
||||||
protected $user;
|
|
||||||
|
|
||||||
public function __construct(ITrashManager $trashManager, IUser $user, ITrashItem $data) {
|
|
||||||
$this->trashManager = $trashManager;
|
$this->trashManager = $trashManager;
|
||||||
$this->user = $user;
|
|
||||||
$this->data = $data;
|
$this->data = $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -80,11 +76,11 @@ abstract class AbstractTrash implements ITrash {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getOriginalLocation(): string {
|
public function getOriginalLocation(): string {
|
||||||
return $this->data->getOriginalLocation($this->user);
|
return $this->data->getOriginalLocation();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function delete() {
|
public function delete() {
|
||||||
$this->trashManager->removeItem($this->user, $this->data);
|
$this->trashManager->removeItem($this->data);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function restore(): bool {
|
public function restore(): bool {
|
||||||
|
|
|
@ -30,13 +30,13 @@ use Sabre\DAV\ICollection;
|
||||||
|
|
||||||
abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
|
abstract class AbstractTrashFolder extends AbstractTrash implements ICollection, ITrash {
|
||||||
public function getChildren(): array {
|
public function getChildren(): array {
|
||||||
$entries = $this->trashManager->listTrashFolder($this->user, $this->data);
|
$entries = $this->trashManager->listTrashFolder($this->data);
|
||||||
|
|
||||||
$children = array_map(function (ITrashItem $entry) {
|
$children = array_map(function (ITrashItem $entry) {
|
||||||
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
|
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);
|
}, $entries);
|
||||||
|
|
||||||
return $children;
|
return $children;
|
||||||
|
|
|
@ -31,14 +31,6 @@ use Sabre\DAV\INode;
|
||||||
|
|
||||||
|
|
||||||
class RestoreFolder implements ICollection, IMoveTarget {
|
class RestoreFolder implements ICollection, IMoveTarget {
|
||||||
|
|
||||||
/** @var string */
|
|
||||||
protected $userId;
|
|
||||||
|
|
||||||
public function __construct(string $userId) {
|
|
||||||
$this->userId = $userId;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function createFile($name, $data = null) {
|
public function createFile($name, $data = null) {
|
||||||
throw new Forbidden();
|
throw new Forbidden();
|
||||||
}
|
}
|
||||||
|
|
|
@ -73,7 +73,7 @@ class TrashHome implements ICollection {
|
||||||
|
|
||||||
public function getChild($name) {
|
public function getChild($name) {
|
||||||
if ($name === 'restore') {
|
if ($name === 'restore') {
|
||||||
return new RestoreFolder($this->user->getUID());
|
return new RestoreFolder();
|
||||||
}
|
}
|
||||||
if ($name === 'trash') {
|
if ($name === 'trash') {
|
||||||
return new TrashRoot($this->user, $this->trashManager);
|
return new TrashRoot($this->user, $this->trashManager);
|
||||||
|
@ -84,7 +84,7 @@ class TrashHome implements ICollection {
|
||||||
|
|
||||||
public function getChildren(): array {
|
public function getChildren(): array {
|
||||||
return [
|
return [
|
||||||
new RestoreFolder($this->user->getUID()),
|
new RestoreFolder(),
|
||||||
new TrashRoot($this->user, $this->trashManager)
|
new TrashRoot($this->user, $this->trashManager)
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
|
@ -69,9 +69,9 @@ class TrashRoot implements ICollection {
|
||||||
|
|
||||||
$children = array_map(function (ITrashItem $entry) {
|
$children = array_map(function (ITrashItem $entry) {
|
||||||
if ($entry->getType() === FileInfo::TYPE_FOLDER) {
|
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);
|
}, $entries);
|
||||||
|
|
||||||
return $children;
|
return $children;
|
||||||
|
|
|
@ -43,12 +43,11 @@ interface ITrashBackend {
|
||||||
/**
|
/**
|
||||||
* List all trash items in a subfolder in the trashbin
|
* List all trash items in a subfolder in the trashbin
|
||||||
*
|
*
|
||||||
* @param IUser $user
|
|
||||||
* @param ITrashItem $folder
|
* @param ITrashItem $folder
|
||||||
* @return ITrashItem[]
|
* @return ITrashItem[]
|
||||||
* @since 15.0.0
|
* @since 15.0.0
|
||||||
*/
|
*/
|
||||||
public function listTrashFolder(IUser $user, ITrashItem $folder): array;
|
public function listTrashFolder(ITrashItem $folder): array;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Restore a trashbin item
|
* Restore a trashbin item
|
||||||
|
@ -61,11 +60,10 @@ interface ITrashBackend {
|
||||||
/**
|
/**
|
||||||
* Permanently remove an item from trash
|
* Permanently remove an item from trash
|
||||||
*
|
*
|
||||||
* @param IUser $user
|
|
||||||
* @param ITrashItem $item
|
* @param ITrashItem $item
|
||||||
* @since 15.0.0
|
* @since 15.0.0
|
||||||
*/
|
*/
|
||||||
public function removeItem(IUser $user, ITrashItem $item);
|
public function removeItem(ITrashItem $item);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Move a file or folder to trash
|
* Move a file or folder to trash
|
||||||
|
|
|
@ -67,4 +67,12 @@ interface ITrashItem extends FileInfo {
|
||||||
* @since 15.0.0
|
* @since 15.0.0
|
||||||
*/
|
*/
|
||||||
public function isRootItem(): bool;
|
public function isRootItem(): bool;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the user for which this trash item applies
|
||||||
|
*
|
||||||
|
* @return IUser
|
||||||
|
* @since 15.0.0
|
||||||
|
*/
|
||||||
|
public function getUser(): IUser;
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,35 +49,38 @@ class LegacyTrashBackend implements ITrashBackend {
|
||||||
* @param ITrashItem $parent
|
* @param ITrashItem $parent
|
||||||
* @return ITrashItem[]
|
* @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() : '';
|
$parentTrashPath = ($parent instanceof ITrashItem) ? $parent->getTrashPath() : '';
|
||||||
$isRoot = $parent === null;
|
$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(
|
return new TrashItem(
|
||||||
$this,
|
$this,
|
||||||
$isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName(),
|
$isRoot ? $file['extraData'] : $parent->getOriginalLocation() . '/' . $file->getName(),
|
||||||
$file->getMTime(),
|
$file->getMTime(),
|
||||||
$parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
|
$parentTrashPath . '/' . $file->getName() . ($isRoot ? '.d' . $file->getMtime() : ''),
|
||||||
$file
|
$file,
|
||||||
|
$user
|
||||||
);
|
);
|
||||||
}, $items);
|
}, $items);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listTrashRoot(IUser $user): array {
|
public function listTrashRoot(IUser $user): array {
|
||||||
$entries = Helper::getTrashFiles('/', $user->getUID());
|
$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());
|
$entries = Helper::getTrashFiles($folder->getTrashPath(), $user->getUID());
|
||||||
return $this->mapTrashItems($entries, $folder);
|
return $this->mapTrashItems($entries, $user ,$folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function restoreItem(ITrashItem $item) {
|
public function restoreItem(ITrashItem $item) {
|
||||||
Trashbin::restore($item->getTrashPath(), $item->getName(), $item->isRootItem() ? $item->getDeletedTime() : null);
|
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()) {
|
if ($item->isRootItem()) {
|
||||||
$path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
|
$path = substr($item->getTrashPath(), 0, -strlen('.d' . $item->getDeletedTime()));
|
||||||
Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());
|
Trashbin::delete($path, $user->getUID(), $item->getDeletedTime());
|
||||||
|
|
|
@ -35,22 +35,23 @@ class TrashItem implements ITrashItem {
|
||||||
private $trashPath;
|
private $trashPath;
|
||||||
/** @var FileInfo */
|
/** @var FileInfo */
|
||||||
private $fileInfo;
|
private $fileInfo;
|
||||||
|
/** @var IUser */
|
||||||
|
private $user;
|
||||||
|
|
||||||
/**
|
public function __construct(
|
||||||
* TrashItem constructor.
|
ITrashBackend $backend,
|
||||||
*
|
string $originalLocation,
|
||||||
* @param ITrashBackend $backend
|
int $deletedTime,
|
||||||
* @param string $originalLocation
|
string $trashPath,
|
||||||
* @param int $deletedTime
|
FileInfo $fileInfo,
|
||||||
* @param string $trashPath
|
IUser $user
|
||||||
* @param FileInfo $fileInfo
|
) {
|
||||||
*/
|
|
||||||
public function __construct(ITrashBackend $backend, string $originalLocation, int $deletedTime, string $trashPath, FileInfo $fileInfo) {
|
|
||||||
$this->backend = $backend;
|
$this->backend = $backend;
|
||||||
$this->orignalLocation = $originalLocation;
|
$this->orignalLocation = $originalLocation;
|
||||||
$this->deletedTime = $deletedTime;
|
$this->deletedTime = $deletedTime;
|
||||||
$this->trashPath = $trashPath;
|
$this->trashPath = $trashPath;
|
||||||
$this->fileInfo = $fileInfo;
|
$this->fileInfo = $fileInfo;
|
||||||
|
$this->user = $user;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTrashBackend(): ITrashBackend {
|
public function getTrashBackend(): ITrashBackend {
|
||||||
|
@ -73,6 +74,10 @@ class TrashItem implements ITrashItem {
|
||||||
return substr_count($this->getTrashPath(), '/') === 1;
|
return substr_count($this->getTrashPath(), '/') === 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getUser(): IUser {
|
||||||
|
return $this->user;
|
||||||
|
}
|
||||||
|
|
||||||
public function getEtag() {
|
public function getEtag() {
|
||||||
return $this->fileInfo->getEtag();
|
return $this->fileInfo->getEtag();
|
||||||
}
|
}
|
||||||
|
@ -93,95 +98,75 @@ class TrashItem implements ITrashItem {
|
||||||
return $this->fileInfo->getInternalPath();
|
return $this->fileInfo->getInternalPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getPath() {
|
public function getPath() {
|
||||||
return $this->fileInfo->getPath();
|
return $this->fileInfo->getPath();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getMimetype() {
|
public function getMimetype() {
|
||||||
return $this->fileInfo->getMimetype();
|
return $this->fileInfo->getMimetype();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getMimePart() {
|
public function getMimePart() {
|
||||||
return $this->fileInfo->getMimePart();
|
return $this->fileInfo->getMimePart();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getStorage() {
|
public function getStorage() {
|
||||||
return $this->fileInfo->getStorage();
|
return $this->fileInfo->getStorage();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getId() {
|
public function getId() {
|
||||||
return $this->fileInfo->getId();
|
return $this->fileInfo->getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isEncrypted() {
|
public function isEncrypted() {
|
||||||
return $this->fileInfo->isEncrypted();
|
return $this->fileInfo->isEncrypted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getPermissions() {
|
public function getPermissions() {
|
||||||
return $this->fileInfo->getPermissions();
|
return $this->fileInfo->getPermissions();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getType() {
|
public function getType() {
|
||||||
return $this->fileInfo->getType();
|
return $this->fileInfo->getType();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isReadable() {
|
public function isReadable() {
|
||||||
return $this->fileInfo->isReadable();
|
return $this->fileInfo->isReadable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isUpdateable() {
|
public function isUpdateable() {
|
||||||
return $this->fileInfo->isUpdateable();
|
return $this->fileInfo->isUpdateable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isCreatable() {
|
public function isCreatable() {
|
||||||
return $this->fileInfo->isCreatable();
|
return $this->fileInfo->isCreatable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isDeletable() {
|
public function isDeletable() {
|
||||||
return $this->fileInfo->isDeletable();
|
return $this->fileInfo->isDeletable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isShareable() {
|
public function isShareable() {
|
||||||
return $this->fileInfo->isShareable();
|
return $this->fileInfo->isShareable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isShared() {
|
public function isShared() {
|
||||||
return $this->fileInfo->isShared();
|
return $this->fileInfo->isShared();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function isMounted() {
|
public function isMounted() {
|
||||||
return $this->fileInfo->isMounted();
|
return $this->fileInfo->isMounted();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getMountPoint() {
|
public function getMountPoint() {
|
||||||
return $this->fileInfo->getMountPoint();
|
return $this->fileInfo->getMountPoint();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getOwner() {
|
public function getOwner() {
|
||||||
return $this->fileInfo->getOwner();
|
return $this->fileInfo->getOwner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function getChecksum() {
|
public function getChecksum() {
|
||||||
return $this->fileInfo->getChecksum();
|
return $this->fileInfo->getChecksum();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -57,16 +57,16 @@ class TrashManager implements ITrashManager {
|
||||||
return $item->getTrashBackend();
|
return $item->getTrashBackend();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function listTrashFolder(IUser $user, ITrashItem $folder): array {
|
public function listTrashFolder(ITrashItem $folder): array {
|
||||||
return $this->getBackendForItem($folder)->listTrashFolder($user, $folder);
|
return $this->getBackendForItem($folder)->listTrashFolder($folder);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function restoreItem(ITrashItem $item) {
|
public function restoreItem(ITrashItem $item) {
|
||||||
return $this->getBackendForItem($item)->restoreItem($item);
|
return $this->getBackendForItem($item)->restoreItem($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function removeItem(IUser $user, ITrashItem $item) {
|
public function removeItem(ITrashItem $item) {
|
||||||
$this->getBackendForItem($item)->removeItem($user, $item);
|
$this->getBackendForItem($item)->removeItem($item);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue