-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathMockDestination.php
More file actions
101 lines (86 loc) · 3.18 KB
/
MockDestination.php
File metadata and controls
101 lines (86 loc) · 3.18 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
<?php
namespace Utopia\Tests\Unit\Adapters;
use Utopia\Migration\Destination;
use Utopia\Migration\Resource;
use Utopia\Migration\Resources\Functions\Deployment;
use Utopia\Migration\Resources\Storage\File;
class MockDestination extends Destination
{
public array $data = [];
public function getGroupData(string $group): array
{
return $this->data[$group] ?? [];
}
public function getResourceTypeData(string $group, string $resourceType): array
{
return array_keys($this->data[$group][$resourceType]) ?? [];
}
public function getResourceById(string $group, string $resourceType, string $resourceId): ?Resource
{
return $this->data[$group][$resourceType][$resourceId] ?? null;
}
public static function getName(): string
{
return 'MockDestination';
}
public static function getSupportedResources(): array
{
return [
Resource::TYPE_COLUMN,
Resource::TYPE_BUCKET,
Resource::TYPE_TABLE,
Resource::TYPE_DATABASE,
Resource::TYPE_ROW,
Resource::TYPE_FILE,
Resource::TYPE_FUNCTION,
Resource::TYPE_DEPLOYMENT,
Resource::TYPE_SITE,
Resource::TYPE_SITE_DEPLOYMENT,
Resource::TYPE_SITE_VARIABLE,
Resource::TYPE_HASH,
Resource::TYPE_INDEX,
Resource::TYPE_USER,
Resource::TYPE_ENVIRONMENT_VARIABLE,
Resource::TYPE_TEAM,
Resource::TYPE_MEMBERSHIP,
Resource::TYPE_PLATFORM,
Resource::TYPE_API_KEY,
Resource::TYPE_PROVIDER,
Resource::TYPE_TOPIC,
Resource::TYPE_SUBSCRIBER,
Resource::TYPE_MESSAGE,
];
}
public function import(array $resources, callable $callback): void
{
foreach ($resources as $resource) {
/** @var Resource $resource */
switch ($resource->getName()) {
case 'Deployment':
/** @var Deployment $resource */
if ($resource->getStart() === 0) {
$this->data[$resource->getGroup()][$resource->getName()][$resource->getId()] = $resource;
}
// file_put_contents($this->path . 'deployments/' . $resource->getId() . '.tar.gz', $resource->getData(), FILE_APPEND);
break;
case Resource::TYPE_FILE:
/** @var File $resource */
break;
}
if (!key_exists($resource->getGroup(), $this->data)) {
$this->data[$resource->getGroup()] = [];
}
if (!key_exists($resource->getName(), $this->data[$resource->getGroup()])) {
$this->data[$resource->getGroup()][$resource->getName()] = [];
}
$this->data[$resource->getGroup()][$resource->getName()][$resource->getId()] = $resource;
$resource->setStatus(Resource::STATUS_SUCCESS);
$this->cache->update($resource);
}
$callback($resources);
}
public function report(array $resources = [], array $resourceIds = []): array
{
return [];
}
}