From 24ebbab21aabb60848d4294a634805b2ffa42e7b Mon Sep 17 00:00:00 2001 From: Arjen Miedema Date: Tue, 4 Jun 2024 08:32:50 +0200 Subject: [PATCH] Add `created_at` field to attachments model (#29) --- CHANGELOG.md | 1 + src/Api/Data/AttachmentInterface.php | 15 +++++++++++++++ src/Model/Attachment.php | 12 ++++++++++++ src/etc/db_schema.xml | 1 + src/etc/db_schema_whitelist.json | 3 ++- 5 files changed, 31 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e325511..ed68935 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -22,6 +22,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/2.0.0. ### Added - Added changelog and readme files +- `created_at` field to attachments database table and model ## [1.5.4] - 2024-02-14 diff --git a/src/Api/Data/AttachmentInterface.php b/src/Api/Data/AttachmentInterface.php index b1f78a4..3ede4ac 100644 --- a/src/Api/Data/AttachmentInterface.php +++ b/src/Api/Data/AttachmentInterface.php @@ -9,6 +9,8 @@ namespace JcElectronics\ExactOrders\Api\Data; +use DateTime; + interface AttachmentInterface { public const KEY_ID = 'attachment_id', @@ -16,6 +18,7 @@ interface AttachmentInterface KEY_FILE_CONTENT = 'file_content', KEY_ENTITY_ID = 'entity_id', KEY_ENTITY_TYPE_ID = 'entity_type_id', + KEY_CREATED_AT = 'created_at', ENTITY_TYPE_INVOICE = 'invoice', ENTITY_TYPE_ORDER = 'order'; @@ -78,4 +81,16 @@ public function getFileContent(): ?string; * @return self */ public function setFileContent(string $fileContent): self; + + /** + * @return DateTime + */ + public function getCreatedAt(): DateTime; + + /** + * @param DateTime $createdAt + * + * @return self + */ + public function setCreatedAt(DateTime $createdAt): self; } diff --git a/src/Model/Attachment.php b/src/Model/Attachment.php index fd9ff8a..91c229e 100644 --- a/src/Model/Attachment.php +++ b/src/Model/Attachment.php @@ -9,6 +9,8 @@ namespace JcElectronics\ExactOrders\Model; +use DateTime; +use DateTimeInterface; use JcElectronics\ExactOrders\Api\Data\AttachmentInterface; use JcElectronics\ExactOrders\Model\ResourceModel\Attachment as AttachmentResourceModel; use Magento\Framework\DataObject\IdentityInterface; @@ -78,6 +80,16 @@ public function setFileContent(string $fileContent): self return $this; } + public function getCreatedAt(): DateTime + { + return new DateTime($this->_getData(self::KEY_CREATED_AT)); + } + + public function setCreatedAt(DateTime $createdAt): self + { + return $this->setData(self::KEY_CREATED_AT, $createdAt->format('Y-m-d H:i:s')); + } + private function normalizeFilename(string $fileName): string { $pathInfo = pathinfo($fileName); diff --git a/src/etc/db_schema.xml b/src/etc/db_schema.xml index 96f36ef..6eed75c 100644 --- a/src/etc/db_schema.xml +++ b/src/etc/db_schema.xml @@ -82,6 +82,7 @@ + diff --git a/src/etc/db_schema_whitelist.json b/src/etc/db_schema_whitelist.json index 44db06d..b9f6728 100644 --- a/src/etc/db_schema_whitelist.json +++ b/src/etc/db_schema_whitelist.json @@ -14,7 +14,8 @@ "attachment_id": true, "entity_id": true, "entity_type_id": true, - "file": true + "file": true, + "created_at": true }, "constraint": { "PRIMARY": true,