From 109cbb95c8b9b74333309c5873ef351e353ef6d6 Mon Sep 17 00:00:00 2001 From: afrasiyabhaider Date: Mon, 16 Sep 2024 01:22:17 +0100 Subject: [PATCH 1/3] Accessor set for is_open_tracking and is_click_tracking - The issue is in sendportal_campaigns table we have 2 columns is_open_tracking and is_click_tracking , it have value stored as 0, 1 but the expected value by function is true/false - https://github.com/mettle/sendportal/issues/313 --- src/Models/Campaign.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/Models/Campaign.php b/src/Models/Campaign.php index 3ffac05d..ff2409c8 100644 --- a/src/Models/Campaign.php +++ b/src/Models/Campaign.php @@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\BelongsToMany; use Illuminate\Database\Eloquent\Relations\MorphMany; +use Illuminate\Database\Eloquent\Casts\Attribute; /** * @property int $id @@ -388,4 +389,25 @@ public function allDraftsCreated(): bool return $this->active_subscriber_count === $this->messages()->count(); } + + /** + * Interact with `is_open_tracking` attribute. + */ + protected function isOpenTracking(): Attribute + { + return Attribute::make( + get: fn(mixed $value) => (bool)$value, + ); + } + + + /** + * Interact with `is_click_tracking` attribute. + */ + protected function isClickTracking($value) + { + return Attribute::make( + get: fn(mixed $value) => (bool)$value, + ); + } } From 2d6f066f0736348826799c041e75243e1da0fae0 Mon Sep 17 00:00:00 2001 From: afrasiyabhaider Date: Mon, 16 Sep 2024 01:28:44 +0100 Subject: [PATCH 2/3] bool attribute casting updated to boolean - as per laravel https://laravel.com/docs/10.x/eloquent-mutators#attribute-casting --- src/Models/Campaign.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Models/Campaign.php b/src/Models/Campaign.php index ff2409c8..3cc3430a 100644 --- a/src/Models/Campaign.php +++ b/src/Models/Campaign.php @@ -96,11 +96,11 @@ protected function casts(): array 'workspace_id' => 'int', 'template_id' => 'int', 'email_service_id' => 'int', - 'is_open_tracking' => 'bool', - 'is_click_tracking' => 'bool', + 'is_open_tracking' => 'boolean', + 'is_click_tracking' => 'boolean', 'scheduled_at' => 'datetime', - 'save_as_draft' => 'bool', - 'send_to_all' => 'bool', + 'save_as_draft' => 'boolean', + 'send_to_all' => 'boolean', ]; } From 776c9e9dfea8758f5457d44ff284ef3b495380e0 Mon Sep 17 00:00:00 2001 From: afrasiyabhaider Date: Mon, 16 Sep 2024 11:30:28 +0100 Subject: [PATCH 3/3] Mutator updated --- src/Models/Campaign.php | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/Models/Campaign.php b/src/Models/Campaign.php index 3cc3430a..0864b72a 100644 --- a/src/Models/Campaign.php +++ b/src/Models/Campaign.php @@ -393,21 +393,17 @@ public function allDraftsCreated(): bool /** * Interact with `is_open_tracking` attribute. */ - protected function isOpenTracking(): Attribute + protected function getIsOpenTrackingAttribute($value) { - return Attribute::make( - get: fn(mixed $value) => (bool)$value, - ); + return (bool)$value; } /** * Interact with `is_click_tracking` attribute. */ - protected function isClickTracking($value) + protected function getIsClickTrackingAttribute($value) { - return Attribute::make( - get: fn(mixed $value) => (bool)$value, - ); + return (bool)$value; } }