AbstractTrash.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
  5. * SPDX-License-Identifier: AGPL-3.0-or-later
  6. */
  7. namespace OCA\Files_Trashbin\Sabre;
  8. use OCA\Files_Trashbin\Trash\ITrashItem;
  9. use OCA\Files_Trashbin\Trash\ITrashManager;
  10. use OCP\Files\FileInfo;
  11. use OCP\IUser;
  12. abstract class AbstractTrash implements ITrash {
  13. /** @var ITrashItem */
  14. protected $data;
  15. /** @var ITrashManager */
  16. protected $trashManager;
  17. public function __construct(ITrashManager $trashManager, ITrashItem $data) {
  18. $this->trashManager = $trashManager;
  19. $this->data = $data;
  20. }
  21. public function getFilename(): string {
  22. return $this->data->getName();
  23. }
  24. public function getDeletionTime(): int {
  25. return $this->data->getDeletedTime();
  26. }
  27. public function getFileId(): int {
  28. return $this->data->getId();
  29. }
  30. public function getFileInfo(): FileInfo {
  31. return $this->data;
  32. }
  33. /**
  34. * @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
  35. * @return int|float
  36. */
  37. public function getSize(): int|float {
  38. return $this->data->getSize();
  39. }
  40. public function getLastModified(): int {
  41. return $this->data->getMtime();
  42. }
  43. public function getContentType(): string {
  44. return $this->data->getMimetype();
  45. }
  46. public function getETag(): string {
  47. return $this->data->getEtag();
  48. }
  49. public function getName(): string {
  50. return $this->data->getName();
  51. }
  52. public function getOriginalLocation(): string {
  53. return $this->data->getOriginalLocation();
  54. }
  55. public function getTitle(): string {
  56. return $this->data->getTitle();
  57. }
  58. public function getDeletedBy(): ?IUser {
  59. return $this->data->getDeletedBy();
  60. }
  61. public function delete() {
  62. $this->trashManager->removeItem($this->data);
  63. }
  64. public function restore(): bool {
  65. $this->trashManager->restoreItem($this->data);
  66. return true;
  67. }
  68. }