Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExternalFolder.php « Model « lib - github.com/nextcloud/backup.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e834547fdd0221c292e69691453c4f589e8ed275 (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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
<?php

declare(strict_types=1);


/**
 * Nextcloud - Backup now. Restore later.
 *
 * This file is licensed under the Affero General Public License version 3 or
 * later. See the COPYING file.
 *
 * @author Maxence Lange <maxence@artificial-owl.com>
 * @copyright 2021, Maxence Lange <maxence@artificial-owl.com>
 * @license GNU AGPL version 3 or any later version
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as
 * published by the Free Software Foundation, either version 3 of the
 * License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 */


namespace OCA\Backup\Model;

use ArtificialOwl\MySmallPhpTools\Db\Nextcloud\nc23\INC23QueryRow;
use ArtificialOwl\MySmallPhpTools\Exceptions\InvalidItemException;
use ArtificialOwl\MySmallPhpTools\IDeserializable;
use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools;
use ArtificialOwl\MySmallPhpTools\Traits\TStringTools;
use JsonSerializable;
use OC\Files\Node\Folder;

/**
 * Class ExternalFolder
 *
 * @package OCA\Backup\Model
 */
class ExternalFolder implements JsonSerializable, INC23QueryRow, IDeserializable {
	use TArrayTools;
	use TStringTools;


	/** @var int */
	private $storageId = 0;

	/** @var string */
	private $storage;

	/** @var string */
	private $root = '';

	/** @var Folder */
	private $rootFolder;


	/**
	 * ExternalFolder constructor.
	 */
	public function __construct(int $storageId = 0, string $storage = '') {
		$this->storageId = $storageId;
		$this->storage = $storage;
	}


	/**
	 * @param int $storageId
	 *
	 * @return ExternalFolder
	 */
	public function setStorageId(int $storageId): self {
		$this->storageId = $storageId;

		return $this;
	}

	/**
	 * @return int
	 */
	public function getStorageId(): int {
		return $this->storageId;
	}


	/**
	 * @param string $storage
	 *
	 * @return ExternalFolder
	 */
	public function setStorage(string $storage): self {
		$this->storage = $storage;

		return $this;
	}

	/**
	 * @return string
	 */
	public function getStorage(): string {
		return $this->storage;
	}


	/**
	 * @param string $root
	 *
	 * @return ExternalFolder
	 */
	public function setRoot(string $root): self {
		$this->root = $root;

		return $this;
	}

	/**
	 * @return string
	 */
	public function getRoot(): string {
		return $this->root;
	}


	/**
	 * @param Folder $rootFolder
	 *
	 * @return ExternalFolder
	 */
	public function setRootFolder(Folder $rootFolder): self {
		$this->rootFolder = $rootFolder;

		return $this;
	}

	/**
	 * @return Folder
	 */
	public function getRootFolder(): Folder {
		return $this->rootFolder;
	}

	/**
	 * @return bool
	 */
	public function hasRootFolder(): bool {
		return !is_null($this->rootFolder);
	}


	/**
	 * @param array $data
	 *
	 * @return ExternalFolder
	 */
	public function importFromDatabase(array $data): INC23QueryRow {
		$this->setStorageId($this->getInt('storage_id', $data))
			 ->setRoot($this->get('root', $data));

		return $this;
	}


	/**
	 * @param array $data
	 *
	 * @return ExternalFolder
	 * @throws InvalidItemException
	 */
	public function import(array $data): IDeserializable {
		$this->setStorageId($this->getInt('storageId', $data))
			 ->setStorage($this->get('storage', $data))
			 ->setRoot($this->get('root', $data));

		if ($this->getStorageId() === 0) {
			throw new InvalidItemException();
		}

		return $this;
	}


	/**
	 * @return array
	 */
	public function jsonSerialize(): array {
		return [
			'storageId' => $this->getStorageId(),
			'storage' => $this->getStorage(),
			'root' => $this->getRoot()
		];
	}
}