-
-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update the subscriptions upon submit #19
Labels
Comments
|
Here is a quick fix that does not require using a different hook: --- a/src/Resources/contao/classes/Newsletter.php
+++ b/src/Resources/contao/classes/Newsletter.php
@@ -802,8 +802,20 @@ class Newsletter extends \Backend
// E-mail address has changed
if (!empty($_POST) && $strEmail != '' && $strEmail != $objUser->email)
{
- $this->Database->prepare("UPDATE tl_newsletter_recipients SET email=? WHERE email=?")
- ->execute($strEmail, $objUser->email);
+ $objCount = $this->Database->prepare("SELECT COUNT(*) AS count FROM tl_newsletter_recipients WHERE email=?")
+ ->execute($strEmail);
+
+ // Delete the old subscription if the new e-mail address exists (see #19)
+ if ($objCount->count > 0)
+ {
+ $this->Database->prepare("DELETE FROM tl_newsletter_recipients WHERE email=?")
+ ->execute($objUser->email);
+ }
+ else
+ {
+ $this->Database->prepare("UPDATE tl_newsletter_recipients SET email=? WHERE email=?")
+ ->execute($strEmail, $objUser->email);
+ }
$objUser->email = $strEmail;
} |
leofeyer
added a commit
that referenced
this issue
Apr 18, 2018
|
I guess ebcd6c7 is enough for the time being. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Right now, the newsletter bundle tries to update the member subscriptions in the
onload_callback:newsletter-bundle/src/Resources/contao/dca/tl_member.php
Line 15 in f8301a9
However, this will cause an integrity constraint violation if an e-mail address exists already:
How to reproduce
The
onload_callbackis executed before the user input is validated and stored (tl_member.emailhas the'unique' => trueflag set). However, it should be executed upon submit instead, so Contao shows the "duplicate entry in field e-mail" error message and only updates the subscriptions after validating the user input.@contao/developers Is this a bug or a feature?
The text was updated successfully, but these errors were encountered: