|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Utopia\Migration\Resources\Templates; |
| 4 | + |
| 5 | +use Utopia\Migration\Resource; |
| 6 | +use Utopia\Migration\Transfer; |
| 7 | + |
| 8 | +/** |
| 9 | + * Custom email template — one row per (templateId, locale) pair. The resource |
| 10 | + * `id` follows the storage key format `email.{templateId}-{locale}` so |
| 11 | + * destination read-then-merge can address the slot directly. |
| 12 | + */ |
| 13 | +class EmailTemplate extends Resource |
| 14 | +{ |
| 15 | + public function __construct( |
| 16 | + string $id, |
| 17 | + private readonly string $templateId, |
| 18 | + private readonly string $locale, |
| 19 | + private readonly string $subject, |
| 20 | + private readonly string $body, |
| 21 | + private readonly string $senderName = '', |
| 22 | + private readonly string $senderEmail = '', |
| 23 | + private readonly string $replyToEmail = '', |
| 24 | + private readonly string $replyToName = '', |
| 25 | + string $createdAt = '', |
| 26 | + string $updatedAt = '', |
| 27 | + ) { |
| 28 | + $this->id = $id; |
| 29 | + $this->createdAt = $createdAt; |
| 30 | + $this->updatedAt = $updatedAt; |
| 31 | + } |
| 32 | + |
| 33 | + /** |
| 34 | + * @param array<string, mixed> $array |
| 35 | + */ |
| 36 | + public static function fromArray(array $array): self |
| 37 | + { |
| 38 | + return new self( |
| 39 | + $array['id'], |
| 40 | + (string) $array['templateId'], |
| 41 | + (string) $array['locale'], |
| 42 | + (string) ($array['subject'] ?? ''), |
| 43 | + (string) ($array['message'] ?? ''), |
| 44 | + (string) ($array['senderName'] ?? ''), |
| 45 | + (string) ($array['senderEmail'] ?? ''), |
| 46 | + (string) ($array['replyToEmail'] ?? ''), |
| 47 | + (string) ($array['replyToName'] ?? ''), |
| 48 | + createdAt: $array['createdAt'] ?? '', |
| 49 | + updatedAt: $array['updatedAt'] ?? '', |
| 50 | + ); |
| 51 | + } |
| 52 | + |
| 53 | + /** |
| 54 | + * @return array<string, mixed> |
| 55 | + */ |
| 56 | + public function jsonSerialize(): array |
| 57 | + { |
| 58 | + return [ |
| 59 | + 'id' => $this->id, |
| 60 | + 'templateId' => $this->templateId, |
| 61 | + 'locale' => $this->locale, |
| 62 | + 'subject' => $this->subject, |
| 63 | + 'message' => $this->body, |
| 64 | + 'senderName' => $this->senderName, |
| 65 | + 'senderEmail' => $this->senderEmail, |
| 66 | + 'replyToEmail' => $this->replyToEmail, |
| 67 | + 'replyToName' => $this->replyToName, |
| 68 | + 'createdAt' => $this->createdAt, |
| 69 | + 'updatedAt' => $this->updatedAt, |
| 70 | + ]; |
| 71 | + } |
| 72 | + |
| 73 | + public static function getName(): string |
| 74 | + { |
| 75 | + return Resource::TYPE_PROJECT_EMAIL_TEMPLATE; |
| 76 | + } |
| 77 | + |
| 78 | + public function getGroup(): string |
| 79 | + { |
| 80 | + return Transfer::GROUP_PROJECTS; |
| 81 | + } |
| 82 | + |
| 83 | + public function getTemplateId(): string |
| 84 | + { |
| 85 | + return $this->templateId; |
| 86 | + } |
| 87 | + |
| 88 | + public function getLocale(): string |
| 89 | + { |
| 90 | + return $this->locale; |
| 91 | + } |
| 92 | + |
| 93 | + public function getSubject(): string |
| 94 | + { |
| 95 | + return $this->subject; |
| 96 | + } |
| 97 | + |
| 98 | + public function getBody(): string |
| 99 | + { |
| 100 | + return $this->body; |
| 101 | + } |
| 102 | + |
| 103 | + public function getSenderName(): string |
| 104 | + { |
| 105 | + return $this->senderName; |
| 106 | + } |
| 107 | + |
| 108 | + public function getSenderEmail(): string |
| 109 | + { |
| 110 | + return $this->senderEmail; |
| 111 | + } |
| 112 | + |
| 113 | + public function getReplyToEmail(): string |
| 114 | + { |
| 115 | + return $this->replyToEmail; |
| 116 | + } |
| 117 | + |
| 118 | + public function getReplyToName(): string |
| 119 | + { |
| 120 | + return $this->replyToName; |
| 121 | + } |
| 122 | +} |
0 commit comments