Skip to content

Commit e9aef98

Browse files
authored
Merge pull request #146 from utopia-php/feat-message-migration
2 parents c2d0169 + f6b8f04 commit e9aef98

File tree

16 files changed

+1298
-0
lines changed

16 files changed

+1298
-0
lines changed

src/Migration/Destinations/Appwrite.php

Lines changed: 403 additions & 0 deletions
Large diffs are not rendered by default.

src/Migration/Destinations/Local.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ public static function getSupportedResources(): array
7070
Resource::TYPE_FUNCTION,
7171
Resource::TYPE_DEPLOYMENT,
7272
Resource::TYPE_ENVIRONMENT_VARIABLE,
73+
74+
// Messaging
75+
Resource::TYPE_PROVIDER,
76+
Resource::TYPE_TOPIC,
77+
Resource::TYPE_SUBSCRIBER,
78+
Resource::TYPE_MESSAGE,
7379
];
7480
}
7581

src/Migration/Resource.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ abstract class Resource implements \JsonSerializable
4646

4747
public const TYPE_INDEX = 'index';
4848

49+
public const TYPE_PROVIDER = 'provider';
50+
51+
public const TYPE_TOPIC = 'topic';
52+
4953
// Children (Resources that are created by other resources)
5054

5155
public const TYPE_COLUMN = 'column';
@@ -60,6 +64,10 @@ abstract class Resource implements \JsonSerializable
6064

6165
public const TYPE_ENVIRONMENT_VARIABLE = 'environment-variable';
6266

67+
public const TYPE_SUBSCRIBER = 'subscriber';
68+
69+
public const TYPE_MESSAGE = 'message';
70+
6371
// legacy terminologies
6472
public const TYPE_DOCUMENT = 'document';
6573
public const TYPE_ATTRIBUTE = 'attribute';
@@ -89,6 +97,10 @@ abstract class Resource implements \JsonSerializable
8997
self::TYPE_ENVIRONMENT_VARIABLE,
9098
self::TYPE_TEAM,
9199
self::TYPE_MEMBERSHIP,
100+
self::TYPE_PROVIDER,
101+
self::TYPE_TOPIC,
102+
self::TYPE_SUBSCRIBER,
103+
self::TYPE_MESSAGE,
92104

