Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
388 changes: 388 additions & 0 deletions src/Migration/Destinations/Appwrite.php

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions src/Migration/Destinations/Local.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public static function getSupportedResources(): array
Resource::TYPE_FUNCTION,
Resource::TYPE_DEPLOYMENT,
Resource::TYPE_ENVIRONMENT_VARIABLE,

// Messaging
Resource::TYPE_PROVIDER,
Resource::TYPE_TOPIC,
Resource::TYPE_SUBSCRIBER,
Resource::TYPE_MESSAGE,
];
}

Expand Down
13 changes: 13 additions & 0 deletions src/Migration/Resource.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,15 @@ abstract class Resource implements \JsonSerializable

public const TYPE_ENVIRONMENT_VARIABLE = 'environment-variable';

// Messaging
public const TYPE_PROVIDER = 'provider';

public const TYPE_TOPIC = 'topic';

public const TYPE_SUBSCRIBER = 'subscriber';

public const TYPE_MESSAGE = 'message';

// legacy terminologies
public const TYPE_DOCUMENT = 'document';
public const TYPE_ATTRIBUTE = 'attribute';
Expand All @@ -80,6 +89,10 @@ abstract class Resource implements \JsonSerializable
self::TYPE_ENVIRONMENT_VARIABLE,
self::TYPE_TEAM,
self::TYPE_MEMBERSHIP,
self::TYPE_PROVIDER,
self::TYPE_TOPIC,
self::TYPE_SUBSCRIBER,
self::TYPE_MESSAGE,

// legacy
self::TYPE_DOCUMENT,
Expand Down
172 changes: 172 additions & 0 deletions src/Migration/Resources/Messaging/Message.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
<?php

namespace Utopia\Migration\Resources\Messaging;

use Utopia\Migration\Resource;
use Utopia\Migration\Transfer;

class Message extends Resource
{
/**
* @param string $id
* @param string $providerType
* @param array<string> $topics
* @param array<string> $users
* @param array<string> $targets
* @param array<string, mixed> $data
* @param string $messageStatus
* @param string $scheduledAt
* @param string $deliveredAt
* @param array<string> $deliveryErrors
* @param int $deliveredTotal
* @param array<string, string> $targetUserMap Source target ID => source user ID mapping for ID resolution
*/
public function __construct(
string $id,
private readonly string $providerType,
private readonly array $topics = [],
private readonly array $users = [],
private readonly array $targets = [],
private readonly array $data = [],
private readonly string $messageStatus = '',
private readonly string $scheduledAt = '',
private readonly string $deliveredAt = '',
private readonly array $deliveryErrors = [],
private readonly int $deliveredTotal = 0,
private readonly array $targetUserMap = [],
protected string $createdAt = '',
protected string $updatedAt = '',
) {
$this->id = $id;
}

/**
* @param array<string, mixed> $array
* @return self
*/
public static function fromArray(array $array): self
{
return new self(
$array['id'],
$array['providerType'] ?? '',
$array['topics'] ?? [],
$array['users'] ?? [],
$array['targets'] ?? [],
$array['data'] ?? [],
$array['messageStatus'] ?? $array['status'] ?? '',
$array['scheduledAt'] ?? '',
$array['deliveredAt'] ?? '',
$array['deliveryErrors'] ?? [],
$array['deliveredTotal'] ?? 0,
$array['targetUserMap'] ?? [],
$array['createdAt'] ?? '',
$array['updatedAt'] ?? '',
);
}

/**
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'providerType' => $this->providerType,
'topics' => $this->topics,
'users' => $this->users,
'targets' => $this->targets,
'data' => $this->data,
'messageStatus' => $this->messageStatus,
'scheduledAt' => $this->scheduledAt,
'deliveredAt' => $this->deliveredAt,
'deliveryErrors' => $this->deliveryErrors,
'deliveredTotal' => $this->deliveredTotal,
'targetUserMap' => $this->targetUserMap,
'createdAt' => $this->createdAt,
'updatedAt' => $this->updatedAt,
];
}

public static function getName(): string
{
return Resource::TYPE_MESSAGE;
}

public function getGroup(): string
{
return Transfer::GROUP_MESSAGING;
}

public function getProviderType(): string
{
return $this->providerType;
}

/**
* @return array<string>
*/
public function getTopics(): array
{
return $this->topics;
}

/**
* @return array<string>
*/
public function getUsers(): array
{
return $this->users;
}

/**
* @return array<string>
*/
public function getTargets(): array
{
return $this->targets;
}

/**
* @return array<string, mixed>
*/
public function getData(): array
{
return $this->data;
}

public function getMessageStatus(): string
{
return $this->messageStatus;
}

public function getScheduledAt(): string
{
return $this->scheduledAt;
}

public function getDeliveredAt(): string
{
return $this->deliveredAt;
}

/**
* @return array<string>
*/
public function getDeliveryErrors(): array
{
return $this->deliveryErrors;
}

public function getDeliveredTotal(): int
{
return $this->deliveredTotal;
}

/**
* @return array<string, string>
*/
public function getTargetUserMap(): array
{
return $this->targetUserMap;
}
}
115 changes: 115 additions & 0 deletions src/Migration/Resources/Messaging/Provider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
<?php

namespace Utopia\Migration\Resources\Messaging;

use Utopia\Migration\Resource;
use Utopia\Migration\Transfer;

class Provider extends Resource
{
/**
* @param string $id
* @param string $name
* @param string $provider
* @param string $type
* @param bool $enabled
* @param array<string, mixed> $credentials
* @param array<string, mixed> $options
*/
public function __construct(
string $id,
private readonly string $name,
private readonly string $provider,
private readonly string $type,
private readonly bool $enabled = true,
private readonly array $credentials = [],
private readonly array $options = [],
protected string $createdAt = '',
protected string $updatedAt = '',
) {
$this->id = $id;
}

/**
* @param array<string, mixed> $array
* @return self
*/
public static function fromArray(array $array): self
{
return new self(
$array['id'],
$array['name'] ?? '',
$array['provider'] ?? '',
$array['type'] ?? '',
$array['enabled'] ?? true,
$array['credentials'] ?? [],
$array['options'] ?? [],
$array['createdAt'] ?? '',
$array['updatedAt'] ?? '',
);
}

/**
* @return array<string, mixed>
*/
public function jsonSerialize(): array
{
return [
'id' => $this->id,
'name' => $this->name,
'provider' => $this->provider,
'type' => $this->type,
'enabled' => $this->enabled,
'credentials' => $this->credentials,
'options' => $this->options,
'createdAt' => $this->createdAt,
'updatedAt' => $this->updatedAt,
];
}

public static function getName(): string
{
return Resource::TYPE_PROVIDER;
}

public function getGroup(): string
{
return Transfer::GROUP_MESSAGING;
}

public function getProviderName(): string
{
return $this->name;
}

public function getProvider(): string
{
return $this->provider;
}

public function getType(): string
{
return $this->type;
}

public function getEnabled(): bool
{
return $this->enabled;
}

/**
* @return array<string, mixed>
*/
public function getCredentials(): array
{
return $this->credentials;
}

/**
* @return array<string, mixed>
*/
public function getOptions(): array
{
return $this->options;
}
}
Loading