Prevent infinite loop and use correct subscribers
method
#6
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hey!
Sorry for bombarding you with PRs across the different repos all at once haha!
This PR fixes a possible infinite loop that I've come across while working with the Laravel SDK.
First off, apologies if I've done any of this wrong. If it's something you might consider merging, please give me a shout if there's anything you might need changing 🙂
Context
I have a Laravel artisan command that I run every day on my site that grabs the total amount of subscribers for my newsletter and then stores it in the database. I'm currently using Revue but I'm migrating over to using Mailcoach.
At first, I tried using the following code, but I kept getting
0
as the count:I'm not quite sure why I was getting 0, so I moved on to try a different method instead:
The call to
subscribers
is where the issue occurs.The Issue
It seems that the
subscribers
method calls itself and ends up in an infinite loop which eventually breaks.I copied the approach used in the
subscriber
method in theEmailList
and passed thesubscribers
call through to the$this->mailcoach
object instead. This appears to then fetch the correct data as intended.I also updated the method's return type so that it would return a
PaginatedResults
object instead. I don't know if this is okay to do, or whether it would have been better to return an array instead to prevent the breaking change.Hopefully, the changes I've done are all okay. But, as I say, please give me a shout if there's anything you might want me to change if you think it's worth merging 😄