mettle / sendportal

Open-source self-hosted email marketing. Manage your own newsletters at a fraction of the cost.
https://sendportal.io
MIT License
1.72k stars 339 forks source link

[Bug] Updating subscriber via API doesn't update column 'unsubscribe_event_id' #221

Closed 77media-creations closed 1 year ago

77media-creations commented 2 years ago

Using the latest version 2.

Issue

Updating a subscriber via API doesn't update column 'unsubscribe_event_id' and which causes the following error when visiting the (same) subscriber edit page via UI.

TypeError Sendportal\Base\Models\UnsubscribeEventType::findById(): Return value must be of type string, array returned (View: /Users/sohal/SynologyDrive/Dropbox/Coding/laravel/sendportal/vendor/mettle/sendportal-core/resources/views/subscribers/show.blade.php)

How to reproduce?

  1. Make a subscriber (either by API or manually).
  2. Update the subscriber using API and send unsubscribed_at' => now() with the request.
  3. Via UI, visit the subscriber edit page, the above error will show.

Upon digging deeper, I found that the methods storeOrUpdate() and update() do not set any value for the column unsubscribe_event_id and leave it NULL which is supposed to be a required INT value to be able to show the subscriber edit page when the unsubscribed_at has a date value set.

Possible fix.

Similar to Sendportal\Base\Http\Controllers\Subscribers\SubscribersController.php, a check should be implemented before unsubscribing in the Api/SubscribersController.php file.

HeadStudios commented 1 year ago

Hi, noticed there hasn't been many answers to questions on issues - I'm just wondering if you've gotten your issue resolved?

JonoB commented 1 year ago

I agree that it should work something like the SubscribersController. Happy to accept a PR

HeadStudios commented 1 year ago

I agree that it should work something like the SubscribersController. Happy to accept a PR

Glad to hear there are still contributors active in the repo that have committed. Looking forward to growing and contributing this installation - I like SendPortal's simplicity. Thank you for responding.