AbstractTrash.php 2.2 KB

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