93105
// legacy
94106
self::TYPE_DOCUMENT,
Lines changed: 160 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,160 @@
1+
<?php
2+
3+
namespace Utopia\Migration\Resources\Messaging;
4+
5+
use Utopia\Migration\Resource;
6+
use Utopia\Migration\Transfer;
7+
8+
class Message extends Resource
9+
{
10+
/**
11+
* @param string $id
12+
* @param string $providerType
13+
* @param array<string> $topics
14+
* @param array<string> $users
15+
* @param array<string> $targets
16+
* @param array<string, mixed> $data
17+
* @param string $messageStatus
18+
* @param string $scheduledAt
19+
* @param string $deliveredAt
20+
* @param array<string> $deliveryErrors
21+
* @param int $deliveredTotal
22+
*/
23+
public function __construct(
24+
string $id,
25+
private readonly string $providerType,
26+
private readonly array $topics = [],
27+
private readonly array $users = [],
28+
private readonly array $targets = [],
29+
private readonly array $data = [],
30+
private readonly string $messageStatus = '',
31+
private readonly string $scheduledAt = '',
32+
private readonly string $deliveredAt = '',
33+
private readonly array $deliveryErrors = [],
34+
private readonly int $deliveredTotal = 0,
35+
protected string $createdAt = '',
36+
protected string $updatedAt = '',
37+
) {
38+
$this->id = $id;
39+
}
40+
41+
/**
42+
* @param array<string, mixed> $array
43+
* @return self
44+
*/
45+
public static function fromArray(array $array): self
46+
{
47+
return new self(
48+
$array['id'],
49+
$array['providerType'] ?? '',
50+
$array['topics'] ?? [],
51+
$array['users'] ?? [],
52+
$array['targets'] ?? [],
53+
$array['data'] ?? [],
54+
$array['messageStatus'] ?? $array['status'] ?? '',
55+
$array['scheduledAt'] ?? '',
56+
$array['deliveredAt'] ?? '',
57+
$array['deliveryErrors'] ?? [],
58+
$array['deliveredTotal'] ?? 0,
59+
$array['createdAt'] ?? '',
60+
$array['updatedAt'] ?? '',
61+
);
62+
}
63+
64+
/**
65+
* @return array<string, mixed>
66+
*/
67+
public function jsonSerialize(): array
68+
{
69+
return [
70+
'id' => $this->id,
71+
'providerType' => $this->providerType,
72+
'topics' => $this->topics,
73+
'users' => $this->users,
74+
'targets' => $this->targets,
75+
'data' => $this->data,
76+
'messageStatus' => $this->messageStatus,
77+
'scheduledAt' => $this->scheduledAt,
78+
'deliveredAt' => $this->deliveredAt,
79+
'deliveryErrors' => $this->deliveryErrors,
80+
'deliveredTotal' => $this->deliveredTotal,
81+
'createdAt' => $this->createdAt,
82+
'updatedAt' => $this->updatedAt,
83+
];
84+
}
85+
86+
public static function getName(): string
87+
{
88+
return Resource::TYPE_MESSAGE;
89+
}
90+
91+
public function getGroup(): string
92+
{
93+
return Transfer::GROUP_MESSAGING;
94+
}
95+
96+
public function getProviderType(): string
97+
{
98+
return $this->providerType;
99+
}
100+
101+
/**
102+
* @return array<string>
103+
*/
104+
public function getTopics(): array
105+
{
106+
return $this->topics;
107+
}
108+
109+
/**
110+
* @return array<string>
111+
*/
112+
public function getUsers(): array
113+
{
114+
return $this->users;
115+
}
116+
117+
/**
118+
* @return array<string>
119+
*/
120+
public function getTargets(): array
121+
{
122+
return $this->targets;
123+
}
124+
125+
/**
126+
* @return array<string, mixed>
127+
*/
128+
public function getData(): array
129+
{
130+
return $this->data;
131+
}
132+
133+
public function getMessageStatus(): string
134+
{
135+
return $this->messageStatus;
136+
}
137+
138+
public function getScheduledAt(): string
139+
{
140+
return $this->scheduledAt;
141+
}
142+
143+
public function getDeliveredAt(): string
144+
{
145+
return $this->deliveredAt;
146+
}
147+
148+
/**
149+
* @return array<string>
150+
*/
151+
public function getDeliveryErrors(): array
152+
{
153+
return $this->deliveryErrors;
154+
}
155+
156+
public function getDeliveredTotal(): int
157+
{
158+
return $this->deliveredTotal;
159+
}
160+
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
<?php
2+
3+
namespace Utopia\Migration\Resources\Messaging;
4+
5+
use Utopia\Migration\Resource;
6+
use Utopia\Migration\Transfer;
7+
8+
class Provider extends Resource
9+
{
10+
/**
11+
* @param string $id
12+
* @param string $name
13+
* @param string $provider
14+
* @param string $type
15+
* @param bool $enabled
16+
* @param array<string, mixed> $credentials
17+
* @param array<string, mixed> $options
18+
*/
19+
public function __construct(
20+
string $id,
21+
private readonly string $name,
22+
private readonly string $provider,
23+
private readonly string $type,
24+
private readonly bool $enabled = true,
25+
private readonly array $credentials = [],
26+
private readonly array $options = [],
27+
protected string $createdAt = '',
28+
protected string $updatedAt = '',
29+
) {
30+
$this->id = $id;
31+
}
32+
33+
/**
34+
* @param array<string, mixed> $array
35+
* @return self
36+
*/
37+
public static function fromArray(array $array): self
38+
{
39+
return new self(
40+
$array['id'],
41+
$array['name'] ?? '',
42+
$array['provider'] ?? '',
43+
$array['type'] ?? '',
44+
$array['enabled'] ?? true,
45+
$array['credentials'] ?? [],
46+
$array['options'] ?? [],
47+
$array['createdAt'] ?? '',
48+
$array['updatedAt'] ?? '',
49+
);
50+
}
51+
52+
/**
53+
* @return array<string, mixed>
54+
*/
55+
public function jsonSerialize(): array
56+
{
57+
return [
58+
'id' => $this->id,
59+
'name' => $this->name,
60+
'provider' => $this->provider,
61+
'type' => $this->type,
62+
'enabled' => $this->enabled,
63+
'credentials' => $this->credentials,
64+
'options' => $this->options,
65+
'createdAt' => $this->createdAt,
66+
'updatedAt' => $this->updatedAt,
67+
];
68+
}
69+
70+
public static function getName(): string
71+
{
72+
return Resource::TYPE_PROVIDER;
73+
}
74+
75+
public function getGroup(): string
76+
{
77+
return Transfer::GROUP_MESSAGING;
78+
}
79+
80+
public function getProviderName(): string
81+
{
82+
return $this->name;
83+
}
84+
85+
public function getProvider(): string
86+
{
87+
return $this->provider;
88+
}
89+
90+
public function getType(): string
91+
{
92+
return $this->type;
93+
}
94+
95+
public function getEnabled(): bool
96+
{
97+
return $this->enabled;
98+
}
99+
100+
/**
101+
* @return array<string, mixed>
102+
*/
103+
public function getCredentials(): array
104+
{
105+
return $this->credentials;
106+
}
107+
108+
/**
109+
* @return array<string, mixed>
110+
*/
111+
public function getOptions(): array
112+
{
113+
return $this->options;
114+
}
115+
}

0 commit comments

Comments
 (0)