summaryrefslogtreecommitdiffstats
path: root/apps/files_trashbin/lib/Sabre/AbstractTrash.php
blob: e46a7d5d638e0f5749b0266a9bd98b2b39fbd511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
<?php

declare(strict_types=1);

/**
 * SPDX-FileCopyrightText: 2018 Nextcloud GmbH and Nextcloud contributors
 * SPDX-License-Identifier: AGPL-3.0-or-later
 */
namespace OCA\Files_Trashbin\Sabre;

use OCA\Files_Trashbin\Trash\ITrashItem;
use OCA\Files_Trashbin\Trash\ITrashManager;
use OCP\Files\FileInfo;
use OCP\IUser;

abstract class AbstractTrash implements ITrash {
	/** @var ITrashItem */
	protected $data;

	/** @var ITrashManager */
	protected $trashManager;

	public function __construct(ITrashManager $trashManager, ITrashItem $data) {
		$this->trashManager = $trashManager;
		$this->data = $data;
	}

	public function getFilename(): string {
		return $this->data->getName();
	}

	public function getDeletionTime(): int {
		return $this->data->getDeletedTime();
	}

	public function getFileId(): int {
		return $this->data->getId();
	}

	public function getFileInfo(): FileInfo {
		return $this->data;
	}

	/**
	 * @psalm-suppress ImplementedReturnTypeMismatch \Sabre\DAV\IFile::getSize signature does not support 32bit
	 * @return int|float
	 */
	public function getSize(): int|float {
		return $this->data->getSize();
	}

	public function getLastModified(): int {
		return $this->data->getMtime();
	}

	public function getContentType(): string {
		return $this->data->getMimetype();
	}

	public function getETag(): string {
		return $this->data->getEtag();
	}

	public function getName(): string {
		return $this->data->getName();
	}

	public function getOriginalLocation(): string {
		return $this->data->getOriginalLocation();
	}

	public function getTitle(): string {
		return $this->data->getTitle();
	}

	public function getDeletedBy(): ?IUser {
		return $this->data->getDeletedBy();
	}

	public function delete() {
		$this->trashManager->removeItem($this->data);
	}

	public function restore(): bool {
		$this->trashManager->restoreItem($this->data);
		return true;
	}
}