Problem Description
On the Simplenews page, the Send Status count is wrong when user are registered from their Drupal account.
The language is empty and therefore there is an error, and the entity is not saved.
Because of that the count is not updated and it's confusing because the emails are sent correctly. I added a patch just to add a control, but I think, more work needs to be done.
Here is an exemple below that explains the situation :
Let say I have 4 subscribers
1 in undefined
1 in english
2 in french
I have one newsletter issue in fr.
What I expect is the newsletter issue to display 0/2 on the admin/content/simplenews page and then when the newsletter is sent I expect the 2 subscribers in french to receive the newsletter and the number to display 2/2.
What I have is that the newsletter issue display 0/4 on the admin/content/simplenews page and then when the newsletter is sent, the 4 subscribers receive the newsletter and the number displayed is still 0/4 at the end.
Proposed resolution
Warning: I (AdamPS) am writing this, and I have never used multilingual Drupal. I am making some guesses. I assume that there is a single Newsletter form to send the newsletter. This form will send all translations - there is no way to send the French newsletter to all French subscribers but not send the English one. The newsletter should appear on the "Newsletter issues" page once - not one line for each translation. The count of issues sent should include all translations - not a separate count for each translation.
Therefore we don't need to count separately for each translation. The simplenews_issue field should not be translatable. There should be a single count for the issue, not one count for each translation. This makes the code much simpler and clearer:
1) In sendSpool() remove the call to getTranslation() and instead update $entity->simplenews_issue.
2) In updateSendStatus() the code becomes much easier, something like this. This is good because the existing code is very confusing and buggy.
foreach ($nodes as $nid => $node) {
$count = $this->spoolStorage->countMails(['entity_id' => $nid, 'entity_type' => 'node']);
if ($count == 0) {
$node->simplenews_issue->status = SIMPLENEWS_STATUS_SEND_READY;
$node->save();
}
}
Remaining tasks
- Please can someone check my assumptions above and confirm.
- Write a patch and test.
| Comment | File | Size | Author |
|---|---|---|---|
| #109 | simplenews.count-error.3106374-interdiff-107-109.txt | 366 bytes | adamps |
| #109 | simplenews.count-error.3106374-109.patch | 6.58 KB | adamps |
| #107 | simplenews.count-error.3106374-107.patch | 6.59 KB | adamps |
| #8 | Add_control_for_undefined_language.patch | 1.08 KB | pbonnefoi |
Issue fork simplenews-3106374
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
adamps commentedPlease can you describe exactly the sequence of steps to reproduce, what you actually see and what you expect to see.
Best of all would be if you upload a patch that includes a test that fails.
Comment #3
pbonnefoi commentedActually digging with what I'm trying to do I found multiple problems.
Let say I have 4 subscribers
1 in undefined
1 in english
2 in french
I have one newsletter issue in fr.
What I expect is the newsletter issue to display 0/2 on the admin/content/simplenews page and then when the newsletter is sent I expect the 2 subscribers in french to receive the newsletter and the number to display 2/2.
What I have is that the newsletter issue display 0/4 on the admin/content/simplenews page and then when the newsletter is sent, the 4 subscribers receive the newsletter and the number displayed is still 0/4 at the end.
Comment #4
adamps commentedThanks for the clarification.
1) The problem with counting is definitely a bug. It seems like the same as #3109499: Error when news item doesn't have translate which I have just closed as a duplicate of this. Please can you update the issue summary with some of the info from comment #3 and also the error message from that issue. Then at least we will have a clear description of what the bug is which is a good start.
2) You are asking what should happen if a there isn't a translation available for a subscriber. You suggest that the subscriber should be skipped. Actually the subscriber gets a newsletter - possibly in the default language? I don't really agree that this is a bug; it's just the way the module works. If we change that, then it could create a problem for other sites that are happy with the way it works currently.
If you would like to skip these subscribers you could look into custom code that throws SkipMailException.
Comment #5
pbonnefoi commentedComment #6
pbonnefoi commented@AdamPS Thanks for your fast answer. I updated the issue, but I will rework it soon.
For point number 2, The newsletter issue is a node that can be managed in multilanguage just like any nodes. If I create a newsletter issue only in french, then the english subscribers will receive a newsletter in French. I think it's confusing for the subscribers. Anyway, I'll look into SkipMailException.
Comment #7
adamps commentedThanks. Yes I understand why you are asking for point 2 - all I'm saying is that we can't necessarily change it now without breaking other sites.
Comment #8
pbonnefoi commentedComment #9
pbonnefoi commented@AdamPS I used SkipMailException and it works nicely. I updated my patch and now at least I have 2/4 when emails are sent to the two french subscribers.
Comment #10
alex_optimComment #11
adamps commentedThanks for the patch. I'm really busy right now but I will have a look as soon as I can.
Comment #12
adamps commentedTest fail was a random - setting back to NR.
I'm hesitating because the way the code works seems really weird. I don't use multiple languages on any sites so it's harder for me to be sure.
Comment #13
afagioliSame shoes here.
Scenario: a newsletter is XX-xx language is going to be sent. Not every subscriber language is XX-xx
Since this scenario is breaking the code, we definitely have a bug to be fixed soon. Subscribers are waiting for news :)
*
**SELECT**
***What if subscriber language doesn't match items language?***
**** OPT 1 -> don't send if language doesn't match ****
**** OPT 2 -> send to everybody, adding a "This newsletter is written in the XX-xx language" ****
*
I would propose to add this options somewhere inside "/admin/config/services/simplenews/settings/newsletter"
Comment #14
adamps commentedI am the only active maintainer of this module. I am an English native speaker and I have never worked on a multi-language Drupal website. Before I can check in this fix I will need some more help from the community. Please see the questions in #12. They can be answered by anyone - you don't need to be a developer. Except #3 which isn't really a question anyway.
This would need to be a separate issue - that's a feature not a bug. See #4. It's fine to propose an idea. But nothing will change unless someone writes a patch.
Comment #15
afagioliSounds good, Adam.
Looks like that piece of code is somehow unfinished.
I will post a new feature request as issue, which eventually will fix this bug also.
Comment #16
afagioliSo, from this issue we see that on a multilanguage installation, simplenews breaks when languages change.
From experience, we know user subscribes from the newsletter title. If I subscribe to the newsletter named "Newsletter sulla cucina inglese" I'm no way expecting to receive news in English and - as publisher - I will write in italian language. Can't imagine nor can remember newsletter written in different languages.
If design is accepted, happy to apply this via patch
Comment #17
afagioliComment #18
afagioliComment #19
afagiolipbonnefoi,
is that scenario you describe above real? I mean, do you really have a newsletter with subscribers expecting news in different languages?
From my experience, audience subscribes the newsletter by the "title" field, expressed in a clear language. At that point subscribers expect news in "that" language. As subscriber at "The best English cooking Newsletter ", I expect to receive recipes in English language, even if my preferred language is not English.
I can't see value in supporting newsletter with multilanguage content. And this is also breaking the module.
If the use case you define is real (I believe not very popular though), maybe we should move that in a sub-module.
Find a bit more at https://www.drupal.org/project/simplenews/issues/3153612
Comment #20
adamps commented@afagioli Please can we try to be more flexible? I don't believe it is right for one person to insist that a certain feature is unpopular and should be removed just because that feature has a bug. If we continue like that then the module will have no features left. Some people are following this issue which suggests they care about the multi-lingual.
Why can't a newsletter have translated titles in multiple languages??
Comment #21
afagioliIn this very issue, I'm asking pbonnefoi if that real case actually exists.
I have plenty of flexibility, @Adam.
At today, we have very rarely used features (if ever) breaking a module. We have the sub-module approach as friends (already mentioned before).
Let's keep the wider conversation at https://www.drupal.org/project/simplenews/issues/3153612
Comment #22
afagioliPlease Adam,
remove the postponed status.
We need to fix this soon,
How can I help?
Comment #23
adamps commentedThank you @pbonnefoi for a very clear problem description. This is something we should support and I agree there is a bug.
@afagioli Thank you for your offer to help. I have updated the issue summary to describe the remaining tasks.
Comment #24
afagioliThanks for the recent progress, Adam.
I usually manage multilanguage Drupal websites on regular basis. From my experience, listening users, working for authors, I've developed an assumption where multilanguage content support is not a requirement. For this, pbonnefoi experience would be very interesting to ear.
I re-designed simplenews without MCS here
https://github.com/augustofagioli/d8_simplenews_nomcs where the same spooler bug still lives. So, thank you for your code above. Super-welcome.
Aside that bug, that new design is much cleaner and managing multilanguage newsletter seems to be very easy and effective for subscribers and editors
I'm open to discussion and happy to submit that patch here when usable.
Comment #25
afagioliPlease find a patch with:
* bugfix
* improved design for sending newsletter in multiple languages
* improved UI for editors
Comment #26
afagioliComment #28
afagioliPlease find a new patch with interdiff.
Thanks for your patience
Comment #29
afagioliComment #31
afagioliTest is failing on features apparently untouched and actually working. At this point, not sure what to do.
Help appreciated.
Thanks
Comment #32
berdirYour patch seems to consist mostly of unrelated changes. Based on the changes in the .info.yml files, it looks like you downloaded a release and then made that into a new repository, now your patch is reverting a lot of changes that happened since tehn.
Don't do that. Use git clone to get the repository and then make changes in branches. It's going to be very tedious to untangle that and remove all the changes that you didn't actually do.
Comment #33
afagioliCool. Thanks. Will do
Comment #34
afagioliPlease find a patch as per #32 with:
* bugfix;
* improved design for sending newsletter in multiple languages;
* improved UI for editors;
Known BUG: "UI related: Edit Newsletter node > Exposing wrong Newsletter language on select newsletter change.
Comment #35
afagioliComment #37
afagioliSuggestions at #32 - applied - did not help.
More help is welcome. Thanks
Comment #38
afagioliAs reference, please find updated code at https://github.com/augustofagioli/d8_simplenews_nomcs
Comment #39
afagioliTrying to clarify what @Berdir understands at https://www.drupal.org/project/simplenews/issues/3106374#comment-13735921
Your patch seems to consist mostly of unrelated changes.The patch above proposes an improved approach for multilanguage newsletters. Shortly:
. and a new "language" field for newsletter entities is added.
. users subscribe by newsletter's language
. newsletter content types are no more translatable (who needs that?)
. improved UI for editors
more at:
. https://www.drupal.org/project/simplenews/issues/3106374#comment-13710161
. https://www.drupal.org/project/simplenews/issues/3153612
Comment #40
afagioliWe see at https://www.drupal.org/project/simplenews/issues/3106374#comment-13745208 that automated test failed on buggy text code with a @TODO in it (see
SimplenewsSendTest.php)Who will take care of that?
Comment #41
afagioliPlease find a patch as per #40 with:
* bugfix;
* improved design for sending newsletter in multiple languages;
* improved UI for editors;
* test code check
Known BUG: "UI related: Edit Newsletter node > Exposing wrong Newsletter language on select newsletter change.
Comment #42
afagioliComment #44
afagioliPlease find a second patch as per #40 with:
* bugfix;
* improved design for sending newsletter in multiple languages;
* improved UI for editors;
* test code check
Known BUG: "UI related: Edit Newsletter node > Exposing wrong Newsletter language on select newsletter change.
Comment #45
afagioliComment #47
afagioliPlease find yet another patch as per #40 with:
* bugfix;
* improved design for sending newsletter in multiple languages;
* improved UI for editors;
* test code check
Known BUG: "UI related: Edit Newsletter node > Exposing wrong Newsletter language on select newsletter change.
Comment #48
afagioliComment #50
afagioliPlease find yet another patch as per #40 with:
* bugfix;
* improved design for sending newsletter in multiple languages;
* improved UI for editors;
* test code check
Known BUG: "UI related: Edit Newsletter node > Exposing wrong Newsletter language on select newsletter change.
Comment #51
afagioliComment #52
afagioliAutomated test finally passed.
Please ask if you need more
Comment #53
afagioliHell Alex and Berdir Mantainers,
the requested patch is there. Test passed.
Do you need more from me to make some further steps forward?
Thanks
Comment #54
afagioliping!
Comment #55
adamps commentedHi @afagioli, it's great that you are enthusiastic to work on this. It seems that you propose to make each newsletter a single language only. That's not what this issue is about. Please create a new issue if you want to do that.
However in this comment, @Berdir already stated:
so I don't think it's likely to happen.
Comment #56
afagioliHalo @AdamPS,
Simplenews has many issues to be fixed. Some of them are crossing one eachother very frequently.
That's why you opened a specific META issue See your own https://www.drupal.org/project/simplenews/issues/3153612#comment-13716433
As things are, the considerable efforts you 2 active maintainers are making here seems to be not enough. Simplenews is a crucial module for Drupal which deserves more energies.
Please consider opening crucial decisions to more people. Widely shared choices are always the best.
Comment #57
afagioliping
Comment #58
adamps commentedThis issue needs work. The proposed work is clearly described in the issue summary. You are welcome to upload a patch.
Decisions are absolutely open for discussion. However please keep the discussion relevant to the issue. This issue is a simple bug, and it is not the place to discuss major changes - not even if your major changes could solve the bug. You should raise a separate issue specific to your change.
Comment #59
afagioliThanks for your reply and for your declaration to be so open, AdamPS.
A sign of life from the pbonnefoi who arose this issue would have be very useful. not received yet. Shame.
Matter of fact, in this issue you find clear direction from me as multilanguage newsletter user from years. And a patch also.
In the most concise way, in the newsletter's real world there is no fixed connection between user language and newsletter language.
From experience, we know user most of times subscribes from the newsletter title. If I subscribe to the newsletter named "Newsletter sulla cucina inglese" I'm no way expecting to receive news in English and - as publisher - I will write posts in italian language. Can't imagine nor can remember newsletter written in different languages. We have so many prove around of this [ https://www.drupal.org/project/simplenews/issues/3153612#comment-13801877 ]
Sad to say, this issue would fix a bad designed (far too old?) feature.
Comment #60
afagioliThis is my simplenews fork where multilanguage pain is removed.
If don't need a strict relation between user language and newsletter language, you are ready to go with this
https://github.com/augustofagioli/d8_simplenews_better_ui
If you do instead, please share with us your user case. Very interested in knowing more.
Comment #61
adamps commentedComment #62
adamps commentedComment #63
adamps commentedThis issue also causes #3178885: Missing langcode causes send to fail without actionable information
Comment #64
afagioliComment #65
geek-merlinI ran into this to with 2.x branch. The logger exception with type "cron" as googlefood:
InvalidArgumentException: Invalid translation language (en) specified. in Drupal\Core\Entity\ContentEntityBase->getTranslation() (Zeile 873 in /var/www/html/web/core/lib/Drupal/Core/Entity/ContentEntityBase.php).Comment #66
geek-merlinThanks @AdamPS and @Berdir for keeping the issue on track. The code review is concise and makes sense.
Comment #67
geek-merlinOK i worked on this, created an issue fork and pushed to it. Setting NR.
Comment #69
geek-merlinCreated an MR, not testbot is running.
Comment #70
geek-merlinIn fact i need the 2.x backport.
Comment #76
geek-merlinOK i boldly made a backport MR !3: https://git.drupalcode.org/project/simplenews/-/merge_requests/3
(i only had to change the hook_update_n)
...but seems like d.o does not support a backport displaying in the issue and triggering testbot yet.
Comment #77
geek-merlinOK 3.x patch !1 looks goodd, but testbot seems still stuck on #2990645: "Build Successful" is treated as a test failure which i don't grok. Or is it #3099061: Can't run PHPUnit tests since Drupal 8.8.0 on PHP 7.3+?
Comment #78
afagioliThanks for popping in here, @geek-merlin
So nice to see more activity on simplenews. On the edge of the contest, I'd really like to know more about how to handle multilanguage subscription. As you read above, to me, this feature deserves some improvment.
Cheers
Comment #79
geek-merlin@AdamPS
OK i fully agree with your directions and coded it to the issue branch / MR.
I do NOT understand why i have to trigger a custom php7.2 test to get results (the branch tests are on 7.3 and green).
Also i do NOT understand why this change makes which tests fail.
So passing to someone else to work on this.
Comment #80
adamps commentedThanks @geek-merlin. I'm not yet familiar with the new merge request system. I see you have made several commits, but the later ones appear to revert some of the earlier ones. Did you end up with anything that will be useful for someone else to continue from? Do you have any questions I can help with?
Comment #81
geek-merlin@AdamPS
> I'm not yet familiar with the new merge request system.
It's a real blessing, but as you see i bumped on edges when i added a backport branch.
> I see you have made several commits, but the later ones appear to revert some of the earlier ones.
Yah, that's part of the branch concept, you can only add commits so history is retained. (Later in the merge there is an option to squash though.)
> Did you end up with anything that will be useful for someone else to continue from? Do you have any questions I can help with?
Well, i coded down your suggested approach from the IS, and added a migrate hook that makes the field untranslatable (Re-thinking it, i did not test if that changes the test outcomes), so that this convoluted issue has a good direciton again, and in the hope it's easy win. But it isn't, some tests are red.
Next step is to debug what happens here and why tests go red. (I currently have no time to do that though.)
So thanks for asking, if you look at the tests and have an idea, great, if not, the quest is up to someone doing the debugging.
Comment #82
adamps commentedI am willing to look but I don't understand the new system well enough to decode your work. If you would like my view please can you either upload a patch the old-fashioned way or start over again with a new merge request that only has the real changes, not unrelated coding standards, reverting or backports.
Comment #83
geek-merlin@AdamPS: Great! If you click on MR1 and then on the "changes" tab, you see the complete resulting diff. Does this help?
Comment #84
adamps commentedI got it thanks. Potentially I could leave comments directly on your branch but I don't know how so I will write them here the old-fashioned way:
You need a few more changes in
sendSpool(), something like this:[$row->langcode].foreach ($ids as $entity_id => $counts)Comment #85
geek-merlin@AdamPS #84: OMG how could i miss this. Thanks for the review.
Implemented everything and am confident that this is the way to go.
Unfortunately tests still give neither red nor green, but i'v got no bandwidth to look into this.
Also leaving NW so to decide if / what automated tests we need to add.
Comment #86
cbccharlie commentedWhen there is a multi-language newsletter, the number of emails sent is showing wrong:
This patch is a workaround, but I think the entire multi-language part of the module should be revised.
Comment #87
afagioliGood to ear that. I've been shouting this out lot for a while now :)
Since Simplenews is such a crucial module for Drupal today. I believe once more of us will reach this point, a more open conversation about how to improve simplenews will start.
Thanks a lot
Comment #88
cbccharlie commentedI'm uploading a new patch to fix a cache count error.
Comment #89
adamps commented@ cbccharlie There is already an issue fork that I believe is the right solution - it simplifies the code, reducing the likelihood of multi-language bugs. The status is "needs work" because of the tests: some are failing and there should have a new test that covers this bug. For anyone who would like to help then fixing the tests is the next step.
There are several other issues for conversations about wider changes to simplenews and anyone is welcome to join the discussion there. This issue is for discussing this specific bug and the comments here should be specific to that.
Comment #90
afagioliThat's sounds so good, AdamPS.
Can you link us the that fork, please?
Thanks
Comment #91
geek-merlin#90: https://www.drupal.org/docs/develop/git/using-git-to-contribute-to-drupa...
hth!
Comment #92
afagioliThanks for confimirng, #91
At #60 we have:
Waiting to know whether mantaioners are on the same page
Comment #93
adamps commentedThis was in #89. Maybe it wasn't unclear? This issue is for a specific bug. Please use a different issue for discussing major redesigns.
Comment #94
afagioliThanks for clarifing, AdamPS.
Could you link us to the fork you mentioned at #89 ?
Thanks
Comment #95
cbccharlie commented@afagioli, I think @adamps refers to the following merge requests:
Comment #96
afagioliThanks @cbccharlie, that looks like a good start for me, really.
I'd been on this for a while, now. A few other good starts similar to this got lost in confusion.
Before moving forward, I'd prefer to wait for the mantainer preference, which is moving the focus somewhere else.
@AdamPS - as maintainer - could you please clearly share with us what you expect from contributors.
I read also on project home page
previous mantainers called themselves out of this. Does it means we can safely ignore their "No way" to the "we-dont-translate-newsletter" approach is we are proposing here?
I apologise for typing all these words. At this stage, not easy to do without.
Thanks
Comment #97
afagioliThis link comes handy to have the wider scenario of the "we-dont-translate-newsletters" thing:
Simplenews issues about multilanguage
Comment #98
adamps commentedSure. Basically there are lots of issues about specific bugs. The comments there should be only about those bugs. Please don't put comments there saying "we should make a major change to how multi-language works" - that just creates a distraction for all the people trying to solve those bugs.
Instead you should raise a new issue for your proposal to make a major change. All the people who are interested then can join you.
I'm sorry but I'm not going to answer that here:-) As above, this issue is for discussing this specific bug.
Comment #99
afagiolihttps://www.drupal.org/project/simplenews/issues/3181267
Comment #100
afagioliNo answer expected from you, Adam :)
Thanks
Comment #102
adamps commentedWell to me it is a real curse. I have just spent an hour and accidentally pushed the entire messy MR to 3.x rather than to the merge branch and this is impossible to undo. The merge branch is now in a mess because it is behind 3.x so I closed it. If anyone is willing to upload a patch in the old fashioned way then I will look at it.
Comment #103
adamps commentedComment #104
adamps commentedSorry @geek-merlin I'll stick with the ways I know for now - here's a patch that puts the changes in the MR back. Getting the results from the testbot now.
Comment #105
adamps commentedComment #107
adamps commentedComment #108
adamps commentedFixed the tests, now ready to go. I will commit in 1 week. Any review or comments welcome before then.
Comment #109
adamps commentedRebase
Comment #111
adamps commented