AbstractTrash.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * @copyright Copyright (c) 2018 Robin Appelman <robin@icewind.nl>
  5. *
  6. * @author Robin Appelman <robin@icewind.nl>
  7. *
  8. * @license GNU AGPL version 3 or any later version
  9. *
  10. * This program is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License as
  12. * published by the Free Software Foundation, either version 3 of the
  13. * License, or (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU Affero General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU Affero General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. *
  23. */
  24. namespace OCA\Files_Trashbin\Sabre;
  25. use OCA\Files_Trashbin\Trash\ITrashItem;
  26. use OCA\Files_Trashbin\Trash\ITrashManager;
  27. use OCP\Files\FileInfo;
  28. use OCP\IUser;
  29. abstract class AbstractTrash implements ITrash {
  30. /** @var ITrashItem */
  31. protected $data;
  32. /** @var ITrashManager */
  33. protected $trashManager;
  34. public function __construct(ITrashManager $trashManager, ITrashItem $data) {
  35. $this->trashManager = $trashManager;
  36. $this->data = $data;
  37. }
  38. public function getFilename(): string {
  39. return $this->data->getName();
  40. }
  41. public function getDeletionTime(): int {
  42. return $this->data->getDeletedTime();
  43. }
  44. public function getFileId(): int {
  45. return $this->data->getId();
  46. }
  47. public function getFileInfo(): FileInfo {
  48. return $this->data;
  49. }
  50. /**
  51. * @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
  52. * @return int|float
  53. */
  54. public function getSize(): int|float {
  55. return $this->data->getSize();
  56. }
  57. public function getLastModified(): int {
  58. return $this->data->getMtime();
  59. }
  60. public function getContentType(): string {
  61. return $this->data->getMimetype();
  62. }
  63. public function getETag(): string {
  64. return $this->data->getEtag();
  65. }
  66. public function getName(): string {
  67. return $this->data->getName();
  68. }
  69. public function getOriginalLocation(): string {
  70. return $this->data->getOriginalLocation();
  71. }
  72. public function getTitle(): string {
  73. return $this->data->getTitle();
  74. }
  75. public function getDeletedBy(): ?IUser {
  76. return $this->data->getDeletedBy();
  77. }
  78. public function delete() {
  79. $this->trashManager->removeItem($this->data);
  80. }
  81. public function restore(): bool {
  82. $this->trashManager->restoreItem($this->data);
  83. return true;
  84. }
  85. }