-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathResource.php
More file actions
303 lines (226 loc) · 7.17 KB
/
Resource.php
File metadata and controls
303 lines (226 loc) · 7.17 KB
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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<?php
namespace Utopia\Migration;
abstract class Resource implements \JsonSerializable
{
public const STATUS_PENDING = 'pending';
public const STATUS_SUCCESS = 'success';
public const STATUS_ERROR = 'error';
public const STATUS_SKIPPED = 'skip';
public const STATUS_PROCESSING = 'processing';
public const STATUS_WARNING = 'warning';
/**
* For some transfers (namely Firebase) we have to keep resources in cache that do not necessarily need to be Transferred
* This status is used to mark resources that are not going to be transferred but are still needed for the transfer to work
* e.g Documents are required for Database transfers because of schema tracing in firebase
*/
public const STATUS_DISREGARDED = 'disregarded';
// Master Resources
public const TYPE_BUCKET = 'bucket';
public const TYPE_TABLE = 'table';
public const TYPE_DATABASE = 'database';
public const TYPE_DATABASE_LEGACY = 'legacy';
public const TYPE_DATABASE_TABLESDB = 'tablesdb';
public const TYPE_DATABASE_DOCUMENTSDB = 'documentsdb';
public const TYPE_DATABASE_VECTORSDB = 'vectorsdb';
public const TYPE_ROW = 'row';
public const TYPE_FILE = 'file';
public const TYPE_USER = 'user';
public const TYPE_TEAM = 'team';
public const TYPE_MEMBERSHIP = 'membership';
public const TYPE_FUNCTION = 'function';
public const TYPE_SITE = 'site';
public const TYPE_INDEX = 'index';
public const TYPE_PROVIDER = 'provider';
public const TYPE_TOPIC = 'topic';
// Children (Resources that are created by other resources)
public const TYPE_COLUMN = 'column';
public const TYPE_DEPLOYMENT = 'deployment';
public const TYPE_SITE_DEPLOYMENT = 'site-deployment';
public const TYPE_SITE_VARIABLE = 'site-variable';
public const TYPE_HASH = 'hash';
public const TYPE_ENVIRONMENT_VARIABLE = 'environment-variable';
public const TYPE_SUBSCRIBER = 'subscriber';
public const TYPE_MESSAGE = 'message';
// Backups
public const TYPE_BACKUP_POLICY = 'backup-policy';
// legacy terminologies
public const TYPE_DOCUMENT = 'document';
public const TYPE_ATTRIBUTE = 'attribute';
public const TYPE_COLLECTION = 'collection';
private const TYPE_MAP = [
Resource::TYPE_ROW => Resource::TYPE_DOCUMENT,
Resource::TYPE_COLUMN => Resource::TYPE_ATTRIBUTE,
Resource::TYPE_TABLE => Resource::TYPE_COLLECTION,
];
public const ALL_RESOURCES = [
self::TYPE_COLUMN,
self::TYPE_BUCKET,
self::TYPE_TABLE,
self::TYPE_DATABASE,
self::TYPE_DATABASE_VECTORSDB,
self::TYPE_DATABASE_DOCUMENTSDB,
self::TYPE_ROW,
self::TYPE_FILE,
self::TYPE_FUNCTION,
self::TYPE_DEPLOYMENT,
self::TYPE_SITE,
self::TYPE_SITE_DEPLOYMENT,
self::TYPE_SITE_VARIABLE,
self::TYPE_HASH,
self::TYPE_INDEX,
self::TYPE_USER,
self::TYPE_ENVIRONMENT_VARIABLE,
self::TYPE_TEAM,
self::TYPE_MEMBERSHIP,
self::TYPE_PROVIDER,
self::TYPE_TOPIC,
self::TYPE_SUBSCRIBER,
self::TYPE_MESSAGE,
self::TYPE_BACKUP_POLICY,
// legacy
self::TYPE_DOCUMENT,
self::TYPE_ATTRIBUTE,
self::TYPE_COLLECTION,
];
// index terminology is same for all
public const DATABASE_TYPE_RESOURCE_MAP = [
self::TYPE_DATABASE => [
'entity' => self::TYPE_TABLE,
'field' => self::TYPE_COLUMN,
'record' => self::TYPE_ROW,
],
self::TYPE_DATABASE_DOCUMENTSDB => [
'entity' => self::TYPE_COLLECTION,
// HACK: not required in documentsdb but adding it for consistency in the db reader(not gonna impact)
'field' => self::TYPE_ATTRIBUTE,
'record' => self::TYPE_DOCUMENT,
],
self::TYPE_DATABASE_VECTORSDB => [
'entity' => self::TYPE_COLLECTION,
'field' => self::TYPE_ATTRIBUTE,
'record' => self::TYPE_DOCUMENT,
]
];
public const ENTITY_TYPE_RESOURCE_MAP = [
self::TYPE_TABLE => [
'field' => self::TYPE_COLUMN,
'record' => self::TYPE_ROW,
'index' => self::TYPE_INDEX
],
self::TYPE_COLLECTION => [
'field' => self::TYPE_ATTRIBUTE,
'record' => self::TYPE_DOCUMENT,
'index' => self::TYPE_INDEX
],
];
protected string $id = '';
protected string $originalId = '';
protected string $sequence = '';
protected string $createdAt = '';
protected string $updatedAt = '';
protected string $status = self::STATUS_PENDING;
protected string $message = '';
/**
* @var array<string>
*/
protected array $permissions = [];
abstract public static function getName(): string;
abstract public function getGroup(): string;
public static function isSupported(string|array $types, array $resources): bool
{
$allTypes = [];
$types = (array) $types;
foreach ($types as $type) {
$allTypes[] = $type;
if (isset(self::TYPE_MAP[$type])) {
$allTypes[] = self::TYPE_MAP[$type];
}
}
return (bool) \array_intersect($resources, $allTypes);
}
public function getId(): string
{
return $this->id;
}
public function setId(string $id): self
{
$this->id = $id;
return $this;
}
public function getOriginalId(): string
{
return $this->originalId;
}
public function setOriginalId(string $originalId): self
{
$this->originalId = $originalId;
return $this;
}
public function getSequence(): string
{
return $this->sequence;
}
public function setSequence(string $sequence): self
{
$this->sequence = $sequence;
return $this;
}
public function getStatus(): string
{
return $this->status;
}
public function setStatus(string $status, string $message = ''): self
{
$this->status = $status;
$this->message = $message;
return $this;
}
public function getMessage(): string
{
return $this->message;
}
public function setMessage(string $message): self
{
$this->message = $message;
return $this;
}
/**
* @return array<string>
*/
public function getPermissions(): array
{
return $this->permissions;
}
/**
* @param array<string> $permissions
*/
public function setPermissions(array $permissions): self
{
$this->permissions = $permissions;
return $this;
}
/**
* @returns string
*/
public function getCreatedAt(): string
{
return $this->createdAt;
}
/**
* @returns string
*/
public function getUpdatedAt(): string
{
return $this->updatedAt;
}
public function setCreatedAt(string $date): self
{
$this->createdAt = $date;
return $this;
}
public function setUpdatedAt(string $date): self
{
$this->updatedAt = $date;
return $this;
}
}